mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Finished BackupServer and UpdateServer
This commit is contained in:
parent
824daed0d1
commit
0f3c6e6be9
28 changed files with 618 additions and 216 deletions
|
|
@ -3,15 +3,37 @@ using System.Collections.Generic;
|
|||
|
||||
namespace ServerManagerTool.Lib
|
||||
{
|
||||
public class ServerBranchSnapshot
|
||||
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 ServerBranchSnapshotComparer : IEqualityComparer<ServerBranchSnapshot>
|
||||
public class BranchSnapshotComparer : IEqualityComparer<BranchSnapshot>
|
||||
{
|
||||
public bool Equals(ServerBranchSnapshot x, ServerBranchSnapshot y)
|
||||
public bool Equals(BranchSnapshot x, BranchSnapshot y)
|
||||
{
|
||||
//Check whether the compared objects reference the same data.
|
||||
if (Object.ReferenceEquals(x, y)) return true;
|
||||
|
|
@ -24,7 +46,7 @@ namespace ServerManagerTool.Lib
|
|||
return x.BranchName == y.BranchName;
|
||||
}
|
||||
|
||||
public int GetHashCode(ServerBranchSnapshot snapshot)
|
||||
public int GetHashCode(BranchSnapshot snapshot)
|
||||
{
|
||||
//Check whether the object is null
|
||||
if (snapshot is null) return 0;
|
||||
|
|
@ -94,7 +94,7 @@ namespace ServerManagerTool.Lib
|
|||
await this.Runtime.StopAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> UpgradeAsync(CancellationToken cancellationToken, bool updateServer, ServerBranchSnapshot branch, bool validate, bool updateMods, ProgressDelegate progressCallback)
|
||||
public async Task<bool> UpgradeAsync(CancellationToken cancellationToken, bool updateServer, BranchSnapshot branch, bool validate, bool updateMods, ProgressDelegate progressCallback)
|
||||
{
|
||||
await this.Runtime.AttachToProfile(this.Profile);
|
||||
var success = await this.Runtime.UpgradeAsync(cancellationToken, updateServer, branch, validate, updateMods, progressCallback);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
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;
|
||||
|
|
@ -105,6 +106,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)
|
||||
{
|
||||
|
|
@ -264,7 +266,15 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
if (updateServer)
|
||||
{
|
||||
UpgradeLocal(true, cancellationToken, true);
|
||||
try
|
||||
{
|
||||
ServerStatusChangeCallback?.Invoke(ServerStatus.Updating);
|
||||
UpgradeLocal(true, cancellationToken, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ServerStatusChangeCallback?.Invoke(ServerStatus.Stopped);
|
||||
}
|
||||
}
|
||||
|
||||
if (ExitCode != EXITCODE_NORMALEXIT)
|
||||
|
|
@ -2869,7 +2879,7 @@ namespace ServerManagerTool.Lib
|
|||
return ExitCode;
|
||||
}
|
||||
|
||||
public int PerformProfileUpdate(ServerBranchSnapshot branch, ServerProfileSnapshot profile)
|
||||
public int PerformProfileUpdate(BranchSnapshot branch, ServerProfileSnapshot profile)
|
||||
{
|
||||
_profile = profile;
|
||||
|
||||
|
|
@ -2945,7 +2955,7 @@ namespace ServerManagerTool.Lib
|
|||
return ExitCode;
|
||||
}
|
||||
|
||||
public int PerformServerBranchUpdate(ServerBranchSnapshot branch)
|
||||
public int PerformServerBranchUpdate(BranchSnapshot branch)
|
||||
{
|
||||
if (branch == null)
|
||||
return EXITCODE_NORMALEXIT;
|
||||
|
|
@ -3233,8 +3243,8 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
if (exitCode == EXITCODE_NORMALEXIT)
|
||||
{
|
||||
var branches = _profiles.Keys.Where(p => p.EnableAutoUpdate).Select(p => new ServerBranchSnapshot() { BranchName = p.BranchName, BranchPassword = p.BranchPassword}).Distinct(new ServerBranchSnapshotComparer()).ToArray();
|
||||
var exitCodes = new ConcurrentDictionary<ServerBranchSnapshot, int>();
|
||||
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
|
||||
if (Config.Default.AutoUpdate_ParallelUpdate)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ namespace ServerManagerTool.Lib
|
|||
{
|
||||
public class ServerProfileSnapshot
|
||||
{
|
||||
private ServerProfileSnapshot()
|
||||
{
|
||||
}
|
||||
|
||||
public string ProfileId;
|
||||
public string ProfileName;
|
||||
public string InstallDirectory;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,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;
|
||||
|
|
@ -439,7 +439,7 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
|
||||
CheckServerWorldFileExists();
|
||||
UpdateServerStatus(ServerStatus.Initializing, this.Availability, false);
|
||||
UpdateServerStatus(ServerStatus.Initializing, false);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -498,12 +498,12 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpgradeAsync(CancellationToken cancellationToken, bool updateServer, ServerBranchSnapshot branch, bool validate, bool updateMods, ProgressDelegate progressCallback)
|
||||
public async Task<bool> UpgradeAsync(CancellationToken cancellationToken, bool updateServer, BranchSnapshot branch, bool validate, bool updateMods, ProgressDelegate progressCallback)
|
||||
{
|
||||
return await UpgradeAsync(cancellationToken, updateServer, branch, validate, updateMods, null, progressCallback);
|
||||
}
|
||||
|
||||
public async Task<bool> UpgradeAsync(CancellationToken cancellationToken, bool updateServer, ServerBranchSnapshot branch, bool validate, bool updateMods, string[] updateModIds, ProgressDelegate progressCallback)
|
||||
public async Task<bool> UpgradeAsync(CancellationToken cancellationToken, bool updateServer, BranchSnapshot branch, bool validate, bool updateMods, string[] updateModIds, ProgressDelegate progressCallback)
|
||||
{
|
||||
if (updateServer && !Environment.Is64BitOperatingSystem)
|
||||
{
|
||||
|
|
@ -520,7 +520,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.DataDir);
|
||||
|
|
@ -957,7 +957,7 @@ namespace ServerManagerTool.Lib
|
|||
finally
|
||||
{
|
||||
this.lastModStatusQuery = DateTime.MinValue;
|
||||
UpdateServerStatus(ServerStatus.Stopped, Availability, false);
|
||||
UpdateServerStatus(ServerStatus.Stopped, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -993,6 +993,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;
|
||||
|
|
@ -1006,32 +1011,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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue