From dd6d9cb70eac2ba1db4bb059f3b3e4c2a41e914c Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Sat, 20 Dec 2025 17:11:45 -0300 Subject: [PATCH] save last settings on server creator --- Knossos.NET/Models/GlobalSettings.cs | 52 +++++++++++++++---- Knossos.NET/Models/MultiCfg.cs | 5 +- .../Windows/ServerCreatorViewModel.cs | 33 +++++++++++- 3 files changed, 78 insertions(+), 12 deletions(-) diff --git a/Knossos.NET/Models/GlobalSettings.cs b/Knossos.NET/Models/GlobalSettings.cs index 45129d52..574e3815 100644 --- a/Knossos.NET/Models/GlobalSettings.cs +++ b/Knossos.NET/Models/GlobalSettings.cs @@ -1,18 +1,17 @@  -using System.Text.Json; +using Avalonia.Threading; +using IniParser; +using Knossos.NET.Classes; +using Knossos.NET.ViewModels; using System; -using System.Text.Json.Serialization; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using System.Text.Encodings.Web; -using Knossos.NET.Classes; -using IniParser; -using Avalonia.Threading; -using Knossos.NET.ViewModels; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; -using System.Collections.Generic; -using System.Linq; -using Knossos.NET.Views; namespace Knossos.NET.Models { @@ -88,6 +87,37 @@ public AutoUpdateFsoBuilds(bool stable = false, bool rc = false, bool nightly = } } + public struct StandaloneServerSettings + { + + public StandaloneServerSettings(MultiCfg multiCfg, string id, string version, int buildType) : this() + { + this.extraOptions = multiCfg.Others; + this.banList = multiCfg.Ban; + this.pxoChannel = multiCfg.PXOChannel; + this.usePxo = multiCfg.UsePXO; + this.noVoice = multiCfg.NoVoice; + this.port = multiCfg.Port; + this.name = multiCfg.Name; + this.password = multiCfg.Password; + this.buildType = buildType; + this.modId = id; + this.modVersion = version; + } + + public List extraOptions { get; set; } + public List banList { get; set; } + public string? pxoChannel { get; set; } + public bool usePxo { get; set; } + public bool noVoice { get; set; } + public int port { get; set; } + public string? name { get; set; } + public string? password { get; set; } + public int buildType { get; set; } + public string modId { get; set; } + public string modVersion { get; set; } + } + /* Knossos Settings */ [JsonPropertyName("base_path")] public string? basePath { get; set; } = null; @@ -139,6 +169,9 @@ public bool closeToTray { [JsonPropertyName("ignored_launcher_updates")] public List ignoredLauncherUpdates { get; set; } = new List(); + [JsonPropertyName("standalone_server_settings")] + public StandaloneServerSettings? standaloneServerSettings { get; set;} = null; + /* * Settings that can wait to be saved at app close so we dont have to call save() all the time * use JsonIgnore, private and '_' for the actual variable name @@ -699,6 +732,7 @@ public void Load() } MainWindowViewModel.Instance?.InstalledModsView?.ResetFilters(); } + standaloneServerSettings = tempSettings.standaloneServerSettings; ReadFS2IniValues(); Log.Add(Log.LogSeverity.Information, "GlobalSettings.Load()", "Global settings have been loaded"); diff --git a/Knossos.NET/Models/MultiCfg.cs b/Knossos.NET/Models/MultiCfg.cs index ba59c057..94c93ad9 100644 --- a/Knossos.NET/Models/MultiCfg.cs +++ b/Knossos.NET/Models/MultiCfg.cs @@ -24,7 +24,8 @@ public class MultiCfg /// Data is saved in {modfolder}\data\multi.cfg /// /// - public void LoadData(Mod mod) + /// Returns true/false if successfull + public bool LoadData(Mod mod) { UsePXO = false; NoVoice = false; @@ -91,6 +92,7 @@ public void LoadData(Mod mod) Others.Add(line.ToLower()); } } + return true; } else { @@ -101,6 +103,7 @@ public void LoadData(Mod mod) { Log.Add(Log.LogSeverity.Error, "MultiCfg.LoadData()", ex); } + return false; } /// diff --git a/Knossos.NET/ViewModels/Windows/ServerCreatorViewModel.cs b/Knossos.NET/ViewModels/Windows/ServerCreatorViewModel.cs index f21c711c..ab899980 100644 --- a/Knossos.NET/ViewModels/Windows/ServerCreatorViewModel.cs +++ b/Knossos.NET/ViewModels/Windows/ServerCreatorViewModel.cs @@ -1,4 +1,5 @@ using CommunityToolkit.Mvvm.ComponentModel; +using Knossos.NET.Classes; using Knossos.NET.Models; using Knossos.NET.Views; using System; @@ -66,6 +67,22 @@ internal int ModIndex [ObservableProperty] public int buildType = 0; + public ServerCreatorViewModel() + { + //load last selected mod + if (Knossos.globalSettings.standaloneServerSettings != null) + { + var selectedMod = listOfMods.FirstOrDefault(x => x.id == Knossos.globalSettings.standaloneServerSettings.Value.modId + && x.version == Knossos.globalSettings.standaloneServerSettings.Value.modVersion); + if (selectedMod != null) + { + var index = listOfMods.IndexOf(selectedMod); + if(index >= 0) + ModIndex = index; + } + } + } + /// /// Load multi.cfg file for the currently selected mod in the list /// @@ -78,9 +95,19 @@ internal void LoadCFG() PxoChannel = "#Eleh"; try { - if (ModIndex >= 0) + if (Knossos.globalSettings.standaloneServerSettings != null) + { + BanList = string.Join(Environment.NewLine, Knossos.globalSettings.standaloneServerSettings.Value.banList); + ExtraOptions = string.Join(Environment.NewLine, Knossos.globalSettings.standaloneServerSettings.Value.extraOptions); + Name = Knossos.globalSettings.standaloneServerSettings.Value.name; + Password = Knossos.globalSettings.standaloneServerSettings.Value.password; + UsePxo = Knossos.globalSettings.standaloneServerSettings.Value.usePxo; + NoVoice = Knossos.globalSettings.standaloneServerSettings.Value.noVoice; + Port = Knossos.globalSettings.standaloneServerSettings.Value.port; + PxoChannel = Knossos.globalSettings.standaloneServerSettings.Value.pxoChannel ?? "#Eleh"; + } + if (ModIndex >= 0 && Cfg.LoadData(ListOfMods[ModIndex])) { - Cfg.LoadData(ListOfMods[ModIndex]); UsePxo = Cfg.UsePXO; Name = Cfg.Name; Password = Cfg.Password; @@ -134,6 +161,8 @@ internal void SaveCFG() Cfg.Others = ExtraOptions.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries).ToList(); } Cfg.SaveData(ListOfMods[ModIndex]); + Knossos.globalSettings.standaloneServerSettings = new GlobalSettings.StandaloneServerSettings(Cfg, ListOfMods[ModIndex].id, ListOfMods[ModIndex].version, BuildType); + Knossos.globalSettings.Save(); } } catch (Exception ex)