Server Import/Set Location Changes

- when changing the location, the profile will be updated to use the new config files.
This commit is contained in:
Brett Hewitson 2022-06-19 00:04:01 +10:00
parent a2d5c92c00
commit 7015523837
12 changed files with 100 additions and 27 deletions

View file

@ -70,7 +70,7 @@ namespace ServerManagerTool.Lib
public static Server FromPath(string path)
{
var loadedProfile = ServerProfile.LoadFrom(path);
var loadedProfile = ServerProfile.LoadFrom(path, profile: null);
if (loadedProfile == null)
return null;
return new Server(loadedProfile);

View file

@ -3511,10 +3511,23 @@ namespace ServerManagerTool.Lib
#region Methods
#region Common Methods
public void ChangeInstallationFolder(string folder)
public void ChangeInstallationFolder(string folder, bool reloadConfigFiles)
{
InstallDirectory = folder;
if (reloadConfigFiles)
{
var serverConfigPath = GetProfileServerConfigDir();
if (Directory.Exists(serverConfigPath))
{
var serverConfigFile = Path.Combine(serverConfigPath, Config.Default.ServerGameUserSettingsConfigFile);
if (File.Exists(serverConfigFile))
{
LoadFromConfigFiles(serverConfigFile, this, exclusions: null);
}
}
}
LoadServerFiles(true, true, true);
SetupServerFilesWatcher();
}
@ -4035,12 +4048,12 @@ namespace ServerManagerTool.Lib
return LoadFromProfileFile(file, profile);
var filePath = Path.GetDirectoryName(file);
profile = LoadFromINIFiles(file, profile);
profile = LoadFromConfigFiles(file, profile, exclusions: null);
if (filePath.EndsWith(Config.Default.ServerConfigRelativePath))
{
var installDirectory = filePath.Replace(Config.Default.ServerConfigRelativePath, string.Empty).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
profile.ChangeInstallationFolder(installDirectory);
profile.ChangeInstallationFolder(installDirectory, reloadConfigFiles: false);
}
if (profile.PlayerLevels.Count == 0)
@ -4075,7 +4088,7 @@ namespace ServerManagerTool.Lib
return profile;
}
public static ServerProfile LoadFromINIFiles(string file, ServerProfile profile, IEnumerable<Enum> exclusions = null)
public static ServerProfile LoadFromConfigFiles(string file, ServerProfile profile, IEnumerable<Enum> exclusions = null)
{
if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
return null;
@ -4186,10 +4199,10 @@ namespace ServerManagerTool.Lib
return null;
}
var configIniPath = Path.Combine(GetProfileServerConfigDir(profile), Config.Default.ServerGameUserSettingsConfigFile);
if (File.Exists(configIniPath))
var serverConfigFile = Path.Combine(GetProfileServerConfigDir(profile), Config.Default.ServerGameUserSettingsConfigFile);
if (File.Exists(serverConfigFile))
{
profile = LoadFromINIFiles(configIniPath, profile);
profile = LoadFromConfigFiles(serverConfigFile, profile, exclusions: null);
}
profile._lastSaveLocation = file;
@ -4460,10 +4473,10 @@ namespace ServerManagerTool.Lib
//
string configDir = GetProfileServerConfigDir();
Directory.CreateDirectory(configDir);
SaveINIFile(configDir);
SaveConfigFile(configDir);
}
public void SaveINIFile(string profileIniDir, IEnumerable<Enum> exclusions = null)
public void SaveConfigFile(string profileIniDir, IEnumerable<Enum> exclusions = null)
{
if (exclusions == null)
exclusions = GetExclusions();

View file

@ -1036,10 +1036,12 @@ namespace ServerManagerTool
private void SelectInstallDirectory_Click(object sender, RoutedEventArgs e)
{
var dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
dialog.Title = _globalizer.GetResourceString("ServerSettings_InstallServer_Title");
if (!String.IsNullOrWhiteSpace(Settings.InstallDirectory))
var dialog = new CommonOpenFileDialog
{
IsFolderPicker = true,
Title = _globalizer.GetResourceString("ServerSettings_InstallServer_Title")
};
if (!string.IsNullOrWhiteSpace(Settings.InstallDirectory))
{
dialog.InitialDirectory = Settings.InstallDirectory;
}
@ -1047,7 +1049,10 @@ namespace ServerManagerTool
var result = dialog.ShowDialog(Window.GetWindow(this));
if (result == CommonFileDialogResult.Ok)
{
Settings.ChangeInstallationFolder(dialog.FileName);
Settings.ServerMap = string.Empty;
Settings.TotalConversionModId = string.Empty;
Settings.ChangeInstallationFolder(dialog.FileName, reloadConfigFiles: true);
}
}
@ -2047,7 +2052,7 @@ namespace ServerManagerTool
var configIniFile = Path.Combine(ServerProfile.GetProfileServerConfigDir(Settings), Config.Default.ServerGameUserSettingsConfigFile);
// load only this section, using the full exclusion list
var tempServerProfile = ServerProfile.LoadFromINIFiles(configIniFile, null, exclusions);
var tempServerProfile = ServerProfile.LoadFromConfigFiles(configIniFile, null, exclusions);
// perform a profile sync
Settings.SyncSettings(ServerProfileCategory.CustomGameUserSettings, tempServerProfile);
}
@ -2208,7 +2213,7 @@ namespace ServerManagerTool
var configIniFile = Path.Combine(ServerProfile.GetProfileServerConfigDir(Settings), Config.Default.ServerGameUserSettingsConfigFile);
// load only this section, using the full exclusion list
var tempServerProfile = ServerProfile.LoadFromINIFiles(configIniFile, null, exclusions);
var tempServerProfile = ServerProfile.LoadFromConfigFiles(configIniFile, null, exclusions);
// perform a profile sync
Settings.SyncSettings(ServerProfileCategory.CustomGameSettings, tempServerProfile);
}
@ -2369,7 +2374,7 @@ namespace ServerManagerTool
var configIniFile = Path.Combine(ServerProfile.GetProfileServerConfigDir(Settings), Config.Default.ServerGameUserSettingsConfigFile);
// load only this section, using the full exclusion list
var tempServerProfile = ServerProfile.LoadFromINIFiles(configIniFile, null, exclusions);
var tempServerProfile = ServerProfile.LoadFromConfigFiles(configIniFile, null, exclusions);
// perform a profile sync
Settings.SyncSettings(ServerProfileCategory.CustomEngineSettings, tempServerProfile);
}

View file

@ -25,6 +25,7 @@
<br/>
<ul>
<li>Gamedata Files - when adding, deleteing or reloading the gamedata files via the gamedata window, the server manager will reload them and update the settings window.</li>
<li>Main Window - when changing the location of the server, it will reload the profile with the config settings in the new location.</li>
<li>Main Window - added discord server button.</li>
<li>Main Window - re-organised the buttons.</li>
<li>pt-BR Translation file updated.</li>

View file

@ -19,6 +19,7 @@
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Main Window - when changing the location of the server, it will reload the profile with the config settings in the new location.</li>
<li>Main Window - added discord server button.</li>
<li>Main Window - re-organised the buttons.</li>
</ul>

View file

@ -70,7 +70,7 @@ namespace ServerManagerTool.Lib
public static Server FromPath(string path)
{
var loadedProfile = ServerProfile.LoadFrom(path);
var loadedProfile = ServerProfile.LoadFrom(path, profile: null);
if (loadedProfile == null)
return null;
return new Server(loadedProfile);

View file

@ -213,7 +213,7 @@ namespace ServerManagerTool.Lib
set { SetValue(QueryPortProperty, value); }
}
public static readonly DependencyProperty ServerMapProperty = DependencyProperty.Register(nameof(ServerMap), typeof(string), typeof(ServerProfile), new PropertyMetadata("ConanSandbox"));
public static readonly DependencyProperty ServerMapProperty = DependencyProperty.Register(nameof(ServerMap), typeof(string), typeof(ServerProfile), new PropertyMetadata(String.Empty));
[DataMember]
public string ServerMap
{
@ -225,7 +225,7 @@ namespace ServerManagerTool.Lib
}
}
public static readonly DependencyProperty ServerMapSaveFileNameProperty = DependencyProperty.Register(nameof(ServerMapSaveFileName), typeof(string), typeof(ServerProfile), new PropertyMetadata("game.db"));
public static readonly DependencyProperty ServerMapSaveFileNameProperty = DependencyProperty.Register(nameof(ServerMapSaveFileName), typeof(string), typeof(ServerProfile), new PropertyMetadata(String.Empty));
[DataMember]
public string ServerMapSaveFileName
{
@ -710,10 +710,23 @@ namespace ServerManagerTool.Lib
#region Methods
#region Common Methods
public void ChangeInstallationFolder(string folder)
public void ChangeInstallationFolder(string folder, bool reloadConfigFiles)
{
InstallDirectory = folder;
if (reloadConfigFiles)
{
var serverConfigPath = GetProfileServerConfigDir();
if (Directory.Exists(serverConfigPath))
{
var serverConfigFile = Path.Combine(serverConfigPath, Config.Default.ServerGameConfigFile);
if (File.Exists(serverConfigFile))
{
LoadFromConfigFiles(serverConfigFile, this, exclusions: null);
}
}
}
LoadServerFiles(true, true);
SetupServerFilesWatcher();
}
@ -903,12 +916,12 @@ namespace ServerManagerTool.Lib
return LoadFromProfileFile(file, profile);
var filePath = Path.GetDirectoryName(file);
profile = LoadFromConfigFiles(file, profile);
profile = LoadFromConfigFiles(file, profile, exclusions: null);
if (filePath.EndsWith(Config.Default.ServerConfigRelativePath))
{
var installDirectory = filePath.Replace(Config.Default.ServerConfigRelativePath, string.Empty).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
profile.ChangeInstallationFolder(installDirectory);
profile.ChangeInstallationFolder(installDirectory, reloadConfigFiles: false);
}
return profile;
@ -927,6 +940,13 @@ namespace ServerManagerTool.Lib
profile = profile ?? new ServerProfile();
iniFile.Deserialize(profile, exclusions);
if (string.IsNullOrWhiteSpace(profile.ServerModIds) && iniPath.EndsWith(Config.Default.ServerConfigRelativePath))
{
var installDirectory = iniPath.Replace(Config.Default.ServerConfigRelativePath, string.Empty).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
var modIds = ModUtils.ReadModListFile(installDirectory);
profile.ServerModIds = string.Join(",", modIds);
}
return profile;
}

View file

@ -796,7 +796,7 @@ namespace ServerManagerTool
IsFolderPicker = true,
Title = _globalizer.GetResourceString("ServerSettings_InstallServer_Title")
};
if (!String.IsNullOrWhiteSpace(Settings.InstallDirectory))
if (!string.IsNullOrWhiteSpace(Settings.InstallDirectory))
{
dialog.InitialDirectory = Settings.InstallDirectory;
}
@ -804,7 +804,10 @@ namespace ServerManagerTool
var result = dialog.ShowDialog(Window.GetWindow(this));
if (result == CommonFileDialogResult.Ok)
{
Settings.ChangeInstallationFolder(dialog.FileName);
Settings.ServerMap = string.Empty;
Settings.ServerMapSaveFileName = string.Empty;
Settings.ChangeInstallationFolder(dialog.FileName, reloadConfigFiles: true);
}
}

View file

@ -1,11 +1,11 @@
using ServerManagerTool.Common;
using ServerManagerTool.Common.Extensions;
using ServerManagerTool.Common.Lib;
using ServerManagerTool.Common.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace ServerManagerTool.Utils
{
@ -170,6 +170,28 @@ namespace ServerManagerTool.Utils
}
}
public static List<string> ReadModListFile(string installDirectory)
{
if (string.IsNullOrWhiteSpace(installDirectory) || !Directory.Exists(installDirectory))
return new List<string>();
// get the folder/file details
var modRootFolder = GetModRootPath(installDirectory);
var modListFileName = Config.Default.ServerModListFile;
var modListFile = IOUtils.NormalizePath(Path.Combine(modRootFolder, modListFileName));
// check if the folder/file exists
if (!Directory.Exists(modRootFolder) || !File.Exists(modListFile))
return new List<string>();
var modFiles = File.ReadAllLines(modListFile);
return modFiles
.Select(m => Path.GetFileNameWithoutExtension(m))
.Where(m => m.IsNumeric())
.Where(m => !string.IsNullOrWhiteSpace(m))
.ToList();
}
public static List<string> ValidateModList(List<string> modIdList)
{
// remove all duplicate mod ids.

View file

@ -20,6 +20,7 @@
<br/>
<ul>
<li>Gamedata Files - when adding, deleteing or reloading the gamedata files via the gamedata window, the server manager will reload them and update the settings window.</li>
<li>Main Window - when changing the location of the server, it will reload the profile with the config settings in the new location.</li>
<li>Main Window - added discord server button.</li>
<li>Main Window - re-organised the buttons.</li>
</ul>

View file

@ -19,6 +19,7 @@
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Main Window - when changing the location of the server, it will reload the profile with the config settings in the new location.</li>
<li>Main Window - added discord server button.</li>
<li>Main Window - re-organised the buttons.</li>
</ul>

View file

@ -1,4 +1,5 @@
using System;
using System.Linq;
namespace ServerManagerTool.Common.Extensions
{
@ -13,5 +14,10 @@ namespace ServerManagerTool.Common.Extensions
return value.IndexOf(substring, comparisonType) >= 0;
}
public static bool IsNumeric(this string value)
{
return value.All(char.IsNumber);
}
}
}