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] Fix bug in SetFilePath() #356

Merged
merged 1 commit into from
Apr 28, 2022
Merged
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
50 changes: 23 additions & 27 deletions windows/QMK Toolbox/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down