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

@ -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>