allow update after install

This commit is contained in:
2024-06-20 06:11:41 +02:00
parent 6808f772c1
commit f3b2d07117

View File

@@ -37,18 +37,34 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
return InstallInfos.Parse(content); return InstallInfos.Parse(content);
} }
public async Task<UpdateCheckResult> Check() public async Task<UpdateCheckResult> Check(bool allowUpdaterAfterInstall = true)
{ {
var result = new UpdateCheckResult(); var result = new UpdateCheckResult();
var hasConfig = ModpackInfo.HasModpackInfo(localPath);
InstallInfos installInfos = null;
UpdateInfos updateInfos = null;
if (ModpackInfo.HasModpackInfo(localPath)) if (!hasConfig)
{ {
var infos = await DownloadUpdateInfos(); installInfos = await DownloadInstallInfos();
var modpackInfo = ModpackInfo.Load(localPath);
if (infos is not null && infos.Updates.Count != 0) if (installInfos is not null && installInfos.Actions.Count != 0)
{ {
var updatesOrderes = infos.Updates.OrderByDescending(n => n.Version); result.Actions.AddRange(installInfos.Actions);
result.LatestVersion = installInfos.Version;
}
else
result.HasError = true;
}
if (allowUpdaterAfterInstall)
{
updateInfos = await DownloadUpdateInfos();
var modpackInfo = ModpackInfo.HasModpackInfo(localPath) ? ModpackInfo.Load(localPath) : new();
if (updateInfos is not null && updateInfos.Updates.Count != 0)
{
var updatesOrderes = updateInfos.Updates.OrderByDescending(n => n.Version);
result.LatestVersion = updatesOrderes.First().Version; result.LatestVersion = updatesOrderes.First().Version;
result.CurrentVersion = modpackInfo.Version; result.CurrentVersion = modpackInfo.Version;
result.IsInstalled = true; result.IsInstalled = true;
@@ -76,19 +92,6 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
result.HasError = true; result.HasError = true;
} }
if (!result.IsInstalled)
{
var infos = await DownloadInstallInfos();
if (infos is not null && infos.Actions.Count != 0)
{
result.Actions.AddRange(infos.Actions);
result.LatestVersion = infos.Version;
}
else
result.HasError = true;
}
return result; return result;
} }