From eb4d9b050539eeb115b6998edb7e2ed7dc531686 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Sat, 2 Sep 2023 23:58:34 +1000 Subject: [PATCH 1/5] [Windows] Upgrade to .NET 6 --- windows/QMK Toolbox.sln | 8 +- windows/QMK Toolbox/AboutBox.cs | 2 +- windows/QMK Toolbox/App.config | 3 - windows/QMK Toolbox/FodyWeavers.xsd | 30 +++ .../QMK Toolbox/KeyTester/KeyTesterWindow.cs | 2 +- windows/QMK Toolbox/MainWindow.cs | 17 +- .../QMK Toolbox/Properties/AssemblyInfo.cs | 35 ---- .../Properties/Settings.Designer.cs | 4 +- windows/QMK Toolbox/QMK Toolbox.csproj | 189 +++--------------- 9 files changed, 82 insertions(+), 208 deletions(-) delete mode 100644 windows/QMK Toolbox/Properties/AssemblyInfo.cs diff --git a/windows/QMK Toolbox.sln b/windows/QMK Toolbox.sln index 95f7e2b73c..57e250eb39 100644 --- a/windows/QMK Toolbox.sln +++ b/windows/QMK Toolbox.sln @@ -1,9 +1,9 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31424.327 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QMK Toolbox", "QMK Toolbox\QMK Toolbox.csproj", "{1F8BE719-CB0D-4A67-8422-B0C3A1B823F7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QMK Toolbox", "QMK Toolbox\QMK Toolbox.csproj", "{1F8BE719-CB0D-4A67-8422-B0C3A1B823F7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/windows/QMK Toolbox/AboutBox.cs b/windows/QMK Toolbox/AboutBox.cs index 1b332b7248..8708738d47 100644 --- a/windows/QMK Toolbox/AboutBox.cs +++ b/windows/QMK Toolbox/AboutBox.cs @@ -26,7 +26,7 @@ public string AssemblyTitle return titleAttribute.Title; } } - return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); + return System.IO.Path.GetFileNameWithoutExtension(path: Assembly.GetExecutingAssembly().Location); } } diff --git a/windows/QMK Toolbox/App.config b/windows/QMK Toolbox/App.config index ff501ce07a..1c4afd8cf5 100644 --- a/windows/QMK Toolbox/App.config +++ b/windows/QMK Toolbox/App.config @@ -49,7 +49,4 @@ - - - diff --git a/windows/QMK Toolbox/FodyWeavers.xsd b/windows/QMK Toolbox/FodyWeavers.xsd index 44a53744ff..05e92c1147 100644 --- a/windows/QMK Toolbox/FodyWeavers.xsd +++ b/windows/QMK Toolbox/FodyWeavers.xsd @@ -17,6 +17,16 @@ A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. + + + A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks + + + + + A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. + + A list of unmanaged 32 bit assembly names to include, delimited with line breaks. @@ -43,6 +53,16 @@ Controls if .pdbs for reference assemblies are also embedded. + + + Controls if runtime assemblies are also embedded. + + + + + Controls whether the runtime assemblies are embedded with their full path or only with their assembly name. + + Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. @@ -73,6 +93,16 @@ A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. + + + A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with | + + + + + A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with |. + + A list of unmanaged 32 bit assembly names to include, delimited with |. diff --git a/windows/QMK Toolbox/KeyTester/KeyTesterWindow.cs b/windows/QMK Toolbox/KeyTester/KeyTesterWindow.cs index 7ef28336bb..f6a63ada28 100644 --- a/windows/QMK Toolbox/KeyTester/KeyTesterWindow.cs +++ b/windows/QMK Toolbox/KeyTester/KeyTesterWindow.cs @@ -166,7 +166,7 @@ protected override bool ProcessKeyMessage(ref Message m) if (m.Msg == WM_KEYDOWN || m.Msg == WM_KEYUP || m.Msg == WM_SYSKEYDOWN || m.Msg == WM_SYSKEYUP) { int vKey = m.WParam.ToInt32(); - int scanCode = (m.LParam.ToInt32() >> 16) & 0x1FF; + int scanCode = (int)((m.LParam.ToInt64() >> 16) & 0x1FF); KeyControl pressedKeyControl = GetKeyControlForKey(vKey, scanCode); if (pressedKeyControl != null) diff --git a/windows/QMK Toolbox/MainWindow.cs b/windows/QMK Toolbox/MainWindow.cs index d433130b9b..b0697ccdc5 100644 --- a/windows/QMK Toolbox/MainWindow.cs +++ b/windows/QMK Toolbox/MainWindow.cs @@ -12,6 +12,8 @@ using System.IO; using System.Linq; using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; using System.Security.Permissions; using System.Windows.Forms; @@ -128,7 +130,6 @@ private void MainWindow_DragDrop(object sender, DragEventArgs e) SetFilePath(((string[])e.Data.GetData(DataFormats.FileDrop, false)).First()); } - [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] protected override void WndProc(ref Message m) { if (m.Msg == NativeMethods.WmShowme) @@ -432,19 +433,23 @@ private void LoadLocalFile(string path) filepathBox.SelectedItem = path; } - private void DownloadFile(string url) + private async void DownloadFile(string url) { logTextBox.LogInfo($"Downloading the file: {url}"); try { string destFile = Path.Combine(KnownFolders.Downloads.Path, url.Substring(url.LastIndexOf("/") + 1)); - using (var wb = new WebClient()) + + var client = new HttpClient(); + client.DefaultRequestHeaders.UserAgent.ParseAdd("QMK Toolbox"); + + var response = await client.GetAsync(url); + using (var fs = new FileStream(destFile, FileMode.CreateNew)) { - wb.Headers.Add("User-Agent", "QMK Toolbox"); - wb.DownloadFile(url, destFile); + await response.Content.CopyToAsync(fs); + logTextBox.LogInfo($"File saved to: {destFile}"); } - logTextBox.LogInfo($"File saved to: {destFile}"); LoadLocalFile(destFile); } diff --git a/windows/QMK Toolbox/Properties/AssemblyInfo.cs b/windows/QMK Toolbox/Properties/AssemblyInfo.cs deleted file mode 100644 index 5e7fa3c3c6..0000000000 --- a/windows/QMK Toolbox/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("QMK Toolbox")] -[assembly: AssemblyDescription("A flashing/debug utility for devices running QMK Firmware")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("QMK")] -[assembly: AssemblyProduct("QMK Toolbox")] -[assembly: AssemblyCopyright("Copyright © 2022 QMK")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("1f8be719-cb0d-4a67-8422-b0c3a1b823f7")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.2")] -[assembly: AssemblyFileVersion("0.2.2")] diff --git a/windows/QMK Toolbox/Properties/Settings.Designer.cs b/windows/QMK Toolbox/Properties/Settings.Designer.cs index 288e90fa7f..84c22f9c7a 100644 --- a/windows/QMK Toolbox/Properties/Settings.Designer.cs +++ b/windows/QMK Toolbox/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace QMK_Toolbox.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.7.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -129,7 +129,7 @@ public bool driversInstalled { this["driversInstalled"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("False")] diff --git a/windows/QMK Toolbox/QMK Toolbox.csproj b/windows/QMK Toolbox/QMK Toolbox.csproj index 00a849bd65..7e7adb8bbe 100644 --- a/windows/QMK Toolbox/QMK Toolbox.csproj +++ b/windows/QMK Toolbox/QMK Toolbox.csproj @@ -1,40 +1,11 @@ - - - + - Debug - AnyCPU - {1F8BE719-CB0D-4A67-8422-B0C3A1B823F7} + net6.0-windows10.0.17763.0 WinExe - Properties - QMK_Toolbox qmk_toolbox - v4.8 - 512 - true - - - - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + true + true + true Resources\output.ico @@ -44,137 +15,40 @@ Properties\app.manifest + 0.2.2 + 0.2.2 + QMK Toolbox + Copyright © 2023 QMK + QMK + A flashing/debug utility for devices running QMK Firmware + 0.2.2 + QMK Toolbox - - - - - - - - - - - - - - - - - Form - - - AboutBox.cs - - + Component - + Component - - - - - - Form - - - HidConsoleWindow.cs - - + UserControl - - KeyControl.cs - - - Form - - - KeyTesterWindow.cs - - + Component - - + Component - - Form - - - MainWindow.cs - - - - + Component - - - - - - - - - - - - - - - - - - - - - - - - AboutBox.cs - - - HidConsoleWindow.cs - - - KeyControl.cs - - - KeyTesterWindow.cs - - - MainWindow.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - True - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - + + True True Settings.settings - True - - - @@ -208,27 +82,30 @@ - - - - 4.1.0 + 5.7.0 + all 3.3.40 + - 4.1.0 + 4.7.0 runtime; build; native; contentfiles; analyzers; buildtransitive all 1.3.0 - - 5.0.0 - + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + - \ No newline at end of file From 55a82a90aa03596db823416f1994c2cb3cf59265 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Sun, 3 Sep 2023 00:15:07 +1000 Subject: [PATCH 2/5] Fix output path --- .github/workflows/build.yml | 2 +- windows/install_compiler.iss | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6f94f78ea5..cd3f4bdc6a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: - uses: actions/upload-artifact@v3 with: name: qmk_toolbox.exe - path: windows/QMK Toolbox/bin/Release/qmk_toolbox.exe + path: windows/QMK Toolbox/bin/Release/net6.0-windows10.0.17763.0/qmk_toolbox.exe - uses: actions/upload-artifact@v3 with: diff --git a/windows/install_compiler.iss b/windows/install_compiler.iss index a342664939..5926166003 100644 --- a/windows/install_compiler.iss +++ b/windows/install_compiler.iss @@ -38,7 +38,7 @@ Name: "english"; MessagesFile: "compiler:Default.isl" Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}" [Files] -Source: "QMK Toolbox\bin\Release\qmk_toolbox.exe"; DestDir: "{app}"; Flags: ignoreversion +Source: "QMK Toolbox\bin\Release\net6.0-windows10.0.17763.0\qmk_toolbox.exe"; DestDir: "{app}"; Flags: ignoreversion ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons] From 733eee57b8d05a0b5cdfbfa89fa43bf509dd5416 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Sun, 3 Sep 2023 12:57:15 +1000 Subject: [PATCH 3/5] Update solution and bump minimum Windows version --- .github/workflows/build.yml | 2 +- readme.md | 2 +- windows/QMK Toolbox.sln | 6 ++++-- windows/QMK Toolbox/QMK Toolbox.csproj | 2 +- windows/install_compiler.iss | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cd3f4bdc6a..931f0e5440 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: - uses: actions/upload-artifact@v3 with: name: qmk_toolbox.exe - path: windows/QMK Toolbox/bin/Release/net6.0-windows10.0.17763.0/qmk_toolbox.exe + path: windows/QMK Toolbox/bin/Release/net6.0-windows10.0.19041.0/qmk_toolbox.exe - uses: actions/upload-artifact@v3 with: diff --git a/readme.md b/readme.md index 44b548de88..d271eccf8c 100644 --- a/readme.md +++ b/readme.md @@ -50,7 +50,7 @@ See the [QMK Docs](https://docs.qmk.fm/#/newbs_testing_debugging?id=debugging) f ### System Requirements * macOS 10.15 (Catalina) or higher -* Windows 10 May 2019 Update or higher (earlier with [.NET Framework 4.8](https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/versions-and-dependencies#net-framework-48)) +* Windows 10 May 2020 Update (20H1) or higher ### Dependencies diff --git a/windows/QMK Toolbox.sln b/windows/QMK Toolbox.sln index 57e250eb39..b838802731 100644 --- a/windows/QMK Toolbox.sln +++ b/windows/QMK Toolbox.sln @@ -1,7 +1,6 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.0.31903.59 +VisualStudioVersion = 17.7.34024.191 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QMK Toolbox", "QMK Toolbox\QMK Toolbox.csproj", "{1F8BE719-CB0D-4A67-8422-B0C3A1B823F7}" EndProject @@ -19,4 +18,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {081E0F05-87B8-4176-B803-07A8DA0C4A5C} + EndGlobalSection EndGlobal diff --git a/windows/QMK Toolbox/QMK Toolbox.csproj b/windows/QMK Toolbox/QMK Toolbox.csproj index 7e7adb8bbe..3236032e7d 100644 --- a/windows/QMK Toolbox/QMK Toolbox.csproj +++ b/windows/QMK Toolbox/QMK Toolbox.csproj @@ -1,6 +1,6 @@  - net6.0-windows10.0.17763.0 + net6.0-windows10.0.19041.0 WinExe qmk_toolbox true diff --git a/windows/install_compiler.iss b/windows/install_compiler.iss index 5926166003..cbe3b7a30b 100644 --- a/windows/install_compiler.iss +++ b/windows/install_compiler.iss @@ -38,7 +38,7 @@ Name: "english"; MessagesFile: "compiler:Default.isl" Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}" [Files] -Source: "QMK Toolbox\bin\Release\net6.0-windows10.0.17763.0\qmk_toolbox.exe"; DestDir: "{app}"; Flags: ignoreversion +Source: "QMK Toolbox\bin\Release\net6.0-windows10.0.19041.0\qmk_toolbox.exe"; DestDir: "{app}"; Flags: ignoreversion ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons] From ed9f472d76ba0d089bf8e02210d6e69745c9fe3d Mon Sep 17 00:00:00 2001 From: fauxpark Date: Thu, 7 Sep 2023 15:11:23 +1000 Subject: [PATCH 4/5] Some small cleanups recommended by VS --- windows/QMK Toolbox/AboutBox.cs | 80 +------------------ windows/QMK Toolbox/BetterComboBox.cs | 2 + .../QMK Toolbox/BindableToolStripMenuItem.cs | 10 +-- windows/QMK Toolbox/ComboBoxPlaceholder.cs | 7 +- .../Helpers/EmbeddedResourceHelper.cs | 20 ++--- .../HidConsole/HidConsoleDevice.cs | 8 +- .../HidConsole/HidConsoleListener.cs | 22 ++--- .../HidConsole/HidConsoleWindow.cs | 8 +- .../QMK Toolbox/KeyTester/KeyTesterWindow.cs | 2 +- windows/QMK Toolbox/MainWindow.cs | 11 +-- .../QMK Toolbox/MicrocontrollerSelector.cs | 2 +- windows/QMK Toolbox/Program.cs | 10 +-- .../Usb/Bootloader/BootloaderDevice.cs | 19 ++--- windows/QMK Toolbox/Usb/UsbDevice.cs | 2 +- windows/QMK Toolbox/Usb/UsbListener.cs | 31 +++---- 15 files changed, 60 insertions(+), 174 deletions(-) diff --git a/windows/QMK Toolbox/AboutBox.cs b/windows/QMK Toolbox/AboutBox.cs index 8708738d47..4b641842ae 100644 --- a/windows/QMK Toolbox/AboutBox.cs +++ b/windows/QMK Toolbox/AboutBox.cs @@ -1,5 +1,4 @@ -using System.Reflection; -using System.Windows.Forms; +using System.Windows.Forms; namespace QMK_Toolbox { @@ -8,84 +7,9 @@ partial class AboutBox : Form public AboutBox() { InitializeComponent(); - versionLabel.Text = $"Version {AssemblyVersion}"; + versionLabel.Text = $"Version {Application.ProductVersion}"; } - #region Assembly Attribute Accessors - - public string AssemblyTitle - { - get - { - var attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); - if (attributes.Length > 0) - { - var titleAttribute = (AssemblyTitleAttribute)attributes[0]; - if (titleAttribute.Title != "") - { - return titleAttribute.Title; - } - } - return System.IO.Path.GetFileNameWithoutExtension(path: Assembly.GetExecutingAssembly().Location); - } - } - - public string AssemblyVersion => Application.ProductVersion; - - public string AssemblyDescription - { - get - { - var attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); - if (attributes.Length == 0) - { - return ""; - } - return ((AssemblyDescriptionAttribute)attributes[0]).Description; - } - } - - public string AssemblyProduct - { - get - { - var attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); - if (attributes.Length == 0) - { - return ""; - } - return ((AssemblyProductAttribute)attributes[0]).Product; - } - } - - public string AssemblyCopyright - { - get - { - var attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); - if (attributes.Length == 0) - { - return ""; - } - return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; - } - } - - public string AssemblyCompany - { - get - { - var attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); - if (attributes.Length == 0) - { - return ""; - } - return ((AssemblyCompanyAttribute)attributes[0]).Company; - } - } - - #endregion Assembly Attribute Accessors - private void GithubLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start(githubLink.Text); diff --git a/windows/QMK Toolbox/BetterComboBox.cs b/windows/QMK Toolbox/BetterComboBox.cs index e1b8d58a4b..d810614174 100644 --- a/windows/QMK Toolbox/BetterComboBox.cs +++ b/windows/QMK Toolbox/BetterComboBox.cs @@ -9,7 +9,9 @@ public override string Text get { if (Items.Count == 0 && SelectedIndex > -1) + { SelectedIndex = -1; + } return base.Text; } set => base.Text = value; diff --git a/windows/QMK Toolbox/BindableToolStripMenuItem.cs b/windows/QMK Toolbox/BindableToolStripMenuItem.cs index c9dc052900..292d24f6a8 100644 --- a/windows/QMK Toolbox/BindableToolStripMenuItem.cs +++ b/windows/QMK Toolbox/BindableToolStripMenuItem.cs @@ -13,10 +13,7 @@ public BindingContext BindingContext { get { - if (_bindingContext == null) - { - _bindingContext = new BindingContext(); - } + _bindingContext ??= new BindingContext(); return _bindingContext; } set @@ -32,10 +29,7 @@ public ControlBindingsCollection DataBindings { get { - if (_dataBindings == null) - { - _dataBindings = new ControlBindingsCollection(this); - } + _dataBindings ??= new ControlBindingsCollection(this); return _dataBindings; } } diff --git a/windows/QMK Toolbox/ComboBoxPlaceholder.cs b/windows/QMK Toolbox/ComboBoxPlaceholder.cs index 17de9ce1ac..bb6ec716d8 100644 --- a/windows/QMK Toolbox/ComboBoxPlaceholder.cs +++ b/windows/QMK Toolbox/ComboBoxPlaceholder.cs @@ -9,7 +9,7 @@ public class ComboBoxPlaceholder : ComboBox { private const uint CB_SETCUEBANNER = 0x1703; - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] + [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = false)] private static extern IntPtr SendMessage(HandleRef hWnd, uint msg, IntPtr wParam, string lParam); private string _placeholderText = string.Empty; @@ -26,10 +26,7 @@ public string PlaceholderText get { return _placeholderText; } set { - if (value == null) - { - value = string.Empty; - } + value ??= string.Empty; if (!_placeholderText.Equals(value, StringComparison.CurrentCulture)) { diff --git a/windows/QMK Toolbox/Helpers/EmbeddedResourceHelper.cs b/windows/QMK Toolbox/Helpers/EmbeddedResourceHelper.cs index 360d8c530c..17eb0af05f 100644 --- a/windows/QMK Toolbox/Helpers/EmbeddedResourceHelper.cs +++ b/windows/QMK Toolbox/Helpers/EmbeddedResourceHelper.cs @@ -34,13 +34,9 @@ public static void ExtractResource(string file) if (!File.Exists(destPath)) { - using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"QMK_Toolbox.Resources.{file}")) - { - using (var filestream = new FileStream(destPath, FileMode.Create)) - { - stream?.CopyTo(filestream); - } - } + using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"QMK_Toolbox.Resources.{file}"); + using var filestream = new FileStream(destPath, FileMode.Create); + stream?.CopyTo(filestream); } } @@ -55,13 +51,9 @@ public static void ExtractResources(IEnumerable files) public static string GetResourceContent(string file) { - using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"QMK_Toolbox.Resources.{file}")) - { - using (StreamReader reader = new StreamReader(stream)) - { - return reader.ReadToEnd(); - } - } + using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"QMK_Toolbox.Resources.{file}"); + using StreamReader reader = new(stream); + return reader.ReadToEnd(); } } } diff --git a/windows/QMK Toolbox/HidConsole/HidConsoleDevice.cs b/windows/QMK Toolbox/HidConsole/HidConsoleDevice.cs index d82da18ef5..d4a8c395ab 100644 --- a/windows/QMK Toolbox/HidConsole/HidConsoleDevice.cs +++ b/windows/QMK Toolbox/HidConsole/HidConsoleDevice.cs @@ -64,8 +64,8 @@ private void HidDeviceReportEvent(HidReport report) while (lineEnd >= 0) { // Fire delegate with completed lines until we have none left - string completedLine = currentLine.Substring(0, lineEnd); - currentLine = currentLine.Substring(lineEnd + 1); + string completedLine = currentLine[..lineEnd]; + currentLine = currentLine[(lineEnd + 1)..]; lineEnd = currentLine.IndexOf('\n'); consoleReportReceived?.Invoke(this, completedLine); } @@ -80,7 +80,7 @@ private static string GetManufacturerString(IHidDevice d) if (d == null) return ""; d.ReadManufacturer(out var bs); - return System.Text.Encoding.Default.GetString(bs.Where(b => b > 0).ToArray()); + return Encoding.Default.GetString(bs.Where(b => b > 0).ToArray()); } private static string GetProductString(IHidDevice d) @@ -88,7 +88,7 @@ private static string GetProductString(IHidDevice d) if (d == null) return ""; d.ReadProduct(out var bs); - return System.Text.Encoding.Default.GetString(bs.Where(b => b > 0).ToArray()); + return Encoding.Default.GetString(bs.Where(b => b > 0).ToArray()); } } } diff --git a/windows/QMK Toolbox/HidConsole/HidConsoleListener.cs b/windows/QMK Toolbox/HidConsole/HidConsoleListener.cs index 0007af2987..c00dadf442 100644 --- a/windows/QMK Toolbox/HidConsole/HidConsoleListener.cs +++ b/windows/QMK Toolbox/HidConsole/HidConsoleListener.cs @@ -36,7 +36,7 @@ private void EnumerateHidDevices(bool connected) if (device != null && !listed) { - HidConsoleDevice consoleDevice = new HidConsoleDevice(device) + HidConsoleDevice consoleDevice = new(device) { consoleReportReceived = HidConsoleReportReceived }; @@ -73,14 +73,14 @@ public void HidConsoleReportReceived(HidConsoleDevice device, string data) private ManagementEventWatcher deviceConnectedWatcher; private ManagementEventWatcher deviceDisconnectedWatcher; - private ManagementEventWatcher CreateManagementEventWatcher(string eventType) + private static ManagementEventWatcher CreateManagementEventWatcher(string eventType) { return new ManagementEventWatcher($"SELECT * FROM {eventType} WITHIN 2 WHERE TargetInstance ISA 'Win32_PnPEntity' AND TargetInstance.DeviceID LIKE 'HID%'"); } private void HidDeviceWmiEvent(object sender, EventArrivedEventArgs e) { - if (!(e.NewEvent["TargetInstance"] is ManagementBaseObject _)) + if (e.NewEvent["TargetInstance"] is not ManagementBaseObject _) { return; } @@ -92,23 +92,14 @@ private void HidDeviceWmiEvent(object sender, EventArrivedEventArgs e) public void Start() { - if (Devices == null) - { - Devices = new List(); - } + Devices ??= new List(); EnumerateHidDevices(true); - if (deviceConnectedWatcher == null) - { - deviceConnectedWatcher = CreateManagementEventWatcher("__InstanceCreationEvent"); - } + deviceConnectedWatcher ??= CreateManagementEventWatcher("__InstanceCreationEvent"); deviceConnectedWatcher.EventArrived += HidDeviceWmiEvent; deviceConnectedWatcher.Start(); - if (deviceDisconnectedWatcher == null) - { - deviceDisconnectedWatcher = CreateManagementEventWatcher("__InstanceDeletionEvent"); - } + deviceDisconnectedWatcher ??= CreateManagementEventWatcher("__InstanceDeletionEvent"); deviceDisconnectedWatcher.EventArrived += HidDeviceWmiEvent; deviceDisconnectedWatcher.Start(); } @@ -133,6 +124,7 @@ public void Dispose() Stop(); deviceConnectedWatcher?.Dispose(); deviceDisconnectedWatcher?.Dispose(); + GC.SuppressFinalize(this); } } } diff --git a/windows/QMK Toolbox/HidConsole/HidConsoleWindow.cs b/windows/QMK Toolbox/HidConsole/HidConsoleWindow.cs index 50d45c55ee..bf3e5cb5d9 100644 --- a/windows/QMK Toolbox/HidConsole/HidConsoleWindow.cs +++ b/windows/QMK Toolbox/HidConsole/HidConsoleWindow.cs @@ -40,7 +40,7 @@ private void HidConsoleWindow_FormClosing(object sender, FormClosingEventArgs e) #endregion #region HID Console - private readonly HidConsoleListener consoleListener = new HidConsoleListener(); + private readonly HidConsoleListener consoleListener = new(); private HidConsoleDevice lastReportedDevice; @@ -105,9 +105,9 @@ private void UpdateConsoleList() #region Log Box private void LogContextMenuStrip_Opening(object sender, CancelEventArgs e) { - copyToolStripMenuItem.Enabled = (logTextBox.SelectedText.Length > 0); - selectAllToolStripMenuItem.Enabled = (logTextBox.Text.Length > 0); - clearToolStripMenuItem.Enabled = (logTextBox.Text.Length > 0); + copyToolStripMenuItem.Enabled = logTextBox.SelectedText.Length > 0; + selectAllToolStripMenuItem.Enabled = logTextBox.Text.Length > 0; + clearToolStripMenuItem.Enabled = logTextBox.Text.Length > 0; } private void CopyToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/windows/QMK Toolbox/KeyTester/KeyTesterWindow.cs b/windows/QMK Toolbox/KeyTester/KeyTesterWindow.cs index f6a63ada28..bd51d72e9b 100644 --- a/windows/QMK Toolbox/KeyTester/KeyTesterWindow.cs +++ b/windows/QMK Toolbox/KeyTester/KeyTesterWindow.cs @@ -171,7 +171,7 @@ protected override bool ProcessKeyMessage(ref Message m) if (pressedKeyControl != null) { - pressedKeyControl.Pressed = (m.Msg == WM_KEYDOWN || m.Msg == WM_SYSKEYDOWN); + pressedKeyControl.Pressed = m.Msg == WM_KEYDOWN || m.Msg == WM_SYSKEYDOWN; pressedKeyControl.Tested = true; } diff --git a/windows/QMK Toolbox/MainWindow.cs b/windows/QMK Toolbox/MainWindow.cs index b0697ccdc5..482c99f795 100644 --- a/windows/QMK Toolbox/MainWindow.cs +++ b/windows/QMK Toolbox/MainWindow.cs @@ -11,17 +11,14 @@ using System.ComponentModel; using System.IO; using System.Linq; -using System.Net; using System.Net.Http; -using System.Net.Http.Headers; -using System.Security.Permissions; using System.Windows.Forms; namespace QMK_Toolbox { public partial class MainWindow : Form { - private readonly WindowState windowState = new WindowState(); + private readonly WindowState windowState = new(); private readonly string _filePassedIn = string.Empty; @@ -174,7 +171,7 @@ private void MainWindow_FormClosed(object sender, FormClosedEventArgs e) #endregion Window Events #region USB Devices & Bootloaders - private readonly UsbListener usbListener = new UsbListener(); + private readonly UsbListener usbListener = new(); private void BootloaderDeviceConnected(BootloaderDevice device) { @@ -414,7 +411,7 @@ private void SetFilePath(string filepath) { if (filepath.StartsWith("qmk:")) { - string unwrappedUrl = filepath.Substring(filepath.StartsWith("qmk://") ? 6 : 4); + string unwrappedUrl = filepath[(filepath.StartsWith("qmk://") ? 6 : 4)..]; DownloadFile(unwrappedUrl); } else @@ -439,7 +436,7 @@ private async void DownloadFile(string url) try { - string destFile = Path.Combine(KnownFolders.Downloads.Path, url.Substring(url.LastIndexOf("/") + 1)); + string destFile = Path.Combine(KnownFolders.Downloads.Path, url[(url.LastIndexOf("/") + 1)..]); var client = new HttpClient(); client.DefaultRequestHeaders.UserAgent.ParseAdd("QMK Toolbox"); diff --git a/windows/QMK Toolbox/MicrocontrollerSelector.cs b/windows/QMK Toolbox/MicrocontrollerSelector.cs index 4c71e4a8ce..920f414d0d 100644 --- a/windows/QMK Toolbox/MicrocontrollerSelector.cs +++ b/windows/QMK Toolbox/MicrocontrollerSelector.cs @@ -13,7 +13,7 @@ protected override void OnHandleCreated(EventArgs e) if (!DesignMode) { - List> microcontrollerDataSource = new List>(); + List> microcontrollerDataSource = new(); string[] microcontrollers = EmbeddedResourceHelper.GetResourceContent("mcu-list.txt").Split('\n'); foreach (string microcontroller in microcontrollers) diff --git a/windows/QMK Toolbox/Program.cs b/windows/QMK Toolbox/Program.cs index 220c7b3a9d..6da04fa2a5 100644 --- a/windows/QMK Toolbox/Program.cs +++ b/windows/QMK Toolbox/Program.cs @@ -13,7 +13,7 @@ internal static class Program /// /// - private static readonly Mutex Mutex = new Mutex(true, "{8F7F0AC4-B9A1-45fd-A8CF-72F04E6BDE8F}"); + private static readonly Mutex Mutex = new(true, "{8F7F0AC4-B9A1-45fd-A8CF-72F04E6BDE8F}"); [STAThread] private static void Main(string[] args) @@ -37,10 +37,8 @@ private static void Main(string[] args) // jump on top of all the other windows if (args.Length > 0) { - using (var sw = new StreamWriter(Path.Combine(Path.GetTempPath(), "qmk_toolbox_file.txt"))) - { - sw.WriteLine(args[0]); - } + using var sw = new StreamWriter(Path.Combine(Path.GetTempPath(), "qmk_toolbox_file.txt")); + sw.WriteLine(args[0]); } NativeMethods.PostMessage( (IntPtr)NativeMethods.HwndBroadcast, @@ -60,7 +58,7 @@ internal class NativeMethods [DllImport("user32")] public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam); - [DllImport("user32")] + [DllImport("user32", CharSet = CharSet.Unicode)] public static extern int RegisterWindowMessage(string message); } } diff --git a/windows/QMK Toolbox/Usb/Bootloader/BootloaderDevice.cs b/windows/QMK Toolbox/Usb/Bootloader/BootloaderDevice.cs index c275c7e91c..96fbc1e935 100644 --- a/windows/QMK Toolbox/Usb/Bootloader/BootloaderDevice.cs +++ b/windows/QMK Toolbox/Usb/Bootloader/BootloaderDevice.cs @@ -2,7 +2,6 @@ using System.Diagnostics; using System.IO; using System.Management; -using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -63,7 +62,7 @@ protected async Task RunProcessAsync(string command, string args) { PrintMessage($"{command} {args}", MessageType.Command); - using (var process = new Process + using var process = new Process { StartInfo = { @@ -76,10 +75,8 @@ protected async Task RunProcessAsync(string command, string args) RedirectStandardError = true }, EnableRaisingEvents = true - }) - { - return await RunProcessAsync(process).ConfigureAwait(false); - } + }; + return await RunProcessAsync(process).ConfigureAwait(false); } private Task RunProcessAsync(Process process) @@ -130,14 +127,12 @@ protected void PrintMessage(string message, MessageType type) protected string FindComPort() { - using (var searcher = new ManagementObjectSearcher("SELECT PNPDeviceID, DeviceID FROM Win32_SerialPort")) + using var searcher = new ManagementObjectSearcher("SELECT PNPDeviceID, DeviceID FROM Win32_SerialPort"); + foreach (var device in searcher.Get()) { - foreach (var device in searcher.Get()) + if (device.GetPropertyValue("PNPDeviceID").ToString().Equals(WmiDevice.GetPropertyValue("PNPDeviceID").ToString())) { - if (device.GetPropertyValue("PNPDeviceID").ToString().Equals(WmiDevice.GetPropertyValue("PNPDeviceID").ToString())) - { - return device.GetPropertyValue("DeviceID").ToString(); - } + return device.GetPropertyValue("DeviceID").ToString(); } } diff --git a/windows/QMK Toolbox/Usb/UsbDevice.cs b/windows/QMK Toolbox/Usb/UsbDevice.cs index 6cb3b3f063..ac911c60c5 100644 --- a/windows/QMK Toolbox/Usb/UsbDevice.cs +++ b/windows/QMK Toolbox/Usb/UsbDevice.cs @@ -6,7 +6,7 @@ namespace QMK_Toolbox.Usb { public class UsbDevice : IUsbDevice { - private static readonly Regex HardwareIdTripletRegex = new Regex(@"USB\\VID_([0-9A-F]{4})&PID_([0-9A-F]{4})&REV_([0-9A-F]{4}).*"); + private static readonly Regex HardwareIdTripletRegex = new(@"USB\\VID_([0-9A-F]{4})&PID_([0-9A-F]{4})&REV_([0-9A-F]{4}).*"); public ManagementBaseObject WmiDevice { get; } diff --git a/windows/QMK Toolbox/Usb/UsbListener.cs b/windows/QMK Toolbox/Usb/UsbListener.cs index 29ea045567..70cd4f9512 100644 --- a/windows/QMK Toolbox/Usb/UsbListener.cs +++ b/windows/QMK Toolbox/Usb/UsbListener.cs @@ -1,4 +1,5 @@ using QMK_Toolbox.Usb.Bootloader; +using System; using System.Collections.Generic; using System.Linq; using System.Management; @@ -6,9 +7,9 @@ namespace QMK_Toolbox.Usb { - public class UsbListener + public class UsbListener: IDisposable { - private static readonly Regex UsbIdRegex = new Regex(@"USB\\VID_([0-9A-F]{4})&PID_([0-9A-F]{4})&REV_([0-9A-F]{4})"); + private static readonly Regex UsbIdRegex = new(@"USB\\VID_([0-9A-F]{4})&PID_([0-9A-F]{4})&REV_([0-9A-F]{4})"); public List Devices { get; private set; } @@ -85,14 +86,14 @@ private void FlashOutputReceived(BootloaderDevice device, string data, MessageTy private ManagementEventWatcher deviceConnectedWatcher; private ManagementEventWatcher deviceDisconnectedWatcher; - private ManagementEventWatcher CreateManagementEventWatcher(string eventType) + private static ManagementEventWatcher CreateManagementEventWatcher(string eventType) { return new ManagementEventWatcher($"SELECT * FROM {eventType} WITHIN 2 WHERE TargetInstance ISA 'Win32_PnPEntity' AND TargetInstance.DeviceID LIKE 'USB%'"); } private void UsbDeviceWmiEvent(object sender, EventArrivedEventArgs e) { - if (!(e.NewEvent["TargetInstance"] is ManagementBaseObject _)) + if (e.NewEvent["TargetInstance"] is not ManagementBaseObject _) { return; } @@ -104,23 +105,14 @@ private void UsbDeviceWmiEvent(object sender, EventArrivedEventArgs e) public void Start() { - if (Devices == null) - { - Devices = new List(); - } + Devices ??= new List(); EnumerateUsbDevices(true); - if (deviceConnectedWatcher == null) - { - deviceConnectedWatcher = CreateManagementEventWatcher("__InstanceCreationEvent"); - } + deviceConnectedWatcher ??= CreateManagementEventWatcher("__InstanceCreationEvent"); deviceConnectedWatcher.EventArrived += UsbDeviceWmiEvent; deviceConnectedWatcher.Start(); - if (deviceDisconnectedWatcher == null) - { - deviceDisconnectedWatcher = CreateManagementEventWatcher("__InstanceDeletionEvent"); - } + deviceDisconnectedWatcher ??= CreateManagementEventWatcher("__InstanceDeletionEvent"); deviceDisconnectedWatcher.EventArrived += UsbDeviceWmiEvent; deviceDisconnectedWatcher.Start(); } @@ -145,11 +137,12 @@ public void Dispose() Stop(); deviceConnectedWatcher?.Dispose(); deviceDisconnectedWatcher?.Dispose(); + GC.SuppressFinalize(this); } private static IUsbDevice CreateDevice(ManagementBaseObject d) { - UsbDevice usbDevice = new UsbDevice(d); + UsbDevice usbDevice = new(d); switch (GetDeviceType(usbDevice.VendorId, usbDevice.ProductId, usbDevice.RevisionBcd)) { @@ -171,7 +164,7 @@ private static IUsbDevice CreateDevice(ManagementBaseObject d) case BootloaderType.HalfKay: return new HalfKayDevice(usbDevice); case BootloaderType.KiibohdDfu: - return new KiibohdDfuDevice(usbDevice); + return new KiibohdDfuDevice(usbDevice); case BootloaderType.LufaHid: case BootloaderType.QmkHid: return new LufaHidDevice(usbDevice); @@ -187,6 +180,8 @@ private static IUsbDevice CreateDevice(ManagementBaseObject d) return new UsbTinyIspDevice(usbDevice); case BootloaderType.Wb32Dfu: return new Wb32DfuDevice(usbDevice); + default: + break; } return usbDevice; From d74771d483c9d1555b7d19e4950df936625955ef Mon Sep 17 00:00:00 2001 From: fauxpark Date: Thu, 14 Sep 2023 17:40:35 +1000 Subject: [PATCH 5/5] Don't append target framework to output path --- .github/workflows/build.yml | 2 +- windows/QMK Toolbox/QMK Toolbox.csproj | 1 + windows/install_compiler.iss | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 931f0e5440..6f94f78ea5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: - uses: actions/upload-artifact@v3 with: name: qmk_toolbox.exe - path: windows/QMK Toolbox/bin/Release/net6.0-windows10.0.19041.0/qmk_toolbox.exe + path: windows/QMK Toolbox/bin/Release/qmk_toolbox.exe - uses: actions/upload-artifact@v3 with: diff --git a/windows/QMK Toolbox/QMK Toolbox.csproj b/windows/QMK Toolbox/QMK Toolbox.csproj index 3236032e7d..ab2f8a04d4 100644 --- a/windows/QMK Toolbox/QMK Toolbox.csproj +++ b/windows/QMK Toolbox/QMK Toolbox.csproj @@ -6,6 +6,7 @@ true true true + false Resources\output.ico diff --git a/windows/install_compiler.iss b/windows/install_compiler.iss index cbe3b7a30b..a342664939 100644 --- a/windows/install_compiler.iss +++ b/windows/install_compiler.iss @@ -38,7 +38,7 @@ Name: "english"; MessagesFile: "compiler:Default.isl" Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}" [Files] -Source: "QMK Toolbox\bin\Release\net6.0-windows10.0.19041.0\qmk_toolbox.exe"; DestDir: "{app}"; Flags: ignoreversion +Source: "QMK Toolbox\bin\Release\qmk_toolbox.exe"; DestDir: "{app}"; Flags: ignoreversion ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons]