From fe6a14c4ad2b822f7fd0d4942039086a7f2d1809 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 30 Oct 2021 03:21:45 +0100 Subject: [PATCH] WIP: global hotkey --- MainForm.Designer.cs | 7 +- MainForm.cs | 194 ++++++++++++++++-- Models/AppSession.cs | 7 +- OptionsForm.cs | 125 ++++++++++- OptionsForm.resx | 20 ++ RyzStudio/IO/SmartDirectory.cs | 39 ++-- .../ThemedForms/TextBox/TButtonTextBox.cs | 2 +- 7 files changed, 341 insertions(+), 53 deletions(-) diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index ac4d541..3ed0c6b 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -230,6 +230,7 @@ namespace RandomFileRunner this.optionsToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.F12))); this.optionsToolStripMenuItem.Size = new System.Drawing.Size(168, 22); this.optionsToolStripMenuItem.Text = "&Options"; + this.optionsToolStripMenuItem.Click += new System.EventHandler(this.optionsToolStripMenuItem_Click); // // helpToolStripMenuItem1 // @@ -342,8 +343,8 @@ namespace RandomFileRunner this.textBox1.Margin = new System.Windows.Forms.Padding(10, 0, 0, 10); this.textBox1.Name = "textBox1"; this.textBox1.NormalImage = ((System.Drawing.Image)(resources.GetObject("textBox1.NormalImage"))); - this.textBox1.Padding = new System.Windows.Forms.Padding(10, 9, 9, 8); - this.textBox1.Size = new System.Drawing.Size(318, 33); + this.textBox1.Padding = new System.Windows.Forms.Padding(10, 9, 9, 9); + this.textBox1.Size = new System.Drawing.Size(318, 34); this.textBox1.SubmitButton = null; this.textBox1.TabIndex = 44; this.textBox1.UseSystemPasswordChar = false; @@ -451,7 +452,7 @@ namespace RandomFileRunner this.Controls.Add(this.pictureBox1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "MainForm"; - this.Text = "222"; + this.Text = "Random File Runner"; ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); diff --git a/MainForm.cs b/MainForm.cs index c0896b1..140ba35 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -2,9 +2,11 @@ using RyzStudio.Windows.Forms; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.IO; +using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Windows.Forms; @@ -12,6 +14,21 @@ namespace RandomFileRunner { public partial class MainForm : Form { + [DllImport("user32.dll")] + protected static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk); + + [DllImport("user32.dll")] + protected static extern bool UnregisterHotKey(IntPtr hWnd, int id); + + //protected const int MOD_NONE = 0x0000; + //protected const int MOD_ALT = 0x1; + //protected const int MOD_CONTROL = 0x2; + //protected const int MOD_SHIFT = 0x4; + //protected const int MOD_WIN = 0x8; + protected const int WM_HOTKEY = 0x312; + protected const int WM_QUERYENDSESSION = 0x0011; + + protected readonly Random randy; protected OptionsForm optionsForm = null; @@ -32,15 +49,47 @@ namespace RandomFileRunner randy = new Random(); } - protected override void OnFormClosing(FormClosingEventArgs e) + protected override void OnClosing(CancelEventArgs e) { + base.OnClosing(e); + if (this.IsBusy) { e.Cancel = true; return; } - base.OnFormClosing(e); + if (this.CurrentSession.ClosePrevOnNext) CloseCurrentProcess(currentProcess); + + if (this.CurrentSession.NextHotKey != null) + { + if (this.CurrentSession.NextHotKey.KeyCode != Keys.None) + { +//#if !DEBUG + UnregisterHotKey((IntPtr)Handle, 1); +//#endif + } + } + } + + protected override void WndProc(ref Message m) + { + switch (m.Msg) + { + case WM_HOTKEY: + if (m.WParam.ToInt32() == 1) button5_MouseClick(null, null); + + break; + //case WM_QUERYENDSESSION: + // requestExit = true; + // //this.Close(); + // Application.Exit(); + + // break; + default: break; + } + + base.WndProc(ref m); } @@ -63,20 +112,9 @@ namespace RandomFileRunner } } - public AppSession CurrentSession { get; set; } = new AppSession(); - protected void AddSearchItem(string line) - { - memoBox1.Text = memoBox1.Text.Trim(); - - // above line-break - if (!string.IsNullOrWhiteSpace(memoBox1.Text)) memoBox1.Text += Environment.NewLine; - - memoBox1.Text += line + Environment.NewLine; - } - protected bool SearchDirecory_OnFound(string file, ulong searchCount, int searchQueue) { if (!string.IsNullOrWhiteSpace(file)) @@ -91,6 +129,29 @@ namespace RandomFileRunner } + /// + /// Options + /// + /// + /// + private void optionsToolStripMenuItem_Click(object sender, EventArgs e) + { + if (this.IsBusy) + { + return; + } + + if (optionsForm == null) optionsForm = new OptionsForm(this.CurrentSession); + if (optionsForm.ShowDialog() == DialogResult.OK) + { + this.CurrentSession = optionsForm.Session; + + InvalidateHotKey(); + //this.TopMost = this.CurrentSession.AlwaysOnTop; + } + } + + /// /// Search /// @@ -135,7 +196,7 @@ namespace RandomFileRunner if (Directory.Exists(item)) { - SmartDirectory.GetFiles(item, textBox1.Text, SearchDirecory_OnFound); + SmartDirectory.GetFiles(item, textBox1.Text, this.CurrentSession.SearchTopDirectoryOnly, SearchDirecory_OnFound); ThreadControl.SetText(label2, foundFiles.Count.ToString()); @@ -232,9 +293,49 @@ namespace RandomFileRunner /// /// /// - private void button5_MouseClick(object sender, MouseEventArgs e) + private async void button5_MouseClick(object sender, MouseEventArgs e) { + await Task.Run(() => + { + if (this.IsBusy) return; + //this.IsBusy = true; + + if (this.CurrentSession == null) this.CurrentSession = new AppSession(); + + if (this.CurrentSession.ClosePrevOnNext) CloseCurrentProcess(currentProcess); + + string filename = null; + + // retry 8 times + for (int i = 0; i < this.CurrentSession.RetryOnError; i++) + { + filename = foundFiles[randy.Next(0, (foundFiles.Count - 1))]; + if (File.Exists(filename)) + { + continue; + } + + filename = null; + } + + if (!string.IsNullOrWhiteSpace(filename)) + { + ProcessStartInfo psi = new ProcessStartInfo(filename); + psi.UseShellExecute = true; + + try + { + currentProcess = Process.Start(psi); + } + catch (Exception) + { + // do nothing + } + } + + //this.IsBusy = false; + }); } /// @@ -248,5 +349,68 @@ namespace RandomFileRunner } + protected void AddSearchItem(string line) + { + memoBox1.Text = memoBox1.Text.Trim(); + + // above line-break + if (!string.IsNullOrWhiteSpace(memoBox1.Text)) memoBox1.Text += Environment.NewLine; + + memoBox1.Text += line + Environment.NewLine; + } + + private void CloseCurrentProcess(Process p) + { + if (p == null) return; + + try + { + p.CloseMainWindow(); + //p.Close(); + } + catch (Exception) + { + // do nothing + } + } + + private void InvalidateHotKey() + { +//#if !DEBUG + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => + { + UnregisterHotKey((IntPtr)Handle, 1); + })); + } + else + { + UnregisterHotKey((IntPtr)Handle, 1); + } +//#endif + + if (this.CurrentSession.NextHotKey != null) + { + if (this.CurrentSession.NextHotKey.KeyCode != Keys.None) + { +//#if !DEBUG + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => + { + RegisterHotKey((IntPtr)Handle, 1, this.CurrentSession.NextHotKey.ModifierCode, this.CurrentSession.NextHotKey.Key); + })); + } + else + { + RegisterHotKey((IntPtr)Handle, 1, this.CurrentSession.NextHotKey.ModifierCode, this.CurrentSession.NextHotKey.Key); + } +//#endif + } + } + } + + } } diff --git a/Models/AppSession.cs b/Models/AppSession.cs index cf6c473..1f85ef3 100644 --- a/Models/AppSession.cs +++ b/Models/AppSession.cs @@ -19,12 +19,9 @@ public bool ClosePrevOnNext { get; set; } = false; - public HotKeyOptions NextHotKey { get; set; } = null; + public int RetryOnError { get; set; } = 8; - - public bool AlwaysOnTop { get; set; } = false; - - public int NoFrames { get; set; } = 3; + public HotKeyOptions NextHotKey { get; set; } = new HotKeyOptions(); } } diff --git a/OptionsForm.cs b/OptionsForm.cs index 62c78b7..4d930a5 100644 --- a/OptionsForm.cs +++ b/OptionsForm.cs @@ -12,6 +12,11 @@ namespace RandomFileRunner private System.Windows.Forms.Label label8; private RyzStudio.Windows.Forms.THorizontalSeparator tHorizontalSeparator1; private TNumericPickerBox pickerBox2; + private TKeyCodeTextBox textBox1; + private TYesNoPickerBox pickerBox3; + private Label label1; + private RyzStudio.Windows.Forms.THorizontalSeparator tHorizontalSeparator3; + private Label label2; private RyzStudio.Windows.Forms.THorizontalSeparator tHorizontalSeparator2; @@ -24,6 +29,8 @@ namespace RandomFileRunner private void InitializeComponent() { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(OptionsForm)); + RyzStudio.Windows.ThemedForms.TKeyCodeTextBox.Results results1 = new RyzStudio.Windows.ThemedForms.TKeyCodeTextBox.Results(); this.button1 = new RyzStudio.Windows.ThemedForms.TButton(); this.pickerBox1 = new RyzStudio.Windows.ThemedForms.TYesNoPickerBox(); this.label6 = new System.Windows.Forms.Label(); @@ -31,6 +38,11 @@ namespace RandomFileRunner this.tHorizontalSeparator1 = new RyzStudio.Windows.Forms.THorizontalSeparator(); this.tHorizontalSeparator2 = new RyzStudio.Windows.Forms.THorizontalSeparator(); this.pickerBox2 = new RyzStudio.Windows.ThemedForms.TNumericPickerBox(); + this.textBox1 = new RyzStudio.Windows.ThemedForms.TKeyCodeTextBox(); + this.pickerBox3 = new RyzStudio.Windows.ThemedForms.TYesNoPickerBox(); + this.label1 = new System.Windows.Forms.Label(); + this.tHorizontalSeparator3 = new RyzStudio.Windows.Forms.THorizontalSeparator(); + this.label2 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // button1 @@ -42,7 +54,7 @@ namespace RandomFileRunner this.button1.IsSelected = false; this.button1.LabelText = "&Save"; this.button1.Location = new System.Drawing.Point(241, 469); - this.button1.Margin = new System.Windows.Forms.Padding(10); + this.button1.Margin = new System.Windows.Forms.Padding(10, 0, 10, 10); this.button1.Name = "button1"; this.button1.OverImage = null; this.button1.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); @@ -73,9 +85,9 @@ namespace RandomFileRunner this.label6.Margin = new System.Windows.Forms.Padding(0); this.label6.Name = "label6"; this.label6.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label6.Size = new System.Drawing.Size(117, 34); + this.label6.Size = new System.Drawing.Size(81, 34); this.label6.TabIndex = 182; - this.label6.Text = "Generate No. Frames"; + this.label6.Text = "Retry On Error"; this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // label8 @@ -87,9 +99,9 @@ namespace RandomFileRunner this.label8.Margin = new System.Windows.Forms.Padding(0); this.label8.Name = "label8"; this.label8.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label8.Size = new System.Drawing.Size(89, 34); + this.label8.Size = new System.Drawing.Size(143, 34); this.label8.TabIndex = 186; - this.label8.Text = "Always-On-Top"; + this.label8.Text = "Search Top Directory Only"; this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // tHorizontalSeparator1 @@ -100,7 +112,7 @@ namespace RandomFileRunner this.tHorizontalSeparator1.AutoScrollMinSize = new System.Drawing.Size(0, 0); this.tHorizontalSeparator1.BackColor = System.Drawing.Color.Transparent; this.tHorizontalSeparator1.Location = new System.Drawing.Point(10, 437); - this.tHorizontalSeparator1.Margin = new System.Windows.Forms.Padding(10, 0, 10, 0); + this.tHorizontalSeparator1.Margin = new System.Windows.Forms.Padding(5, 0, 5, 10); this.tHorizontalSeparator1.MaximumSize = new System.Drawing.Size(4920, 2); this.tHorizontalSeparator1.MinimumSize = new System.Drawing.Size(0, 22); this.tHorizontalSeparator1.Name = "tHorizontalSeparator1"; @@ -116,7 +128,7 @@ namespace RandomFileRunner this.tHorizontalSeparator2.AutoScrollMinSize = new System.Drawing.Size(0, 0); this.tHorizontalSeparator2.BackColor = System.Drawing.Color.Transparent; this.tHorizontalSeparator2.Location = new System.Drawing.Point(10, 59); - this.tHorizontalSeparator2.Margin = new System.Windows.Forms.Padding(10, 0, 10, 0); + this.tHorizontalSeparator2.Margin = new System.Windows.Forms.Padding(5, 0, 5, 10); this.tHorizontalSeparator2.MaximumSize = new System.Drawing.Size(4920, 2); this.tHorizontalSeparator2.MinimumSize = new System.Drawing.Size(0, 22); this.tHorizontalSeparator2.Name = "tHorizontalSeparator2"; @@ -138,11 +150,95 @@ namespace RandomFileRunner this.pickerBox2.TabIndex = 193; this.pickerBox2.Value = 0; // + // textBox1 + // + this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.textBox1.BackColor = System.Drawing.Color.Transparent; + this.textBox1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.textBox1.HighlightImage = ((System.Drawing.Image)(resources.GetObject("textBox1.HighlightImage"))); + results1.IsAlt = false; + results1.IsCtrl = false; + results1.IsShift = false; + results1.Key = System.Windows.Forms.Keys.None; + this.textBox1.KeyCodeResults = results1; + this.textBox1.Location = new System.Drawing.Point(241, 197); + this.textBox1.Margin = new System.Windows.Forms.Padding(10, 0, 0, 10); + this.textBox1.Name = "textBox1"; + this.textBox1.NormalImage = ((System.Drawing.Image)(resources.GetObject("textBox1.NormalImage"))); + this.textBox1.Padding = new System.Windows.Forms.Padding(10, 9, 9, 9); + this.textBox1.Size = new System.Drawing.Size(128, 34); + this.textBox1.SubmitButton = null; + this.textBox1.TabIndex = 194; + this.textBox1.UseSystemPasswordChar = false; + // + // pickerBox3 + // + this.pickerBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.pickerBox3.BackColor = System.Drawing.Color.Transparent; + this.pickerBox3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.pickerBox3.Location = new System.Drawing.Point(285, 127); + this.pickerBox3.Margin = new System.Windows.Forms.Padding(10, 4, 10, 4); + this.pickerBox3.Name = "pickerBox3"; + this.pickerBox3.Padding = new System.Windows.Forms.Padding(10, 6, 7, 5); + this.pickerBox3.Size = new System.Drawing.Size(84, 34); + this.pickerBox3.SubmitButton = null; + this.pickerBox3.TabIndex = 195; + this.pickerBox3.Value = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.BackColor = System.Drawing.Color.Transparent; + this.label1.ForeColor = System.Drawing.SystemColors.ControlText; + this.label1.Location = new System.Drawing.Point(10, 127); + this.label1.Margin = new System.Windows.Forms.Padding(0); + this.label1.Name = "label1"; + this.label1.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); + this.label1.Size = new System.Drawing.Size(169, 34); + this.label1.TabIndex = 196; + this.label1.Text = "Close Current Process On Next"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // tHorizontalSeparator3 + // + this.tHorizontalSeparator3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tHorizontalSeparator3.AutoScrollMargin = new System.Drawing.Size(0, 0); + this.tHorizontalSeparator3.AutoScrollMinSize = new System.Drawing.Size(0, 0); + this.tHorizontalSeparator3.BackColor = System.Drawing.Color.Transparent; + this.tHorizontalSeparator3.Location = new System.Drawing.Point(10, 165); + this.tHorizontalSeparator3.Margin = new System.Windows.Forms.Padding(5, 0, 5, 10); + this.tHorizontalSeparator3.MaximumSize = new System.Drawing.Size(4920, 2); + this.tHorizontalSeparator3.MinimumSize = new System.Drawing.Size(0, 22); + this.tHorizontalSeparator3.Name = "tHorizontalSeparator3"; + this.tHorizontalSeparator3.Padding = new System.Windows.Forms.Padding(0, 10, 0, 10); + this.tHorizontalSeparator3.Size = new System.Drawing.Size(364, 22); + this.tHorizontalSeparator3.TabIndex = 197; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.BackColor = System.Drawing.Color.Transparent; + this.label2.ForeColor = System.Drawing.SystemColors.ControlText; + this.label2.Location = new System.Drawing.Point(10, 197); + this.label2.Margin = new System.Windows.Forms.Padding(0); + this.label2.Name = "label2"; + this.label2.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); + this.label2.Size = new System.Drawing.Size(81, 34); + this.label2.TabIndex = 198; + this.label2.Text = "Retry On Error"; + this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // // OptionsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(384, 521); + this.Controls.Add(this.label2); + this.Controls.Add(this.tHorizontalSeparator3); + this.Controls.Add(this.label1); + this.Controls.Add(this.pickerBox3); + this.Controls.Add(this.textBox1); this.Controls.Add(this.pickerBox2); this.Controls.Add(this.tHorizontalSeparator2); this.Controls.Add(this.tHorizontalSeparator1); @@ -164,8 +260,10 @@ namespace RandomFileRunner this.DialogResult = System.Windows.Forms.DialogResult.None; - pickerBox1.Value = this.Session.AlwaysOnTop; - pickerBox2.Clear(1, 20, this.Session.NoFrames); + pickerBox1.Value = this.Session.SearchTopDirectoryOnly; + pickerBox2.Clear(0, 20, this.Session.RetryOnError); + pickerBox3.Value = this.Session.ClosePrevOnNext; + if (this.Session.NextHotKey != null) textBox1.UpdateKeyCode(this.Session.NextHotKey.IsCtrl, this.Session.NextHotKey.IsAlt, this.Session.NextHotKey.IsShift, this.Session.NextHotKey.KeyCode); } @@ -176,8 +274,13 @@ namespace RandomFileRunner { if (this.Session == null) this.Session = new AppSession(); - this.Session.AlwaysOnTop = pickerBox1.Value; - this.Session.NoFrames = pickerBox2.Value; + this.Session.SearchTopDirectoryOnly = pickerBox1.Value; + this.Session.RetryOnError = pickerBox2.Value; + this.Session.ClosePrevOnNext = pickerBox3.Value; + this.Session.NextHotKey.IsCtrl = textBox1.KeyCodeResults.IsCtrl; + this.Session.NextHotKey.IsAlt = textBox1.KeyCodeResults.IsAlt; + this.Session.NextHotKey.IsShift = textBox1.KeyCodeResults.IsShift; + this.Session.NextHotKey.Key = textBox1.KeyCodeResults.KeyCode; this.DialogResult = DialogResult.OK; this.Close(); diff --git a/OptionsForm.resx b/OptionsForm.resx index f298a7b..5c8d053 100644 --- a/OptionsForm.resx +++ b/OptionsForm.resx @@ -57,4 +57,24 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAYAAAAmlE46AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wAAADsABataJCQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAClSURBVDhP7dI/ + DgFBGIbxSVTKjcRx3MLqXYCOjkocQcMF3MAZOIKaE5AthOexf2QnbJQKb/JLJvO9XzLFhCgtbHDBveB5 + DWcfM8ANC0wKnr1LUUsbHXSxxBlJxDtnduy6E04on/Utd0IPOxwxxBT9iHfO7Nh155kV9vmxMXbsVvkv + vvIji4f82Bg7tcUxrpih/NyxOeyMUMVPu0WGd39TzuzQDeEB5/ZKvTSyulEAAAAASUVORK5CYII= + + + + + iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAYAAAAmlE46AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wAAADsABataJCQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAADTSURBVDhP7ZI7 + CsJQEEUfWFmK4HLchdpnA9ppp5W4BBtdQNyBC0ilRf6VdVyBwUL03JdXxC/YWThwmDcz94YJjKmH7/uN + OI7XaZqekiS5Cr1hpZmTPQemAeILeU4eC/dWr+9kVQRB0MzzvB2GYQfBAsExiqJWHfU0k0ZaeQyNAuxa + X1CYLMu6/MOW4kD2YAK9B9TznGYrj12XVZY0drb4ENJI68q/sR4/YoS9K9+GNHdGLmIEJV+cku1xP4Jh + Ri7JQ2erDp3mBs7w6jaFZht74MaYGwmLbkeRGexGAAAAAElFTkSuQmCC + + \ No newline at end of file diff --git a/RyzStudio/IO/SmartDirectory.cs b/RyzStudio/IO/SmartDirectory.cs index 2921c02..11ef2af 100644 --- a/RyzStudio/IO/SmartDirectory.cs +++ b/RyzStudio/IO/SmartDirectory.cs @@ -2,16 +2,13 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Security.AccessControl; -using System.Text; -using System.Threading.Tasks; namespace RandomFileRunner.IO { public class SmartDirectory { - public static List GetFiles(string path, string pattern) + public static List GetFiles(string path, string pattern, bool searchTopOnly) { List fileList = new List(); List directoryList = new List(); @@ -43,14 +40,17 @@ namespace RandomFileRunner.IO continue; } - foreach (string item in searchDirList) + if (!searchTopOnly) { - if (!IsDirectoryAccessible(item)) + foreach (string item in searchDirList) { - continue; - } + if (!IsDirectoryAccessible(item)) + { + continue; + } - directoryList.Add(item); + directoryList.Add(item); + } } foreach (string item in Directory.EnumerateFiles(directory, "*", SearchOption.TopDirectoryOnly)) @@ -73,7 +73,7 @@ namespace RandomFileRunner.IO return fileList; } - public static void GetFiles(string path, string pattern, Func callback) + public static void GetFiles(string path, string pattern, bool searchTopOnly, Func callback) { List directoryList = new List(); ulong searchCount = 0; @@ -108,17 +108,20 @@ namespace RandomFileRunner.IO continue; } - foreach (string item in searchDirList) + if (!searchTopOnly) { - if (!IsDirectoryAccessible(item)) + foreach (string item in searchDirList) { - continue; + if (!IsDirectoryAccessible(item)) + { + continue; + } + + directoryList.Add(item); + searchCount++; + + callback(null, searchCount, directoryList.Count); } - - directoryList.Add(item); - searchCount++; - - callback(null, searchCount, directoryList.Count); } foreach (string item in Directory.EnumerateFiles(directory, "*", SearchOption.TopDirectoryOnly)) diff --git a/RyzStudio/Windows/ThemedForms/TextBox/TButtonTextBox.cs b/RyzStudio/Windows/ThemedForms/TextBox/TButtonTextBox.cs index 3ffd98d..908994c 100644 --- a/RyzStudio/Windows/ThemedForms/TextBox/TButtonTextBox.cs +++ b/RyzStudio/Windows/ThemedForms/TextBox/TButtonTextBox.cs @@ -8,7 +8,7 @@ public partial class TButtonTextBox : RyzStudio.Windows.ThemedForms.TUserControl { - protected readonly Padding defaultPadding = new Padding(6, 5, 6, 5); + protected readonly Padding defaultPadding = new Padding(6, 5, 6, 6); protected readonly Padding defaultMargin = new Padding(10, 0, 0, 10);