some more bugfixes & cleanup

This commit is contained in:
2024-06-22 13:39:17 +02:00
parent 4b78ce1b6f
commit 11e9290fc8
5 changed files with 150 additions and 124 deletions

View File

@@ -2,7 +2,6 @@
namespace ModpackUpdater.Manager;
public static class Extensions
{
public static bool IsSide(this Side @this, Side side)
@@ -30,7 +29,7 @@ public static class Extensions
foreach (FileInfo @file in dir.GetFiles())
{
string targetFilePath = Path.Combine(destinationDir, @file.Name);
@file.CopyTo(targetFilePath);
@file.CopyTo(targetFilePath, true);
}
// If recursive and copying subdirectories, recursively call this method
@@ -43,5 +42,4 @@ public static class Extensions
}
}
}
}

View File

@@ -42,6 +42,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
InstallInfos installInfos = null;
UpdateInfos updateInfos = null;
var result = new UpdateCheckResult();
var exists = modpackInfo.Exists;
if (updateConfig.Maintenance && !options.IgnoreMaintenance)
{
@@ -55,7 +56,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
return result;
}
if (!modpackInfo.Exists)
if (!exists)
{
installInfos = await DownloadInstallInfos();
@@ -66,6 +67,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
{
result.Actions.AddRange(installInfos.Actions);
result.LatestVersion = installInfos.Version;
result.CurrentVersion = installInfos.Version;
}
}
@@ -73,7 +75,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
result.HasError = true;
}
if (options.AllowUpdaterAfterInstall)
if (exists || options.AllowUpdaterAfterInstall)
{
updateInfos = await DownloadUpdateInfos();
@@ -81,11 +83,13 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
{
var updatesOrderes = updateInfos.Updates.OrderByDescending(n => n.Version);
result.LatestVersion = updatesOrderes.First().Version;
if (exists)
result.CurrentVersion = modpackInfo.Version;
result.IsInstalled = true;
var checkingVersionIndex = 0;
var checkingVersion = updatesOrderes.ElementAtOrDefault(checkingVersionIndex);
var actionsZeroIndex = result.Actions.Count; // Ensure we insert update actions behind install actions
while (checkingVersion is not null && checkingVersion.Version > result.CurrentVersion)
{
@@ -97,7 +101,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
actionsToAdd.Add(action);
}
result.Actions.InsertRange(0, actionsToAdd);
result.Actions.InsertRange(actionsZeroIndex, actionsToAdd);
checkingVersionIndex += 1;
checkingVersion = updatesOrderes.ElementAtOrDefault(checkingVersionIndex);

View File

@@ -16,7 +16,7 @@ public class ModpackInfo
[JsonIgnore]
public string LocaLPath { get; private set; }
[JsonIgnore]
public bool Exists => Directory.Exists(LocaLPath);
public bool Exists => File.Exists(GetFilePath(LocaLPath));
public void Save()
{

View File

@@ -22,6 +22,8 @@ public partial class Form1
if (!string.IsNullOrWhiteSpace(updateOptions.ProfileFolder))
LoadMinecraftProfile(updateOptions.ProfileFolder);
else if (!string.IsNullOrWhiteSpace(AppConfig.Instance.LastMinecraftProfilePath))
LoadMinecraftProfile(AppConfig.Instance.LastMinecraftProfilePath);
}
public Form1()
@@ -38,44 +40,49 @@ public partial class Form1
RadButton_PasteModpackConfig.SvgImage = AppSymbolFactory.Instance.GetSvgImage(AppSymbols.paste, SvgImageSize.Small);
}
private bool IsMinecaftProfileLoaded()
private void LoadMinecraftProfile(string folderPath)
{
RadTextBoxControl_MinecraftProfileFolder.Text = folderPath;
AppConfig.Instance.LastMinecraftProfilePath = folderPath;
if (string.IsNullOrWhiteSpace(folderPath))
return;
try
{
modpackInfo = ModpackInfo.TryLoad(folderPath);
RadTextBoxControl_ModpackConfig.Text = modpackInfo.ExtrasKey;
radTextBoxControl_InstallKey.Text = modpackInfo.ExtrasKey;
}
catch
{
return !string.IsNullOrEmpty(GetMinecraftProfilePath());
}
private string GetMinecraftProfilePath()
{
return RadTextBoxControl_MinecraftProfileFolder.Text.Trim();
CheckStatusAndUpdate();
}
private bool IsUpdateConfigLoaded()
private void LoadUpdateConfigFile(string filePath)
{
RadTextBoxControl_ModpackConfig.Text = filePath;
if (string.IsNullOrWhiteSpace(filePath))
return;
try
{
updateConfig = ModpackConfig.LoadFromUrl(filePath);
}
catch (Exception)
{
return !string.IsNullOrEmpty(GetUpdateconfigPath());
}
private string GetUpdateconfigPath()
{
return RadTextBoxControl_ModpackConfig.Text.Trim();
CheckStatusAndUpdate();
}
private bool CheckStatus()
private void LoadInstallKey(string installKey)
{
bool CheckStatusRet;
if (!IsMinecaftProfileLoaded())
{
SetStatus(LangRes.StatusText_MinecraftProfileWarning, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.general_warning_sign, SvgImageSize.Small));
CheckStatusRet = false;
}
else if (!IsUpdateConfigLoaded())
{
SetStatus(LangRes.StatusText_MinecraftProfileWarning, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.general_warning_sign, SvgImageSize.Small));
CheckStatusRet = false;
}
else
CheckStatusRet = true;
return CheckStatusRet;
radTextBoxControl_InstallKey.Text = modpackInfo.ExtrasKey = installKey;
CheckStatusAndUpdate();
}
private void SetStatus(string statusText, RadSvgImage image)
@@ -90,58 +97,47 @@ public partial class Form1
RadLabel_Status.SvgImage = null;
}
private void LoadMinecraftProfile(string folderPath)
private void CheckStatusAndUpdate()
{
RadTextBoxControl_MinecraftProfileFolder.Text = folderPath;
if (IsMinecaftProfileLoaded())
{
try
{
modpackInfo = ModpackInfo.TryLoad(folderPath);
radTextBoxControl_InstallKey.Text = modpackInfo.ExtrasKey;
}
catch
{
RadTextBoxControl_MinecraftProfileFolder.Text = string.Empty;
}
if (string.IsNullOrWhiteSpace(RadTextBoxControl_ModpackConfig.Text) && !string.IsNullOrWhiteSpace(modpackInfo?.ConfigUrl))
LoadUpdateConfigFile(modpackInfo.ConfigUrl);
else if (IsUpdateConfigLoaded())
if (CheckStatus())
RadButton_CheckForUpdates.PerformClick();
}
else
ClearStatus();
}
private void LoadUpdateConfigFile(string filePath)
private bool CheckStatus()
{
static ModpackConfig loadConfig(string filePath)
if (modpackInfo == null || string.IsNullOrWhiteSpace(RadTextBoxControl_MinecraftProfileFolder.Text) /*|| modpackInfo.Valid*/)
{
try
{
return ModpackConfig.LoadFromUrl(filePath);
SetStatus(LangRes.StatusText_MinecraftProfileWarning, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.general_warning_sign, SvgImageSize.Small));
RadButton_PasteModpackConfig.Enabled = false;
radButton_PasteInstallKey.Enabled = false;
RadButton_CheckForUpdates.Enabled = false;
RadButton_Install.Enabled = false;
return false;
}
catch (Exception)
else if (updateConfig == null || string.IsNullOrWhiteSpace(RadTextBoxControl_ModpackConfig.Text))
{
SetStatus(LangRes.StatusText_ConfigIncompleteOrNotLoaded, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.general_warning_sign, SvgImageSize.Small));
RadButton_PasteModpackConfig.Enabled = true;
radButton_PasteInstallKey.Enabled = false;
RadButton_CheckForUpdates.Enabled = false;
RadButton_Install.Enabled = false;
return false;
}
return null;
}
RadTextBoxControl_ModpackConfig.Text = filePath;
if (!string.IsNullOrWhiteSpace(filePath) && loadConfig(filePath) is ModpackConfig modpackConfig)
else if (updateConfig.Maintenance && !updateOptions.IgnoreMaintenance)
{
if (updateConfig.Maintenance && !updateOptions.IgnoreMaintenance)
SetStatus(LangRes.StatusText_Maintenance, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.services, SvgImageSize.Small));
else
RadButton_CheckForUpdates.PerformClick();
}
else
{
ClearStatus();
RadButton_PasteModpackConfig.Enabled = true;
radButton_PasteInstallKey.Enabled = true;
RadButton_CheckForUpdates.Enabled = false;
RadButton_Install.Enabled = false;
return false;
}
RadButton_PasteModpackConfig.Enabled = true;
radButton_PasteInstallKey.Enabled = true;
RadButton_CheckForUpdates.Enabled = true;
RadButton_Install.Enabled = false;
return true;
}
private async Task ExecuteUpdate(bool doInstall)
@@ -150,63 +146,93 @@ public partial class Form1
updater.InstallProgessUpdated += Update_InstallProgessUpdated;
updater.CheckingProgressUpdated += Updated_CheckingProgresssUpdated;
void error()
{
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.close, SvgImageSize.Small));
currentUpdating = false;
}
void installing()
{
SetStatus(LangRes.StatusText_Installing, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.software_installer, SvgImageSize.Small));
currentUpdating = true;
}
void updatesAvailable()
{
SetStatus(LangRes.StatusText_UpdateAvailable, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.software_installer, SvgImageSize.Small));
}
void everythingOk()
{
SetStatus(LangRes.StatusTest_EverythingOk, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.done, SvgImageSize.Small));
currentUpdating = false;
}
// Check only if not pressed "install", not really needed otherwise.
if (lastUpdateCheckResult is null || !doInstall)
{
SetStatus(LangRes.StatusText_CheckingForUpdates, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.update_done, SvgImageSize.Small));
// Check for extras once again
modpackInfo.ExtrasKey = radTextBoxControl_InstallKey.Text.Trim();
updateOptions.IncludeExtras = AppFeatures.AllowExtras.IsEnabled(new AllowExtrasFeatureContext(modpackInfo, updateConfig));
try
{
lastUpdateCheckResult = await updater.Check(updateOptions);
}
catch
catch(Exception)
{
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.close, SvgImageSize.Small));
}
finally
{
}
}
if (lastUpdateCheckResult is null || lastUpdateCheckResult.HasError)
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.close, SvgImageSize.Small));
else if (lastUpdateCheckResult.HasUpdates)
{
if (doInstall)
{
SetStatus(LangRes.StatusText_Installing, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.software_installer, SvgImageSize.Small));
currentUpdating = true;
try
{
if (await updater.Install(lastUpdateCheckResult) == true)
{
lastUpdateCheckResult = null; // Reset last update check, a new one would be needed now.
SetStatus(LangRes.StatusTest_EverythingOk, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.done, SvgImageSize.Small));
}
else
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.close, SvgImageSize.Small));
}
catch (Exception)
{
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.close, SvgImageSize.Small));
error();
if (Debugger.IsAttached)
throw;
}
finally
{
currentUpdating = false;
}
}
else
SetStatus(LangRes.StatusText_UpdateAvailable, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.software_installer, SvgImageSize.Small));
// Error while update check
if (lastUpdateCheckResult is null || lastUpdateCheckResult.HasError)
{
error();
return;
}
// No updates available
if (!lastUpdateCheckResult.HasUpdates)
{
everythingOk();
return;
}
// Updates available (but don't install)
if (!doInstall)
{
updatesAvailable();
return;
}
// Install updates
installing();
currentUpdating = true;
try
{
// Install
if (await updater.Install(lastUpdateCheckResult) == false)
{
error();
return;
}
// Success
lastUpdateCheckResult = null; // Reset last update check, a new one would be needed now.
everythingOk();
}
catch (Exception)
{
// Error
error();
if (Debugger.IsAttached)
throw;
}
else
SetStatus(LangRes.StatusTest_EverythingOk, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.done, SvgImageSize.Small));
}
private void Update_InstallProgessUpdated(UpdateCheckResult result, int processedSyncs)
@@ -238,7 +264,7 @@ public partial class Form1
{
if (modpackInfo == null)
return;
radTextBoxControl_InstallKey.Text = modpackInfo.ExtrasKey = Clipboard.GetText();
LoadInstallKey(Clipboard.GetText());
}
private void RadButton_RefreshConfig_Click(object sender, EventArgs e)
@@ -249,7 +275,6 @@ public partial class Form1
private async void ButtonX_CheckForUpdates_Click(object sender, EventArgs e)
{
ClearStatus();
if (CheckStatus())
await ExecuteUpdate(false);
}
@@ -258,7 +283,6 @@ public partial class Form1
if (!currentUpdating)
{
ClearStatus();
if (CheckStatus())
await ExecuteUpdate(true);
}
}