load modpack info before modpack installer

This commit is contained in:
2024-06-20 15:05:01 +02:00
parent 604d35856f
commit c97a04c4ce
6 changed files with 64 additions and 33 deletions

View File

@@ -1,11 +0,0 @@
namespace ModpackUpdater.Manager;
public class MinecraftProfileChecker
{
public static bool CheckProfile(string folderPath)
{
// Todo: Adds some checks to verify, if the current folder is a minecraft folder.
return true;
}
}

View File

@@ -3,7 +3,7 @@ using System.IO.Compression;
namespace ModpackUpdater.Manager;
public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInfo)
{
private class LocalZipCacheEntry
{
@@ -40,7 +40,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
public async Task<UpdateCheckResult> Check(UpdateCheckOptions options)
{
var result = new UpdateCheckResult();
var hasConfig = ModpackInfo.HasModpackInfo(localPath);
var hasConfig = modpackInfo.Exists;
InstallInfos installInfos = null;
UpdateInfos updateInfos = null;
@@ -71,7 +71,6 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
if (options.AllowUpdaterAfterInstall)
{
updateInfos = await DownloadUpdateInfos();
var modpackInfo = ModpackInfo.HasModpackInfo(localPath) ? ModpackInfo.Load(localPath) : new();
if (updateInfos is not null && updateInfos.Updates.Count != 0)
{
@@ -108,18 +107,12 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
public async Task<bool?> Install(UpdateCheckResult checkResult)
{
ModpackInfo modpackInfo;
int processed = 0;
var localZipCache = new List<LocalZipCacheEntry>();
if (ModpackInfo.HasModpackInfo(localPath))
modpackInfo = ModpackInfo.Load(localPath);
else
modpackInfo = new();
foreach (InstallAction iaction in checkResult.Actions)
{
string destFilePath = Path.Combine(localPath, iaction.DestPath);
string destFilePath = Path.Combine(modpackInfo.LocaLPath, iaction.DestPath);
if (iaction is UpdateAction uaction)
{
@@ -141,7 +134,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
break;
case UpdateActionType.Copy:
{
var srcFilePath = Path.Combine(localPath, uaction.SrcPath);
var srcFilePath = Path.Combine(modpackInfo.LocaLPath, uaction.SrcPath);
if (uaction.IsDirectory)
{
if (Directory.Exists(srcFilePath))
@@ -156,7 +149,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
break;
case UpdateActionType.Move:
{
var srcFilePath = Path.Combine(localPath, uaction.SrcPath);
var srcFilePath = Path.Combine(modpackInfo.LocaLPath, uaction.SrcPath);
if (uaction.IsDirectory)
{
if (Directory.Exists(srcFilePath))
@@ -180,7 +173,8 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
// Save new modpack info
modpackInfo.Version = checkResult.LatestVersion;
modpackInfo.Save(localPath);
modpackInfo.ConfigUrl = updateConfig.ConfigUrl;
modpackInfo.Save();
// Delete cached zip files
foreach (var task in localZipCache)