Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Upgrade to .NET 6 #421

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions windows/QMK Toolbox.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31424.327
# Visual Studio Version 17
VisualStudioVersion = 17.7.34024.191
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
Expand All @@ -19,4 +18,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {081E0F05-87B8-4176-B803-07A8DA0C4A5C}
EndGlobalSection
EndGlobal
80 changes: 2 additions & 78 deletions windows/QMK Toolbox/AboutBox.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Windows.Forms;
using System.Windows.Forms;

namespace QMK_Toolbox
{
Expand All @@ -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(Assembly.GetExecutingAssembly().CodeBase);
}
}

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);
Expand Down
3 changes: 0 additions & 3 deletions windows/QMK Toolbox/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,4 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<System.Windows.Forms.ApplicationConfigurationSection>
<add key="DpiAwareness" value="PerMonitorV2" />
</System.Windows.Forms.ApplicationConfigurationSection>
</configuration>
2 changes: 2 additions & 0 deletions windows/QMK Toolbox/BetterComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public override string Text
get
{
if (Items.Count == 0 && SelectedIndex > -1)
{
SelectedIndex = -1;
}
return base.Text;
}
set => base.Text = value;
Expand Down
10 changes: 2 additions & 8 deletions windows/QMK Toolbox/BindableToolStripMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ public BindingContext BindingContext
{
get
{
if (_bindingContext == null)
{
_bindingContext = new BindingContext();
}
_bindingContext ??= new BindingContext();
return _bindingContext;
}
set
Expand All @@ -32,10 +29,7 @@ public ControlBindingsCollection DataBindings
{
get
{
if (_dataBindings == null)
{
_dataBindings = new ControlBindingsCollection(this);
}
_dataBindings ??= new ControlBindingsCollection(this);
return _dataBindings;
}
}
Expand Down
7 changes: 2 additions & 5 deletions windows/QMK Toolbox/ComboBoxPlaceholder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
{
Expand Down
30 changes: 30 additions & 0 deletions windows/QMK Toolbox/FodyWeavers.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
Expand All @@ -43,6 +53,16 @@
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeRuntimeReferences" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if runtime assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseRuntimeReferencePaths" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls whether the runtime assemblies are embedded with their full path or only with their assembly name.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCompression" type="xs:boolean">
<xs:annotation>
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
Expand Down Expand Up @@ -73,6 +93,16 @@
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
Expand Down
20 changes: 6 additions & 14 deletions windows/QMK Toolbox/Helpers/EmbeddedResourceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -55,13 +51,9 @@ public static void ExtractResources(IEnumerable<string> 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();
}
}
}
8 changes: 4 additions & 4 deletions windows/QMK Toolbox/HidConsole/HidConsoleDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -80,15 +80,15 @@ 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)
{
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());
}
}
}
22 changes: 7 additions & 15 deletions windows/QMK Toolbox/HidConsole/HidConsoleListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private void EnumerateHidDevices(bool connected)

if (device != null && !listed)
{
HidConsoleDevice consoleDevice = new HidConsoleDevice(device)
HidConsoleDevice consoleDevice = new(device)
{
consoleReportReceived = HidConsoleReportReceived
};
Expand Down Expand Up @@ -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;
}
Expand All @@ -92,23 +92,14 @@ private void HidDeviceWmiEvent(object sender, EventArrivedEventArgs e)

public void Start()
{
if (Devices == null)
{
Devices = new List<HidConsoleDevice>();
}
Devices ??= new List<HidConsoleDevice>();
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();
}
Expand All @@ -133,6 +124,7 @@ public void Dispose()
Stop();
deviceConnectedWatcher?.Dispose();
deviceDisconnectedWatcher?.Dispose();
GC.SuppressFinalize(this);
}
}
}
8 changes: 4 additions & 4 deletions windows/QMK Toolbox/HidConsole/HidConsoleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions windows/QMK Toolbox/KeyTester/KeyTesterWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ 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)
{
pressedKeyControl.Pressed = (m.Msg == WM_KEYDOWN || m.Msg == WM_SYSKEYDOWN);
pressedKeyControl.Pressed = m.Msg == WM_KEYDOWN || m.Msg == WM_SYSKEYDOWN;
pressedKeyControl.Tested = true;
}

Expand Down
Loading