load modpack info before modpack installer
This commit is contained in:
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@ using System.IO.Compression;
|
|||||||
|
|
||||||
namespace ModpackUpdater.Manager;
|
namespace ModpackUpdater.Manager;
|
||||||
|
|
||||||
public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
|
public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInfo)
|
||||||
{
|
{
|
||||||
private class LocalZipCacheEntry
|
private class LocalZipCacheEntry
|
||||||
{
|
{
|
||||||
@@ -40,7 +40,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
|
|||||||
public async Task<UpdateCheckResult> Check(UpdateCheckOptions options)
|
public async Task<UpdateCheckResult> Check(UpdateCheckOptions options)
|
||||||
{
|
{
|
||||||
var result = new UpdateCheckResult();
|
var result = new UpdateCheckResult();
|
||||||
var hasConfig = ModpackInfo.HasModpackInfo(localPath);
|
var hasConfig = modpackInfo.Exists;
|
||||||
InstallInfos installInfos = null;
|
InstallInfos installInfos = null;
|
||||||
UpdateInfos updateInfos = null;
|
UpdateInfos updateInfos = null;
|
||||||
|
|
||||||
@@ -71,7 +71,6 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
|
|||||||
if (options.AllowUpdaterAfterInstall)
|
if (options.AllowUpdaterAfterInstall)
|
||||||
{
|
{
|
||||||
updateInfos = await DownloadUpdateInfos();
|
updateInfos = await DownloadUpdateInfos();
|
||||||
var modpackInfo = ModpackInfo.HasModpackInfo(localPath) ? ModpackInfo.Load(localPath) : new();
|
|
||||||
|
|
||||||
if (updateInfos is not null && updateInfos.Updates.Count != 0)
|
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)
|
public async Task<bool?> Install(UpdateCheckResult checkResult)
|
||||||
{
|
{
|
||||||
ModpackInfo modpackInfo;
|
|
||||||
int processed = 0;
|
int processed = 0;
|
||||||
var localZipCache = new List<LocalZipCacheEntry>();
|
var localZipCache = new List<LocalZipCacheEntry>();
|
||||||
|
|
||||||
if (ModpackInfo.HasModpackInfo(localPath))
|
|
||||||
modpackInfo = ModpackInfo.Load(localPath);
|
|
||||||
else
|
|
||||||
modpackInfo = new();
|
|
||||||
|
|
||||||
foreach (InstallAction iaction in checkResult.Actions)
|
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)
|
if (iaction is UpdateAction uaction)
|
||||||
{
|
{
|
||||||
@@ -141,7 +134,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
|
|||||||
break;
|
break;
|
||||||
case UpdateActionType.Copy:
|
case UpdateActionType.Copy:
|
||||||
{
|
{
|
||||||
var srcFilePath = Path.Combine(localPath, uaction.SrcPath);
|
var srcFilePath = Path.Combine(modpackInfo.LocaLPath, uaction.SrcPath);
|
||||||
if (uaction.IsDirectory)
|
if (uaction.IsDirectory)
|
||||||
{
|
{
|
||||||
if (Directory.Exists(srcFilePath))
|
if (Directory.Exists(srcFilePath))
|
||||||
@@ -156,7 +149,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
|
|||||||
break;
|
break;
|
||||||
case UpdateActionType.Move:
|
case UpdateActionType.Move:
|
||||||
{
|
{
|
||||||
var srcFilePath = Path.Combine(localPath, uaction.SrcPath);
|
var srcFilePath = Path.Combine(modpackInfo.LocaLPath, uaction.SrcPath);
|
||||||
if (uaction.IsDirectory)
|
if (uaction.IsDirectory)
|
||||||
{
|
{
|
||||||
if (Directory.Exists(srcFilePath))
|
if (Directory.Exists(srcFilePath))
|
||||||
@@ -180,7 +173,8 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
|
|||||||
|
|
||||||
// Save new modpack info
|
// Save new modpack info
|
||||||
modpackInfo.Version = checkResult.LatestVersion;
|
modpackInfo.Version = checkResult.LatestVersion;
|
||||||
modpackInfo.Save(localPath);
|
modpackInfo.ConfigUrl = updateConfig.ConfigUrl;
|
||||||
|
modpackInfo.Save();
|
||||||
|
|
||||||
// Delete cached zip files
|
// Delete cached zip files
|
||||||
foreach (var task in localZipCache)
|
foreach (var task in localZipCache)
|
||||||
|
|||||||
@@ -9,9 +9,14 @@ public class ModpackConfig
|
|||||||
public string UpdateUrl { get; set; }
|
public string UpdateUrl { get; set; }
|
||||||
public string InstallUrl { get; set; }
|
public string InstallUrl { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public string ConfigUrl { get; set; }
|
||||||
|
|
||||||
public static ModpackConfig LoadFromUrl(string url)
|
public static ModpackConfig LoadFromUrl(string url)
|
||||||
{
|
{
|
||||||
string result = new HttpClient().GetStringAsync(url).Result;
|
string result = new HttpClient().GetStringAsync(url).Result;
|
||||||
return JsonConvert.DeserializeObject<ModpackConfig>(result);
|
var config = JsonConvert.DeserializeObject<ModpackConfig>(result);
|
||||||
|
config.ConfigUrl = url;
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,15 +10,35 @@ public class ModpackInfo
|
|||||||
|
|
||||||
[JsonConverter(typeof(VersionConverter))]
|
[JsonConverter(typeof(VersionConverter))]
|
||||||
public Version Version { get; set; }
|
public Version Version { get; set; }
|
||||||
|
public string ConfigUrl { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public string LocaLPath { get; private set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public bool Exists => Directory.Exists(LocaLPath);
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
File.WriteAllText(Conversions.ToString(GetFilePath(LocaLPath)), JsonConvert.SerializeObject(this));
|
||||||
|
}
|
||||||
|
|
||||||
public void Save(string mcRoot)
|
public void Save(string mcRoot)
|
||||||
{
|
{
|
||||||
File.WriteAllText(Conversions.ToString(GetFilePath(mcRoot)), JsonConvert.SerializeObject(this));
|
LocaLPath = mcRoot;
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ModpackInfo TryLoad(string mcRoot)
|
||||||
|
{
|
||||||
|
if (HasModpackInfo(mcRoot))
|
||||||
|
return Load(mcRoot);
|
||||||
|
return new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ModpackInfo Load(string mcRoot)
|
public static ModpackInfo Load(string mcRoot)
|
||||||
{
|
{
|
||||||
return JsonConvert.DeserializeObject<ModpackInfo>(File.ReadAllText(Conversions.ToString(GetFilePath(mcRoot))));
|
var info = JsonConvert.DeserializeObject<ModpackInfo>(File.ReadAllText(GetFilePath(mcRoot)));
|
||||||
|
info.LocaLPath = mcRoot;
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasModpackInfo(string mcRoot)
|
public static bool HasModpackInfo(string mcRoot)
|
||||||
@@ -26,7 +46,7 @@ public class ModpackInfo
|
|||||||
return File.Exists(Conversions.ToString(GetFilePath(mcRoot)));
|
return File.Exists(Conversions.ToString(GetFilePath(mcRoot)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static object GetFilePath(string mcRoot)
|
private static string GetFilePath(string mcRoot)
|
||||||
{
|
{
|
||||||
return Path.Combine(mcRoot, FILENAME_MODPACKINFO);
|
return Path.Combine(mcRoot, FILENAME_MODPACKINFO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace ModpackUpdater;
|
|||||||
|
|
||||||
public partial class Form1
|
public partial class Form1
|
||||||
{
|
{
|
||||||
|
private ModpackInfo modpackInfo = null;
|
||||||
private ModpackConfig updateConfig = new();
|
private ModpackConfig updateConfig = new();
|
||||||
private bool currentUpdating = false;
|
private bool currentUpdating = false;
|
||||||
private UpdateCheckResult lastUpdateCheckResult = null;
|
private UpdateCheckResult lastUpdateCheckResult = null;
|
||||||
@@ -65,7 +66,7 @@ public partial class Form1
|
|||||||
{
|
{
|
||||||
bool CheckStatusRet;
|
bool CheckStatusRet;
|
||||||
|
|
||||||
if (!IsMinecaftProfileLoaded() || !MinecraftProfileChecker.CheckProfile(GetMinecraftProfilePath()))
|
if (!IsMinecaftProfileLoaded())
|
||||||
{
|
{
|
||||||
SetStatus(LangRes.StatusText_MinecraftProfileWarning, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.general_warning_sign, SvgImageSize.Small));
|
SetStatus(LangRes.StatusText_MinecraftProfileWarning, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.general_warning_sign, SvgImageSize.Small));
|
||||||
CheckStatusRet = false;
|
CheckStatusRet = false;
|
||||||
@@ -98,7 +99,21 @@ public partial class Form1
|
|||||||
RadTextBoxControl_MinecraftProfileFolder.Text = folderPath;
|
RadTextBoxControl_MinecraftProfileFolder.Text = folderPath;
|
||||||
|
|
||||||
if (IsUpdateConfigLoaded())
|
if (IsUpdateConfigLoaded())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
modpackInfo = ModpackInfo.TryLoad(folderPath);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
RadTextBoxControl_MinecraftProfileFolder.Text = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(RadTextBoxControl_ModpackConfig.Text) && !string.IsNullOrWhiteSpace(modpackInfo?.ConfigUrl))
|
||||||
|
LoadUpdateConfigFile(modpackInfo.ConfigUrl);
|
||||||
|
else
|
||||||
RadButton_CheckForUpdates.PerformClick();
|
RadButton_CheckForUpdates.PerformClick();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ClearStatus();
|
ClearStatus();
|
||||||
}
|
}
|
||||||
@@ -127,7 +142,7 @@ public partial class Form1
|
|||||||
|
|
||||||
private async Task ExecuteUpdate(bool doInstall)
|
private async Task ExecuteUpdate(bool doInstall)
|
||||||
{
|
{
|
||||||
var updater = new ModpackInstaller(updateConfig, GetMinecraftProfilePath());
|
var updater = new ModpackInstaller(updateConfig, modpackInfo);
|
||||||
updater.InstallProgessUpdated += Update_InstallProgessUpdated;
|
updater.InstallProgessUpdated += Update_InstallProgessUpdated;
|
||||||
updater.CheckingProgressUpdated += Updated_CheckingProgresssUpdated;
|
updater.CheckingProgressUpdated += Updated_CheckingProgresssUpdated;
|
||||||
|
|
||||||
|
|||||||
@@ -73,8 +73,9 @@ public static class Program
|
|||||||
|
|
||||||
private static void InstallWithoutGui(UpdateCheckOptionsAdv updateOptions, bool silent)
|
private static void InstallWithoutGui(UpdateCheckOptionsAdv updateOptions, bool silent)
|
||||||
{
|
{
|
||||||
var config = ModpackConfig.LoadFromUrl(updateOptions.ModpackConfig);
|
var info = ModpackInfo.TryLoad(updateOptions.ProfileFolder);
|
||||||
var installer = new ModpackInstaller(config, updateOptions.ProfileFolder);
|
var config = ModpackConfig.LoadFromUrl(CheckModpackConfigUrl(updateOptions.ModpackConfig, info));
|
||||||
|
var installer = new ModpackInstaller(config, info);
|
||||||
var result = installer.Check(updateOptions).Result;
|
var result = installer.Check(updateOptions).Result;
|
||||||
|
|
||||||
if (!silent && !updateOptions.NoUpdate && new AppUpdater().Check().Result)
|
if (!silent && !updateOptions.NoUpdate && new AppUpdater().Check().Result)
|
||||||
@@ -89,4 +90,11 @@ public static class Program
|
|||||||
else if (!silent)
|
else if (!silent)
|
||||||
Console.WriteLine("No updates available");
|
Console.WriteLine("No updates available");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string CheckModpackConfigUrl(string configUrl, ModpackInfo info)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(configUrl) && !string.IsNullOrWhiteSpace(info.ConfigUrl))
|
||||||
|
return info.ConfigUrl;
|
||||||
|
return configUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user