diff options
author | Mary-nyan <mary@mary.zone> | 2022-12-12 15:17:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-12 15:17:22 +0100 |
commit | 6fe88115a302f4b4da38d8aac1baac7ada548be0 (patch) | |
tree | 5183f827121c29dedc7cc754c944c4a08f673746 | |
parent | 475fa4d390d4a2f3f486e4e0ba0b9334ea25f0f7 (diff) |
misc: Some fixes to the updaters (#4092)1.1.465
This was meant to be only an upgrade of how we set unix permission in
the updater to use .NET 7 new APIs, but I end up finding bugs along the
way.
Changelog:
- Remove direct usage of chmod to use File.SetUnixFileMode.
- Fix command line being broken when updating (#3744) but on
Ryujinx.Ava.
- Makes Ryujinx.Ava updater fallback to Ryujinx executable if current
name isn't found.
- Make permission setter function more generic.
-rw-r--r-- | Ryujinx.Ava/Modules/Updater/Updater.cs | 29 | ||||
-rw-r--r-- | Ryujinx/Modules/Updater/Updater.cs | 21 |
2 files changed, 29 insertions, 21 deletions
diff --git a/Ryujinx.Ava/Modules/Updater/Updater.cs b/Ryujinx.Ava/Modules/Updater/Updater.cs index a48156c4..b3a1ef30 100644 --- a/Ryujinx.Ava/Modules/Updater/Updater.cs +++ b/Ryujinx.Ava/Modules/Updater/Updater.cs @@ -11,6 +11,7 @@ using Ryujinx.Ava.Ui.Controls; using Ryujinx.Ava.Ui.Windows; using Ryujinx.Common; using Ryujinx.Common.Logging; +using Ryujinx.Ui.Common.Helper; using System; using System.Collections.Generic; using System.Diagnostics; @@ -278,14 +279,15 @@ namespace Ryujinx.Modules { string ryuName = Path.GetFileName(Environment.ProcessPath); string ryuExe = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ryuName); - var ryuArg = Environment.GetCommandLineArgs().Skip(1); - if (!OperatingSystem.IsWindows()) + if (!Path.Exists(ryuExe)) { - chmod(ryuExe, Convert.ToUInt32("0777", 8)); + ryuExe = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, OperatingSystem.IsWindows() ? "Ryujinx.exe" : "Ryujinx"); } - Process.Start(ryuExe, ryuArg); + SetFileExecutable(ryuExe); + + Process.Start(ryuExe, CommandLineState.Arguments); Environment.Exit(0); } @@ -456,16 +458,19 @@ namespace Ryujinx.Modules worker.Start(); } - [DllImport("libc", SetLastError = true)] - private static extern int chmod(string path, uint mode); - - private static void SetUnixPermissions() + private static void SetFileExecutable(string path) { - string ryuBin = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Ryujinx"); + const UnixFileMode ExecutableFileMode = UnixFileMode.UserExecute | + UnixFileMode.UserWrite | + UnixFileMode.UserRead | + UnixFileMode.GroupRead | + UnixFileMode.GroupWrite | + UnixFileMode.OtherRead | + UnixFileMode.OtherWrite; - if (!OperatingSystem.IsWindows()) + if (!OperatingSystem.IsWindows() && File.Exists(path)) { - chmod(ryuBin, 493); + File.SetUnixFileMode(path, ExecutableFileMode); } } @@ -586,7 +591,7 @@ namespace Ryujinx.Modules Directory.Delete(UpdateDir, true); - SetUnixPermissions(); + SetFileExecutable(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Ryujinx")); UpdateSuccessful = true; diff --git a/Ryujinx/Modules/Updater/Updater.cs b/Ryujinx/Modules/Updater/Updater.cs index 194d35e5..0a1cb53b 100644 --- a/Ryujinx/Modules/Updater/Updater.cs +++ b/Ryujinx/Modules/Updater/Updater.cs @@ -387,16 +387,19 @@ namespace Ryujinx.Modules worker.Start(); } - [DllImport("libc", SetLastError = true)] - private static extern int chmod(string path, uint mode); - - private static void SetUnixPermissions() + private static void SetFileExecutable(string path) { - string ryuBin = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Ryujinx"); - - if (!OperatingSystem.IsWindows()) + const UnixFileMode ExecutableFileMode = UnixFileMode.UserExecute | + UnixFileMode.UserWrite | + UnixFileMode.UserRead | + UnixFileMode.GroupRead | + UnixFileMode.GroupWrite | + UnixFileMode.OtherRead | + UnixFileMode.OtherWrite; + + if (!OperatingSystem.IsWindows() && File.Exists(path)) { - chmod(ryuBin, 493); + File.SetUnixFileMode(path, ExecutableFileMode); } } @@ -519,7 +522,7 @@ namespace Ryujinx.Modules Directory.Delete(UpdateDir, true); - SetUnixPermissions(); + SetFileExecutable(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Ryujinx")); updateDialog.MainText.Text = "Update Complete!"; updateDialog.SecondaryText.Text = "Do you want to restart Ryujinx now?"; |