Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion Knossos.NET/ViewModels/Templates/Tasks/PrepareModPkg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,47 @@
using System.Linq;
using System.Threading.Tasks;
using System.Threading;
using Avalonia.Threading;
using Knossos.NET.Views;
using VP.NET;

namespace Knossos.NET.ViewModels
{
public partial class TaskItemViewModel : ViewModelBase
{
private static readonly SemaphoreSlim uploadRetryPromptLock = new(1, 1);

private async Task ConfirmPackageCompressionRetry(string archivePath, string modFullPath)
{
await uploadRetryPromptLock.WaitAsync(cancellationTokenSource!.Token);
try
{
if (cancellationTokenSource.IsCancellationRequested)
throw new TaskCanceledException();

var libraryPath = Knossos.GetKnossosLibraryPath() ?? modFullPath;
var result = MessageBox.MessageBoxResult.Cancel;
await Dispatcher.UIThread.InvokeAsync(async () =>
{
result = await MessageBox.Show(MainWindow.instance,
"The package archive could not be created or failed its integrity check. " +
"This may mean that the drive containing the Knossos.NET library has run out of free space.\n\n" +
"Free some space in the library, then select Continue to retry.\n\n" +
"Library path:\n" + libraryPath + "\n\n" +
"Archive path:\n" + archivePath,
"Package creation failed",
MessageBox.MessageBoxButtons.ContinueCancel);
});

if (result != MessageBox.MessageBoxResult.Continue)
throw new TaskCanceledException();
}
finally
{
uploadRetryPromptLock.Release();
}
}

private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, CancellationTokenSource? cancelSource = null)
{
try
Expand Down Expand Up @@ -113,6 +148,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
//Disable failing and instead delete the file if it exists
//throw new TaskCanceledException();
await KnUtils.DeleteFileSafe(zipPath, cancellationTokenSource);
await ConfirmPackageCompressionRetry(zipPath, modFullPath);
}
else
{
Expand All @@ -132,7 +168,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
Info = "Retry: Compressing (7z)";
await KnUtils.DeleteFileSafe(zipPath, cancellationTokenSource);
crcAttempt++;
await Task.Delay(1000);
await ConfirmPackageCompressionRetry(zipPath, modFullPath);
}
}
if (cancellationTokenSource.IsCancellationRequested)
Expand Down Expand Up @@ -195,6 +231,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
//Disable failing and instead delete the file if it exists
//throw new TaskCanceledException();
await KnUtils.DeleteFileSafe(zipPath + ".tar.gz", cancellationTokenSource);
await ConfirmPackageCompressionRetry(zipPath + ".tar.gz", modFullPath);
}
else
{
Expand All @@ -216,6 +253,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
Info = "Retry: Compressing (.tar.gz)";
await KnUtils.DeleteFileSafe(zipPath + ".tar.gz", cancellationTokenSource);
crcAttempt++;
await ConfirmPackageCompressionRetry(zipPath + ".tar.gz", modFullPath);
}
}
} while (!crcResult);
Expand All @@ -234,6 +272,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
//Disable failing and instead delete the file if it exists
//throw new TaskCanceledException();
await KnUtils.DeleteFileSafe(zipPath, cancellationTokenSource);
await ConfirmPackageCompressionRetry(zipPath, modFullPath);
}
else
{
Expand All @@ -255,6 +294,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
Info = "Retry: Compressing (7z)";
await KnUtils.DeleteFileSafe(zipPath, cancellationTokenSource);
crcAttempt++;
await ConfirmPackageCompressionRetry(zipPath, modFullPath);
}
}
} while (!crcResult);
Expand Down