Auto Update Tweaks

Support Zip Creation - added new config settings.
This commit is contained in:
Brett Hewitson 2021-12-20 10:16:02 +10:00
parent aa265bfbb6
commit 8bf57a71b9
14 changed files with 233 additions and 140 deletions

View file

@ -442,7 +442,7 @@
<value />
</setting>
<setting name="AutoUpdate_ParallelUpdate" serializeAs="String">
<value>True</value>
<value>False</value>
</setting>
<setting name="AutoUpdate_UpdateReasonPrefix" serializeAs="String">
<value>Server Update Reason:</value>
@ -517,7 +517,7 @@
<value>True</value>
</setting>
<setting name="AutoUpdate_SequencialDelayPeriod" serializeAs="String">
<value>0</value>
<value>10</value>
</setting>
<setting name="BackupWorldFile" serializeAs="String">
<value>True</value>

View file

@ -1088,7 +1088,7 @@ namespace ServerManagerTool {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool AutoUpdate_ParallelUpdate {
get {
return ((bool)(this["AutoUpdate_ParallelUpdate"]));
@ -1680,7 +1680,7 @@ namespace ServerManagerTool {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")]
[global::System.Configuration.DefaultSettingValueAttribute("10")]
public int AutoUpdate_SequencialDelayPeriod {
get {
return ((int)(this["AutoUpdate_SequencialDelayPeriod"]));

View file

@ -300,7 +300,7 @@
<Value Profile="(Default)" />
</Setting>
<Setting Name="AutoUpdate_ParallelUpdate" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="AutoUpdate_UpdateReasonPrefix" Type="System.String" Scope="User">
<Value Profile="(Default)">Server Update Reason:</Value>
@ -471,7 +471,7 @@
<Value Profile="(Default)">-listen -nosteamclient -game -server -log</Value>
</Setting>
<Setting Name="AutoUpdate_SequencialDelayPeriod" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
<Value Profile="(Default)">10</Value>
</Setting>
<Setting Name="BackupWorldFile" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>

View file

@ -22,6 +22,7 @@ using System.Net.Mail;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using WPFSharp.Globalizer;
@ -762,7 +763,8 @@ namespace ServerManagerTool.Lib
success = false;
LogProfileMessage("****************************");
LogProfileMessage("ERROR: Failed server update.");
LogProfileMessage("****************************\r\n");
LogProfileMessage("****************************");
LogProfileMessage("Check steamcmd logs for more information why the server update failed.\r\n");
if (Config.Default.SteamCmdRedirectOutput)
LogProfileMessage($"If the server update keeps failing try disabling the '{_globalizer.GetResourceString("GlobalSettings_SteamCmdRedirectOutputLabel")}' option in the settings window.\r\n");
@ -935,6 +937,7 @@ namespace ServerManagerTool.Lib
LogProfileMessage("***************************");
LogProfileMessage("ERROR: Mod download failed.");
LogProfileMessage("***************************\r\n");
LogProfileMessage("Check steamcmd logs for more information why the mod update failed.\r\n");
if (Config.Default.SteamCmdRedirectOutput)
LogProfileMessage($"If the mod update keeps failing try disabling the '{_globalizer.GetResourceString("GlobalSettings_SteamCmdRedirectOutputLabel")}' option in the settings window.\r\n");
@ -1152,6 +1155,7 @@ namespace ServerManagerTool.Lib
}
// stop the server
LogProfileMessage("");
StopServer(CancellationToken.None);
if (ExitCode != EXITCODE_NORMALEXIT)
@ -1162,6 +1166,7 @@ namespace ServerManagerTool.Lib
emailMessage.AppendLine($"Server Manager version: {App.Instance.Version}");
// make a backup of the current profile and config files.
LogProfileMessage("");
CreateProfileBackupArchiveFile(_profile);
if (ExitCode != EXITCODE_NORMALEXIT)
@ -1170,6 +1175,7 @@ namespace ServerManagerTool.Lib
if (BackupWorldFile)
{
// make a backup of the current world file.
LogProfileMessage("");
CreateServerBackupArchiveFile(emailMessage, _profile);
if (ExitCode != EXITCODE_NORMALEXIT)
@ -1184,6 +1190,7 @@ namespace ServerManagerTool.Lib
alertMessage.AppendLine(Config.Default.Alert_UpdateResults);
// check if the server needs to be updated
LogProfileMessage("");
if (updateServer)
{
Task.Delay(5000).Wait();
@ -1212,6 +1219,9 @@ namespace ServerManagerTool.Lib
LogProfileMessage("Validated server files (*new*).");
}
// update the version number
_profile.LastInstalledVersion = GetServerVersion(GetServerVersionFile()).ToString();
LogProfileMessage("Updated server from cache. See patch notes.");
LogProfileMessage(Config.Default.AppPatchNotesUrl);
@ -1241,10 +1251,16 @@ namespace ServerManagerTool.Lib
LogProfileMessage("Server is already up to date, no update required.");
}
var serverVersion = GetServerVersion(GetServerVersionFile()).ToString();
LogProfileMessage($"Server version: {serverVersion}");
emailMessage.AppendLine($"Server version: {serverVersion}");
if (ExitCode != EXITCODE_NORMALEXIT)
return;
// check if the mods need to be updated
LogProfileMessage("");
if (updateModIds.Count > 0)
{
Task.Delay(5000).Wait();
@ -1329,6 +1345,7 @@ namespace ServerManagerTool.Lib
}
ModUtils.CreateModListFile(_profile.InstallDirectory, _profile.ServerModIds);
LogProfileMessage("");
LogProfileMessage("Modlist file updated.");
if (ExitCode == EXITCODE_NORMALEXIT)
@ -1344,12 +1361,14 @@ namespace ServerManagerTool.Lib
}
else
{
LogProfileMessage("Mods are already up to date, no updates required.");
if (modIdList.Count > 0)
LogProfileMessage("Mods are already up to date, no updates required.");
}
if (ExitCode != EXITCODE_NORMALEXIT)
return;
LogProfileMessage("");
if (Config.Default.AutoUpdate_OverrideServerStartup)
{
if (_serverRunning)
@ -1374,13 +1393,15 @@ namespace ServerManagerTool.Lib
}
else
{
if (updateModIds.Count > 0)
LogProfileMessage("");
if (modIdList.Count > 0)
LogProfileMessage("The server and mods files are already up to date, no updates required.");
else
LogProfileMessage("The server files are already up to date, no updates required.");
_serverRunning = GetServerProcess() != null;
LogProfileMessage("");
if (Config.Default.AutoUpdate_OverrideServerStartup)
{
if (!_serverRunning)
@ -1574,7 +1595,10 @@ namespace ServerManagerTool.Lib
{
// failed max limit reached
if (Config.Default.SteamCmdRedirectOutput)
{
LogMessage("Check steamcmd logs for more information why the mod cache update failed.\r\n");
LogMessage($"If the mod cache update keeps failing try disabling the '{_globalizer.GetResourceString("GlobalSettings_SteamCmdRedirectOutputLabel")}' option in the Server Manager settings window.");
}
ExitCode = EXITCODE_CACHEMODUPDATEFAILED;
return;
@ -1693,7 +1717,10 @@ namespace ServerManagerTool.Lib
{
// failed max limit reached
if (Config.Default.SteamCmdRedirectOutput)
{
LogBranchMessage(branchName, $"Check steamcmd logs for more information why the server cache update failed.\r\n");
LogBranchMessage(branchName, $"If the server cache update keeps failing try disabling the '{_globalizer.GetResourceString("GlobalSettings_SteamCmdRedirectOutputLabel")}' option in the ASM settings window.");
}
ExitCode = EXITCODE_CACHESERVERUPDATEFAILED;
return;
@ -1721,6 +1748,9 @@ namespace ServerManagerTool.Lib
else
LogBranchMessage(branchName, $"Server cache does not exist.");
var cacheVersion = GetServerVersion(GetServerCacheVersionFile(branchName)).ToString();
LogBranchMessage(branchName, $"Server cache version: {cacheVersion}");
LogBranchMessage(branchName, "-----------------------------");
LogBranchMessage(branchName, "Finished server cache update.");
LogBranchMessage(branchName, "-----------------------------");
@ -1740,7 +1770,6 @@ namespace ServerManagerTool.Lib
{
_profile = profile;
// create the backup file.
try
{
@ -2197,6 +2226,8 @@ namespace ServerManagerTool.Lib
private static string GetServerCacheTimeFile(string branchName) => IOUtils.NormalizePath(Path.Combine(GetServerCacheFolder(branchName), Config.Default.LastUpdatedTimeFile));
private static string GetServerCacheVersionFile(string branchName) => IOUtils.NormalizePath(Path.Combine(GetServerCacheFolder(branchName), Config.Default.ServerBinaryRelativePath, Config.Default.ServerExeFile));
private string GetServerExecutableFile() => IOUtils.NormalizePath(Path.Combine(_profile.InstallDirectory, Config.Default.ServerBinaryRelativePath, Config.Default.ServerExeFile));
private DateTime GetServerLatestTime(string timeFile)
@ -2239,6 +2270,35 @@ namespace ServerManagerTool.Lib
private string GetServerSaveFolder() => IOUtils.NormalizePath(Path.Combine(_profile.InstallDirectory, Config.Default.SavedFilesRelativePath));
private string GetServerVersionFile() => IOUtils.NormalizePath(Path.Combine(_profile.InstallDirectory, Config.Default.ServerBinaryRelativePath, Config.Default.ServerExeFile));
public static Version GetServerVersion(string versionFile)
{
if (!string.IsNullOrWhiteSpace(versionFile) && File.Exists(versionFile))
{
try
{
var info = FileVersionInfo.GetVersionInfo(versionFile);
var version = $"{info.ProductMajorPart}.{info.ProductMinorPart}";
var name = info.ProductName;
var match = Regex.Match(name, @"\(([0-9]*)\)");
if (match.Success && match.Groups.Count >= 2)
{
var serverVersion = $"{version}.{match.Groups[1].Value}";
if (!string.IsNullOrWhiteSpace(serverVersion) && Version.TryParse(serverVersion, out Version temp))
return temp;
}
}
catch (Exception)
{
// do nothing, just leave
}
}
return new Version(0, 0);
}
private string GetServerWorldFile()
{
var saveFolder = GetServerSaveFolder();

View file

@ -737,7 +737,6 @@
<cctl:AnnotatedSlider Grid.Row="6" Grid.Column="0" Margin="0" Label="{DynamicResource GlobalSettings_LoggingMaxArchiveFilesLabel}" Value="{Binding Config.LoggingMaxArchiveFiles}" Minimum="1" Maximum="1000" SmallChange="1" LargeChange="5" TickFrequency="5" LabelRelativeWidth="Auto" SliderRelativeWidth="15*" SuffixRelativeWidth="Auto" SuffixRelativeMinWidth="40" Suffix="{DynamicResource SliderUnits_Files}" ToolTip="{DynamicResource GlobalSettings_LoggingMaxArchiveFilesTooltip}" IsEnabled="{Binding Config.LoggingEnabled}"/>
</Grid>
</GroupBox>
</Grid>
</ScrollViewer>
</Grid>

View file

@ -1,12 +1,4 @@
using Microsoft.WindowsAPICodePack.Dialogs;
using ServerManagerTool.Common;
using ServerManagerTool.Common.Lib;
using ServerManagerTool.Common.Model;
using ServerManagerTool.Common.Utils;
using ServerManagerTool.Enums;
using ServerManagerTool.Lib;
using ServerManagerTool.Plugin.Common;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
@ -20,8 +12,15 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using Microsoft.WindowsAPICodePack.Dialogs;
using ServerManagerTool.Common;
using ServerManagerTool.Common.Lib;
using ServerManagerTool.Common.Model;
using ServerManagerTool.Common.Utils;
using ServerManagerTool.Enums;
using ServerManagerTool.Lib;
using ServerManagerTool.Plugin.Common;
using WPFSharp.Globalizer;
namespace ServerManagerTool
@ -685,6 +684,9 @@ namespace ServerManagerTool
comment.AppendLine($"HasDiscordBotToken: {!string.IsNullOrWhiteSpace(Config.Default.DiscordBotToken)}");
comment.AppendLine($"DiscordBotServerId: {Config.Default.DiscordBotServerId}");
comment.AppendLine($"DiscordBotPrefix: {Config.Default.DiscordBotPrefix}");
comment.AppendLine($"DiscordBotLogLevel: {Config.Default.DiscordBotLogLevel}");
comment.AppendLine($"DiscordBotAllowAllBots: {Config.Default.DiscordBotAllowAllBots}");
comment.AppendLine($"DiscordBotWhitelist: {string.Join(";", Config.Default.DiscordBotWhitelist)}");
comment.AppendLine($"AllowDiscordBackup: {Config.Default.AllowDiscordBackup}");
comment.AppendLine($"AllowDiscordRestart: {Config.Default.AllowDiscordRestart}");
comment.AppendLine($"AllowDiscordShutdown: {Config.Default.AllowDiscordShutdown}");
@ -698,10 +700,15 @@ namespace ServerManagerTool
comment.AppendLine($"EmailNotify_ShutdownRestart: {Config.Default.EmailNotify_ShutdownRestart}");
comment.AppendLine($"ServerShutdown_UseShutdownCommand: {Config.Default.ServerShutdown_UseShutdownCommand}");
comment.AppendLine($"ServerShutdown_WorldSaveDelay: {Config.Default.ServerShutdown_WorldSaveDelay}");
comment.AppendLine($"BackupWorldFile: {Config.Default.BackupWorldFile}");
comment.AppendLine($"CloseShutdownWindowWhenFinished: {Config.Default.CloseShutdownWindowWhenFinished}");
comment.AppendLine($"AutoUpdate_VerifyServerAfterUpdate: {Config.Default.AutoUpdate_VerifyServerAfterUpdate}");
comment.AppendLine($"SteamCmdRemoveQuit: {CommonConfig.Default.SteamCmdRemoveQuit}");
comment.AppendLine($"UpdateDirectoryPermissions: {Config.Default.UpdateDirectoryPermissions}");
comment.AppendLine($"LoggingEnabled: {Config.Default.LoggingEnabled}");
comment.AppendLine($"LoggingMaxArchiveDays: {Config.Default.LoggingMaxArchiveDays}");
comment.AppendLine($"LoggingMaxArchiveFiles: {Config.Default.LoggingMaxArchiveFiles}");
comment.AppendLine($"ServerShutdown_WorldSaveDelay: {Config.Default.ServerShutdown_WorldSaveDelay}");
var zipFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), this.Settings.ProfileID + ".zip");
if (File.Exists(zipFile)) File.Delete(zipFile);