Skip to content
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 WheelWizard.Test/Features/GameBananaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private GameBananaModPreview CreateFakeModPreview(int id)
IconUrl = "",
},
ModelName = "Mod",
PreviewMedia = new()
PreviewMedia = new(),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static IServiceCollection AddAutoUpdating(this IServiceCollection service
implementationType = typeof(WindowsUpdatePlatform);
#elif LINUX
// We can enable this again once the auto updater has been fixed and tested
// implementationType = typeof(LinuxUpdatePlatform);
implementationType = typeof(LinuxUpdatePlatform);
#elif MACOS
// MacOS updater
#endif
Expand Down
1 change: 1 addition & 0 deletions WheelWizard/Features/AutoUpdating/Platforms/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LinuxUpdatePlatform.cs text eol=lf
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ private OperationResult CreateAndRunShellScript(string currentFilePath, string n
sleep 1

echo 'Replacing old executable...'
rm -f "{fileSystem.Path.Combine(currentFolder, originalFileName)}"
mv "{fileSystem.Path.Combine(currentFolder, newFileName)}" "{fileSystem.Path.Combine(currentFolder, originalFileName)}"
chmod +x "{fileSystem.Path.Combine(currentFolder, originalFileName)}"
rm -f {EnvHelper.SingleQuotePath(fileSystem.Path.Combine(currentFolder, originalFileName))}
mv {EnvHelper.SingleQuotePath(fileSystem.Path.Combine(currentFolder, newFileName))} {EnvHelper.SingleQuotePath(
fileSystem.Path.Combine(currentFolder, originalFileName)
)}
chmod +x {EnvHelper.SingleQuotePath(fileSystem.Path.Combine(currentFolder, originalFileName))}

echo 'Starting the updated application...'
nohup "{fileSystem.Path.Combine(currentFolder, originalFileName)}" > /dev/null 2>&1 &
nohup {EnvHelper.SingleQuotePath(fileSystem.Path.Combine(currentFolder, originalFileName))} > /dev/null 2>&1 &

echo 'Cleaning up...'
rm -- "{scriptFilePath}"
rm -- {EnvHelper.SingleQuotePath(scriptFilePath)}

echo 'Update completed successfully.'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private OperationResult CreateAndRunPowerShellScript(string currentFilePath, str
Write-Output 'Starting update process...'

# Wait for the original application to exit
while (Get-Process -Name '{{fileSystem.Path.GetFileNameWithoutExtension(originalFileName)}}' -ErrorAction SilentlyContinue) {
while (Get-Process -Name {{EnvHelper.SingleQuotePath(fileSystem.Path.GetFileNameWithoutExtension(originalFileName))}} -ErrorAction SilentlyContinue) {
Write-Output 'Waiting for {{originalFileName}} to exit...'
Start-Sleep -Seconds 1
}
Expand All @@ -129,7 +129,7 @@ private OperationResult CreateAndRunPowerShellScript(string currentFilePath, str

while (-not $deleted -and $retryCount -lt $maxRetries) {
try {
Remove-Item -Path '{{fileSystem.Path.Combine(currentFolder, originalFileName)}}' -Force -ErrorAction Stop
Remove-Item -Path {{EnvHelper.SingleQuotePath(fileSystem.Path.Combine(currentFolder, originalFileName))}} -Force -ErrorAction Stop
$deleted = $true
}
catch {
Expand All @@ -147,10 +147,10 @@ exit 1

Write-Output 'Renaming new executable...'
try {
Rename-Item -Path '{{fileSystem.Path.Combine(
Rename-Item -Path {{EnvHelper.SingleQuotePath(fileSystem.Path.Combine(
currentFolder,
newFileName
)}}' -NewName '{{originalFileName}}' -ErrorAction Stop
))}} -NewName {{EnvHelper.SingleQuotePath(originalFileName)}} -ErrorAction Stop
}
catch {
Write-Output 'Failed to rename {{newFileName}} to {{originalFileName}}. Update aborted.'
Expand All @@ -159,21 +159,21 @@ exit 1
}

Write-Output 'Starting the updated application...'
Start-Process -FilePath '{{fileSystem.Path.Combine(currentFolder, originalFileName)}}'
Start-Process -FilePath {{EnvHelper.SingleQuotePath(fileSystem.Path.Combine(currentFolder, originalFileName))}}

Write-Output 'Cleaning up...'
Remove-Item -Path '{{scriptFilePath}}' -Force
Remove-Item -Path {{EnvHelper.SingleQuotePath(scriptFilePath)}} -Force

Write-Output 'Update completed successfully.'

""";

fileSystem.File.WriteAllText(scriptFilePath, scriptContent);

var processStartInfo = new ProcessStartInfo
{
FileName = "powershell.exe",
Arguments = $"-NoProfile -ExecutionPolicy Bypass -File \"{scriptFilePath}\"",
ArgumentList = { "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", scriptFilePath },
CreateNoWindow = false,
UseShellExecute = false,
WorkingDirectory = currentFolder,
Expand Down
24 changes: 22 additions & 2 deletions WheelWizard/Helpers/EnvHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static bool IsValidUnixCommand(string command)
};

using var process = Process.Start(processInfo);
process.WaitForExit();
return process.ExitCode == 0;
process?.WaitForExit();
return process?.ExitCode == 0;
}
catch
{
Expand Down Expand Up @@ -57,4 +57,24 @@ public static bool IsRelativeLinuxPath(string path)
{
return IsRelativeLinuxPath(path) ? null : path;
}

public static string SingleQuotePath(string path)
{
if (OperatingSystem.IsWindows())
{
// PowerShell expects doubled single quotes inside the quoted string
return $"'{path.Replace("'", "''")}'";
}
return $"'{path.Replace("'", "'\\''")}'";
}

public static string QuotePath(string path)
{
if (OperatingSystem.IsWindows())
{
// Use double quotes outside of PowerShell
return $"\"{path}\"";
}
return SingleQuotePath(path);
}
}
4 changes: 2 additions & 2 deletions WheelWizard/Services/Launcher/Helpers/DolphinLaunchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void AddFilesystemPerm(string newFilesystemPerm, string mode = "")
var flatpakRunCommand = "flatpak run";
fixedFlatpakDolphinLocation = fixedFlatpakDolphinLocation.Replace(
flatpakRunCommand,
$"{flatpakRunCommand} --filesystem=\"{Path.GetFullPath(newFilesystemPerm)}\"{mode}"
$"{flatpakRunCommand} --filesystem={EnvHelper.SingleQuotePath(Path.GetFullPath(newFilesystemPerm))}{mode}"
);
}

Expand Down Expand Up @@ -127,7 +127,7 @@ public static void LaunchDolphin(string arguments = "", bool shellExecute = fals
var startInfo = new ProcessStartInfo();

var cannotPassUserFolder = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && PathManager.IsLinuxDolphinConfigSplit();
var userFolderArgument = cannotPassUserFolder ? "" : $"-u \"{Path.GetFullPath(PathManager.UserFolderPath)}\"";
var userFolderArgument = cannotPassUserFolder ? "" : $"-u {EnvHelper.QuotePath(Path.GetFullPath(PathManager.UserFolderPath))}";
var dolphinLaunchArguments = $"{arguments} {userFolderArgument}";

var dolphinLocation = (string)SettingsManager.DOLPHIN_LOCATION.Get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public static async Task LaunchMiiChannel()
}

if (miiChannelExists)
DolphinLaunchHelper.LaunchDolphin($"-b \"{Path.GetFullPath(MiiChannelPath)}\"");
DolphinLaunchHelper.LaunchDolphin($"-b {EnvHelper.QuotePath(Path.GetFullPath(MiiChannelPath))}");
}
}
2 changes: 1 addition & 1 deletion WheelWizard/Services/Launcher/RrLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task Launch()
RetroRewindLaunchHelper.GenerateLaunchJson();
var dolphinLaunchType = (bool)SettingsManager.LAUNCH_WITH_DOLPHIN.Get() ? "" : "-b";
DolphinLaunchHelper.LaunchDolphin(
$"{dolphinLaunchType} -e \"{Path.GetFullPath(RrLaunchJsonFilePath)}\" --config=Dolphin.Core.EnableCheats=False"
$"{dolphinLaunchType} -e {EnvHelper.QuotePath(Path.GetFullPath(RrLaunchJsonFilePath))} --config=Dolphin.Core.EnableCheats=False"
);
}
catch (Exception ex)
Expand Down
17 changes: 12 additions & 5 deletions WheelWizard/Services/Storage/FilePickerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,30 @@ public static async Task<List<string>> OpenMultipleFilesAsync(string title, IEnu

public static void OpenFolderInFileManager(string folderPath)
{
string? openExecutable;
if (OperatingSystem.IsWindows())
{
Process.Start("explorer.exe", folderPath);
openExecutable = "explorer.exe";
}
else if (OperatingSystem.IsLinux())
{
Process.Start("xdg-open", folderPath);
openExecutable = "xdg-open";
}
else if (OperatingSystem.IsMacOS())
{
// Ensures the ~/Library/Application Support/ folder is escaped properly
folderPath = $"\"{folderPath}\"";
Process.Start("open", folderPath);
openExecutable = "open";
}
else
{
throw new PlatformNotSupportedException("Unsupported operating system.");
}

var info = new ProcessStartInfo(openExecutable)
{
// Ensures the folder path is escaped properly
ArgumentList = { folderPath },
};

Process.Start(info);
}
}
12 changes: 2 additions & 10 deletions WheelWizard/Views/Pages/Settings/WhWzSettings.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,9 @@ private void AutoFillPaths()
DolphinUserPathInput.Text = folderPath;
}

private string WrapOnWhiteSpace(string inputText)
private void AssignWrappedDolphinExeInput(string inputText)
{
if (inputText.Any(character => Char.IsWhiteSpace(character)))
return $"\"{inputText}\"";

return inputText;
}

private async void AssignWrappedDolphinExeInput(string inputText)
{
DolphinExeInput.Text = WrapOnWhiteSpace(inputText);
DolphinExeInput.Text = EnvHelper.SingleQuotePath(inputText);
}

private async void DolphinExeBrowse_OnClick(object sender, RoutedEventArgs e)
Expand Down
Loading