mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Rework where we store upgrades
This commit is contained in:
parent
592fcb17d9
commit
60a23f451f
@ -304,9 +304,13 @@ namespace Wabbajack.Lib
|
||||
{
|
||||
try
|
||||
{
|
||||
if (destination == null)
|
||||
destination = DownloadFolder.Combine(archive.Name);
|
||||
await DownloadDispatcher.DownloadWithPossibleUpgrade(archive, destination.Value);
|
||||
destination ??= DownloadFolder.Combine(archive.Name);
|
||||
|
||||
var result = await DownloadDispatcher.DownloadWithPossibleUpgrade(archive, destination.Value);
|
||||
if (result == DownloadDispatcher.DownloadResult.Update)
|
||||
{
|
||||
await destination.Value.MoveToAsync(destination.Value.Parent.Combine(archive.Hash.ToHex()));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -323,7 +327,6 @@ namespace Wabbajack.Lib
|
||||
Utils.Log("Looking for files to hash");
|
||||
var toHash = DownloadFolder.EnumerateFiles()
|
||||
.Concat(Game.GameLocation().EnumerateFiles())
|
||||
.Where(e => e.Extension != Consts.HashFileExtension)
|
||||
.ToList();
|
||||
|
||||
Utils.Log($"Found {toHash.Count} files to hash");
|
||||
|
@ -91,25 +91,33 @@ namespace Wabbajack.Lib.Downloaders
|
||||
.Select(t => Downloaders.First(d => d.GetType() == t).Prepare()));
|
||||
}
|
||||
|
||||
public static async Task<bool> DownloadWithPossibleUpgrade(Archive archive, AbsolutePath destination)
|
||||
public enum DownloadResult
|
||||
{
|
||||
Failure,
|
||||
Update,
|
||||
Mirror,
|
||||
Success
|
||||
}
|
||||
|
||||
public static async Task<DownloadResult> DownloadWithPossibleUpgrade(Archive archive, AbsolutePath destination)
|
||||
{
|
||||
if (await Download(archive, destination))
|
||||
{
|
||||
await destination.FileHashCachedAsync();
|
||||
return true;
|
||||
return DownloadResult.Success;
|
||||
}
|
||||
|
||||
|
||||
if (await DownloadFromMirror(archive, destination))
|
||||
{
|
||||
await destination.FileHashCachedAsync();
|
||||
return true;
|
||||
return DownloadResult.Mirror;
|
||||
}
|
||||
|
||||
if (!(archive.State is IUpgradingState))
|
||||
{
|
||||
Utils.Log($"Download failed for {archive.Name} and no upgrade from this download source is possible");
|
||||
return false;
|
||||
return DownloadResult.Failure;
|
||||
}
|
||||
|
||||
Utils.Log($"Trying to find solution to broken download for {archive.Name}");
|
||||
@ -119,7 +127,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
{
|
||||
Utils.Log(
|
||||
$"No solution for broken download {archive.Name} {archive.State.PrimaryKeyString} could be found");
|
||||
return false;
|
||||
return DownloadResult.Failure;
|
||||
|
||||
}
|
||||
|
||||
@ -146,10 +154,10 @@ namespace Wabbajack.Lib.Downloaders
|
||||
if (hash != archive.Hash && archive.Hash != default)
|
||||
{
|
||||
Utils.Log("Archive hash didn't match after patching");
|
||||
return false;
|
||||
return DownloadResult.Failure;
|
||||
}
|
||||
|
||||
return true;
|
||||
return DownloadResult.Update;
|
||||
}
|
||||
|
||||
public static async Task<(Archive? Archive, TempFile NewFile)> FindUpgrade(Archive a, Func<Archive, Task<AbsolutePath>>? downloadResolver = null)
|
||||
|
@ -142,7 +142,7 @@ namespace Wabbajack.Server.Test
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(200));
|
||||
}
|
||||
|
||||
Assert.True(await pendingRequest);
|
||||
Assert.Equal(DownloadDispatcher.DownloadResult.Update, await pendingRequest);
|
||||
Assert.Equal(oldDataHash, await tempFile.Path.FileHashAsync());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user