PHPの切り替えを実行。
プラグインのSyntax Highlighterがエラーになるようなので、
wp-content/plugins/crayon-syntax-highlighter/
の中にある、
crayon_langs.cclass.php
の338行目、以下のように変更。
return preg_replace(‘/[^\w-+#]/msi’, ”, $id);
return preg_replace(‘/[^\w\-+#]/msi’, ”, $id);
自分用のメモです。内容が間違っていたり、作りかけで動作しないコードなどあるのでご注意ください。
PHPの切り替えを実行。
プラグインのSyntax Highlighterがエラーになるようなので、
wp-content/plugins/crayon-syntax-highlighter/
の中にある、
crayon_langs.cclass.php
の338行目、以下のように変更。
return preg_replace(‘/[^\w-+#]/msi’, ”, $id);
return preg_replace(‘/[^\w\-+#]/msi’, ”, $id);
|
1 2 3 4 5 6 7 |
Sub test() For Each w In Sheets w.Cells.Validation.Delete Next End Sub |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Sub test() For Each w In Sheets If w.Name = "Sheet2" Then GoTo continue With w.Range("A2:A10").Validation .Delete .Add Type:=xlValidateList, Operator:=xlEqual, Formula1:="テスト1,テスト2" End With continue: Next End Sub |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
Sub test() Set w = ActiveSheet w.Range("A2:K1000").Clear With w.Range("A2:A1000").Validation .Delete .Add Type:=xlValidateList, Operator:=xlEqual, Formula1:="=マスタ!$A$1:$A$776" End With End Sub |
いつも忘れてしまうので。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
// 通常の配列 string[] a = new string[2]; string[] b = new string[] { "a", "b" }; string[] c = new string[2] { "a", "b" }; // 配列の配列(ギザギザ配列) string[][] aa = new string[2][] { new string[]{"2","3"}, new string[]{"a","b","c"} }; // 1行目は2列 // 2行目は3列 for(int row = 0; row < aa.Length; row++) { for(int col = 0; col < aa[row].Length; col++) { MessageBox.Show(aa[row][col]); // 2,3,a,b,c } } // 多次元配列(四角い配列) string[,] bb = new string[2,4]; string[,] cc = new string[2,2] { { "a1", "a2" },{ "b1", "b2" } }; string[,] dd = new string[,] { { "a1", "a2" },{ "b1", "b2" } }; // 3行2列 string[,] ee = new string[3,2] { { "a1", "a2" }, { "b1", "b2" }, { "c1", "c2" } }; // GetLength(0) は行数 GetLength(1)は列数 MessageBox.Show(bb.GetLength(0).ToString()); // 2 MessageBox.Show(bb.GetLength(1).ToString()); // 4 |
以前、fenrir(B@r09u3 Style Op.2)の代替として自分用に作成した検索ソフトにサムネイル機能を追加。
※追記(ファイル添付)
使い方
・解凍後、ffmpeg.exeをフォルダの中に保存。(サムネイル表示しないなら不要)
・scan.txtの中に検索したいパスを記入。(複数行可)
・CreateIndex.exeを実行。
・FileSearch.exeを実行。
・複数検索はバーティカルバー(|)で区切る。AND検索。
・検索結果のリストボックス上:ファイル名をダブルクリックで直接開く。Ctrl+ダブルクリックでフォルダを開く。
・テキストボックス上:Ctrl+Enterで、動画ファイルのサムネイル表示。(数字入力のダイアログは何秒目のサムネイルにするか指定)
・サムネイル上:サムネイルをダブルクリックで直接開く。Ctrl+ダブルクリックでフォルダを開く。
指定フォルダ以下のファイルをインデックスしておき、インクリメンタルサーチの一覧をもとにFFmpegでサムネイルを作成する。
CreateThumbnail1()はUIの部分だけ固まらないようにしているが、サムネイルの作成は並列化していない。CreateThumbnail2()はサムネイルの作成まで並列化している。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; using System.Xml.Serialization; namespace FileSearch { public partial class Form1 : Form { string RemoteIndexPath = Application.StartupPath + @"\remote_index_path.txt"; string IndexPath = Application.StartupPath + @"\index.dat"; List<string> RawItems = new List<string>(); System.Collections.Concurrent.ConcurrentBag<string> FilterItems = new System.Collections.Concurrent.ConcurrentBag<string>(); List<SubForm> Children = new List<SubForm>(); int VisibleCount = 1000; int RawItemCount = 0; string WriteTime = ""; string Needle = ""; object LockObject = new object(); bool IsExit = true; public Form1() { InitializeComponent(); if (!IndexLoad()) return; LoadPosition(); var delayExecute = new DelayExecute(); delayExecute.Execute += (s, e) => SetupDatasource(); textBox1.TextChanged += (s, e) => { lock (LockObject) { IsExit = false; } Needle = textBox1.Text; delayExecute.ReserveExecute(); }; textBox1.KeyDown += (s, e) => OpenSubForm(s, e); listBox1.MouseDoubleClick += (s, e) => OpenFile(s, e); this.SizeChanged += (s, e) => { if (this.WindowState == FormWindowState.Minimized || this.WindowState == FormWindowState.Maximized) return; SavePosition(); }; this.FormClosing += (s, e) => { if (Children.Count > 0) { MessageBox.Show("フォームを全て閉じてください。"); e.Cancel = true; return; } lock (LockObject) { if (!IsExit) e.Cancel = true; } }; } private void OpenSubForm(object sender, KeyEventArgs e) { lock (LockObject) { if (!IsExit) return; } if (FilterItems.Count == 0) return; if (e.Control && e.KeyCode == Keys.Enter) { string startTime = "0"; var input = new InputBox(); input.StartPosition = FormStartPosition.Manual; input.Left = DesktopLocation.X + 10; input.Top = DesktopLocation.Y + 10; input.ShowDialog(); if (input.IsClick) { int.TryParse(input.Value, out int result); startTime = result.ToString(); } var f = new SubForm(textBox1.Text, new List<string>(FilterItems), startTime); string handle = Guid.NewGuid().ToString("N"); f.Id = handle; f.FormClosed += (ss, ee) => { Children = new List<SubForm>(Children.Where(x => x.Id != handle)); }; Children.Add(f); f.Show(); } } private bool IndexLoad() { string remoteIndexPath = ""; if (File.Exists(RemoteIndexPath)) { remoteIndexPath = File.ReadAllText(RemoteIndexPath); } if (!File.Exists(IndexPath) && !File.Exists(remoteIndexPath)) // ローカル、リモートにない場合 { MessageBox.Show("インデックスファイルが見つかりませんでした。"); return false; } else if (File.Exists(IndexPath) && !File.Exists(remoteIndexPath)) // ローカルにあって、リモートにない場合 { RawItems = File.ReadAllLines(IndexPath).ToList(); RawItemCount = RawItems.Count(); WriteTime = File.GetLastWriteTime(IndexPath).ToString("yyyy/MM/dd HH:mm:ss"); } else if (!File.Exists(IndexPath) && File.Exists(remoteIndexPath)) // ローカルになくて、リモートにある場合 { File.Copy(remoteIndexPath, IndexPath); RawItems = File.ReadAllLines(IndexPath).ToList(); RawItemCount = RawItems.Count(); WriteTime = File.GetLastWriteTime(IndexPath).ToString("yyyy/MM/dd HH:mm:ss"); } else if (File.Exists(IndexPath) && File.Exists(remoteIndexPath)) // ローカル、リモートにある場合 { if (File.GetLastWriteTime(IndexPath) < File.GetLastWriteTime(remoteIndexPath)) // リモートの方が最新の場合 { if (DialogResult.Yes == MessageBox.Show("最新のインデックスファイルが存在します。更新しますか?","", MessageBoxButtons.YesNo)) { File.Copy(remoteIndexPath, IndexPath, true); } RawItems = File.ReadAllLines(IndexPath).ToList(); RawItemCount = RawItems.Count(); WriteTime = File.GetLastWriteTime(IndexPath).ToString("yyyy/MM/dd HH:mm:ss"); } else // ローカルの方が最新の場合 { RawItems = File.ReadAllLines(IndexPath).ToList(); RawItemCount = RawItems.Count(); WriteTime = File.GetLastWriteTime(IndexPath).ToString("yyyy/MM/dd HH:mm:ss"); } } return true; } private void SetupDatasource() { var stopwatch = new Stopwatch(); stopwatch.Start(); IEnumerable<string> items = new List<string>(); if (Needle == "") { items = RawItems.Take(VisibleCount); } else { List<string> tmpList = new List<string>(RawItems); foreach (string tmpString in Needle.Split('|')) { tmpList = tmpList.AsParallel().Where(x => x.ToLower().Contains(tmpString.ToLower())).ToList(); } items = tmpList.Take(VisibleCount); } var itemClassList = new System.Collections.Concurrent.ConcurrentBag<ItemClass>(); FilterItems = new System.Collections.Concurrent.ConcurrentBag<string>(); System.Threading.Tasks.Parallel.ForEach(items, item => { itemClassList.Add(new ItemClass() { DisplayItemPath = Path.GetFileName(item) + " . . . ■" + Path.GetDirectoryName(item), ItemPath = item }); FilterItems.Add(item); }); stopwatch.Stop(); Invoke(new Action(() => { listBox1.DataSource = itemClassList.ToList(); listBox1.DisplayMember = "DisplayItemPath"; Text = items.Count() + "/" + RawItemCount + "件表示 (" + stopwatch.ElapsedMilliseconds.ToString() + "ms):" + WriteTime + "インデックス"; })); lock (LockObject) { IsExit = true; } } private void OpenFile(object sender, MouseEventArgs e) { if (listBox1.SelectedItem == null) return; var itemPath = ((ItemClass)listBox1.SelectedItem).ItemPath; if (!File.Exists(itemPath)) { MessageBox.Show("ファイルを開くことができませんでした。"); return; } if (ModifierKeys == Keys.Control) { var info = new ProcessStartInfo("explorer.exe"); info.Arguments = $"/select, \"{itemPath}\""; Process.Start(info); } else { Process.Start(itemPath); } } private void LoadPosition() { if (!File.Exists(Application.StartupPath + @"\dat.xml")) return; this.StartPosition = FormStartPosition.Manual; XmlSerializer xs = new XmlSerializer(typeof(List<int>)); using (StreamReader sr = new StreamReader(Application.StartupPath + @"\dat.xml", Encoding.UTF8)) { try { List<int> items = (List<int>)xs.Deserialize(sr); if (0 > (int)items[2]) { this.StartPosition = FormStartPosition.WindowsDefaultLocation; return; } this.Width = (int)items[0]; this.Height = (int)items[1]; this.Top = (int)items[2]; this.Left = (int)items[3]; } catch { this.StartPosition = FormStartPosition.WindowsDefaultLocation; } } } private void SavePosition() { if (this.WindowState == FormWindowState.Maximized) return; XmlSerializer xs = new XmlSerializer(typeof(List<int>)); using (StreamWriter sw = new StreamWriter(Application.StartupPath + @"\dat.xml", false, Encoding.UTF8)) { List<int> items = new List<int>(); items.Add(this.Width); items.Add(this.Height); items.Add(this.Top); items.Add(this.Left); xs.Serialize(sw, items); } } } struct ItemClass { public string DisplayItemPath { set; get; } public string ItemPath { set; get; } } class DelayExecute { public event EventHandler Execute; // SetupDatasource()を登録 private int DelayTime = 500; System.Threading.Timer Timer; public DelayExecute() { Timer = new System.Threading.Timer(x => { Execute(this, EventArgs.Empty); }); } public void ReserveExecute() // TextChangeで発火 { Timer.Change(DelayTime, Timeout.Infinite); // Timeout.Infiniteは一度だけ呼ぶ } } } |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.IO; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Linq; namespace FileSearch { public partial class SubForm : Form { public string Id { set; get; } object LockObject = new object(); bool IsExit = false; public SubForm(string needle, List<string> filterItems, string startTime) { InitializeComponent(); var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; listView1.MultiSelect = false; listView1.MouseDoubleClick += (s, e) => { string itemPath = listView1.SelectedItems[0].SubItems[1].Text; if (ModifierKeys == Keys.Control) { var info = new ProcessStartInfo("explorer.exe"); info.Arguments = $"/select, \"{itemPath}\""; Process.Start(info); } else { Process.Start(itemPath); } }; this.FormClosing += (s, e) => { lock (LockObject) { if (!IsExit) { tokenSource.Cancel(); e.Cancel = true; } } }; CreateThumbnail2(needle, filterItems, startTime, token); } private async void CreateThumbnail2(string needle, List<string> filterItems, string startTime, CancellationToken token) { ImageList il = new ImageList(); il.ImageSize = new Size(200, 200); il.ColorDepth = ColorDepth.Depth32Bit; listView1.LargeImageList = il; var listItems = new System.Collections.Concurrent.ConcurrentBag<ListViewItem>(); var tasks = new List<Task>(); foreach (string f in filterItems) { if (!File.Exists(f)) continue; if (Path.GetExtension(f) != ".mp4" && Path.GetExtension(f) != ".mkv" && Path.GetExtension(f) != ".flv") continue; var t = Task.Run(() => { if (token.IsCancellationRequested) return; while (!IsHandleCreated) { } int itemCount = 0; string option = " -ss " + startTime + " -i \"" + f + "\" -vframes 1 -f image2 pipe:1"; ProcessStartInfo ps = new ProcessStartInfo(Application.StartupPath + @"\ffmpeg.exe", option); ps.RedirectStandardOutput = true; ps.CreateNoWindow = true; ps.UseShellExecute = false; using (Process p = new Process()) { try { p.StartInfo = ps; if (!p.Start()) throw new Exception(); using (Image img = Image.FromStream(Stream.Synchronized(p.StandardOutput.BaseStream))) { Image thumb = img.GetThumbnailImage(200, 200, null, IntPtr.Zero); Invoke(new Action(() => { il.Images.Add(thumb); itemCount = il.Images.Count; })); } } catch (Exception) { Image img = new Bitmap(200, 200); Invoke(new Action(() => { il.Images.Add(img); itemCount = il.Images.Count; })); } } string fileName = FileNameComp(Path.GetFileName(f), FileSizeUnit(new FileInfo(f).Length)); var item = new ListViewItem(fileName, itemCount-1); item.SubItems.Add(f); listItems.Add(item); Invoke((Action)(() => { Text = "集計 (" + itemCount.ToString() + "件) : " + startTime + "秒 : " + needle; })); }, token); tasks.Add(t); } try { await Task.WhenAll(tasks.ToArray()); } catch { } listView1.Items.AddRange(listItems.ToArray()); Text = "完了 (" + il.Images.Count.ToString() + "件) : " + startTime + "秒 : "+ needle; lock (LockObject) { IsExit = true; } } private async void CreateThumbnail1(string needle, List<string> filterItems, CancellationToken token) { ImageList il = new ImageList(); il.ImageSize = new Size(200, 200); il.ColorDepth = ColorDepth.Depth32Bit; listView1.LargeImageList = il; int itemIndex = 0; await Task.Run(() => { while (!IsHandleCreated) { } foreach (string f in filterItems) { if (token.IsCancellationRequested) break; if (!File.Exists(f)) continue; if (Path.GetExtension(f) != ".mp4" && Path.GetExtension(f) != ".mkv" && Path.GetExtension(f) != ".flv") continue; string ss = "60"; string option = " -ss " + ss + " -i \"" + f + "\" -vframes 1 -f image2 pipe:1"; ProcessStartInfo ps = new ProcessStartInfo(Application.StartupPath + @"\ffmpeg.exe", option); ps.RedirectStandardOutput = true; ps.CreateNoWindow = true; ps.UseShellExecute = false; using (Process p = new Process()) { try { p.StartInfo = ps; if (!p.Start()) throw new Exception(); using (Image img = Image.FromStream(p.StandardOutput.BaseStream)) { Image thumb = img.GetThumbnailImage(200, 200, null, IntPtr.Zero); Invoke(new Action(() => { il.Images.Add(thumb); })); } } catch (Exception) { Image img = new Bitmap(200, 200); Invoke(new Action(() => { il.Images.Add(img); })); } } string fileName = FileNameComp(Path.GetFileName(f), FileSizeUnit(new FileInfo(f).Length)); var item = new ListViewItem(fileName , itemIndex); item.SubItems.Add(f); itemIndex++; Invoke((Action)(() => { Text = "集計 (" + itemIndex.ToString() + "件) : " + needle; listView1.Items.Add(item); })); } Invoke(new Action(() => { Text = "完了 (" + (itemIndex).ToString() + "件) : " + needle; })); }, token); lock (LockObject) { IsExit = true; } } private string FileSizeUnit(long b) { float k = b / 1024; float m = k / 1024; float g = m / 1024; float t = g / 1024; if (t >= 1) return "(" + t.ToString("0.00") + "TB)"; if (g >= 1) return "(" + g.ToString("0.00") + "GB)"; if (m >= 1) return "(" + m.ToString("0.00") + "MB)"; if (k >= 1) return "(" + k.ToString("0.00") + "KB)"; return ""; } private string FileNameComp(string rawFileName, string fileSize) { string fileName = rawFileName; while (TextRenderer.MeasureText(fileName + fileSize, new Font("メイリオ", 9)).Width > 200) { fileName = fileName.Substring(0, fileName.Length - 1); } return fileName + fileSize; } } } |
・呼出3種類
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
using System; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var t1 = new TestClass1(); t1.TestEvent += (s, e) => { Console.WriteLine("TestEvent"); Console.ReadKey(); }; t1.OnTestMethod1(); t1.OnTestMethod2(); t1.OnTestMethod3(); } } class TestClass1 { public event EventHandler TestEvent; // 呼出3種類 public void OnTestMethod1() { if (TestEvent != null) { TestEvent(this, new EventArgs()); } } public void OnTestMethod2() { TestEvent?.Invoke(this, new EventArgs()); } public void OnTestMethod3() => TestEvent?.Invoke(this, new EventArgs()); } } |
・Eventフィールドを省略しない場合
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
using System; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var t1 = new TestClass1(); t1.TestEvent += (s, e) => { Console.WriteLine("Test"); Console.ReadKey(); }; t1.OnTestMethod(); } } class TestClass1 { private EventHandler testEvent; public event EventHandler TestEvent { add { testEvent = testEvent + value; } remove { testEvent = testEvent - value; } } public void OnTestMethod() => testEvent?.Invoke(this, new EventArgs()); } } |
・独自Event定義
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
using System; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var t1 = new TestClass1(); t1.TestEvent += (s, e) => { Console.WriteLine(e.Id.ToString() + ":" + e.Msg); Console.ReadKey(); }; t1.OnTestMethod(1,"hello"); t1.OnTestMethod(2,"bye"); } } // TestEventArgsを引数にとる独自Eventの定義 delegate void TestEventHandler(object sender, TestEventArgs e); class TestClass1 { public event TestEventHandler TestEvent; public void OnTestMethod(int id, string msg) => TestEvent?.Invoke(this, new TestEventArgs(id, msg)); } // 独自EventArgsの定義 class TestEventArgs : EventArgs { public int Id; public string Msg; public TestEventArgs(int i, string m) { this.Id = i; this.Msg = m; } } } |
・async + await定義
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
using System; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var t1 = new TestClass1(); t1.TestEvent += (s, e) => { return Task.Run(() => { Console.WriteLine(e.Id.ToString() + ":" + e.Msg); }); }; t1.OnTestMethod(1,"hello"); Console.ReadKey(); } } // TestEventArgsを引数にとる独自Eventの定義 // Taskを返すEvent delegate Task TestEventHandler(object sender, TestEventArgs e); class TestClass1 { public event TestEventHandler TestEvent; // async + await定義 public async void OnTestMethod(int id, string msg) => await TestEvent?.Invoke(this, new TestEventArgs(id, msg)); } // 独自EventArgsの定義 class TestEventArgs : EventArgs { public int Id; public string Msg; public TestEventArgs(int i, string m) { this.Id = i; this.Msg = m; } } } |
特定のフォルダ以下のファイルをハッシュで比較してみる。過去に何度かファイル破損したことがあったので実験。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
using System; using System.Linq; using System.IO; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string srcBasePath = @"C:\Users\xxx\Desktop\1"; string dstBasePath = @"C:\Users\xxx\Desktop\2"; foreach(var p in Directory.EnumerateFiles(srcBasePath, "*", SearchOption.AllDirectories)) { // 除外する拡張子とファイル名 if (Path.GetExtension(p) == ".db") continue; if (Path.GetFileName (p) == "desktop.ini") continue; string srcHash = FileHash(p); string dstHash = FileHash(p.Replace(srcBasePath, dstBasePath)); if (srcHash == dstHash) { // ハッシュが一致した場合。 } else if (srcHash != dstHash) { // ハッシュが一致しない場合。 Console.WriteLine(p.Replace(srcBasePath, dstBasePath)); Console.WriteLine(dstHash); } } Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); } private static string FileHash(string path) { // 先頭から指定バイト分でハッシュを出しているので、指定以降の不一致ではエラーにならない try { using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { var b = new byte[1024 * 1024]; // 1MB fs.Read(b, 0, 1024 * 1024); using (var ms = new MemoryStream(b)) { var hashProvider = new System.Security.Cryptography.SHA256CryptoServiceProvider(); var bs = hashProvider.ComputeHash(ms); return String.Join("", bs.Select(x => x.ToString("x2")).ToArray()); // BitConverterと結果は同じで違う書き方 } } } catch (Exception) { return ""; } } private static string FileHash2(string path) { // ファイル全てを利用するため、サイズが大きいと時間がかかる。 try { using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { var hashProvider = new System.Security.Cryptography.SHA256CryptoServiceProvider(); var bs = hashProvider.ComputeHash(fs); return BitConverter.ToString(bs).ToLower().Replace("-", ""); } } catch(Exception e) { return e.Message; } } } } |
追記
2021/12/1より本人確認の書類が必要になったようで、取得方法が変更されている。
shinki_my050@brastel.co.jp
宛に必要な情報を送信する。
(氏名、氏名(カナ)、生年月日、国籍、住所(郵便番号含む)、連絡先電話番号、身分証明書のスキャン画像)
数日で送信したメールアドレス宛にユーザーID、PIN番号、パスワード
が送られてくるので、アプリをインストールしログインする。
チャージは
https://www.brastel.com/jpn/myaccount
入金設定>今すぐお支払い>PayPal
から金額、メールアドレスを入力し実行。
追記ここまで
***
固定電話はなくiPhoneだけという状態で、フリーダイヤルにかける必要があったので、My050というサービスを利用してみることにした。ブラステルカードを先に申し込む方法もあるようだけど、急きょ必要になったのでiPhoneから直接アカウントを取得することにした。
以下iPhoneで操作
・AppStoreからMy050を検索しインストール。
・UserIDにnewと入力しSignIn。
・かんたん設定/新規登録。
・ブラステルのアカウントはお持ちですか?に「いいえ」
・携帯電話番号を入力し「認証コードを送信する」
・送られてきた認証コードとメールアドレスを入力。
・今はチャージしないを選択。
iPhoneで最後まで登録できるのかもしれないが、入力作業はPCからのほうが楽なのでiPhoneではここまで。
以下PCで操作
登録したメールアドレスに色々情報がくるので、その中にあるリンクからマイアカウントにログイン。
・個人情報の取り扱いに「同意する」
・名前や住所など必要な情報を入力。
マイアカウント>入金設定>今すぐお支払い
からPayPalを選び、金額とメールアドレスを入力すればPayPalから入金できる。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
using System; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp1 { internal static class Program { [STAThread] static void Main() { string mutexName = System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName; // 固有の文字列にする // Mutexコンストラクタ引数 // 第一引数 // インスタンスを作成したスレッドに所有権を与えるかどうか (True=与える, False=与えない) // Trueの場合はインスタンス生成時にスレッドが所有権を取得する。 // WaitOne()も同じく所有権を取得するが、 // 取得できるまで現在のスレッドが待機状態となる。 // コンストラクタ(第一引数)で所有権を取得する場合は待機しない。 // 第二引数 // インスタンスの名前 // 名前付きにするとOS全体で排他制御できる。 // 名前無しにするとローカルの排他制御のみ。 // 第三引数 // Mutexを作成したかどうかのフラグ。(初期所有権とは関係ない) // すでに同名のMutexが存在している場合は作成できないのでFalseとなる。 // ReleaseMutex()は所有権を解放状態=シグナル状態(signaled)になる。 // ReleaseMutex()はWaitOne()したスレッドからしか呼べない。 // 所有権を解放せずに終了した場合は、放棄状態(abandoned)となり、 // 他のスレッドからのWaitOne()するとExceptionとなる。 // ReleaseMutex()は呼び出しと同じ回数必要 if (false) { var m = new System.Threading.Mutex(false, mutexName); // 初期所有権:取得しない。 bool f = m.WaitOne(0, false); // WaitOne()で所有権の取得を試みる。 MessageBox.Show(f.ToString()); // 最初に起動したときはTrue // MessageBoxが表示されているとき、もう1つ起動するとFalse。 } if (false) { var m = new System.Threading.Mutex(false); // 初期所有権:取得しない。 // 名前付きではない bool f = m.WaitOne(0, false); // WaitOne()で所有権の取得を試みる。 MessageBox.Show(f.ToString()); // 最初に起動したときはTrue // MessageBoxが表示されているとき、もう1つ起動してもTrue } // -------------------------------------------------------- // 第三引数の実験 if (false) { var m = new System.Threading.Mutex(true, mutexName, out bool initialOwnership); // 初期所有権:取得。 MessageBox.Show(initialOwnership.ToString()); // 最初に起動したときはTrue // MessageBoxが表示されているとき、もう1つ起動するとFalse。 } if (false) { var m = new System.Threading.Mutex(false, mutexName, out bool initialOwnership); // 初期所有権:取得しない。 MessageBox.Show(initialOwnership.ToString()); // 最初に起動したときはTrueとなる。 // MessageBoxが表示されているとき、もう1つ起動するとFalse。 // ## 注意 ## // 最初のMessageBoxでは、初期所有権を取得していないがTrueとなるので、 // ここは作成されたかどうか判断している模様。 } // -------------------------------------------------------- // Close,Dispose()後に別スレッドから同名のMutexを作成(コンストラクタ)。 if (false) { var m1 = new System.Threading.Mutex(true, mutexName,out bool f1); MessageBox.Show(f1.ToString()); // true Task.Run(() => { var m2 = new System.Threading.Mutex(true, mutexName, out bool f2); MessageBox.Show(f2.ToString()); // false // Close()していないので作成できない }); MessageBox.Show(""); // これがないとTaskを実行したまま終了してしまう } if (false) { var m1 = new System.Threading.Mutex(true, mutexName, out bool f1); MessageBox.Show(f1.ToString()); // true m1.Close(); // ここがDispose()でも同じ Task.Run(() => { var m2 = new System.Threading.Mutex(true, mutexName, out bool f2); MessageBox.Show(f2.ToString()); // true // Close()しているので作成できる。 }); MessageBox.Show(""); // これがないとTaskを実行したまま終了してしまう } // -------------------------------------------------------- // 作成したMutexを別スレッドでもう一度つかむ。 if (false) { var m = new System.Threading.Mutex(true, mutexName, out bool f); MessageBox.Show(f.ToString()); // true // この部分で、 // 何も記載しないと、待機してしまいTask内のMessageBoxは表示されない // m.ReleaseMutex(); // だけだと下記Taskの中で再度取得(true)できる。 // m.ReleaseMutex(); // m.Close(); // と2つ呼んだ場合、 // m.Close(); // と1つ呼んだ場合 // のどちらも取得できない。(ObjectDisposedException) Task.Run(() => { try { MessageBox.Show(m.WaitOne().ToString()); } catch(Exception e) { MessageBox.Show(e.ToString()); } }); MessageBox.Show(""); // これがないとTaskを実行したまま終了してしまう } // -------------------------------------------------------- // WaitOne()状態でインスタンス破棄 // AbandonedMutexException if (false) { try { var m = new System.Threading.Mutex(false, mutexName); m.WaitOne(); // ここにClose()などあると発生しない } catch (Exception e) { MessageBox.Show(e.ToString()); } MessageBox.Show(""); // 1つ目を起動しMessageBoxが表示されている状態で、2つ目を起動すると、 // 1つ目のMessageBoxが表示されている間は2つ目のMessageBoxは表示されず、 // 1つ目のMessageBoxを閉じると、2つ目の方がAbandonedMutexExceptionになる。 // 2つ目がWaitOne()している状態で、1つ目がReleaseMutex()せず終了したため。 // WaitOne()のあとにClose()やReleaseMutex()があれば、AbandonedMutexExceptionにはならない // ## 注意 ## // m.ReleaseMutex(); // m.Close(); // と2つ呼んだ場合、 // m.Close(); // と1つ呼んだ場合 // どちらも、AbandonedMutexExceptionは発生しない } // -------------------------------------------------------- // 別スレッドからReleaseMutex() // ApplicationException if (true) { var m = new System.Threading.Mutex(true, mutexName); Task.Run(() => { try { m.ReleaseMutex(); // 別スレッド以外からReleaseMutex()を呼んでいるのでApplicationExceptionが発生 // Close()の場合発生しない } catch (Exception e) { MessageBox.Show(e.ToString()); } }); MessageBox.Show(""); // これがないとTaskを実行したまま終了してしまう } } } } |
久しぶりにUEFIを開いてみて、何も変更せず終了した。
その後、再起動してみると、
>問題が発生したため、PCを再起動する必要があります。
と表示され自動で再起動してしまう。
再起動するとUEFIが開くのだが、
カーソルが動くだけで何もできないので、電源ボタンから強制的に再起動すると、また、
>問題が発生したため、PCを再起動する必要があります。
と表示され、再起動というループが発生した。
原因はともかく、UEFIを開いたタイミングだったので
マザボードの電池(CR2032)かなと思い、交換したら直った。
***
以前、電源ボタンを押しても各LEDが光るだけで画面に何も表示されないという症状に陥ったことがあったけど、そのときも確か電池交換で直った。
キーボードのホームポジションから移動するときに分かりやすいので、ずいぶん昔から数字の4,7に目印を付けている。
定番のマイタックやクッションゴムなど色々試してみた結果、
ヒサゴ いろラベル 丸
という商品で落ち着いていた。
久しぶりに同じ商品を検索してみたらもう販売されていないようなので、代替の商品はないかと探してみたけど良さそうなものが見つからなかった。
ふと、手元にあった滑り止めのゴムシール(よく見るグレーのゴム)を4mmのポンチで抜いたらかなり良さそうだったので、しばらく使ってみることにした。
ただこのゴムシールはPCか何かの付属で付いてきて、単体で購入したものではないので、いずれ類似品を探そうかと思う。
マウスソールも付け替えていて、定番のカグスベール(トスベール)を7mmのポンチで抜いて使っている。
穴あけパンチだと歪んでしまうのでポンチを利用。
・追記
キーボードの目印を作り直した。
和気産業GS-02(ゴムシート)にニトムズNo.5000NS(両面テープ)を貼って4mmのポンチで抜いた。
カグスベールもポンチ統一のため4mmで抜いてみることにした。