diff options
author | Isaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com> | 2024-02-11 02:09:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-11 03:09:18 +0100 |
commit | f06d22d6f01e657ebbc0c8ef082739cd468e47b5 (patch) | |
tree | c10a566438d3801b33c1d7b4eff73ea62b2f1a63 /src/Ryujinx.UI.Common/Helper/LinuxHelper.cs | |
parent | 84d6e8d121a1b329d26cc0e462aadd1108d99a04 (diff) |
Infra: Capitalisation Consistency (#6296)1.1.1187
* Rename Ryujinx.UI.Common
* Rename Ryujinx.UI.LocaleGenerator
* Update in Files
AboutWindow
* Configuration State
* Rename projects
* Ryujinx/UI
* Fix build
* Main remaining inconsistencies
* HLE.UI Namespace
* HLE.UI Files
* Namespace
* Ryujinx.UI.Common.Configuration.UI
* Ryujinx.UI.Common,Configuration.UI Files
* More instances
Diffstat (limited to 'src/Ryujinx.UI.Common/Helper/LinuxHelper.cs')
-rw-r--r-- | src/Ryujinx.UI.Common/Helper/LinuxHelper.cs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/Ryujinx.UI.Common/Helper/LinuxHelper.cs b/src/Ryujinx.UI.Common/Helper/LinuxHelper.cs new file mode 100644 index 00000000..b5779379 --- /dev/null +++ b/src/Ryujinx.UI.Common/Helper/LinuxHelper.cs @@ -0,0 +1,62 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Runtime.Versioning; + +namespace Ryujinx.UI.Common.Helper +{ + [SupportedOSPlatform("linux")] + public static class LinuxHelper + { + // NOTE: This value was determined by manual tests and might need to be increased again. + public const int RecommendedVmMaxMapCount = 524288; + public const string VmMaxMapCountPath = "/proc/sys/vm/max_map_count"; + public const string SysCtlConfigPath = "/etc/sysctl.d/99-Ryujinx.conf"; + public static int VmMaxMapCount => int.Parse(File.ReadAllText(VmMaxMapCountPath)); + public static string PkExecPath { get; } = GetBinaryPath("pkexec"); + + private static string GetBinaryPath(string binary) + { + string pathVar = Environment.GetEnvironmentVariable("PATH"); + + if (pathVar is null || string.IsNullOrEmpty(binary)) + { + return null; + } + + foreach (var searchPath in pathVar.Split(":", StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)) + { + string binaryPath = Path.Combine(searchPath, binary); + + if (File.Exists(binaryPath)) + { + return binaryPath; + } + } + + return null; + } + + public static int RunPkExec(string command) + { + if (PkExecPath == null) + { + return 1; + } + + using Process process = new() + { + StartInfo = + { + FileName = PkExecPath, + ArgumentList = { "sh", "-c", command }, + }, + }; + + process.Start(); + process.WaitForExit(); + + return process.ExitCode; + } + } +} |