Finished BackupServer and UpdateServer

This commit is contained in:
Brett Hewitson 2021-12-05 01:56:11 +10:00
parent 824daed0d1
commit 0f3c6e6be9
28 changed files with 618 additions and 216 deletions

View file

@ -5,8 +5,30 @@ namespace ServerManagerTool.Lib
{
public class BranchSnapshot
{
private BranchSnapshot()
{
}
public string BranchName = string.Empty;
public string BranchPassword = string.Empty;
public static BranchSnapshot Create(ServerProfile profile)
{
return new BranchSnapshot
{
BranchName = profile.BranchName,
BranchPassword = profile.BranchPassword
};
}
public static BranchSnapshot Create(ServerProfileSnapshot profile)
{
return new BranchSnapshot
{
BranchName = profile.BranchName,
BranchPassword = profile.BranchPassword
};
}
}
public class BranchSnapshotComparer : IEqualityComparer<BranchSnapshot>

View file

@ -3,6 +3,7 @@ using ServerManagerTool.Common;
using ServerManagerTool.Common.Lib;
using ServerManagerTool.Common.Model;
using ServerManagerTool.Common.Utils;
using ServerManagerTool.Delegates;
using ServerManagerTool.Enums;
using ServerManagerTool.Plugin.Common;
using ServerManagerTool.Utils;
@ -108,6 +109,7 @@ namespace ServerManagerTool.Lib
public int ShutdownInterval = Config.Default.ServerShutdown_GracePeriod;
public ProgressDelegate ProgressCallback = null;
public ProcessWindowStyle SteamCMDProcessWindowStyle = ProcessWindowStyle.Minimized;
public ServerStatusChangeDelegate ServerStatusChangeCallback = null;
public ServerApp(bool resetStartTime = false)
{
@ -261,7 +263,15 @@ namespace ServerManagerTool.Lib
if (updateServer)
{
UpgradeLocal(true, steamCmdRemoveQuit, cancellationToken, true);
try
{
ServerStatusChangeCallback?.Invoke(ServerStatus.Updating);
UpgradeLocal(true, steamCmdRemoveQuit, cancellationToken, true);
}
finally
{
ServerStatusChangeCallback?.Invoke(ServerStatus.Stopped);
}
}
if (ExitCode != EXITCODE_NORMALEXIT)
@ -3060,7 +3070,7 @@ namespace ServerManagerTool.Lib
if (exitCode == EXITCODE_NORMALEXIT)
{
var branches = _profiles.Keys.Where(p => p.EnableAutoUpdate).Select(p => new BranchSnapshot() { BranchName = p.BranchName, BranchPassword = p.BranchPassword }).Distinct(new BranchSnapshotComparer()).ToArray();
var branches = _profiles.Keys.Where(p => p.EnableAutoUpdate).Select(p => BranchSnapshot.Create(p)).Distinct(new BranchSnapshotComparer()).ToArray();
var exitCodes = new ConcurrentDictionary<BranchSnapshot, int>();
// update the server cache for each branch

View file

@ -7,6 +7,10 @@ namespace ServerManagerTool.Lib
{
public class ServerProfileSnapshot
{
private ServerProfileSnapshot()
{
}
public string ProfileId;
public string ProfileName;
public string ServerName;

View file

@ -32,7 +32,7 @@ namespace ServerManagerTool.Lib
public event EventHandler StatusUpdate;
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
private static readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
private readonly List<PropertyChangeNotifier> profileNotifiers = new List<PropertyChangeNotifier>();
private Process serverProcess;
private IAsyncDisposable updateRegistration;
@ -442,7 +442,7 @@ namespace ServerManagerTool.Lib
}
}
UpdateServerStatus(ServerStatus.Initializing, this.Availability, false);
UpdateServerStatus(ServerStatus.Initializing, false);
try
{
@ -516,7 +516,7 @@ namespace ServerManagerTool.Lib
bool isNewInstallation = this.Status == ServerStatus.Uninstalled;
UpdateServerStatus(ServerStatus.Updating, Availability, false);
UpdateServerStatus(ServerStatus.Updating, false);
// Run the SteamCMD to install the server
var steamCmdFile = SteamCmdUpdater.GetSteamCmdFile(Config.Default.DataPath);
@ -938,7 +938,7 @@ namespace ServerManagerTool.Lib
finally
{
this.lastModStatusQuery = DateTime.MinValue;
UpdateServerStatus(ServerStatus.Stopped, Availability, false);
UpdateServerStatus(ServerStatus.Stopped, false);
}
}
@ -961,6 +961,11 @@ namespace ServerManagerTool.Lib
this.lastModStatusQuery = DateTime.MinValue;
}
public void UpdateServerStatus(ServerStatus serverStatus, bool sendAlert)
{
UpdateServerStatus(serverStatus, Availability, sendAlert);
}
public void UpdateServerStatus(ServerStatus serverStatus, AvailabilityStatus availabilityStatus, bool sendAlert)
{
this.Status = serverStatus;
@ -974,32 +979,29 @@ namespace ServerManagerTool.Lib
public void UpdateServerStatusString()
{
switch (Status)
StatusString = GetServerStatusString(Status);
}
public static string GetServerStatusString(ServerStatus status)
{
switch (status)
{
case ServerStatus.Initializing:
StatusString = _globalizer.GetResourceString("ServerSettings_RuntimeStatusInitializingLabel");
break;
return _globalizer.GetResourceString("ServerSettings_RuntimeStatusInitializingLabel");
case ServerStatus.Running:
StatusString = _globalizer.GetResourceString("ServerSettings_RuntimeStatusRunningLabel");
break;
return _globalizer.GetResourceString("ServerSettings_RuntimeStatusRunningLabel");
case ServerStatus.Stopped:
StatusString = _globalizer.GetResourceString("ServerSettings_RuntimeStatusStoppedLabel");
break;
return _globalizer.GetResourceString("ServerSettings_RuntimeStatusStoppedLabel");
case ServerStatus.Stopping:
StatusString = _globalizer.GetResourceString("ServerSettings_RuntimeStatusStoppingLabel");
break;
return _globalizer.GetResourceString("ServerSettings_RuntimeStatusStoppingLabel");
case ServerStatus.Uninstalled:
StatusString = _globalizer.GetResourceString("ServerSettings_RuntimeStatusUninstalledLabel");
break;
return _globalizer.GetResourceString("ServerSettings_RuntimeStatusUninstalledLabel");
case ServerStatus.Unknown:
StatusString = _globalizer.GetResourceString("ServerSettings_RuntimeStatusUnknownLabel");
break;
return _globalizer.GetResourceString("ServerSettings_RuntimeStatusUnknownLabel");
case ServerStatus.Updating:
StatusString = _globalizer.GetResourceString("ServerSettings_RuntimeStatusUpdatingLabel");
break;
return _globalizer.GetResourceString("ServerSettings_RuntimeStatusUpdatingLabel");
default:
StatusString = _globalizer.GetResourceString("ServerSettings_RuntimeStatusUnknownLabel");
break;
return _globalizer.GetResourceString("ServerSettings_RuntimeStatusUnknownLabel");
}
}