From 80060d8e8f98742916a99151937ad48d5325eac7 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Thu, 28 Apr 2022 21:30:47 +1000 Subject: [PATCH] [Windows] Fix bug in SetFilePath() --- windows/QMK Toolbox/MainWindow.cs | 50 ++++++++++++++----------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/windows/QMK Toolbox/MainWindow.cs b/windows/QMK Toolbox/MainWindow.cs index e09b3519d3..c05c64284a 100644 --- a/windows/QMK Toolbox/MainWindow.cs +++ b/windows/QMK Toolbox/MainWindow.cs @@ -445,45 +445,41 @@ private void FilepathBox_KeyDown(object sender, KeyEventArgs e) private void SetFilePath(string filepath) { - if (!filepath.StartsWith("\\\\wsl$")) + if (!string.IsNullOrEmpty(filepath)) { - var uri = new Uri(filepath); - if (uri.Scheme == "qmk") + if (!filepath.StartsWith("\\\\wsl$")) { - string url; - url = filepath.Replace(filepath.Contains("qmk://") ? "qmk://" : "qmk:", ""); - filepath = Path.Combine(KnownFolders.Downloads.Path, filepath.Substring(filepath.LastIndexOf("/") + 1).Replace(".", "_" + Guid.NewGuid().ToString().Substring(0, 8) + ".")); - - try - { - logTextBox.LogInfo($"Downloading the file: {url}"); - DownloadFirmwareFile(url, filepath); - } - catch (Exception) + var uri = new Uri(filepath); + if (uri.Scheme == "qmk") { + string url = filepath.Replace(filepath.Contains("qmk://") ? "qmk://" : "qmk:", ""); + filepath = Path.Combine(KnownFolders.Downloads.Path, filepath.Substring(filepath.LastIndexOf("/") + 1).Replace(".", "_" + Guid.NewGuid().ToString().Substring(0, 8) + ".")); + try { - // Try .bin extension if hex 404'd - url = Path.ChangeExtension(url, "bin"); - filepath = Path.ChangeExtension(filepath, "bin"); - logTextBox.LogInfo($"No .hex file found, trying {url}"); + logTextBox.LogInfo($"Downloading the file: {url}"); DownloadFirmwareFile(url, filepath); } catch (Exception) { - logTextBox.LogError("Something went wrong when trying to get the default keymap file."); - return; + try + { + // Try .bin extension if hex 404'd + url = Path.ChangeExtension(url, "bin"); + filepath = Path.ChangeExtension(filepath, "bin"); + logTextBox.LogInfo($"No .hex file found, trying {url}"); + DownloadFirmwareFile(url, filepath); + } + catch (Exception) + { + logTextBox.LogError("Something went wrong when trying to get the default keymap file."); + return; + } } + logTextBox.LogInfo($"File saved to: {filepath}"); } - logTextBox.LogInfo($"File saved to: {filepath}"); - } - } - else - { - if (string.IsNullOrEmpty(filepath)) - { - return; } + filepathBox.Text = filepath; if (!filepathBox.Items.Contains(filepath)) {