diff --git a/Saradomin/Infrastructure/Services/JavaUpdateService.cs b/Saradomin/Infrastructure/Services/JavaUpdateService.cs index 9ff0e80..61e15c0 100644 --- a/Saradomin/Infrastructure/Services/JavaUpdateService.cs +++ b/Saradomin/Infrastructure/Services/JavaUpdateService.cs @@ -4,7 +4,6 @@ using System.IO.Compression; using System.Net.Http; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Saradomin.Model.Settings.Launcher; using Saradomin.Utilities; namespace Saradomin.Infrastructure.Services diff --git a/Saradomin/Utilities/CrossPlatform.cs b/Saradomin/Utilities/CrossPlatform.cs index 567e149..bb452d3 100644 --- a/Saradomin/Utilities/CrossPlatform.cs +++ b/Saradomin/Utilities/CrossPlatform.cs @@ -188,7 +188,6 @@ namespace Saradomin.Utilities || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) { return Path.Combine( - // Get the XDG_DATA_HOME environment variable, or if it doesn't exist, use the default ~/.local/share LocateUnixUserHome(), "2009scape" ); diff --git a/Saradomin/Utilities/SingleplayerManagement.cs b/Saradomin/Utilities/SingleplayerManagement.cs index 7b933d6..e99802d 100644 --- a/Saradomin/Utilities/SingleplayerManagement.cs +++ b/Saradomin/Utilities/SingleplayerManagement.cs @@ -13,6 +13,7 @@ public static class SingleplayerManagement "game/data/serverstore", "game/worldprops" }; + private static readonly string[] FilesToBackup = { "game/data/eco/ge_resource.emp", @@ -39,6 +40,7 @@ public static class SingleplayerManagement log($" Skipping backup of {dir} because it doesn't exist (Full path attempted: {sourcePath})"); continue; } + string destPath = Path.Combine(newBackupDir, dir); CopyDirectory(sourcePath, destPath); } @@ -51,6 +53,7 @@ public static class SingleplayerManagement log($" Skipping backup of {file} because it doesn't exist (Full path attempted: {sourceFilePath})"); continue; } + string destFilePath = Path.Combine(newBackupDir, file); string directoryForFile = Path.GetDirectoryName(destFilePath); if (!Directory.Exists(directoryForFile)) @@ -130,4 +133,24 @@ public static class SingleplayerManagement log($" Backup from {mostRecentBackupDirName} has been successfully applied."); } -} + + private static Dictionary _confCache; + public static T ParseConf(string key, T defaultValue = default) + { + if (!File.Exists(CrossPlatform.GetSingleplayerHome() + "/game/worldprops/default.conf")) return defaultValue; + _confCache ??= File.ReadLines(CrossPlatform.GetSingleplayerHome() + "/game/worldprops/default.conf") + .Where(line => line.Contains('=')) + .Select(line => line.Split('=')) + .ToDictionary(parts => parts[0].Trim(), parts => parts[1].Trim()); + + return (T)Convert.ChangeType(_confCache[key], typeof(T)); + } + + public static void WriteConf(string key, object value) + { + var filePath = CrossPlatform.GetSingleplayerHome() + "/game/worldprops/default.conf"; + var lines = File.ReadAllLines(filePath); + File.WriteAllLines(filePath, lines.Select(l => l.StartsWith(key + " =") ? $"{key} = {value}" : l)); + _confCache[key] = value.ToString(); + } +} \ No newline at end of file diff --git a/Saradomin/View/Controls/SingleplayerView.axaml b/Saradomin/View/Controls/SingleplayerView.axaml index fa9b26f..5c4d34f 100644 --- a/Saradomin/View/Controls/SingleplayerView.axaml +++ b/Saradomin/View/Controls/SingleplayerView.axaml @@ -97,7 +97,7 @@ Header="singleplayer links">