mirror of
https://github.com/Tribufu/ServerManagers
synced 2026-08-09 04:31:06 +00:00
Server File Changes
- added Testlive server option - changed code to use different appids.
This commit is contained in:
parent
96ba2c3474
commit
a20354c1b1
32 changed files with 969 additions and 812 deletions
|
|
@ -9,6 +9,7 @@ namespace ServerManagerTool.Lib
|
|||
{
|
||||
}
|
||||
|
||||
public string AppIdServer = string.Empty;
|
||||
public string BranchName = string.Empty;
|
||||
public string BranchPassword = string.Empty;
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ namespace ServerManagerTool.Lib
|
|||
{
|
||||
return new BranchSnapshot
|
||||
{
|
||||
AppIdServer = profile.UseTestlive ? Config.Default.AppIdServer_Testlive : string.Empty,
|
||||
BranchName = profile.BranchName,
|
||||
BranchPassword = profile.BranchPassword
|
||||
};
|
||||
|
|
@ -25,6 +27,7 @@ namespace ServerManagerTool.Lib
|
|||
{
|
||||
return new BranchSnapshot
|
||||
{
|
||||
AppIdServer = profile.AppIdServer,
|
||||
BranchName = profile.BranchName,
|
||||
BranchPassword = profile.BranchPassword
|
||||
};
|
||||
|
|
@ -42,17 +45,20 @@ namespace ServerManagerTool.Lib
|
|||
if (x is null || y is null)
|
||||
return false;
|
||||
|
||||
//Check whether the snapshot' properties are equal.
|
||||
return string.Equals(x.BranchName ?? string.Empty, y.BranchName ?? string.Empty, StringComparison.OrdinalIgnoreCase);
|
||||
//Check whether the snapshot properties are equal.
|
||||
var result = string.Equals(x.AppIdServer ?? string.Empty, y.AppIdServer ?? string.Empty, StringComparison.OrdinalIgnoreCase);
|
||||
return result && string.Equals(x.BranchName ?? string.Empty, y.BranchName ?? string.Empty, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public int GetHashCode(BranchSnapshot snapshot)
|
||||
{
|
||||
//Check whether the object is null
|
||||
if (snapshot is null) return 0;
|
||||
if (snapshot is null)
|
||||
return 0;
|
||||
|
||||
//Get hash code for the Name field if it is not null.
|
||||
return snapshot.BranchName == null ? 0 : snapshot.BranchName.GetHashCode();
|
||||
var result = $"{snapshot.AppIdServer ?? ""}-{snapshot.BranchName ?? ""}";
|
||||
return result.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -787,7 +787,7 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
}
|
||||
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(steamCmdRemoveQuit, Config.Default.SteamCmdInstallServerArgsFormat, Config.Default.SteamCmd_AnonymousUsername, _profile.InstallDirectory, Config.Default.AppIdServer, steamCmdInstallServerBetaArgs.ToString(), validate ? "validate" : string.Empty);
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(steamCmdRemoveQuit, Config.Default.SteamCmdInstallServerArgsFormat, Config.Default.SteamCmd_AnonymousUsername, _profile.InstallDirectory, _profile.AppIdServer, steamCmdInstallServerBetaArgs.ToString(), validate ? "validate" : string.Empty);
|
||||
if (steamCmdRemoveQuit)
|
||||
{
|
||||
SteamCMDProcessWindowStyle = ProcessWindowStyle.Normal;
|
||||
|
|
@ -882,8 +882,8 @@ namespace ServerManagerTool.Lib
|
|||
LogProfileMessage($"{modDetail.title}.\r\n");
|
||||
}
|
||||
|
||||
var modCachePath = ModUtils.GetModCachePath(modId);
|
||||
var cacheTimeFile = ModUtils.GetLatestModCacheTimeFile(modId);
|
||||
var modCachePath = ModUtils.GetModCachePath(modId, _profile.AppId);
|
||||
var cacheTimeFile = ModUtils.GetLatestModCacheTimeFile(modId, _profile.AppId);
|
||||
var modPath = ModUtils.GetModPath(_profile.InstallDirectory, modId);
|
||||
var modTimeFile = ModUtils.GetLatestModTimeFile(_profile.InstallDirectory, modId);
|
||||
|
||||
|
|
@ -963,13 +963,9 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
steamCmdArgs = string.Empty;
|
||||
if (Config.Default.SteamCmd_UseAnonymousCredentials)
|
||||
{
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(steamCmdRemoveQuit, Config.Default.SteamCmdInstallModArgsFormat, Config.Default.SteamCmd_AnonymousUsername, Config.Default.AppId, modId);
|
||||
}
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(steamCmdRemoveQuit, Config.Default.SteamCmdInstallModArgsFormat, Config.Default.SteamCmd_AnonymousUsername, _profile.AppId, modId);
|
||||
else
|
||||
{
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(steamCmdRemoveQuit, Config.Default.SteamCmdInstallModArgsFormat, Config.Default.SteamCmd_Username, Config.Default.AppId, modId);
|
||||
}
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(steamCmdRemoveQuit, Config.Default.SteamCmdInstallModArgsFormat, Config.Default.SteamCmd_Username, _profile.AppId, modId);
|
||||
|
||||
modSuccess = ServerUpdater.UpgradeModsAsync(steamCmdFile, steamCmdArgs, workingDirectory, null, null, Config.Default.SteamCmdRedirectOutput ? modOutputHandler : null, cancellationToken, SteamCMDProcessWindowStyle).Result;
|
||||
if (modSuccess && downloadSuccessful)
|
||||
|
|
@ -988,7 +984,7 @@ namespace ServerManagerTool.Lib
|
|||
if (modDetail == null || modDetail.time_updated <= 0)
|
||||
{
|
||||
// get the version number from the steamcmd workshop file.
|
||||
steamLastUpdated = ModUtils.GetSteamWorkshopLatestTime(ModUtils.GetSteamWorkshopFile(), modId).ToString();
|
||||
steamLastUpdated = ModUtils.GetSteamWorkshopLatestTime(ModUtils.GetSteamWorkshopFile(_profile.AppId), modId).ToString();
|
||||
}
|
||||
|
||||
// update the last updated file with the steam updated time.
|
||||
|
|
@ -1156,26 +1152,32 @@ namespace ServerManagerTool.Lib
|
|||
LogProfileMessage("Started server update...");
|
||||
LogProfileMessage("------------------------");
|
||||
LogProfileMessage($"Server Manager version: {App.Instance.Version}");
|
||||
LogProfileMessage($"Server branch: {GetBranchName(_profile.BranchName)}");
|
||||
LogProfileMessage($"Server branch: {GetBranchInfo(_profile.AppIdServer, _profile.BranchName)}");
|
||||
LogProfileMessage($"Profile Name: {_profile.ProfileName}");
|
||||
|
||||
// check if the server needs to be updated
|
||||
var serverCacheLastUpdated = GetServerLatestTime(GetServerCacheTimeFile(_profile?.BranchName));
|
||||
var serverCacheLastUpdated = GetServerLatestTime(GetServerCacheTimeFile(_profile.AppIdServer, _profile.BranchName));
|
||||
var serverLastUpdated = GetServerLatestTime(GetServerTimeFile());
|
||||
var updateServer = serverCacheLastUpdated > serverLastUpdated;
|
||||
|
||||
// check if any of the mods need to be updated
|
||||
var updateModIds = new List<string>();
|
||||
var modIdList = GetModList();
|
||||
var appModList = GetModList();
|
||||
|
||||
// cycle through each mod.
|
||||
foreach (var modId in modIdList)
|
||||
foreach (var appMods in appModList)
|
||||
{
|
||||
// check if the mod needs to be updated.
|
||||
var modCacheLastUpdated = ModUtils.GetModLatestTime(ModUtils.GetLatestModCacheTimeFile(modId));
|
||||
var modLastUpdated = ModUtils.GetModLatestTime(ModUtils.GetLatestModTimeFile(_profile.InstallDirectory, modId));
|
||||
if (modCacheLastUpdated > modLastUpdated || modLastUpdated == 0)
|
||||
updateModIds.Add(modId);
|
||||
if (!appMods.AppId.Equals(_profile.AppId, StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
foreach (var modId in appMods.ModIdList)
|
||||
{
|
||||
// check if the mod needs to be updated.
|
||||
var modCacheLastUpdated = ModUtils.GetModLatestTime(ModUtils.GetLatestModCacheTimeFile(modId, _profile.AppId));
|
||||
var modLastUpdated = ModUtils.GetModLatestTime(ModUtils.GetLatestModTimeFile(_profile.InstallDirectory, modId));
|
||||
if (modCacheLastUpdated > modLastUpdated || modLastUpdated == 0)
|
||||
updateModIds.Add(modId);
|
||||
}
|
||||
}
|
||||
|
||||
if (ExitCode != EXITCODE_NORMALEXIT)
|
||||
|
|
@ -1272,7 +1274,7 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
try
|
||||
{
|
||||
var cacheFolder = GetServerCacheFolder(_profile?.BranchName);
|
||||
var cacheFolder = GetServerCacheFolder(_profile?.AppIdServer, _profile?.BranchName);
|
||||
|
||||
if (Directory.Exists(cacheFolder))
|
||||
{
|
||||
|
|
@ -1293,14 +1295,14 @@ namespace ServerManagerTool.Lib
|
|||
_profile.LastInstalledVersion = GetServerVersion(GetServerVersionFile()).ToString();
|
||||
|
||||
LogProfileMessage("Updated server from cache. See patch notes.");
|
||||
LogProfileMessage(Config.Default.AppPatchNotesUrl);
|
||||
LogProfileMessage(_profile.UseTestlive ? Config.Default.AppPatchNotesUrl_Testlive : Config.Default.AppPatchNotesUrl);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Config.Default.Alert_ServerUpdate))
|
||||
alertMessage.AppendLine(Config.Default.Alert_ServerUpdate);
|
||||
|
||||
emailMessage.AppendLine();
|
||||
emailMessage.AppendLine("Updated server from cache. See patch notes.");
|
||||
emailMessage.AppendLine(Config.Default.AppPatchNotesUrl);
|
||||
emailMessage.AppendLine(_profile.UseTestlive ? Config.Default.AppPatchNotesUrl_Testlive : Config.Default.AppPatchNotesUrl);
|
||||
|
||||
_profile.ServerUpdated = true;
|
||||
}
|
||||
|
|
@ -1346,7 +1348,7 @@ namespace ServerManagerTool.Lib
|
|||
for (var index = 0; index < updateModIds.Count; index++)
|
||||
{
|
||||
var modId = updateModIds[index];
|
||||
var modCachePath = ModUtils.GetModCachePath(modId);
|
||||
var modCachePath = ModUtils.GetModCachePath(modId, _profile.AppId);
|
||||
var modPath = ModUtils.GetModPath(_profile.InstallDirectory, modId);
|
||||
var modName = modDetails?.publishedfiledetails?.FirstOrDefault(m => m.publishedfileid == modId)?.title ?? string.Empty;
|
||||
|
||||
|
|
@ -1431,7 +1433,7 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
else
|
||||
{
|
||||
if (modIdList.Count > 0)
|
||||
if (appModList.Sum(m => m.ModIdList.Count) > 0)
|
||||
LogProfileMessage("Mods are already up to date, no updates required.");
|
||||
}
|
||||
|
||||
|
|
@ -1464,7 +1466,7 @@ namespace ServerManagerTool.Lib
|
|||
else
|
||||
{
|
||||
LogProfileMessage("");
|
||||
if (modIdList.Count > 0)
|
||||
if (appModList.Sum(m => m.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.");
|
||||
|
|
@ -1500,10 +1502,10 @@ namespace ServerManagerTool.Lib
|
|||
private void UpdateModCache()
|
||||
{
|
||||
// get a list of mods to be processed
|
||||
var modIdList = GetModList();
|
||||
var appModList = GetModList();
|
||||
|
||||
// check if there are any mods to be processed
|
||||
if (modIdList.Count == 0)
|
||||
if (appModList.Count == 0 || appModList.Sum(m => m.ModIdList.Count) == 0)
|
||||
{
|
||||
ExitCode = EXITCODE_NORMALEXIT;
|
||||
return;
|
||||
|
|
@ -1515,12 +1517,13 @@ namespace ServerManagerTool.Lib
|
|||
LogMessage("----------------------------");
|
||||
LogMessage($"Server Manager version: {App.Instance.Version}");
|
||||
|
||||
LogMessage($"Downloading mod information for {modIdList.Count} mods from steam.");
|
||||
var totalMods = appModList.Sum(m => m.ModIdList.Count);
|
||||
LogMessage($"Downloading mod information for {totalMods} mods from steam.");
|
||||
|
||||
var forceUpdateMods = Config.Default.ServerUpdate_ForceUpdateModsIfNoSteamInfo || string.IsNullOrWhiteSpace(SteamUtils.SteamWebApiKey);
|
||||
|
||||
// get the details of the mods to be processed.
|
||||
var modDetails = SteamUtils.GetSteamModDetails(modIdList);
|
||||
var modDetails = SteamUtils.GetSteamModDetails(appModList);
|
||||
if (modDetails == null)
|
||||
{
|
||||
if (forceUpdateMods)
|
||||
|
|
@ -1538,19 +1541,19 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
else
|
||||
{
|
||||
LogMessage($"Downloaded mod information for {modIdList.Count} mods from steam.");
|
||||
LogMessage($"Downloaded mod information for {totalMods} mods from steam.");
|
||||
LogMessage("");
|
||||
}
|
||||
|
||||
// cycle through each mod finding which needs to be updated.
|
||||
var updateModIds = new List<string>();
|
||||
var updateMods = new List<(string AppId, List<string> ModIdList)>();
|
||||
if (modDetails == null)
|
||||
{
|
||||
if (forceUpdateMods)
|
||||
{
|
||||
LogMessage("All mods will be updated - unable to download steam information and force mod update is TRUE.");
|
||||
|
||||
updateModIds.AddRange(modIdList);
|
||||
updateMods = appModList;
|
||||
modDetails = new PublishedFileDetailsResponse();
|
||||
}
|
||||
}
|
||||
|
|
@ -1559,46 +1562,67 @@ namespace ServerManagerTool.Lib
|
|||
if (Config.Default.ServerUpdate_ForceUpdateMods)
|
||||
{
|
||||
LogMessage("All mods will be updated - force mod update is TRUE.");
|
||||
updateModIds.AddRange(modIdList);
|
||||
updateMods = appModList;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMessage("Mods will be selectively updated - force mod update is FALSE.");
|
||||
|
||||
foreach (var modId in modIdList)
|
||||
foreach (var appMod in appModList)
|
||||
{
|
||||
var modDetail = modDetails.publishedfiledetails?.FirstOrDefault(m => m.publishedfileid.Equals(modId, StringComparison.OrdinalIgnoreCase));
|
||||
if (modDetail == null)
|
||||
foreach (var modId in appMod.ModIdList)
|
||||
{
|
||||
LogMessage($"Mod {modId} will not be updated - unable to download steam information.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (modDetail.time_updated == 0)
|
||||
{
|
||||
LogMessage($"Mod {modId} will be updated - mod is private.");
|
||||
updateModIds.Add(modId);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cacheTimeFile = ModUtils.GetLatestModCacheTimeFile(modId);
|
||||
|
||||
// check if the mod needs to be updated
|
||||
var steamLastUpdated = modDetail.time_updated;
|
||||
var modCacheLastUpdated = ModUtils.GetModLatestTime(cacheTimeFile);
|
||||
if (steamLastUpdated > modCacheLastUpdated)
|
||||
var modDetail = modDetails.publishedfiledetails?.FirstOrDefault(m => m.publishedfileid.Equals(modId, StringComparison.OrdinalIgnoreCase));
|
||||
if (modDetail == null)
|
||||
{
|
||||
LogMessage($"Mod {modId} will be updated - new version found.");
|
||||
updateModIds.Add(modId);
|
||||
LogMessage($"Mod {modId} will not be updated - unable to download steam information.");
|
||||
continue;
|
||||
}
|
||||
else if (modCacheLastUpdated == 0)
|
||||
|
||||
var updateMod = updateMods.FirstOrDefault(m => m.AppId.Equals(appMod.AppId, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (modDetail.time_updated == 0)
|
||||
{
|
||||
LogMessage($"Mod {modId} will be updated - cache not versioned.");
|
||||
updateModIds.Add(modId);
|
||||
LogMessage($"Mod {modId} will be updated - mod is private.");
|
||||
if (updateMod == default)
|
||||
updateMods.Add((appMod.AppId, new List<string> { modId }));
|
||||
else
|
||||
updateMod.ModIdList.Add(modId);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMessage($"Mod {modId} update skipped - cache contains the latest version.");
|
||||
if (modDetail.creator_app_id is null || modDetail.creator_app_id.Equals(appMod.AppId, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var cacheTimeFile = ModUtils.GetLatestModCacheTimeFile(modId, appMod.AppId);
|
||||
|
||||
// check if the mod needs to be updated
|
||||
var steamLastUpdated = modDetail.time_updated;
|
||||
var modCacheLastUpdated = ModUtils.GetModLatestTime(cacheTimeFile);
|
||||
if (steamLastUpdated > modCacheLastUpdated)
|
||||
{
|
||||
LogMessage($"Mod {modId} will be updated - new version found.");
|
||||
if (updateMod == default)
|
||||
updateMods.Add((appMod.AppId, new List<string> { modId }));
|
||||
else
|
||||
updateMod.ModIdList.Add(modId);
|
||||
}
|
||||
else if (modCacheLastUpdated == 0)
|
||||
{
|
||||
LogMessage($"Mod {modId} will be updated - cache not versioned.");
|
||||
if (updateMod == default)
|
||||
updateMods.Add((appMod.AppId, new List<string> { modId }));
|
||||
else
|
||||
updateMod.ModIdList.Add(modId);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMessage($"Mod {modId} update skipped - cache contains the latest version.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMessage($"Mod {modId} update skipped - mod does not belong to this application.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1613,97 +1637,105 @@ namespace ServerManagerTool.Lib
|
|||
return;
|
||||
}
|
||||
|
||||
var totalUpdateMods = updateMods.Sum(m => m.ModIdList.Count);
|
||||
var updateIndex = 0;
|
||||
|
||||
// cycle through each mod id.
|
||||
for (var index = 0; index < updateModIds.Count; index++)
|
||||
foreach (var appMod in updateMods)
|
||||
{
|
||||
var modId = updateModIds[index];
|
||||
var modDetail = modDetails.publishedfiledetails?.FirstOrDefault(m => m.publishedfileid.Equals(modId, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
var cacheTimeFile = ModUtils.GetLatestModCacheTimeFile(modId);
|
||||
var modCachePath = ModUtils.GetModCachePath(modId);
|
||||
|
||||
var downloadSuccessful = false;
|
||||
|
||||
DataReceivedEventHandler modOutputHandler = (s, e) =>
|
||||
for (var index = 0; index < appMod.ModIdList.Count; index++)
|
||||
{
|
||||
var dataValue = e.Data ?? string.Empty;
|
||||
LogMessage(dataValue);
|
||||
if (dataValue.StartsWith("Success."))
|
||||
var modId = appMod.ModIdList[index];
|
||||
var modDetail = modDetails.publishedfiledetails?.FirstOrDefault(m => m.publishedfileid.Equals(modId, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
var cacheTimeFile = ModUtils.GetLatestModCacheTimeFile(modId, appMod.AppId);
|
||||
var modCachePath = ModUtils.GetModCachePath(modId, appMod.AppId);
|
||||
|
||||
var downloadSuccessful = false;
|
||||
|
||||
DataReceivedEventHandler modOutputHandler = (s, e) =>
|
||||
{
|
||||
downloadSuccessful = true;
|
||||
}
|
||||
};
|
||||
|
||||
LogMessage("");
|
||||
LogMessage($"Started mod cache update {index + 1} of {updateModIds.Count}");
|
||||
LogMessage($"{modId} - {modDetail?.title ?? "<unknown>"}");
|
||||
|
||||
var attempt = 0;
|
||||
while (true)
|
||||
{
|
||||
attempt++;
|
||||
downloadSuccessful = !Config.Default.SteamCmdRedirectOutput;
|
||||
|
||||
// update the mod cache
|
||||
var steamCmdArgs = string.Empty;
|
||||
if (Config.Default.SteamCmd_UseAnonymousCredentials)
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(false, Config.Default.SteamCmdInstallModArgsFormat, Config.Default.SteamCmd_AnonymousUsername, Config.Default.AppId, modId);
|
||||
else
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(false, Config.Default.SteamCmdInstallModArgsFormat, Config.Default.SteamCmd_Username, Config.Default.AppId, modId);
|
||||
var workingDirectory = Config.Default.DataPath;
|
||||
|
||||
var success = ServerUpdater.UpgradeModsAsync(steamCmdFile, steamCmdArgs, workingDirectory, null, null, Config.Default.SteamCmdRedirectOutput ? modOutputHandler : null, CancellationToken.None, SteamCMDProcessWindowStyle).Result;
|
||||
if (success && downloadSuccessful)
|
||||
// download was successful, exit loop and continue.
|
||||
break;
|
||||
|
||||
// download was not successful, log a failed attempt.
|
||||
var logError = $"Mod {modId} cache update failed";
|
||||
if (Config.Default.AutoUpdate_RetryOnFail)
|
||||
logError += $" - attempt {attempt}.";
|
||||
LogError(logError);
|
||||
|
||||
// check if we have reached the max failed attempt limit.
|
||||
if (!Config.Default.AutoUpdate_RetryOnFail || attempt >= MAXRETRIES_STEAM)
|
||||
{
|
||||
// failed max limit reached
|
||||
if (Config.Default.SteamCmdRedirectOutput)
|
||||
var dataValue = e.Data ?? string.Empty;
|
||||
LogMessage(dataValue);
|
||||
if (dataValue.StartsWith("Success."))
|
||||
{
|
||||
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.");
|
||||
downloadSuccessful = true;
|
||||
}
|
||||
};
|
||||
|
||||
updateIndex++;
|
||||
|
||||
LogMessage("");
|
||||
LogMessage($"Started mod cache update {updateIndex} of {totalUpdateMods}");
|
||||
LogMessage($"{modId} - {modDetail?.title ?? "<unknown>"}");
|
||||
|
||||
var attempt = 0;
|
||||
while (true)
|
||||
{
|
||||
attempt++;
|
||||
downloadSuccessful = !Config.Default.SteamCmdRedirectOutput;
|
||||
|
||||
// update the mod cache
|
||||
var steamCmdArgs = string.Empty;
|
||||
if (Config.Default.SteamCmd_UseAnonymousCredentials)
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(false, Config.Default.SteamCmdInstallModArgsFormat, Config.Default.SteamCmd_AnonymousUsername, appMod.AppId, modId);
|
||||
else
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(false, Config.Default.SteamCmdInstallModArgsFormat, Config.Default.SteamCmd_Username, appMod.AppId, modId);
|
||||
var workingDirectory = Config.Default.DataPath;
|
||||
|
||||
var success = ServerUpdater.UpgradeModsAsync(steamCmdFile, steamCmdArgs, workingDirectory, null, null, Config.Default.SteamCmdRedirectOutput ? modOutputHandler : null, CancellationToken.None, SteamCMDProcessWindowStyle).Result;
|
||||
if (success && downloadSuccessful)
|
||||
// download was successful, exit loop and continue.
|
||||
break;
|
||||
|
||||
// download was not successful, log a failed attempt.
|
||||
var logError = $"Mod {modId} cache update failed";
|
||||
if (Config.Default.AutoUpdate_RetryOnFail)
|
||||
logError += $" - attempt {attempt}.";
|
||||
LogError(logError);
|
||||
|
||||
// check if we have reached the max failed attempt limit.
|
||||
if (!Config.Default.AutoUpdate_RetryOnFail || attempt >= MAXRETRIES_STEAM)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
ExitCode = EXITCODE_CACHEMODUPDATEFAILED;
|
||||
return;
|
||||
Task.Delay(5000).Wait();
|
||||
}
|
||||
|
||||
Task.Delay(5000).Wait();
|
||||
}
|
||||
|
||||
// check if any of the mod files have changed.
|
||||
if (Directory.Exists(modCachePath))
|
||||
{
|
||||
var gotNewVersion = new DirectoryInfo(modCachePath).GetFiles("*.*", SearchOption.AllDirectories).Any(file => file.LastWriteTime >= _startTime);
|
||||
|
||||
if (gotNewVersion)
|
||||
LogMessage("***** New version downloaded. *****");
|
||||
else
|
||||
LogMessage("No new version.");
|
||||
|
||||
var steamLastUpdated = modDetail?.time_updated.ToString() ?? string.Empty;
|
||||
if (modDetail == null || modDetail.time_updated <= 0)
|
||||
// check if any of the mod files have changed.
|
||||
if (Directory.Exists(modCachePath))
|
||||
{
|
||||
// get the version number from the steamcmd workshop file.
|
||||
steamLastUpdated = ModUtils.GetSteamWorkshopLatestTime(ModUtils.GetSteamWorkshopFile(), modId).ToString();
|
||||
var gotNewVersion = new DirectoryInfo(modCachePath).GetFiles("*.*", SearchOption.AllDirectories).Any(file => file.LastWriteTime >= _startTime);
|
||||
|
||||
if (gotNewVersion)
|
||||
LogMessage("***** New version downloaded. *****");
|
||||
else
|
||||
LogMessage("No new version.");
|
||||
|
||||
var steamLastUpdated = modDetail?.time_updated.ToString() ?? string.Empty;
|
||||
if (modDetail == null || modDetail.time_updated <= 0)
|
||||
{
|
||||
// get the version number from the steamcmd workshop file.
|
||||
steamLastUpdated = ModUtils.GetSteamWorkshopLatestTime(ModUtils.GetSteamWorkshopFile(appMod.AppId), modId).ToString();
|
||||
}
|
||||
|
||||
File.WriteAllText(cacheTimeFile, steamLastUpdated);
|
||||
LogMessage($"Mod {modId} cache version: {steamLastUpdated}");
|
||||
}
|
||||
else
|
||||
LogMessage($"Mod {modId} cache does not exist.");
|
||||
|
||||
File.WriteAllText(cacheTimeFile, steamLastUpdated);
|
||||
LogMessage($"Mod {modId} cache version: {steamLastUpdated}");
|
||||
LogMessage($"Finished mod {modId} cache update.");
|
||||
}
|
||||
else
|
||||
LogMessage($"Mod {modId} cache does not exist.");
|
||||
|
||||
LogMessage($"Finished mod {modId} cache update.");
|
||||
}
|
||||
|
||||
LogMessage("---------------------------");
|
||||
|
|
@ -1713,13 +1745,13 @@ namespace ServerManagerTool.Lib
|
|||
ExitCode = EXITCODE_NORMALEXIT;
|
||||
}
|
||||
|
||||
private void UpdateServerCache(string branchName, string branchPassword)
|
||||
private void UpdateServerCache(string appIdServer, string branchName, string branchPassword)
|
||||
{
|
||||
LogBranchMessage(branchName, "-------------------------------");
|
||||
LogBranchMessage(branchName, "Starting server cache update...");
|
||||
LogBranchMessage(branchName, "-------------------------------");
|
||||
LogBranchMessage(branchName, $"Server Manager version: {App.Instance.Version}");
|
||||
LogBranchMessage(branchName, $"Server branch: {GetBranchName(branchName)}");
|
||||
LogBranchMessage(appIdServer, branchName, "-------------------------------");
|
||||
LogBranchMessage(appIdServer, branchName, "Starting server cache update...");
|
||||
LogBranchMessage(appIdServer, branchName, "-------------------------------");
|
||||
LogBranchMessage(appIdServer, branchName, $"Server Manager version: {App.Instance.Version}");
|
||||
LogBranchMessage(appIdServer, branchName, $"Server branch: {GetBranchInfo(appIdServer, branchName)}");
|
||||
|
||||
var gotNewVersion = false;
|
||||
var downloadSuccessful = false;
|
||||
|
|
@ -1727,7 +1759,7 @@ namespace ServerManagerTool.Lib
|
|||
var steamCmdFile = SteamCmdUpdater.GetSteamCmdFile(Config.Default.DataPath);
|
||||
if (string.IsNullOrWhiteSpace(steamCmdFile) || !File.Exists(steamCmdFile))
|
||||
{
|
||||
LogBranchError(branchName, $"SteamCMD could not be found. Expected location is {steamCmdFile}");
|
||||
LogBranchError(appIdServer, branchName, $"SteamCMD could not be found. Expected location is {steamCmdFile}");
|
||||
ExitCode = EXITCODE_STEAMCMDNOTFOUND;
|
||||
return;
|
||||
}
|
||||
|
|
@ -1735,7 +1767,7 @@ namespace ServerManagerTool.Lib
|
|||
DataReceivedEventHandler serverOutputHandler = (s, e) =>
|
||||
{
|
||||
var dataValue = e.Data ?? string.Empty;
|
||||
LogBranchMessage(branchName, dataValue);
|
||||
LogBranchMessage(appIdServer, branchName, dataValue);
|
||||
if (!gotNewVersion && dataValue.Contains("downloading,"))
|
||||
{
|
||||
gotNewVersion = true;
|
||||
|
|
@ -1758,9 +1790,9 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
}
|
||||
|
||||
var cacheFolder = GetServerCacheFolder(branchName);
|
||||
var cacheFolder = GetServerCacheFolder(appIdServer, branchName);
|
||||
|
||||
LogBranchMessage(branchName, "Server update started.");
|
||||
LogBranchMessage(appIdServer, branchName, "Server update started.");
|
||||
|
||||
var attempt = 0;
|
||||
while (true)
|
||||
|
|
@ -1771,7 +1803,7 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
// update the server cache
|
||||
var validate = Config.Default.AutoUpdate_ValidateServerFiles;
|
||||
var steamCmdArgs = SteamUtils.BuildSteamCmdArguments(false, Config.Default.SteamCmdInstallServerArgsFormat, Config.Default.SteamCmd_AnonymousUsername, cacheFolder, Config.Default.AppIdServer, steamCmdInstallServerBetaArgs.ToString(), validate ? "validate" : string.Empty);
|
||||
var steamCmdArgs = SteamUtils.BuildSteamCmdArguments(false, Config.Default.SteamCmdInstallServerArgsFormat, Config.Default.SteamCmd_AnonymousUsername, cacheFolder, appIdServer, steamCmdInstallServerBetaArgs.ToString(), validate ? "validate" : string.Empty);
|
||||
var workingDirectory = Config.Default.DataPath;
|
||||
|
||||
var success = ServerUpdater.UpgradeServerAsync(steamCmdFile, steamCmdArgs, workingDirectory, null, null, cacheFolder, Config.Default.SteamCmdRedirectOutput ? serverOutputHandler : null, CancellationToken.None, SteamCMDProcessWindowStyle).Result;
|
||||
|
|
@ -1783,7 +1815,7 @@ namespace ServerManagerTool.Lib
|
|||
var logError = "Server cache update failed";
|
||||
if (Config.Default.AutoUpdate_RetryOnFail)
|
||||
logError += $" - attempt {attempt}.";
|
||||
LogBranchError(branchName, logError);
|
||||
LogBranchError(appIdServer, branchName, logError);
|
||||
|
||||
// check if we have reached the max failed attempt limit.
|
||||
if (!Config.Default.AutoUpdate_RetryOnFail || attempt >= MAXRETRIES_STEAM)
|
||||
|
|
@ -1791,8 +1823,8 @@ 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.");
|
||||
LogBranchMessage(appIdServer, branchName, $"Check steamcmd logs for more information why the server cache update failed.\r\n");
|
||||
LogBranchMessage(appIdServer, branchName, $"If the server cache update keeps failing try disabling the '{_globalizer.GetResourceString("GlobalSettings_SteamCmdRedirectOutputLabel")}' option in the server manager settings window.");
|
||||
}
|
||||
|
||||
ExitCode = EXITCODE_CACHESERVERUPDATEFAILED;
|
||||
|
|
@ -1810,24 +1842,24 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
if (gotNewVersion)
|
||||
{
|
||||
LogBranchMessage(branchName, "***** New version downloaded. *****");
|
||||
LogBranchMessage(appIdServer, branchName, "***** New version downloaded. *****");
|
||||
|
||||
var latestCacheTimeFile = GetServerCacheTimeFile(branchName);
|
||||
var latestCacheTimeFile = GetServerCacheTimeFile(appIdServer, branchName);
|
||||
File.WriteAllText(latestCacheTimeFile, _startTime.ToString("o", CultureInfo.CurrentCulture));
|
||||
}
|
||||
else
|
||||
LogBranchMessage(branchName, "No new version.");
|
||||
LogBranchMessage(appIdServer, branchName, "No new version.");
|
||||
}
|
||||
else
|
||||
LogBranchMessage(branchName, $"Server cache does not exist.");
|
||||
LogBranchMessage(appIdServer, branchName, $"Server cache does not exist.");
|
||||
|
||||
var cacheVersion = GetServerVersion(GetServerCacheVersionFile(branchName)).ToString();
|
||||
LogBranchMessage(branchName, $"Server cache version: {cacheVersion}");
|
||||
var cacheVersion = GetServerVersion(GetServerCacheVersionFile(appIdServer, branchName)).ToString();
|
||||
LogBranchMessage(appIdServer, branchName, $"Server cache version: {cacheVersion}");
|
||||
|
||||
LogBranchMessage(branchName, "-----------------------------");
|
||||
LogBranchMessage(branchName, "Finished server cache update.");
|
||||
LogBranchMessage(branchName, "-----------------------------");
|
||||
LogBranchMessage(branchName, "");
|
||||
LogBranchMessage(appIdServer, branchName, "-----------------------------");
|
||||
LogBranchMessage(appIdServer, branchName, "Finished server cache update.");
|
||||
LogBranchMessage(appIdServer, branchName, "-----------------------------");
|
||||
LogBranchMessage(appIdServer, branchName, "");
|
||||
ExitCode = EXITCODE_NORMALEXIT;
|
||||
}
|
||||
|
||||
|
|
@ -2207,7 +2239,14 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
}
|
||||
|
||||
public static string GetBranchName(string branchName) => string.IsNullOrWhiteSpace(branchName) ? Config.Default.DefaultServerBranchName : branchName;
|
||||
public static string GetBranchInfo(string appIdServer, string branchName)
|
||||
{
|
||||
var branchInfo = string.IsNullOrWhiteSpace(branchName) ? Config.Default.DefaultServerBranchName : branchName;
|
||||
if (!string.IsNullOrWhiteSpace(appIdServer) && !appIdServer.Equals(Config.Default.AppIdServer, StringComparison.OrdinalIgnoreCase))
|
||||
branchInfo += $"_{appIdServer}";
|
||||
|
||||
return branchInfo;
|
||||
}
|
||||
|
||||
private string GetLauncherFile() => IOUtils.NormalizePath(Path.Combine(GetProfileServerConfigDir(_profile), Config.Default.LauncherFile));
|
||||
|
||||
|
|
@ -2254,9 +2293,9 @@ namespace ServerManagerTool.Lib
|
|||
return LogManager.GetLogger(loggerName);
|
||||
}
|
||||
|
||||
private List<string> GetModList()
|
||||
private List<(string AppId, List<string> ModIdList)> GetModList()
|
||||
{
|
||||
var modIdList = new List<string>();
|
||||
var appMods = new List<(string AppId, List<string> ModIdList)>();
|
||||
|
||||
// check if we need to update the mods.
|
||||
if (Config.Default.ServerUpdate_UpdateModsWhenUpdatingServer)
|
||||
|
|
@ -2270,17 +2309,36 @@ namespace ServerManagerTool.Lib
|
|||
if (!profile.EnableAutoUpdate)
|
||||
continue;
|
||||
|
||||
var modIdList = new List<string>();
|
||||
|
||||
modIdList.AddRange(profile.ServerModIds);
|
||||
|
||||
var appMod = appMods.FirstOrDefault(m => m.AppId.Equals(profile.AppId, StringComparison.OrdinalIgnoreCase));
|
||||
if (appMod == default)
|
||||
appMods.Add((profile.AppId, modIdList));
|
||||
else
|
||||
appMod.ModIdList.AddRange(modIdList);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// get all the mods for only the specified profile.
|
||||
var modIdList = new List<string>();
|
||||
|
||||
modIdList.AddRange(_profile.ServerModIds);
|
||||
|
||||
appMods.Add((_profile.AppId, modIdList));
|
||||
}
|
||||
}
|
||||
|
||||
return ModUtils.ValidateModList(modIdList);
|
||||
for (int i = 0; i < appMods.Count; i++)
|
||||
{
|
||||
var validatedModList = ModUtils.ValidateModList(appMods[i].ModIdList);
|
||||
|
||||
appMods[i].ModIdList.Clear();
|
||||
appMods[i].ModIdList.AddRange(validatedModList);
|
||||
}
|
||||
return appMods;
|
||||
}
|
||||
|
||||
public static string GetMutexName(string directory)
|
||||
|
|
@ -2337,11 +2395,15 @@ namespace ServerManagerTool.Lib
|
|||
return IOUtils.NormalizePath(Path.Combine(Config.Default.BackupPath, Config.Default.ServersInstallPath, profile.ProfileId.ToLower()));
|
||||
}
|
||||
|
||||
private static string GetServerCacheFolder(string branchName) => IOUtils.NormalizePath(Path.Combine(Config.Default.AutoUpdate_CacheDir, $"{Config.Default.ServerBranchFolderPrefix}{GetBranchName(branchName)}"));
|
||||
public static string GetServerCacheFolder(string appIdServer, string branchName)
|
||||
{
|
||||
var branchInfo = GetBranchInfo(appIdServer, branchName) ?? "unknown";
|
||||
return IOUtils.NormalizePath(Path.Combine(Config.Default.AutoUpdate_CacheDir, $"{Config.Default.ServerBranchFolderPrefix}{branchInfo}"));
|
||||
}
|
||||
|
||||
private static string GetServerCacheTimeFile(string branchName) => IOUtils.NormalizePath(Path.Combine(GetServerCacheFolder(branchName), Config.Default.LastUpdatedTimeFile));
|
||||
private static string GetServerCacheTimeFile(string appIdServer, string branchName) => IOUtils.NormalizePath(Path.Combine(GetServerCacheFolder(appIdServer, branchName), Config.Default.LastUpdatedTimeFile));
|
||||
|
||||
private static string GetServerCacheVersionFile(string branchName) => IOUtils.NormalizePath(Path.Combine(GetServerCacheFolder(branchName), Config.Default.ServerBinaryRelativePath, Config.Default.ServerExeFile));
|
||||
private static string GetServerCacheVersionFile(string appIdServer, string branchName) => IOUtils.NormalizePath(Path.Combine(GetServerCacheFolder(appIdServer, branchName), Config.Default.ServerBinaryRelativePath, Config.Default.ServerExeFile));
|
||||
|
||||
private string GetServerExecutableFile() => IOUtils.NormalizePath(Path.Combine(_profile.InstallDirectory, Config.Default.ServerBinaryRelativePath, Config.Default.ServerExeFile));
|
||||
|
||||
|
|
@ -2516,7 +2578,7 @@ namespace ServerManagerTool.Lib
|
|||
Debug.WriteLine($"[INFO] {message}");
|
||||
}
|
||||
|
||||
private void LogBranchError(string branchName, string error, bool includeProgressCallback = true)
|
||||
private void LogBranchError(string appIdServer, string branchName, string error, bool includeProgressCallback = true)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(error))
|
||||
return;
|
||||
|
|
@ -2526,10 +2588,12 @@ namespace ServerManagerTool.Lib
|
|||
if (includeProgressCallback)
|
||||
ProgressCallback?.Invoke(0, $"[ERROR] {error}");
|
||||
|
||||
Debug.WriteLine($"[ERROR] (Branch {GetBranchName(branchName) ?? "unknown"}) {error}");
|
||||
var branchInfo = GetBranchInfo(appIdServer, branchName) ?? "unknown";
|
||||
|
||||
Debug.WriteLine($"[ERROR] (Branch {branchInfo}) {error}");
|
||||
}
|
||||
|
||||
private void LogBranchMessage(string branchName, string message, bool includeProgressCallback = true)
|
||||
private void LogBranchMessage(string appIdServer, string branchName, string message, bool includeProgressCallback = true)
|
||||
{
|
||||
message = message ?? string.Empty;
|
||||
|
||||
|
|
@ -2538,7 +2602,9 @@ namespace ServerManagerTool.Lib
|
|||
if (includeProgressCallback)
|
||||
ProgressCallback?.Invoke(0, $"{message}");
|
||||
|
||||
Debug.WriteLine($"[INFO] (Branch {GetBranchName(branchName) ?? "unknown"}) {message}");
|
||||
var branchInfo = GetBranchInfo(appIdServer, branchName) ?? "unknown";
|
||||
|
||||
Debug.WriteLine($"[INFO] (Branch {branchInfo}) {message}");
|
||||
}
|
||||
|
||||
private void LogProfileDebug(string message, bool includeProgressCallback = true)
|
||||
|
|
@ -2957,16 +3023,17 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
Mutex mutex = null;
|
||||
var createdNew = false;
|
||||
var branchInfo = GetBranchInfo(branch.AppIdServer, branch.BranchName) ?? "unknown";
|
||||
|
||||
if (OutputLogs)
|
||||
{
|
||||
_loggerBranch = GetLogger(GetLogFolder(LOGPREFIX_AUTOUPDATE), $"{LOGPREFIX_AUTOUPDATE}", $"BranchUpdate_{GetBranchName(branch.BranchName)}");
|
||||
_loggerBranch = GetLogger(GetLogFolder(LOGPREFIX_AUTOUPDATE), $"{LOGPREFIX_AUTOUPDATE}", $"BranchUpdate_{branchInfo}");
|
||||
_loggerProfile = GetLogger(GetProfileLogFolder(profile.ProfileId, LOGPREFIX_AUTOUPDATE), $"{LOGPREFIX_AUTOUPDATE}_{profile.ProfileId}", "Update");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
LogBranchMessage(branch.BranchName, $"[{_profile.ProfileName}] Started server update process.");
|
||||
LogBranchMessage(branch.AppIdServer, branch.BranchName, $"[{_profile.ProfileName}] Started server update process.");
|
||||
|
||||
// try to establish a mutex for the profile.
|
||||
var mutexName = GetMutexName(_profile.InstallDirectory);
|
||||
|
|
@ -2987,7 +3054,7 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
UpdateFiles();
|
||||
|
||||
LogBranchMessage(branch.BranchName, $"[{_profile.ProfileName}] Finished server update process.");
|
||||
LogBranchMessage(branch.AppIdServer, branch.BranchName, $"[{_profile.ProfileName}] Finished server update process.");
|
||||
|
||||
if (ExitCode != EXITCODE_NORMALEXIT)
|
||||
{
|
||||
|
|
@ -3000,7 +3067,7 @@ namespace ServerManagerTool.Lib
|
|||
{
|
||||
ExitCode = EXITCODE_PROCESSALREADYRUNNING;
|
||||
LogProfileMessage("Cancelled server update process, could not lock server.");
|
||||
LogBranchMessage(branch.BranchName, $"[{_profile.ProfileName}] Cancelled server update process, could not lock server.");
|
||||
LogBranchMessage(branch.AppIdServer, branch.BranchName, $"[{_profile.ProfileName}] Cancelled server update process, could not lock server.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -3047,47 +3114,50 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
Mutex mutex = null;
|
||||
var createdNew = false;
|
||||
var branchInfo = GetBranchInfo(branch.AppIdServer, branch.BranchName) ?? "unknown";
|
||||
|
||||
if (OutputLogs)
|
||||
_loggerBranch = GetLogger(GetLogFolder(LOGPREFIX_AUTOUPDATE), $"{LOGPREFIX_AUTOUPDATE}", $"BranchUpdate_{GetBranchName(branch.BranchName)}");
|
||||
{
|
||||
_loggerBranch = GetLogger(GetLogFolder(LOGPREFIX_AUTOUPDATE), $"{LOGPREFIX_AUTOUPDATE}", $"BranchUpdate_{branchInfo}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
LogMessage($"[{GetBranchName(branch.BranchName)}] Started branch update process.");
|
||||
LogMessage($"[{branchInfo}] Started branch update process.");
|
||||
|
||||
var cacheFolder = GetServerCacheFolder(branch.BranchName);
|
||||
var cacheFolder = GetServerCacheFolder(branch.AppIdServer, branch.BranchName);
|
||||
|
||||
// try to establish a mutex for the profile.
|
||||
var mutexName = GetMutexName(cacheFolder);
|
||||
LogBranchMessage(branch.BranchName, $"Attempting to establish a lock on the cache ({mutexName})");
|
||||
LogBranchMessage(branch.AppIdServer, branch.BranchName, $"Attempting to establish a lock on the cache ({mutexName})");
|
||||
|
||||
mutex = new Mutex(true, mutexName, out createdNew);
|
||||
if (!createdNew)
|
||||
{
|
||||
var timeout = new TimeSpan(0, MUTEX_TIMEOUT, 0);
|
||||
LogBranchMessage(branch.BranchName, $"Could not lock cache, waiting for cache to unlock - timeout set to {timeout}.");
|
||||
LogBranchMessage(branch.AppIdServer, branch.BranchName, $"Could not lock cache, waiting for cache to unlock - timeout set to {timeout}.");
|
||||
createdNew = mutex.WaitOne(timeout);
|
||||
}
|
||||
|
||||
// check if the mutex was established
|
||||
if (createdNew)
|
||||
{
|
||||
LogBranchMessage(branch.BranchName, "Cache lock established.\r\n");
|
||||
LogBranchMessage(branch.AppIdServer, branch.BranchName, "Cache lock established.\r\n");
|
||||
|
||||
// update the server cache for the branch
|
||||
UpdateServerCache(branch.BranchName, branch.BranchPassword);
|
||||
UpdateServerCache(branch.AppIdServer, branch.BranchName, branch.BranchPassword);
|
||||
|
||||
if (ExitCode != EXITCODE_NORMALEXIT)
|
||||
{
|
||||
if (Config.Default.EmailNotify_AutoUpdate)
|
||||
SendEmail($"{GetBranchName(branch.BranchName)} branch update", Config.Default.Alert_UpdateProcessError, true);
|
||||
SendEmail($"{branchInfo} branch update", Config.Default.Alert_UpdateProcessError, true);
|
||||
ProcessAlert(AlertType.Error, Config.Default.Alert_UpdateProcessError);
|
||||
}
|
||||
|
||||
if (ExitCode == EXITCODE_NORMALEXIT)
|
||||
{
|
||||
// get the profile associated with the branch
|
||||
var profiles = _profiles.Keys.Where(p => p.EnableAutoUpdate && string.Equals(p.BranchName, branch.BranchName, StringComparison.OrdinalIgnoreCase));
|
||||
var profiles = _profiles.Keys.Where(p => p.EnableAutoUpdate && string.Equals(p.AppIdServer, branch.AppIdServer, StringComparison.OrdinalIgnoreCase) && string.Equals(p.BranchName, branch.BranchName, StringComparison.OrdinalIgnoreCase));
|
||||
var profileExitCodes = new ConcurrentDictionary<ServerProfileSnapshot, int>();
|
||||
|
||||
if (Config.Default.AutoUpdate_ParallelUpdate)
|
||||
|
|
@ -3132,27 +3202,27 @@ namespace ServerManagerTool.Lib
|
|||
ExitCode = EXITCODE_EXITWITHERRORS;
|
||||
}
|
||||
|
||||
LogMessage($"[{GetBranchName(branch.BranchName)}] Finished branch update process.");
|
||||
LogMessage($"[{branchInfo}] Finished branch update process.");
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitCode = EXITCODE_PROCESSALREADYRUNNING;
|
||||
LogMessage($"[{GetBranchName(branch.BranchName)}] Cancelled branch update process, could not lock cache.");
|
||||
LogMessage($"[{branchInfo}] Cancelled branch update process, could not lock cache.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogBranchError(branch.BranchName, ex.Message);
|
||||
LogBranchError(branch.BranchName, ex.GetType().ToString());
|
||||
LogBranchError(branch.AppIdServer, branch.BranchName, ex.Message);
|
||||
LogBranchError(branch.AppIdServer, branch.BranchName, ex.GetType().ToString());
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
LogBranchMessage(branch.BranchName, $"InnerException - {ex.InnerException.Message}");
|
||||
LogBranchMessage(branch.BranchName, ex.InnerException.GetType().ToString());
|
||||
LogBranchMessage(branch.AppIdServer, branch.BranchName, $"InnerException - {ex.InnerException.Message}");
|
||||
LogBranchMessage(branch.AppIdServer, branch.BranchName, ex.InnerException.GetType().ToString());
|
||||
}
|
||||
LogBranchMessage(branch.BranchName, $"StackTrace\r\n{ex.StackTrace}");
|
||||
LogBranchMessage(branch.AppIdServer, branch.BranchName, $"StackTrace\r\n{ex.StackTrace}");
|
||||
|
||||
if (Config.Default.EmailNotify_AutoUpdate)
|
||||
SendEmail($"{GetBranchName(branch.BranchName)} branch update", Config.Default.Alert_UpdateProcessError, true);
|
||||
SendEmail($"{branchInfo} branch update", Config.Default.Alert_UpdateProcessError, true);
|
||||
ProcessAlert(AlertType.Error, Config.Default.Alert_UpdateProcessError);
|
||||
ExitCode = EXITCODE_UNKNOWNTHREADERROR;
|
||||
}
|
||||
|
|
@ -3169,8 +3239,8 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
}
|
||||
|
||||
LogBranchMessage(branch.BranchName, "");
|
||||
LogBranchMessage(branch.BranchName, $"Exitcode = {ExitCode}");
|
||||
LogBranchMessage(branch.AppIdServer, branch.BranchName, "");
|
||||
LogBranchMessage(branch.AppIdServer, branch.BranchName, $"Exitcode = {ExitCode}");
|
||||
return ExitCode;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -650,6 +650,14 @@ namespace ServerManagerTool.Lib
|
|||
#endregion
|
||||
|
||||
#region Server Details
|
||||
public static readonly DependencyProperty UseTestliveProperty = DependencyProperty.Register(nameof(UseTestlive), typeof(bool), typeof(ServerProfile), new PropertyMetadata(false));
|
||||
[DataMember]
|
||||
public bool UseTestlive
|
||||
{
|
||||
get { return (bool)GetValue(UseTestliveProperty); }
|
||||
set { SetValue(UseTestliveProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty BranchNameProperty = DependencyProperty.Register(nameof(BranchName), typeof(string), typeof(ServerProfile), new PropertyMetadata(String.Empty));
|
||||
[DataMember]
|
||||
public string BranchName
|
||||
|
|
@ -786,7 +794,8 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
try
|
||||
{
|
||||
var manifestFile = ModUtils.GetSteamManifestFile(InstallDirectory);
|
||||
var appIdServer = UseTestlive ? Config.Default.AppIdServer_Testlive : Config.Default.AppIdServer;
|
||||
var manifestFile = ModUtils.GetSteamManifestFile(InstallDirectory, appIdServer);
|
||||
if (string.IsNullOrWhiteSpace(manifestFile) || !File.Exists(manifestFile))
|
||||
return;
|
||||
|
||||
|
|
@ -1256,7 +1265,7 @@ namespace ServerManagerTool.Lib
|
|||
validationMessage = string.Empty;
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
var appId = Config.Default.AppId;
|
||||
var appId = UseTestlive ? Config.Default.AppId_Testlive : Config.Default.AppId;
|
||||
|
||||
// checking the port values are within the valid range
|
||||
if (ServerPort < ushort.MinValue || ServerPort > ushort.MaxValue)
|
||||
|
|
@ -1593,6 +1602,7 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
public void ResetServerDetailsSection()
|
||||
{
|
||||
this.ClearValue(UseTestliveProperty);
|
||||
this.ClearValue(BranchNameProperty);
|
||||
this.ClearValue(BranchPasswordProperty);
|
||||
}
|
||||
|
|
@ -1680,6 +1690,7 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
private void SyncServerDetails(ServerProfile sourceProfile)
|
||||
{
|
||||
this.SetValue(UseTestliveProperty, sourceProfile.UseTestlive);
|
||||
this.SetValue(BranchNameProperty, sourceProfile.BranchName);
|
||||
this.SetValue(BranchPasswordProperty, sourceProfile.BranchPassword);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ namespace ServerManagerTool.Lib
|
|||
public bool MOTDIntervalEnabled;
|
||||
public int MOTDInterval;
|
||||
|
||||
public string AppId;
|
||||
public string AppIdServer;
|
||||
public bool UseTestlive;
|
||||
public string BranchName;
|
||||
public string BranchPassword;
|
||||
|
||||
|
|
@ -75,6 +78,9 @@ namespace ServerManagerTool.Lib
|
|||
MOTDIntervalEnabled = profile.MOTDIntervalEnabled && !string.IsNullOrWhiteSpace(profile.MOTD),
|
||||
MOTDInterval = Math.Max(1, Math.Min(int.MaxValue, profile.MOTDInterval)),
|
||||
|
||||
AppId = profile.UseTestlive ? Config.Default.AppId_Testlive : Config.Default.AppId,
|
||||
AppIdServer = profile.UseTestlive ? Config.Default.AppIdServer_Testlive : Config.Default.AppIdServer,
|
||||
UseTestlive = profile.UseTestlive,
|
||||
BranchName = profile.BranchName,
|
||||
BranchPassword = profile.BranchPassword,
|
||||
|
||||
|
|
|
|||
|
|
@ -659,8 +659,10 @@ namespace ServerManagerTool.Lib
|
|||
// Server Update Section
|
||||
// *********************
|
||||
|
||||
var branchInfo = ServerApp.GetBranchInfo(branch?.AppIdServer, branch?.BranchName);
|
||||
|
||||
progressCallback?.Invoke(0, $"{SteamCmdUpdater.OUTPUT_PREFIX} Starting server update.");
|
||||
progressCallback?.Invoke(0, $"{SteamCmdUpdater.OUTPUT_PREFIX} Server branch: {ServerApp.GetBranchName(branch?.BranchName)}.");
|
||||
progressCallback?.Invoke(0, $"{SteamCmdUpdater.OUTPUT_PREFIX} Server branch: {branchInfo}.");
|
||||
progressCallback?.Invoke(0, $"{SteamCmdUpdater.OUTPUT_PREFIX} Profile name: {this.ProfileSnapshot.ProfileName}.");
|
||||
|
||||
// create the branch arguments
|
||||
|
|
@ -678,8 +680,7 @@ namespace ServerManagerTool.Lib
|
|||
// Check if this is a new server installation.
|
||||
if (isNewInstallation && Config.Default.AutoUpdate_EnableUpdate && !string.IsNullOrWhiteSpace(Config.Default.AutoUpdate_CacheDir))
|
||||
{
|
||||
var branchName = string.IsNullOrWhiteSpace(branch?.BranchName) ? Config.Default.DefaultServerBranchName : branch.BranchName;
|
||||
var cacheFolder = IOUtils.NormalizePath(Path.Combine(Config.Default.AutoUpdate_CacheDir, $"{Config.Default.ServerBranchFolderPrefix}{branchName}"));
|
||||
var cacheFolder = ServerApp.GetServerCacheFolder(branch?.AppIdServer, branch?.BranchName);
|
||||
|
||||
// check if the auto-update facility is enabled and the cache folder defined.
|
||||
if (!string.IsNullOrWhiteSpace(cacheFolder) && Directory.Exists(cacheFolder))
|
||||
|
|
@ -718,7 +719,7 @@ namespace ServerManagerTool.Lib
|
|||
};
|
||||
|
||||
var steamCmdRemoveQuit = CommonConfig.Default.SteamCmdRemoveQuit && !Config.Default.SteamCmdRedirectOutput;
|
||||
var steamCmdArgs = SteamUtils.BuildSteamCmdArguments(steamCmdRemoveQuit, Config.Default.SteamCmdInstallServerArgsFormat, Config.Default.SteamCmd_AnonymousUsername, this.ProfileSnapshot.InstallDirectory, Config.Default.AppIdServer, steamCmdInstallServerBetaArgs.ToString(), validate ? "validate" : string.Empty);
|
||||
var steamCmdArgs = SteamUtils.BuildSteamCmdArguments(steamCmdRemoveQuit, Config.Default.SteamCmdInstallServerArgsFormat, Config.Default.SteamCmd_AnonymousUsername, this.ProfileSnapshot.InstallDirectory, this.ProfileSnapshot.AppIdServer, steamCmdInstallServerBetaArgs.ToString(), validate ? "validate" : string.Empty);
|
||||
var workingDirectory = Config.Default.DataPath;
|
||||
|
||||
success = await ServerUpdater.UpgradeServerAsync(steamCmdFile, steamCmdArgs, workingDirectory, null, null, this.ProfileSnapshot.InstallDirectory, Config.Default.SteamCmdRedirectOutput ? serverOutputHandler : null, cancellationToken, steamCmdRemoveQuit ? ProcessWindowStyle.Normal : ProcessWindowStyle.Minimized);
|
||||
|
|
@ -811,16 +812,27 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
progressCallback?.Invoke(0, $"{SteamCmdUpdater.OUTPUT_PREFIX} Mod {modTitle}.");
|
||||
|
||||
var modCachePath = ModUtils.GetModCachePath(modId);
|
||||
var cacheTimeFile = ModUtils.GetLatestModCacheTimeFile(modId);
|
||||
var modPath = ModUtils.GetModPath(this.ProfileSnapshot.InstallDirectory, modId);
|
||||
var modTimeFile = ModUtils.GetLatestModTimeFile(this.ProfileSnapshot.InstallDirectory, modId);
|
||||
|
||||
var modCacheLastUpdated = 0;
|
||||
var downloadMod = true;
|
||||
var copyMod = true;
|
||||
var updateError = false;
|
||||
|
||||
if (modDetail?.creator_app_id != null && !modDetail.creator_app_id.Equals(this.ProfileSnapshot.AppId, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
progressCallback?.Invoke(0, $"{SteamCmdUpdater.OUTPUT_PREFIX} ***************************************************************************");
|
||||
progressCallback?.Invoke(0, $"{SteamCmdUpdater.OUTPUT_PREFIX} ERROR: Mod cannot be updated, this mod does not belong to this application.");
|
||||
progressCallback?.Invoke(0, $"{SteamCmdUpdater.OUTPUT_PREFIX} ***************************************************************************");
|
||||
|
||||
downloadMod = false;
|
||||
copyMod = false;
|
||||
updateError = true;
|
||||
}
|
||||
|
||||
var modCachePath = ModUtils.GetModCachePath(modId, this.ProfileSnapshot.AppId);
|
||||
var cacheTimeFile = ModUtils.GetLatestModCacheTimeFile(modId, this.ProfileSnapshot.AppId);
|
||||
var modPath = ModUtils.GetModPath(this.ProfileSnapshot.InstallDirectory, modId);
|
||||
var modTimeFile = ModUtils.GetLatestModTimeFile(this.ProfileSnapshot.InstallDirectory, modId);
|
||||
|
||||
if (downloadMod)
|
||||
{
|
||||
// check if the mod needs to be downloaded, or force the download.
|
||||
|
|
@ -893,9 +905,9 @@ namespace ServerManagerTool.Lib
|
|||
var steamCmdArgs = string.Empty;
|
||||
var steamCmdRemoveQuit = CommonConfig.Default.SteamCmdRemoveQuit && !Config.Default.SteamCmdRedirectOutput;
|
||||
if (Config.Default.SteamCmd_UseAnonymousCredentials)
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(steamCmdRemoveQuit, Config.Default.SteamCmdInstallModArgsFormat, Config.Default.SteamCmd_AnonymousUsername, Config.Default.AppId, modId);
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(steamCmdRemoveQuit, Config.Default.SteamCmdInstallModArgsFormat, Config.Default.SteamCmd_AnonymousUsername, this.ProfileSnapshot.AppId, modId);
|
||||
else
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(steamCmdRemoveQuit, Config.Default.SteamCmdInstallModArgsFormat, Config.Default.SteamCmd_Username, Config.Default.AppId, modId);
|
||||
steamCmdArgs = SteamUtils.BuildSteamCmdArguments(steamCmdRemoveQuit, Config.Default.SteamCmdInstallModArgsFormat, Config.Default.SteamCmd_Username, this.ProfileSnapshot.AppId, modId);
|
||||
var workingDirectory = Config.Default.DataPath;
|
||||
|
||||
modSuccess = await ServerUpdater.UpgradeModsAsync(steamCmdFile, steamCmdArgs, workingDirectory, null, null, Config.Default.SteamCmdRedirectOutput ? modOutputHandler : null, cancellationToken, steamCmdRemoveQuit ? ProcessWindowStyle.Normal : ProcessWindowStyle.Minimized);
|
||||
|
|
@ -915,7 +927,7 @@ namespace ServerManagerTool.Lib
|
|||
if (modDetail == null || modDetail.time_updated <= 0)
|
||||
{
|
||||
// get the version number from the steamcmd workshop file.
|
||||
steamLastUpdated = ModUtils.GetSteamWorkshopLatestTime(ModUtils.GetSteamWorkshopFile(), modId).ToString();
|
||||
steamLastUpdated = ModUtils.GetSteamWorkshopLatestTime(ModUtils.GetSteamWorkshopFile(this.ProfileSnapshot.AppId), modId).ToString();
|
||||
}
|
||||
|
||||
// update the last updated file with the steam updated time.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue