some more bugfixes & cleanup
This commit is contained in:
@@ -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)
|
||||
{
|
||||
return !string.IsNullOrEmpty(GetMinecraftProfilePath());
|
||||
}
|
||||
RadTextBoxControl_MinecraftProfileFolder.Text = folderPath;
|
||||
AppConfig.Instance.LastMinecraftProfilePath = folderPath;
|
||||
|
||||
private string GetMinecraftProfilePath()
|
||||
{
|
||||
return RadTextBoxControl_MinecraftProfileFolder.Text.Trim();
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(folderPath))
|
||||
return;
|
||||
|
||||
private bool IsUpdateConfigLoaded()
|
||||
{
|
||||
return !string.IsNullOrEmpty(GetUpdateconfigPath());
|
||||
}
|
||||
|
||||
private string GetUpdateconfigPath()
|
||||
{
|
||||
return RadTextBoxControl_ModpackConfig.Text.Trim();
|
||||
}
|
||||
|
||||
private bool CheckStatus()
|
||||
{
|
||||
bool CheckStatusRet;
|
||||
|
||||
if (!IsMinecaftProfileLoaded())
|
||||
try
|
||||
{
|
||||
SetStatus(LangRes.StatusText_MinecraftProfileWarning, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.general_warning_sign, SvgImageSize.Small));
|
||||
CheckStatusRet = false;
|
||||
modpackInfo = ModpackInfo.TryLoad(folderPath);
|
||||
RadTextBoxControl_ModpackConfig.Text = modpackInfo.ExtrasKey;
|
||||
radTextBoxControl_InstallKey.Text = modpackInfo.ExtrasKey;
|
||||
}
|
||||
else if (!IsUpdateConfigLoaded())
|
||||
catch
|
||||
{
|
||||
SetStatus(LangRes.StatusText_MinecraftProfileWarning, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.general_warning_sign, SvgImageSize.Small));
|
||||
CheckStatusRet = false;
|
||||
}
|
||||
else
|
||||
CheckStatusRet = true;
|
||||
|
||||
return CheckStatusRet;
|
||||
CheckStatusAndUpdate();
|
||||
}
|
||||
|
||||
private void LoadUpdateConfigFile(string filePath)
|
||||
{
|
||||
RadTextBoxControl_ModpackConfig.Text = filePath;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(filePath))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
updateConfig = ModpackConfig.LoadFromUrl(filePath);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
CheckStatusAndUpdate();
|
||||
}
|
||||
|
||||
private void LoadInstallKey(string installKey)
|
||||
{
|
||||
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())
|
||||
RadButton_CheckForUpdates.PerformClick();
|
||||
}
|
||||
else
|
||||
ClearStatus();
|
||||
if (CheckStatus())
|
||||
RadButton_CheckForUpdates.PerformClick();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
return null;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
else if (updateConfig.Maintenance && !updateOptions.IgnoreMaintenance)
|
||||
{
|
||||
SetStatus(LangRes.StatusText_Maintenance, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.services, SvgImageSize.Small));
|
||||
RadButton_PasteModpackConfig.Enabled = true;
|
||||
radButton_PasteInstallKey.Enabled = true;
|
||||
RadButton_CheckForUpdates.Enabled = false;
|
||||
RadButton_Install.Enabled = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
RadTextBoxControl_ModpackConfig.Text = filePath;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(filePath) && loadConfig(filePath) is ModpackConfig modpackConfig)
|
||||
{
|
||||
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 = 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));
|
||||
error();
|
||||
if (Debugger.IsAttached)
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Error while update check
|
||||
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));
|
||||
if (Debugger.IsAttached)
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
currentUpdating = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
SetStatus(LangRes.StatusText_UpdateAvailable, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.software_installer, SvgImageSize.Small));
|
||||
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,8 +275,7 @@ public partial class Form1
|
||||
private async void ButtonX_CheckForUpdates_Click(object sender, EventArgs e)
|
||||
{
|
||||
ClearStatus();
|
||||
if (CheckStatus())
|
||||
await ExecuteUpdate(false);
|
||||
await ExecuteUpdate(false);
|
||||
}
|
||||
|
||||
private async void ButtonX_StartUpdate_Click(object sender, EventArgs e)
|
||||
@@ -258,8 +283,7 @@ public partial class Form1
|
||||
if (!currentUpdating)
|
||||
{
|
||||
ClearStatus();
|
||||
if (CheckStatus())
|
||||
await ExecuteUpdate(true);
|
||||
await ExecuteUpdate(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public static class Program
|
||||
if (ThemeResolutionService.LoadPackageResource("ModpackUpdater.CustomThemes.Office2019DarkBluePurple.tssp"))
|
||||
ThemeResolutionService.ApplicationThemeName = "Office2019DarkBluePurple";
|
||||
|
||||
Application.Run(new Form1(updateOptions));
|
||||
Application.Run(new Form1(updateOptions));
|
||||
}
|
||||
|
||||
private static string GetSettingsPath(int? settingsVersion = 2)
|
||||
|
||||
Reference in New Issue
Block a user