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] Improve embedded resource extraction behaviour #478

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions windows/QMK Toolbox/Helpers/DriverInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public static bool DisplayPrompt()

private static bool InstallDrivers()
{
var driversPath = Path.Combine(Application.LocalUserAppDataPath, DriversListFilename);
var installerPath = Path.Combine(Application.LocalUserAppDataPath, InstallerFilename);
string toolboxData = EmbeddedResourceHelper.GetResourceFolder();
string driversPath = Path.Combine(toolboxData, DriversListFilename);
string installerPath = Path.Combine(toolboxData, InstallerFilename);

if (!File.Exists(driversPath))
{
Expand Down
23 changes: 20 additions & 3 deletions windows/QMK Toolbox/Helpers/EmbeddedResourceHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace QMK_Toolbox.Helpers
{
Expand All @@ -28,9 +28,26 @@ public static class EmbeddedResourceHelper
"libwinpthread-1.dll"
};

public static string GetResourceFolder()
{
string programData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
return Path.Combine(programData, "QMK Toolbox");
}

public static void InitResourceFolder()
{
string toolboxData = GetResourceFolder();
if (Directory.Exists(toolboxData))
{
Directory.Delete(toolboxData, true);
Directory.CreateDirectory(toolboxData);
}
ExtractResources(Resources);
}

public static void ExtractResource(string file)
{
var destPath = Path.Combine(Application.LocalUserAppDataPath, file);
string destPath = Path.Combine(GetResourceFolder(), file);

if (!File.Exists(destPath))
{
Expand Down
11 changes: 10 additions & 1 deletion windows/QMK Toolbox/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions windows/QMK Toolbox/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ private void MainWindow_Load(object sender, EventArgs e)

mcuBox.SelectedValue = Settings.Default.targetSetting;

EmbeddedResourceHelper.ExtractResources(EmbeddedResourceHelper.Resources);

logTextBox.LogInfo($"QMK Toolbox {Application.ProductVersion} (https://qmk.fm/toolbox)");
logTextBox.LogInfo("Supported bootloaders:");
logTextBox.LogInfo(" - ARM DFU (APM32, Kiibohd, STM32, STM32duino) and RISC-V DFU (GD32V) via dfu-util (http://dfu-util.sourceforge.net/)");
Expand Down Expand Up @@ -105,6 +103,7 @@ private void MainWindow_Shown(object sender, EventArgs e)
{
if (Settings.Default.firstStart)
{
EmbeddedResourceHelper.InitResourceFolder();
Settings.Default.Upgrade();
}

Expand Down Expand Up @@ -507,6 +506,11 @@ private void InstallDriversMenuItem_Click(object sender, EventArgs e)
DriverInstaller.DisplayPrompt();
}

private void ClearResourcesMenuItem_Click(object sender, EventArgs e)
{
EmbeddedResourceHelper.InitResourceFolder();
}

private void KeyTesterToolStripMenuItem_Click(object sender, EventArgs e)
{
KeyTesterWindow.GetInstance().Show(this);
Expand Down
9 changes: 5 additions & 4 deletions windows/QMK Toolbox/Usb/Bootloader/BootloaderDevice.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using QMK_Toolbox.Helpers;
using System;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QMK_Toolbox.Usb.Bootloader
{
Expand Down Expand Up @@ -61,14 +61,15 @@ public virtual Task Reset(string mcu)
protected async Task<int> RunProcessAsync(string command, string args)
{
PrintMessage($"{command} {args}", MessageType.Command);
string toolboxData = EmbeddedResourceHelper.GetResourceFolder();

using var process = new Process
{
StartInfo =
{
FileName = Path.Combine(Application.LocalUserAppDataPath, command),
FileName = Path.Combine(toolboxData, command),
Arguments = args,
WorkingDirectory = Application.LocalUserAppDataPath,
WorkingDirectory = toolboxData,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
Expand Down
Loading