Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b79335e85 | |||
| 3e1ab72162 | |||
| a83d109f24 |
@@ -39,11 +39,11 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Mono.Options" Version="6.12.0.148" />
|
<PackageReference Include="Mono.Options" Version="6.12.0.148" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="Pilz.Configuration" Version="3.1.3" />
|
<PackageReference Include="Pilz.Configuration" Version="3.2.0" />
|
||||||
<PackageReference Include="Pilz.Cryptography" Version="2.1.1" />
|
<PackageReference Include="Pilz.Cryptography" Version="2.1.1" />
|
||||||
<PackageReference Include="Pilz.IO" Version="2.1.0" />
|
<PackageReference Include="Pilz.IO" Version="2.1.0" />
|
||||||
<PackageReference Include="Pilz.UI" Version="2.3.10" />
|
<PackageReference Include="Pilz.UI" Version="2.3.14" />
|
||||||
<PackageReference Include="Pilz.UI.Telerik" Version="2.7.4" />
|
<PackageReference Include="Pilz.UI.Telerik" Version="2.8.1" />
|
||||||
<PackageReference Include="Pilz.Win32" Version="2.1.0" />
|
<PackageReference Include="Pilz.Win32" Version="2.1.0" />
|
||||||
<PackageReference Include="UI.for.WinForms.Common" Version="2024.3.806" />
|
<PackageReference Include="UI.for.WinForms.Common" Version="2024.3.806" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
using ModpackUpdater.Manager;
|
using Castle.Core.Logging;
|
||||||
|
using ModpackUpdater.Manager;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Pilz;
|
using Pilz;
|
||||||
using Pilz.Configuration;
|
using Pilz.Configuration;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
[assembly: AssemblyAppVersion("1.6.2.0")]
|
[assembly: AssemblyAppVersion("1.6.3.0")]
|
||||||
|
|
||||||
namespace ModpackUpdater.Apps.Client;
|
namespace ModpackUpdater.Apps.Client;
|
||||||
|
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
private static readonly SettingsManager settingsManager;
|
private static readonly SettingsManager settingsManager;
|
||||||
|
private static readonly ILogger log = new ConsoleLogger();
|
||||||
|
|
||||||
public static ISettings Settings => settingsManager.Instance;
|
public static ISettings Settings => settingsManager.Instance;
|
||||||
|
|
||||||
|
public static ILogger Log => log;
|
||||||
|
|
||||||
[DllImport("kernel32.dll")]
|
[DllImport("kernel32.dll")]
|
||||||
static extern nint GetConsoleWindow();
|
static extern nint GetConsoleWindow();
|
||||||
|
|
||||||
@@ -97,20 +101,23 @@ public static class Program
|
|||||||
updateOptions.IncludeExtras = features.IsEnabled(ModpackFeatures.FeatureAllowExtas, new AllowExtrasFeatureContext(info));
|
updateOptions.IncludeExtras = features.IsEnabled(ModpackFeatures.FeatureAllowExtas, new AllowExtrasFeatureContext(info));
|
||||||
|
|
||||||
// Check for update
|
// Check for update
|
||||||
var installer = new ModpackInstaller(config, info);
|
var installer = new ModpackInstaller(config, info)
|
||||||
|
{
|
||||||
|
Log = Log,
|
||||||
|
};
|
||||||
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)
|
||||||
Console.WriteLine("A new version is available!");
|
Log.Info("A new version is available!");
|
||||||
|
|
||||||
if (result.HasUpdates)
|
if (result.HasUpdates)
|
||||||
{
|
{
|
||||||
var success = installer.Install(result).Result;
|
var success = installer.Install(result).Result;
|
||||||
if (!silent)
|
if (!silent)
|
||||||
Console.WriteLine($"Installation {(success ?? false ? "completed successfully" : "failed")}!");
|
Log.Info($"Installation {(success ?? false ? "completed successfully" : "failed")}!");
|
||||||
}
|
}
|
||||||
else if (!silent)
|
else if (!silent)
|
||||||
Console.WriteLine("No updates available");
|
Log.Info("No updates available");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string CheckModpackConfigUrl(string configUrl, ModpackInfo info)
|
private static string CheckModpackConfigUrl(string configUrl, ModpackInfo info)
|
||||||
|
|||||||
@@ -11,13 +11,13 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="NGitLab" Version="6.55.0" />
|
<PackageReference Include="NGitLab" Version="6.59.0" />
|
||||||
<PackageReference Include="Pilz.Configuration" Version="3.1.3" />
|
<PackageReference Include="Pilz.Configuration" Version="3.2.0" />
|
||||||
<PackageReference Include="Pilz.Plugins.Advanced" Version="2.10.1" />
|
<PackageReference Include="Pilz.Plugins.Advanced" Version="2.10.2" />
|
||||||
<PackageReference Include="Pilz.Plugins.Advanced.UI" Version="1.7.0" />
|
<PackageReference Include="Pilz.Plugins.Advanced.UI" Version="1.8.3" />
|
||||||
<PackageReference Include="Pilz.Plugins.Advanced.UI.Telerik" Version="1.7.0" />
|
<PackageReference Include="Pilz.Plugins.Advanced.UI.Telerik" Version="1.7.2" />
|
||||||
<PackageReference Include="Pilz.UI" Version="2.3.10" />
|
<PackageReference Include="Pilz.UI" Version="2.3.14" />
|
||||||
<PackageReference Include="Pilz.UI.Telerik" Version="2.7.4" />
|
<PackageReference Include="Pilz.UI.Telerik" Version="2.8.1" />
|
||||||
<PackageReference Include="UI.for.WinForms.Common" Version="2024.3.806" />
|
<PackageReference Include="UI.for.WinForms.Common" Version="2024.3.806" />
|
||||||
<PackageReference Include="UI.for.WinForms.GridView" Version="2024.3.806" />
|
<PackageReference Include="UI.for.WinForms.GridView" Version="2024.3.806" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Pilz.UI" Version="2.3.10" />
|
<PackageReference Include="Pilz.UI" Version="2.3.14" />
|
||||||
<PackageReference Include="Pilz.UI.Telerik" Version="2.7.4" />
|
<PackageReference Include="Pilz.UI.Telerik" Version="2.8.1" />
|
||||||
<PackageReference Include="UI.for.WinForms.Common" Version="2024.3.806" />
|
<PackageReference Include="UI.for.WinForms.Common" Version="2024.3.806" />
|
||||||
<PackageReference Include="UI.for.WinForms.Themes" Version="2024.3.806" />
|
<PackageReference Include="UI.for.WinForms.Themes" Version="2024.3.806" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
using Castle.Core.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using FileMode = System.IO.FileMode;
|
using FileMode = System.IO.FileMode;
|
||||||
|
|
||||||
@@ -19,6 +20,8 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
|
|
||||||
public delegate void CheckingProgressUpdatedEventHandler(int toCheck, int processed);
|
public delegate void CheckingProgressUpdatedEventHandler(int toCheck, int processed);
|
||||||
|
|
||||||
|
public ILogger Log { get; set; } = NullLogger.Instance;
|
||||||
|
|
||||||
private readonly HttpClient http = new();
|
private readonly HttpClient http = new();
|
||||||
private readonly ModpackFactory factory = new();
|
private readonly ModpackFactory factory = new();
|
||||||
|
|
||||||
@@ -60,7 +63,6 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
|
|
||||||
installInfos = await DownloadInstallInfos();
|
installInfos = await DownloadInstallInfos();
|
||||||
result.CurrentVersion = modpackInfo.Version ?? new Version("0.0.0.0");
|
result.CurrentVersion = modpackInfo.Version ?? new Version("0.0.0.0");
|
||||||
var curVersion = result.CurrentVersion;
|
|
||||||
|
|
||||||
// Check install actions
|
// Check install actions
|
||||||
if (!exists)
|
if (!exists)
|
||||||
@@ -74,7 +76,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
{
|
{
|
||||||
result.Actions.AddRange(actions);
|
result.Actions.AddRange(actions);
|
||||||
result.LatestVersion = installInfos.Version;
|
result.LatestVersion = installInfos.Version;
|
||||||
curVersion = installInfos.Version;
|
result.CurrentVersion = installInfos.Version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,9 +95,8 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
var checkingVersionIndex = 0;
|
var checkingVersionIndex = 0;
|
||||||
var checkingVersion = updatesOrderes.ElementAtOrDefault(checkingVersionIndex);
|
var checkingVersion = updatesOrderes.ElementAtOrDefault(checkingVersionIndex);
|
||||||
var actionsZeroIndex = result.Actions.Count; // Ensure we insert update actions behind install actions
|
var actionsZeroIndex = result.Actions.Count; // Ensure we insert update actions behind install actions
|
||||||
result.IsInstalled = true;
|
|
||||||
|
|
||||||
while (checkingVersion is not null && checkingVersion.Version > curVersion)
|
while (checkingVersion is not null && checkingVersion.Version > result.CurrentVersion)
|
||||||
{
|
{
|
||||||
var actionsToAdd = new List<UpdateAction>();
|
var actionsToAdd = new List<UpdateAction>();
|
||||||
|
|
||||||
@@ -153,7 +154,8 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
switch (uaction.Type)
|
switch (uaction.Type)
|
||||||
{
|
{
|
||||||
case UpdateActionType.Update:
|
case UpdateActionType.Update:
|
||||||
await InstallFile(destFilePath, sourceUrl, uaction.IsZip, uaction.ZipPath, localZipCache);
|
if (!await InstallFile(destFilePath, sourceUrl, uaction.IsZip, uaction.ZipPath, localZipCache))
|
||||||
|
return false;
|
||||||
break;
|
break;
|
||||||
case UpdateActionType.Delete:
|
case UpdateActionType.Delete:
|
||||||
{
|
{
|
||||||
@@ -198,8 +200,8 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (!await InstallFile(destFilePath, sourceUrl, iaction.IsZip, iaction.ZipPath, localZipCache))
|
||||||
await InstallFile(destFilePath, sourceUrl, iaction.IsZip, iaction.ZipPath, localZipCache);
|
return false;
|
||||||
|
|
||||||
processed += 1;
|
processed += 1;
|
||||||
InstallProgessUpdated?.Invoke(checkResult, processed);
|
InstallProgessUpdated?.Invoke(checkResult, processed);
|
||||||
@@ -217,41 +219,54 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task InstallFile(string destFilePath, string sourceUrl, bool isZip, string zipPath, List<LocalZipCacheEntry> localZipCache)
|
private async Task<bool> InstallFile(string destFilePath, string sourceUrl, bool isZip, string zipPath, List<LocalZipCacheEntry> localZipCache)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(destFilePath));
|
Directory.CreateDirectory(Path.GetDirectoryName(destFilePath));
|
||||||
|
|
||||||
if (!isZip || localZipCache.FirstOrDefault(n => n.DownloadUrl == sourceUrl) is not LocalZipCacheEntry cachedZipInfo)
|
if (!isZip || localZipCache.FirstOrDefault(n => n.DownloadUrl == sourceUrl) is not LocalZipCacheEntry cachedZipInfo)
|
||||||
{
|
{
|
||||||
// Download
|
try
|
||||||
var fsDestinationPath = isZip ? Path.Combine(Path.GetTempPath(), $"mc_update_file_{DateTime.Now.ToBinary()}.zip") : destFilePath;
|
|
||||||
var sRemote = await http.GetStreamAsync(sourceUrl);
|
|
||||||
var fs = new FileStream(fsDestinationPath, FileMode.Create, FileAccess.ReadWrite);
|
|
||||||
await sRemote.CopyToAsync(fs);
|
|
||||||
await fs.FlushAsync();
|
|
||||||
sRemote.Close();
|
|
||||||
fs.Close();
|
|
||||||
|
|
||||||
// Extract
|
|
||||||
if (isZip)
|
|
||||||
{
|
{
|
||||||
// Extract files
|
// Download
|
||||||
var zipDir = Path.Combine(Path.GetDirectoryName(fsDestinationPath), Path.GetFileNameWithoutExtension(fsDestinationPath));
|
var fsDestinationPath = isZip ? Path.Combine(Path.GetTempPath(), $"mc_update_file_{DateTime.Now.ToBinary()}.zip") : destFilePath;
|
||||||
ZipFile.ExtractToDirectory(fsDestinationPath, zipDir);
|
var sRemote = await http.GetStreamAsync(sourceUrl);
|
||||||
|
var fs = new FileStream(fsDestinationPath, FileMode.Create, FileAccess.ReadWrite);
|
||||||
|
await sRemote.CopyToAsync(fs);
|
||||||
|
await fs.FlushAsync();
|
||||||
|
sRemote.Close();
|
||||||
|
fs.Close();
|
||||||
|
|
||||||
// Create cache entry
|
// Extract
|
||||||
cachedZipInfo = new()
|
if (isZip)
|
||||||
{
|
{
|
||||||
DownloadUrl = sourceUrl,
|
// Extract files
|
||||||
ExtractedZipPath = zipDir
|
var zipDir = Path.Combine(Path.GetDirectoryName(fsDestinationPath), Path.GetFileNameWithoutExtension(fsDestinationPath));
|
||||||
};
|
ZipFile.ExtractToDirectory(fsDestinationPath, zipDir);
|
||||||
localZipCache.Add(cachedZipInfo);
|
|
||||||
|
|
||||||
// Remofe temp zip file
|
// Create cache entry
|
||||||
File.Delete(fsDestinationPath);
|
cachedZipInfo = new()
|
||||||
|
{
|
||||||
|
DownloadUrl = sourceUrl,
|
||||||
|
ExtractedZipPath = zipDir
|
||||||
|
};
|
||||||
|
localZipCache.Add(cachedZipInfo);
|
||||||
|
|
||||||
|
// Remofe temp zip file
|
||||||
|
File.Delete(fsDestinationPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cachedZipInfo = null;
|
||||||
|
}
|
||||||
|
catch (HttpRequestException ex)
|
||||||
|
{
|
||||||
|
Log.Error("Could not download file: " + sourceUrl, ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error("Could not install file: " + sourceUrl, ex);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
cachedZipInfo = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle zip file content
|
// Handle zip file content
|
||||||
@@ -261,5 +276,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
var zipSrc = Path.Combine(cachedZipInfo.ExtractedZipPath, zipPath);
|
var zipSrc = Path.Combine(cachedZipInfo.ExtractedZipPath, zipPath);
|
||||||
Extensions.CopyDirectory(zipSrc, destFilePath, true);
|
Extensions.CopyDirectory(zipSrc, destFilePath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,11 +7,12 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Castle.Core" Version="5.1.1" />
|
||||||
<PackageReference Include="CurseForge.APIClient" Version="3.0.0" />
|
<PackageReference Include="CurseForge.APIClient" Version="3.0.0" />
|
||||||
<PackageReference Include="Modrinth.Net" Version="3.4.5" />
|
<PackageReference Include="Modrinth.Net" Version="3.4.5" />
|
||||||
<PackageReference Include="Octokit" Version="13.0.1" />
|
<PackageReference Include="Octokit" Version="13.0.1" />
|
||||||
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
|
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
|
||||||
<PackageReference Include="Unleash.Client" Version="4.1.12" />
|
<PackageReference Include="Unleash.Client" Version="5.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user