From 0c00284d61737074ecba6498c2115d5d0a11ef74 Mon Sep 17 00:00:00 2001 From: Darojax Date: Fri, 13 Sep 2024 15:26:01 +0200 Subject: [PATCH 1/3] Implement version number update and persistent directory --- .gitignore | 5 ++- ArmaReforgerServerTool/Forms/Main.cs | 18 +++++++++ .../Managers/FileIOManager.cs | 38 +++++++++++++++++-- ArmaReforgerServerTool/properties.json | 22 +++++++++++ properties.json | 22 +++++++++++ 5 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 ArmaReforgerServerTool/properties.json create mode 100644 properties.json diff --git a/.gitignore b/.gitignore index 1ef5f3c..16ee12c 100644 --- a/.gitignore +++ b/.gitignore @@ -334,4 +334,7 @@ ASALocalRun/ .localhistory/ # Executables -*.exe \ No newline at end of file +*.exe + +# Scripts +*.ps1 \ No newline at end of file diff --git a/ArmaReforgerServerTool/Forms/Main.cs b/ArmaReforgerServerTool/Forms/Main.cs index e808d0d..cb49935 100644 --- a/ArmaReforgerServerTool/Forms/Main.cs +++ b/ArmaReforgerServerTool/Forms/Main.cs @@ -10,6 +10,7 @@ using ReforgerServerApp.Models; using System.ComponentModel; using Serilog; +using System.Reflection; namespace ReforgerServerApp { @@ -21,6 +22,9 @@ public Main() { InitializeComponent(); + // Set the window title with the version number + this.Text = $"ReforgerServerApp - {GetAppVersion()}"; + CreateServerParameterControls(); serverRunningLabel.Text = string.Empty; @@ -75,6 +79,20 @@ public Main() Mod.GetScenariosForMod("591AF5BDA9F7CE8B"); } + /// + /// Retrieves the application's version number. + /// + /// Formatted version string. + private string GetAppVersion() + { + // Retrieve the version from the assembly metadata using pattern matching + return Assembly.GetExecutingAssembly().GetName().Version switch + { + { } version => $"v{version.Major}.{version.Minor}.{version.Build}.{version.Revision}", + _ => "v0.0.0.0" // Fallback version if Version is null + }; + } + /// /// Initialise tool tips for certain UI elements. /// diff --git a/ArmaReforgerServerTool/Managers/FileIOManager.cs b/ArmaReforgerServerTool/Managers/FileIOManager.cs index 8fb8f05..eb9c287 100644 --- a/ArmaReforgerServerTool/Managers/FileIOManager.cs +++ b/ArmaReforgerServerTool/Managers/FileIOManager.cs @@ -26,6 +26,7 @@ internal class FileIOManager private readonly string m_legacyModDatabaseFile = "./mod_database.txt"; private string m_steamCmdFile; private string m_installDir; + private string lastUsedDirectory; private FileIOManager() { bool modDatabaseExists = File.Exists(ToolPropertiesManager.GetInstance().GetToolProperties().modDatabaseFile); @@ -52,6 +53,7 @@ private FileIOManager() m_installDir = string.Empty; m_steamCmdFile = string.Empty; } + lastUsedDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); } public static FileIOManager GetInstance() @@ -113,13 +115,29 @@ public void ReadModsDatabase() /// public static void SaveConfigurationToFile() { + FileIOManager instance = GetInstance(); using SaveFileDialog sfd = new(); - sfd.InitialDirectory = Environment.SpecialFolder.UserProfile.ToString(); + + // Use lastUsedDirectory if available + if (!string.IsNullOrEmpty(instance.lastUsedDirectory)) + { + sfd.InitialDirectory = instance.lastUsedDirectory; + } + else + { + sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + } + sfd.Filter = "JSON (*.json)|*.json"; if (sfd.ShowDialog() == DialogResult.OK) { ConfigurationManager.GetInstance().CreateConfiguration(); - SaveConfigurationToFile(sfd.FileName); + bool success = SaveConfigurationToFile(sfd.FileName); + if (success) + { + // Update lastUsedDirectory + instance.lastUsedDirectory = Path.GetDirectoryName(sfd.FileName) ?? instance.lastUsedDirectory; + } } } @@ -150,14 +168,28 @@ public static bool SaveConfigurationToFile(string path) /// public static void LoadConfigurationFromFile() { + FileIOManager instance = GetInstance(); using OpenFileDialog ofd = new(); - ofd.InitialDirectory = Environment.SpecialFolder.UserProfile.ToString(); + + // Use lastUsedDirectory if available + if (!string.IsNullOrEmpty(instance.lastUsedDirectory)) + { + ofd.InitialDirectory = instance.lastUsedDirectory; + } + else + { + ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + } + ofd.Filter = "JSON (*.json)|*.json"; if (ofd.ShowDialog() == DialogResult.OK) { string filePath = ofd.FileName; using StreamReader sr = File.OpenText(filePath); ConfigurationManager.GetInstance().PopulateServerConfiguration(sr.ReadToEnd()); + + // Update lastUsedDirectory + instance.lastUsedDirectory = Path.GetDirectoryName(filePath) ?? instance.lastUsedDirectory; } } diff --git a/ArmaReforgerServerTool/properties.json b/ArmaReforgerServerTool/properties.json new file mode 100644 index 0000000..0a3ea65 --- /dev/null +++ b/ArmaReforgerServerTool/properties.json @@ -0,0 +1,22 @@ +{ + "defaultScenarios": [ + "{ECC61978EDCC2B5A}Missions/23_Campaign.conf", + "{59AD59368755F41A}Missions/21_GM_Eden.conf", + "{94FDA7451242150B}Missions/103_Arland_Tutorial.conf", + "{2BBBE828037C6F4B}Missions/22_GM_Arland.conf", + "{C700DB41F0C546E1}Missions/23_Campaign_NorthCentral.conf", + "{28802845ADA64D52}Missions/23_Campaign_SWCoast.conf", + "{DAA03C6E6099D50F}Missions/24_CombatOps.conf", + "{C41618FD18E9D714}Missions/23_Campaign_Arland.conf", + "{DFAC5FABD11F2390}Missions/26_CombatOpsEveron.conf" + ], + "modDatabaseFile": "./mod_database.json", + "installDirectoryFile": "./install_directory.txt", + "updateRepositoryUrl": "https://raw.githubusercontent.com/soda3x/ArmaReforgerServerTool", + "bugReportUrl": "https://github.com/soda3x/ArmaReforgerServerTool/issues", + "checkForUpdatesOnStartup": true, + "steamCmdDownloadUrl": "https://steamcdn-a.akamaihd.net/client/installer", + "armaWorkshopUrl": "https://reforger.armaplatform.com/workshop", + "logFile": "logs/ardst.log", + "minimumLogLevel": "Debug" +} \ No newline at end of file diff --git a/properties.json b/properties.json new file mode 100644 index 0000000..0a3ea65 --- /dev/null +++ b/properties.json @@ -0,0 +1,22 @@ +{ + "defaultScenarios": [ + "{ECC61978EDCC2B5A}Missions/23_Campaign.conf", + "{59AD59368755F41A}Missions/21_GM_Eden.conf", + "{94FDA7451242150B}Missions/103_Arland_Tutorial.conf", + "{2BBBE828037C6F4B}Missions/22_GM_Arland.conf", + "{C700DB41F0C546E1}Missions/23_Campaign_NorthCentral.conf", + "{28802845ADA64D52}Missions/23_Campaign_SWCoast.conf", + "{DAA03C6E6099D50F}Missions/24_CombatOps.conf", + "{C41618FD18E9D714}Missions/23_Campaign_Arland.conf", + "{DFAC5FABD11F2390}Missions/26_CombatOpsEveron.conf" + ], + "modDatabaseFile": "./mod_database.json", + "installDirectoryFile": "./install_directory.txt", + "updateRepositoryUrl": "https://raw.githubusercontent.com/soda3x/ArmaReforgerServerTool", + "bugReportUrl": "https://github.com/soda3x/ArmaReforgerServerTool/issues", + "checkForUpdatesOnStartup": true, + "steamCmdDownloadUrl": "https://steamcdn-a.akamaihd.net/client/installer", + "armaWorkshopUrl": "https://reforger.armaplatform.com/workshop", + "logFile": "logs/ardst.log", + "minimumLogLevel": "Debug" +} \ No newline at end of file From 3970b8b81dfd42acd33930c51fba32eae75b199a Mon Sep 17 00:00:00 2001 From: Darojax <110496226+Darojax@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:53:41 +0200 Subject: [PATCH 2/3] Delete properties.json Appended by accident --- properties.json | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 properties.json diff --git a/properties.json b/properties.json deleted file mode 100644 index 0a3ea65..0000000 --- a/properties.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "defaultScenarios": [ - "{ECC61978EDCC2B5A}Missions/23_Campaign.conf", - "{59AD59368755F41A}Missions/21_GM_Eden.conf", - "{94FDA7451242150B}Missions/103_Arland_Tutorial.conf", - "{2BBBE828037C6F4B}Missions/22_GM_Arland.conf", - "{C700DB41F0C546E1}Missions/23_Campaign_NorthCentral.conf", - "{28802845ADA64D52}Missions/23_Campaign_SWCoast.conf", - "{DAA03C6E6099D50F}Missions/24_CombatOps.conf", - "{C41618FD18E9D714}Missions/23_Campaign_Arland.conf", - "{DFAC5FABD11F2390}Missions/26_CombatOpsEveron.conf" - ], - "modDatabaseFile": "./mod_database.json", - "installDirectoryFile": "./install_directory.txt", - "updateRepositoryUrl": "https://raw.githubusercontent.com/soda3x/ArmaReforgerServerTool", - "bugReportUrl": "https://github.com/soda3x/ArmaReforgerServerTool/issues", - "checkForUpdatesOnStartup": true, - "steamCmdDownloadUrl": "https://steamcdn-a.akamaihd.net/client/installer", - "armaWorkshopUrl": "https://reforger.armaplatform.com/workshop", - "logFile": "logs/ardst.log", - "minimumLogLevel": "Debug" -} \ No newline at end of file From 472ea23bb1fd1c66bdfb0d26428eb0166c59e355 Mon Sep 17 00:00:00 2001 From: Darojax <110496226+Darojax@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:56:33 +0200 Subject: [PATCH 3/3] Delete ArmaReforgerServerTool/properties.json --- ArmaReforgerServerTool/properties.json | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 ArmaReforgerServerTool/properties.json diff --git a/ArmaReforgerServerTool/properties.json b/ArmaReforgerServerTool/properties.json deleted file mode 100644 index 0a3ea65..0000000 --- a/ArmaReforgerServerTool/properties.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "defaultScenarios": [ - "{ECC61978EDCC2B5A}Missions/23_Campaign.conf", - "{59AD59368755F41A}Missions/21_GM_Eden.conf", - "{94FDA7451242150B}Missions/103_Arland_Tutorial.conf", - "{2BBBE828037C6F4B}Missions/22_GM_Arland.conf", - "{C700DB41F0C546E1}Missions/23_Campaign_NorthCentral.conf", - "{28802845ADA64D52}Missions/23_Campaign_SWCoast.conf", - "{DAA03C6E6099D50F}Missions/24_CombatOps.conf", - "{C41618FD18E9D714}Missions/23_Campaign_Arland.conf", - "{DFAC5FABD11F2390}Missions/26_CombatOpsEveron.conf" - ], - "modDatabaseFile": "./mod_database.json", - "installDirectoryFile": "./install_directory.txt", - "updateRepositoryUrl": "https://raw.githubusercontent.com/soda3x/ArmaReforgerServerTool", - "bugReportUrl": "https://github.com/soda3x/ArmaReforgerServerTool/issues", - "checkForUpdatesOnStartup": true, - "steamCmdDownloadUrl": "https://steamcdn-a.akamaihd.net/client/installer", - "armaWorkshopUrl": "https://reforger.armaplatform.com/workshop", - "logFile": "logs/ardst.log", - "minimumLogLevel": "Debug" -} \ No newline at end of file