{"id":4139,"date":"2021-01-06T03:52:58","date_gmt":"2021-01-05T18:52:58","guid":{"rendered":"https:\/\/okamurax.com\/?p=4139"},"modified":"2022-05-09T21:33:09","modified_gmt":"2022-05-09T12:33:09","slug":"c-%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e6%a4%9c%e7%b4%a2%e3%82%a4%e3%83%b3%e3%82%af%e3%83%aa%e3%83%a1%e3%83%b3%e3%82%bf%e3%83%ab%e3%82%b5%e3%83%bc%e3%83%81","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=4139","title":{"rendered":"C# \u30d5\u30a1\u30a4\u30eb\u691c\u7d22(\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30bf\u30eb\u30b5\u30fc\u30c1)"},"content":{"rendered":"<blockquote class=\"wp-embedded-content\" data-secret=\"Or7Ot8hN5p\"><p><a href=\"https:\/\/appbay.org\/?p=4379\">C# \u30d5\u30a1\u30a4\u30eb\u691c\u7d22+\u6307\u5b9a\u79d2\u6570\u3067\u30b5\u30e0\u30cd\u30a4\u30eb\u4f5c\u6210(FFmpeg)<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;C# \u30d5\u30a1\u30a4\u30eb\u691c\u7d22+\u6307\u5b9a\u79d2\u6570\u3067\u30b5\u30e0\u30cd\u30a4\u30eb\u4f5c\u6210(FFmpeg)&#8221; &#8212; \u30c6\u30c3\u30af\u30e1\u30e2\" src=\"https:\/\/appbay.org\/?p=4379&#038;embed=true#?secret=BYz4NBsGg3#?secret=Or7Ot8hN5p\" data-secret=\"Or7Ot8hN5p\" width=\"525\" height=\"296\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>\u4ee5\u524d\u304b\u3089\u3068\u304d\u3069\u304dfenrir(B@r09u3 Style Op.2)\u3068\u3044\u3046\u30d5\u30ea\u30fc\u30bd\u30d5\u30c8\u3092\u5229\u7528\u3057\u3066\u3044\u305f\u304c\u3001\u66f4\u65b0\u304c\u6b62\u307e\u3063\u3066\u3044\u308b\u3088\u3046\u306a\u306e\u3067\u3001\u81ea\u5206\u7528\u306b\u540c\u3058\u3088\u3046\u306a\u30bd\u30d5\u30c8\u3092\u4f5c\u6210\u3057\u305f\u3002\u3082\u3068\u3082\u3068\u30d5\u30a1\u30a4\u30eb\u691c\u7d22\u3060\u3051\u3067\u304d\u308c\u3070\u3044\u3044\u306e\u3067\u3001\u6a5f\u80fd\u3082\u898b\u305f\u76ee\u3082\u9650\u5b9a\u7684\u3002<\/p>\n<pre class=\"lang:c# decode:true\">using System;\r\nusing System.Collections.Generic;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing System.Windows.Forms;\r\n\r\nnamespace CreateIndex\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            Console.WriteLine(\"\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u4f5c\u6210\u4e2d ... \");\r\n\r\n            string scanPath =  Application.StartupPath + @\"\\scan.txt\";\r\n            List&lt;string&gt; rawItems = new List&lt;string&gt;();\r\n\r\n            foreach (string path in File.ReadAllLines(scanPath))\r\n            {\r\n                if (!Directory.Exists(path)) continue;\r\n\r\n                var ln = Directory.EnumerateFiles(path, \"*.*\", SearchOption.AllDirectories).ToList();\r\n                rawItems.AddRange(ln);\r\n            }\r\n\r\n            File.WriteAllLines(Application.StartupPath + @\"\\index.dat\", rawItems);\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<pre class=\"lang:c# decode:true \">using System;\r\nusing System.Collections.Generic;\r\nusing System.Data;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing System.Windows.Forms;\r\nusing System.Xml.Serialization;\r\nusing System.Text;\r\n\r\nnamespace FileSearch\r\n{\r\n    public partial class Form1 : Form\r\n    {\r\n        string RemoteIndexPath = Application.StartupPath + @\"\\remote_index_path.txt\";\r\n        string IndexPath = Application.StartupPath + @\"\\index.dat\";\r\n\r\n        List&lt;string&gt; RawItems = new List&lt;string&gt;();\r\n\r\n        int VisibleCount = 100;\r\n        int RawItemCount = 0;\r\n        string WriteTime = \"\";\r\n \r\n        public Form1()\r\n        {\r\n            InitializeComponent();\r\n\r\n            if (!IndexLoad()) return;\r\n\r\n            LoadPosition();\r\n\r\n            var delayExecute = new DelayExecute();\r\n            delayExecute.Execute += (s, e) =&gt; SetupDatasource();\r\n            textBox1.TextChanged += (s, e) =&gt; delayExecute.ReserveExecute();\r\n\r\n            listBox1.MouseDoubleClick += (s, e) =&gt; OpenFile(s, e);\r\n\r\n            this.FormClosing += (s, e) =&gt; SavePosition();\r\n        }\r\n\r\n        private bool IndexLoad()\r\n        {\r\n            \r\n            if (!File.Exists(RemoteIndexPath)) \/\/ \u30ea\u30e2\u30fc\u30c8\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u304c\u306a\u3044\u5834\u5408\r\n            {\r\n                MessageBox.Show(\"\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30d5\u30a1\u30a4\u30eb\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002\"); \r\n                return false;\r\n            }\r\n            \r\n            string remoteIndexPath = File.ReadAllText(RemoteIndexPath);\r\n\r\n            if (!File.Exists(IndexPath) &amp;&amp; !File.Exists(remoteIndexPath)) \/\/ \u30ed\u30fc\u30ab\u30eb\u3001\u30ea\u30e2\u30fc\u30c8\u306b\u306a\u3044\u5834\u5408\r\n            {\r\n                MessageBox.Show(\"\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30d5\u30a1\u30a4\u30eb\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002\");\r\n                return false;\r\n            }\r\n            else if (File.Exists(IndexPath) &amp;&amp; !File.Exists(remoteIndexPath)) \/\/ \u30ed\u30fc\u30ab\u30eb\u306b\u3042\u3063\u3066\u3001\u30ea\u30e2\u30fc\u30c8\u306b\u306a\u3044\u5834\u5408\r\n            {\r\n                RawItems = File.ReadAllLines(IndexPath).ToList();\r\n                RawItemCount = RawItems.Count();\r\n                WriteTime = File.GetLastWriteTime(IndexPath).ToString(\"yyyy\/MM\/dd HH:mm:ss\");\r\n            }\r\n            else if (!File.Exists(IndexPath) &amp;&amp; File.Exists(remoteIndexPath)) \/\/ \u30ed\u30fc\u30ab\u30eb\u306b\u306a\u304f\u3066\u3001\u30ea\u30e2\u30fc\u30c8\u306b\u3042\u308b\u5834\u5408\r\n            {\r\n                File.Copy(remoteIndexPath, IndexPath);\r\n                RawItems = File.ReadAllLines(IndexPath).ToList();\r\n                RawItemCount = RawItems.Count();\r\n                WriteTime = File.GetLastWriteTime(IndexPath).ToString(\"yyyy\/MM\/dd HH:mm:ss\");\r\n            }\r\n            else if (File.Exists(IndexPath) &amp;&amp; File.Exists(remoteIndexPath)) \/\/ \u30ed\u30fc\u30ab\u30eb\u3001\u30ea\u30e2\u30fc\u30c8\u306b\u3042\u308b\u5834\u5408\r\n            {\r\n                if (File.GetLastWriteTime(IndexPath) &lt; File.GetLastWriteTime(remoteIndexPath)) \/\/ \u30ea\u30e2\u30fc\u30c8\u306e\u65b9\u304c\u6700\u65b0\u306e\u5834\u5408\r\n                { \r\n                    if (DialogResult.Yes == MessageBox.Show(\"\u6700\u65b0\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3057\u307e\u3059\u3002\u66f4\u65b0\u3057\u307e\u3059\u304b\uff1f\",\"\", MessageBoxButtons.YesNo))\r\n                    {\r\n                        File.Copy(remoteIndexPath, IndexPath, true);\r\n                    }\r\n                    RawItems = File.ReadAllLines(IndexPath).ToList();\r\n                    RawItemCount = RawItems.Count();\r\n                    WriteTime = File.GetLastWriteTime(IndexPath).ToString(\"yyyy\/MM\/dd HH:mm:ss\");\r\n                }\r\n                else \/\/ \u30ed\u30fc\u30ab\u30eb\u306e\u65b9\u304c\u6700\u65b0\u306e\u5834\u5408\r\n                {\r\n                    RawItems = File.ReadAllLines(IndexPath).ToList();\r\n                    RawItemCount = RawItems.Count();\r\n                    WriteTime = File.GetLastWriteTime(IndexPath).ToString(\"yyyy\/MM\/dd HH:mm:ss\");\r\n                }\r\n            }\r\n            return true;\r\n        }\r\n\r\n        private void SetupDatasource()\r\n        {\r\n            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();\r\n            stopwatch.Start();\r\n\r\n            string needle = \"\";\r\n\r\n            Invoke((MethodInvoker)(() =&gt; {\r\n                needle = textBox1.Text;\r\n            }));\r\n\r\n            IEnumerable&lt;string&gt; items = new List&lt;string&gt;(VisibleCount);\r\n            \r\n            if (needle == \"\")\r\n            {\r\n                items = RawItems.Take(VisibleCount);\r\n            }\r\n            else\r\n            {\r\n                List&lt;string&gt; tmpList = new List&lt;string&gt;(RawItems);\r\n                tmpList.Capacity = RawItemCount;\r\n\r\n                foreach (string tmpString in needle.Split('|'))\r\n                {\r\n                    tmpList = tmpList.AsParallel().Where(x =&gt; x.ToLower().Contains(tmpString.ToLower())).ToList();\r\n                }\r\n                items = tmpList.Take(VisibleCount);\r\n            }\r\n\r\n            var itemClassList = new System.Collections.Concurrent.ConcurrentBag&lt;ItemClass&gt;();\r\n\r\n            System.Threading.Tasks.Parallel.ForEach(items, item =&gt;\r\n            {\r\n                itemClassList.Add(new ItemClass()\r\n                {\r\n                    DisplayItemPath = Path.GetFileName(item) + \" . . . \u25a0\" + Path.GetDirectoryName(item),\r\n                    ItemPath = item\r\n                });\r\n            });\r\n\r\n            stopwatch.Stop();\r\n\r\n            Invoke((MethodInvoker)(() =&gt; {\r\n                listBox1.DataSource = itemClassList.ToList();\r\n                listBox1.DisplayMember = \"DisplayItemPath\";\r\n                Text = items.Count() + \"\/\" + RawItemCount + \"\u4ef6\u8868\u793a (\" + stopwatch.ElapsedMilliseconds.ToString() + \"ms)\uff1a\" + WriteTime + \"\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\";\r\n            }));\r\n        }\r\n\r\n        private void OpenFile(object sender, MouseEventArgs e)\r\n        {\r\n            var itemPath = ((ItemClass)listBox1.SelectedItem).ItemPath;\r\n\r\n            if (!File.Exists(itemPath))\r\n            {\r\n                MessageBox.Show(\"\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002\");\r\n                return;\r\n            } \r\n\r\n            if (ModifierKeys == Keys.Control)\r\n            {\r\n                System.Diagnostics.Process.Start(Path.GetDirectoryName(itemPath));\r\n            }\r\n            else\r\n            {\r\n                System.Diagnostics.Process.Start(itemPath);\r\n            }\r\n        }\r\n        private void LoadPosition()\r\n        {\r\n            if (!File.Exists(Application.StartupPath + @\"\\dat.xml\")) return;\r\n\r\n            this.StartPosition = FormStartPosition.Manual;\r\n\r\n            XmlSerializer xs = new XmlSerializer(typeof(List&lt;int&gt;));\r\n            using (StreamReader sr = new StreamReader(Application.StartupPath + @\"\\dat.xml\", Encoding.UTF8))\r\n            {\r\n                try\r\n                {\r\n                    List&lt;int&gt; items = (List&lt;int&gt;)xs.Deserialize(sr);\r\n\r\n                    this.Width = (int)items[0];\r\n                    this.Height = (int)items[1];\r\n                    this.Top = (int)items[2];\r\n                    this.Left = (int)items[3];\r\n                }\r\n                catch\r\n                {\r\n                    this.StartPosition = FormStartPosition.WindowsDefaultLocation;\r\n                }\r\n            }\r\n        }\r\n\r\n        private void SavePosition()\r\n        {\r\n            if (this.WindowState == FormWindowState.Maximized) return;\r\n\r\n            XmlSerializer xs = new XmlSerializer(typeof(List&lt;int&gt;));\r\n            using (StreamWriter sw = new StreamWriter(Application.StartupPath + @\"\\dat.xml\", false, Encoding.UTF8))\r\n            {\r\n                List&lt;int&gt; items = new List&lt;int&gt;();\r\n\r\n                items.Add(this.Width);\r\n                items.Add(this.Height);\r\n                items.Add(this.Top);\r\n                items.Add(this.Left);\r\n\r\n                xs.Serialize(sw, items);\r\n            }\r\n        }\r\n    }\r\n\r\n    struct ItemClass\r\n    {\r\n        public string DisplayItemPath { set; get; }\r\n        public string ItemPath { set; get; }\r\n    }\r\n\r\n    class DelayExecute\r\n    {\r\n        public event EventHandler Execute;\r\n        private int DelayTime = 500;\r\n\r\n        System.Threading.Timer Timer;\r\n\r\n        public DelayExecute()\r\n        {\r\n            Timer = new System.Threading.Timer(x =&gt; {\r\n                Execute(this, EventArgs.Empty);\r\n            });\r\n        }\r\n\r\n        public void ReserveExecute()\r\n        {\r\n            Timer.Change(DelayTime, System.Threading.Timeout.Infinite);\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C# \u30d5\u30a1\u30a4\u30eb\u691c\u7d22+\u6307\u5b9a\u79d2\u6570\u3067\u30b5\u30e0\u30cd\u30a4\u30eb\u4f5c\u6210(FFmpeg) \u4ee5\u524d\u304b\u3089\u3068\u304d\u3069\u304dfenrir(B@r09u3 Style Op.2)\u3068\u3044\u3046\u30d5\u30ea\u30fc\u30bd\u30d5\u30c8\u3092\u5229\u7528\u3057\u3066\u3044\u305f\u304c\u3001\u66f4\u65b0\u304c\u6b62\u307e\u3063\u3066\u3044\u308b\u3088\u3046\u306a\u306e\u3067\u3001\u81ea\u5206\u7528\u306b\u540c\u3058\u3088\u3046\u306a\u30bd\u30d5\u30c8 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=4139\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;C# \u30d5\u30a1\u30a4\u30eb\u691c\u7d22(\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30bf\u30eb\u30b5\u30fc\u30c1)&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9],"class_list":["post-4139","post","type-post","status-publish","format-standard","hentry","category-1","tag-c-net"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/4139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4139"}],"version-history":[{"count":6,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/4139\/revisions"}],"predecessor-version":[{"id":5026,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/4139\/revisions\/5026"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}