diff --git a/Saradomin/Infrastructure/Services/ClientLaunchService.cs b/Saradomin/Infrastructure/Services/ClientLaunchService.cs index e824081..e5a2201 100644 --- a/Saradomin/Infrastructure/Services/ClientLaunchService.cs +++ b/Saradomin/Infrastructure/Services/ClientLaunchService.cs @@ -37,9 +37,9 @@ namespace Saradomin.Infrastructure.Services Arguments = $"-Dsun.java2d.uiScale={_settingsService.Client.UiScale} " + $"-DclientFps={_settingsService.Client.Fps} " - + $"-DclientHomeOverride=\"{_settingsService.Launcher.InstallationDirectory}/\" " + + $"-DclientHomeOverride=\"{CrossPlatform.Get2009scapeHome()}/\" " + $"-jar \"{_clientUpdateService.PreferredTargetFilePath}\"", - WorkingDirectory = $"{_settingsService.Launcher.InstallationDirectory}", + WorkingDirectory = $"{CrossPlatform.Get2009scapeHome()}", UseShellExecute = true, WindowStyle = ProcessWindowStyle.Hidden } diff --git a/Saradomin/Infrastructure/Services/ClientUpdateService.cs b/Saradomin/Infrastructure/Services/ClientUpdateService.cs index 2184ecc..cfa53bc 100644 --- a/Saradomin/Infrastructure/Services/ClientUpdateService.cs +++ b/Saradomin/Infrastructure/Services/ClientUpdateService.cs @@ -20,7 +20,7 @@ namespace Saradomin.Infrastructure.Services public string ClientHashURL => "https://gitlab.com/2009scape/rt4-client/-/jobs/artifacts/master/raw/client/build/libs/rt4-client.jar.sha256?job=build"; public string PreferredTargetFilePath => - CrossPlatform.Locate2009scapeExecutable(); + CrossPlatform.Get2009scapeExecutable(); public event EventHandler DownloadProgressChanged; diff --git a/Saradomin/Infrastructure/Services/JavaUpdateService.cs b/Saradomin/Infrastructure/Services/JavaUpdateService.cs index 334e07a..9ff0e80 100644 --- a/Saradomin/Infrastructure/Services/JavaUpdateService.cs +++ b/Saradomin/Infrastructure/Services/JavaUpdateService.cs @@ -18,11 +18,11 @@ namespace Saradomin.Infrastructure.Services string downloadUrl = CrossPlatform.GetJava11DownloadUrl(); string downloadPath = Path.Combine( - CrossPlatform.LocateDefault2009scapeHome(), + CrossPlatform.Get2009scapeHome(), "jre11" + Path.GetExtension(downloadUrl) ); string extractedPath = Path.Combine( - CrossPlatform.LocateDefault2009scapeHome(), + CrossPlatform.Get2009scapeHome(), "jre11" ); @@ -61,7 +61,7 @@ namespace Saradomin.Infrastructure.Services if (Path.GetExtension(downloadUrl) == ".zip") { // Don't use /tmp because Directory.Move doesn't work cross-partition - string tempDir = Path.Combine(CrossPlatform.LocateDefault2009scapeHome(), "jre11_temp"); + string tempDir = Path.Combine(CrossPlatform.Get2009scapeHome(), "jre11_temp"); if (Directory.Exists(tempDir)) Directory.Delete(tempDir, true); await Task.Run(() => ZipFile.ExtractToDirectory(downloadPath, tempDir)); Directory.Move(Directory.GetDirectories(tempDir)[0], extractedPath); diff --git a/Saradomin/Infrastructure/Services/PluginManagementService.cs b/Saradomin/Infrastructure/Services/PluginManagementService.cs index 14a1f6c..2059bc4 100644 --- a/Saradomin/Infrastructure/Services/PluginManagementService.cs +++ b/Saradomin/Infrastructure/Services/PluginManagementService.cs @@ -4,6 +4,7 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Threading.Tasks; +using Saradomin.Utilities; namespace Saradomin.Infrastructure.Services { @@ -13,7 +14,7 @@ namespace Saradomin.Infrastructure.Services public PluginManagementService(ISettingsService settings) { - PluginRepositoryPath = Path.Combine(settings.Launcher.InstallationDirectory, "plugins"); + PluginRepositoryPath = Path.Combine(CrossPlatform.Get2009scapeHome(), "plugins"); } public Task> EnumerateInstalledPlugins() diff --git a/Saradomin/Infrastructure/Services/SettingsService.cs b/Saradomin/Infrastructure/Services/SettingsService.cs index 4585f84..5bd999f 100644 --- a/Saradomin/Infrastructure/Services/SettingsService.cs +++ b/Saradomin/Infrastructure/Services/SettingsService.cs @@ -12,10 +12,10 @@ namespace Saradomin.Infrastructure.Services public ClientSettings Client { get; private set; } = new(); private string ClientSettingsPath - => Path.Combine(Launcher.InstallationDirectory, ClientSettings.FileName); + => Path.Combine(CrossPlatform.Get2009scapeHome(), ClientSettings.FileName); private string LauncherSettingsPath - => Path.Combine(CrossPlatform.LocateSaradominHome(), LauncherSettings.FileName); + => Path.Combine(CrossPlatform.GetSaradominHome(), LauncherSettings.FileName); public SettingsService() { @@ -30,7 +30,7 @@ namespace Saradomin.Infrastructure.Services private void TryReadConfigurationData() { - Directory.CreateDirectory(CrossPlatform.LocateSaradominHome()); + Directory.CreateDirectory(CrossPlatform.GetSaradominHome()); if (File.Exists(LauncherSettingsPath)) { @@ -44,7 +44,7 @@ namespace Saradomin.Infrastructure.Services SaveLauncherSettings(); } - Directory.CreateDirectory(Launcher!.InstallationDirectory); + Directory.CreateDirectory(CrossPlatform.Get2009scapeHome()); if (File.Exists(ClientSettingsPath)) { using (var stream = File.OpenRead(ClientSettingsPath)) diff --git a/Saradomin/Infrastructure/Services/SingleplayerUpdateService.cs b/Saradomin/Infrastructure/Services/SingleplayerUpdateService.cs index 68e48aa..aa0d795 100644 --- a/Saradomin/Infrastructure/Services/SingleplayerUpdateService.cs +++ b/Saradomin/Infrastructure/Services/SingleplayerUpdateService.cs @@ -18,7 +18,7 @@ namespace Saradomin.Infrastructure.Services "https://gitlab.com/2009scape/singleplayer/windows/-/archive/master/windows-master.zip"; string downloadPath = Path.Combine( - CrossPlatform.LocateDefault2009scapeHome(), + CrossPlatform.Get2009scapeHome(), "singleplayer" + Path.GetExtension(downloadUrl) ); @@ -54,13 +54,13 @@ namespace Saradomin.Infrastructure.Services SingleplayerDownloadProgressChanged?.Invoke(this, new Tuple(1f, false)); - if (Directory.Exists(CrossPlatform.LocateSingleplayerHome())) Directory.Delete(CrossPlatform.LocateSingleplayerHome(), true); + if (Directory.Exists(CrossPlatform.GetSingleplayerHome())) Directory.Delete(CrossPlatform.GetSingleplayerHome(), true); // Don't use /tmp because Directory.Move doesn't work cross-partition - string tempDir = Path.Combine(CrossPlatform.LocateDefault2009scapeHome(), "singleplayer_temp"); + string tempDir = Path.Combine(CrossPlatform.Get2009scapeHome(), "singleplayer_temp"); if (Directory.Exists(tempDir)) Directory.Delete(tempDir, true); await Task.Run(() => ZipFile.ExtractToDirectory(downloadPath, tempDir)); - Directory.Move(Directory.GetDirectories(tempDir)[0], CrossPlatform.LocateSingleplayerHome()); + Directory.Move(Directory.GetDirectories(tempDir)[0], CrossPlatform.GetSingleplayerHome()); Directory.Delete(tempDir, true); File.Delete(downloadPath); diff --git a/Saradomin/Model/Settings/Launcher/LauncherSettings.cs b/Saradomin/Model/Settings/Launcher/LauncherSettings.cs index bb02dff..0bd6aff 100644 --- a/Saradomin/Model/Settings/Launcher/LauncherSettings.cs +++ b/Saradomin/Model/Settings/Launcher/LauncherSettings.cs @@ -9,12 +9,9 @@ namespace Saradomin.Model.Settings.Launcher public bool PlaceCloseButtonOnLeft { get; set; } = false; public bool ExitAfterLaunchingClient { get; set; } = true; public bool AllowMultiboxing { get; set; } = false; - public bool CheckForClientUpdatesOnLaunch { get; set; } = true; public bool CheckForServerProfilesOnLaunch { get; set; } = true; - public string JavaExecutableLocation { get; set; } - public string InstallationDirectory { get; set; } = CrossPlatform.LocateDefault2009scapeHome(); protected override void OnSettingsModified(string propertyName) { diff --git a/Saradomin/Utilities/CrossPlatform.cs b/Saradomin/Utilities/CrossPlatform.cs index 256a6b5..567e149 100644 --- a/Saradomin/Utilities/CrossPlatform.cs +++ b/Saradomin/Utilities/CrossPlatform.cs @@ -36,7 +36,6 @@ namespace Saradomin.Utilities } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - Console.WriteLine("Opening " + path + "..."); Process.Start("xdg-open", path); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -183,7 +182,7 @@ namespace Saradomin.Utilities ); } - public static string LocateDefault2009scapeHome() + public static string Get2009scapeHome() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) @@ -203,7 +202,7 @@ namespace Saradomin.Utilities } } - public static string LocateSaradominHome() + public static string GetSaradominHome() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) @@ -215,51 +214,37 @@ namespace Saradomin.Utilities "saradomin" ); } - else - { - return Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - "2009scape", - "saradomin" - ); - } + + return Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), + "2009scape", + "saradomin" + ); } - public static string LocateSingleplayerBackupsHome() + public static string GetSingleplayerBackupsHome() { - return Path.Combine(LocateDefault2009scapeHome(), "singleplayer_backups"); + return Path.Combine(Get2009scapeHome(), "singleplayer_backups"); } - public static string LocateSingleplayerHome() + public static string GetSingleplayerHome() { - return Path.Combine(LocateDefault2009scapeHome(), "singleplayer"); + return Path.Combine(Get2009scapeHome(), "singleplayer"); } public static string LocateSingleplayerExecutable() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return Path.Combine(LocateSingleplayerHome(), "launch.bat"); - } - - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - return Path.Combine(LocateSingleplayerHome(), "launch.sh"); - } - - // TODO - MacOS - throw new InvalidOperationException("Unsupported OS for singleplayer: " + - RuntimeInformation.OSArchitecture); + return Path.Combine(GetSingleplayerHome(), RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "launch.bat" : "launch.sh"); } - public static string Locate2009scapeExecutable() + public static string Get2009scapeExecutable() { - return Path.Combine(LocateDefault2009scapeHome(), "2009scape.jar"); + return Path.Combine(Get2009scapeHome(), "2009scape.jar"); } - public static string LocateServerProfilesPath(string baseDirectory) + public static string GetServerProfilePath(string baseDirectory) { - baseDirectory ??= LocateDefault2009scapeHome(); + baseDirectory ??= Get2009scapeHome(); return Path.Combine(baseDirectory, "server_profiles.json"); } diff --git a/Saradomin/Utilities/SingleplayerManagement.cs b/Saradomin/Utilities/SingleplayerManagement.cs index 97f42fd..7b933d6 100644 --- a/Saradomin/Utilities/SingleplayerManagement.cs +++ b/Saradomin/Utilities/SingleplayerManagement.cs @@ -21,22 +21,22 @@ public static class SingleplayerManagement public static void MakeBackup(Action log) { - if (!Directory.Exists(CrossPlatform.LocateSingleplayerBackupsHome())) - Directory.CreateDirectory(CrossPlatform.LocateSingleplayerBackupsHome()); + if (!Directory.Exists(CrossPlatform.GetSingleplayerBackupsHome())) + Directory.CreateDirectory(CrossPlatform.GetSingleplayerBackupsHome()); string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss"); string newBackupDir = Path.Combine( - CrossPlatform.LocateSingleplayerBackupsHome(), + CrossPlatform.GetSingleplayerBackupsHome(), timestamp ); Directory.CreateDirectory(newBackupDir); foreach (string dir in DirsToBackup) { - string sourcePath = Path.Combine(CrossPlatform.LocateSingleplayerHome(), dir); + string sourcePath = Path.Combine(CrossPlatform.GetSingleplayerHome(), dir); if (!Directory.Exists(sourcePath)) { - log($" Skipping backup of {dir} because it doesn't exist (Full path attempted: {sourcePath}"); + log($" Skipping backup of {dir} because it doesn't exist (Full path attempted: {sourcePath})"); continue; } string destPath = Path.Combine(newBackupDir, dir); @@ -45,10 +45,10 @@ public static class SingleplayerManagement foreach (string file in FilesToBackup) { - string sourceFilePath = Path.Combine(CrossPlatform.LocateSingleplayerHome(), file); + string sourceFilePath = Path.Combine(CrossPlatform.GetSingleplayerHome(), file); if (!File.Exists(sourceFilePath)) { - log($" Skipping backup of {file} because it doesn't exist (Full path attempted: {sourceFilePath}"); + log($" Skipping backup of {file} because it doesn't exist (Full path attempted: {sourceFilePath})"); continue; } string destFilePath = Path.Combine(newBackupDir, file); @@ -87,8 +87,8 @@ public static class SingleplayerManagement public static void ApplyLatestBackup(Action log) { - var backupHome = CrossPlatform.LocateSingleplayerBackupsHome(); - var singleplayerHome = CrossPlatform.LocateSingleplayerHome(); + var backupHome = CrossPlatform.GetSingleplayerBackupsHome(); + var singleplayerHome = CrossPlatform.GetSingleplayerHome(); // Get all backup directories var backupDirectories = Directory.GetDirectories(backupHome); diff --git a/Saradomin/View/Controls/SettingsView.axaml b/Saradomin/View/Controls/SettingsView.axaml index 2dfc685..e2d2998 100644 --- a/Saradomin/View/Controls/SettingsView.axaml +++ b/Saradomin/View/Controls/SettingsView.axaml @@ -44,6 +44,7 @@ Width="300" Margin="2,0,0,0" HorizontalAlignment="Left" + IsReadOnly="True" Classes="NormalTextBox" Text="{Binding Launcher.JavaExecutableLocation, Mode=TwoWay}" Watermark="Enter a path to java or java.exe..." /> @@ -59,40 +60,6 @@ ToolTip.Tip="Browse..." /> - - - - - - -