some bugfixing & more
This commit is contained in:
@@ -81,7 +81,10 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
|
|||||||
var infos = await DownloadInstallInfos();
|
var infos = await DownloadInstallInfos();
|
||||||
|
|
||||||
if (infos is not null && infos.Actions.Count != 0)
|
if (infos is not null && infos.Actions.Count != 0)
|
||||||
|
{
|
||||||
result.Actions.AddRange(infos.Actions);
|
result.Actions.AddRange(infos.Actions);
|
||||||
|
result.LatestVersion = infos.Version;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
result.HasError = true;
|
result.HasError = true;
|
||||||
}
|
}
|
||||||
@@ -176,32 +179,45 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
|
|||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(destFilePath));
|
Directory.CreateDirectory(Path.GetDirectoryName(destFilePath));
|
||||||
|
|
||||||
// Download
|
if (!isZip || localZipCache.FirstOrDefault(n => n.DownloadUrl == sourceUrl) is not LocalZipCacheEntry cachedZipInfo)
|
||||||
var fsDestinationPath = isZip ? Path.Combine(Path.GetTempPath(), $"mc_update_file_{DateTime.Now.ToBinary()}.zip") : destFilePath;
|
|
||||||
var sRemote = await httpClient.GetStreamAsync(sourceUrl);
|
|
||||||
var fs = new FileStream(destFilePath, FileMode.Create, FileAccess.ReadWrite);
|
|
||||||
await sRemote.CopyToAsync(fs);
|
|
||||||
sRemote.Close();
|
|
||||||
fs.Close();
|
|
||||||
|
|
||||||
// Handle zip file
|
|
||||||
if (isZip)
|
|
||||||
{
|
{
|
||||||
|
// Download
|
||||||
|
var fsDestinationPath = isZip ? Path.Combine(Path.GetTempPath(), $"mc_update_file_{DateTime.Now.ToBinary()}.zip") : destFilePath;
|
||||||
|
var sRemote = await httpClient.GetStreamAsync(sourceUrl);
|
||||||
|
var fs = new FileStream(fsDestinationPath, FileMode.Create, FileAccess.ReadWrite);
|
||||||
|
await sRemote.CopyToAsync(fs);
|
||||||
|
await fs.FlushAsync();
|
||||||
|
sRemote.Close();
|
||||||
|
fs.Close();
|
||||||
|
|
||||||
// Extract
|
// Extract
|
||||||
var zipDir = $"{Path.GetFileNameWithoutExtension(fsDestinationPath)}_extracted";
|
if (isZip)
|
||||||
ZipFile.ExtractToDirectory(fsDestinationPath, zipDir);
|
|
||||||
|
|
||||||
// Copy content
|
|
||||||
var zipSrc = Path.Combine(zipDir, zipPath);
|
|
||||||
Extensions.CopyDirectory(zipSrc, destFilePath, true);
|
|
||||||
|
|
||||||
// Delete/cache temporary files
|
|
||||||
File.Delete(fsDestinationPath);
|
|
||||||
localZipCache?.Add(new LocalZipCacheEntry
|
|
||||||
{
|
{
|
||||||
DownloadUrl = sourceUrl,
|
// Extract files
|
||||||
ExtractedZipPath = zipDir
|
var zipDir = Path.Combine(Path.GetDirectoryName(fsDestinationPath), Path.GetFileNameWithoutExtension(fsDestinationPath));
|
||||||
});
|
ZipFile.ExtractToDirectory(fsDestinationPath, zipDir);
|
||||||
|
|
||||||
|
// Create cache entry
|
||||||
|
cachedZipInfo = new()
|
||||||
|
{
|
||||||
|
DownloadUrl = sourceUrl,
|
||||||
|
ExtractedZipPath = zipDir
|
||||||
|
};
|
||||||
|
localZipCache.Add(cachedZipInfo);
|
||||||
|
|
||||||
|
// Remofe temp zip file
|
||||||
|
File.Delete(fsDestinationPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cachedZipInfo = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle zip file content
|
||||||
|
if (cachedZipInfo != null)
|
||||||
|
{
|
||||||
|
// Copy content
|
||||||
|
var zipSrc = Path.Combine(cachedZipInfo.ExtractedZipPath, zipPath);
|
||||||
|
Extensions.CopyDirectory(zipSrc, destFilePath, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
namespace ModpackUpdater.Model;
|
namespace ModpackUpdater.Model;
|
||||||
|
|
||||||
public class InstallInfos
|
public class InstallInfos
|
||||||
{
|
{
|
||||||
public List<InstallAction> Actions { get; private set; } = [];
|
[JsonConverter(typeof(VersionConverter))]
|
||||||
|
public Version Version { get; set; }
|
||||||
|
public List<InstallAction> Actions { get; } = [];
|
||||||
|
|
||||||
public static InstallInfos Parse(string content)
|
public static InstallInfos Parse(string content)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using ModpackUpdater.Manager;
|
using ModpackUpdater.Manager;
|
||||||
using ModpackUpdater.Model;
|
using ModpackUpdater.Model;
|
||||||
using ModpackUpdater.My.Resources;
|
using ModpackUpdater.My.Resources;
|
||||||
|
using System.Diagnostics;
|
||||||
using Telerik.WinControls;
|
using Telerik.WinControls;
|
||||||
using Telerik.WinControls.UI;
|
using Telerik.WinControls.UI;
|
||||||
|
|
||||||
@@ -142,9 +143,11 @@ public partial class Form1
|
|||||||
else
|
else
|
||||||
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, MySymbols.icons8_delete_16px);
|
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, MySymbols.icons8_delete_16px);
|
||||||
}
|
}
|
||||||
catch
|
catch(Exception)
|
||||||
{
|
{
|
||||||
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, MySymbols.icons8_delete_16px);
|
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, MySymbols.icons8_delete_16px);
|
||||||
|
if (Debugger.IsAttached)
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public static class Program
|
|||||||
MigrateLegacySettings(GetSettingsPath(null));
|
MigrateLegacySettings(GetSettingsPath(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[STAThread]
|
||||||
internal static void Main(string[] args)
|
internal static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var options = new Options(args);
|
var options = new Options(args);
|
||||||
|
|||||||
Reference in New Issue
Block a user