Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion Knossos.NET/Classes/KnUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ public static bool IsFileInUse(string filePath)
/// <summary>
/// Deletes a file checking if it exists first and then waits for the file to be closed.
/// </summary>
public static void DeleteFileSafe(string filePath)
public static async Task DeleteFileSafe(string filePath, CancellationTokenSource? cancellationToken = null)
{
try
{
Expand All @@ -1221,6 +1221,9 @@ public static void DeleteFileSafe(string filePath)
while (IsFileInUse(filePath))
{
Log.Add(Log.LogSeverity.Information, "TaskItemViewModel.PrepareModPkg()", "Waiting for file to be closed to delete it: " + filePath);
await Task.Delay(100);
if (cancellationToken != null && cancellationToken.IsCancellationRequested)
throw new TaskCanceledException();
}
File.Delete(filePath);
}
Expand Down
15 changes: 9 additions & 6 deletions Knossos.NET/ViewModels/Templates/Tasks/PrepareModPkg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.PrepareModPkg()", "Error while compressing the package");
//Disable failing and instead delete the file if it exists
//throw new TaskCanceledException();
KnUtils.DeleteFileSafe(zipPath);
await KnUtils.DeleteFileSafe(zipPath, cancellationTokenSource);
}
else
{
Expand All @@ -132,7 +132,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
ProgressBarMax = 100;
ProgressCurrent = 0;
Info = "Retry: Compressing (7z)";
KnUtils.DeleteFileSafe(zipPath);
await KnUtils.DeleteFileSafe(zipPath, cancellationTokenSource);
crcAttempt++;
}
}
Expand Down Expand Up @@ -193,7 +193,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.PrepareModPkg()", "Error while compressing the package");
//Disable failing and instead delete the file if it exists
//throw new TaskCanceledException();
KnUtils.DeleteFileSafe(zipPath + ".tar.gz");
await KnUtils.DeleteFileSafe(zipPath + ".tar.gz", cancellationTokenSource);
}
else
{
Expand All @@ -213,7 +213,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
ProgressBarMax = 100;
ProgressCurrent = 0;
Info = "Retry: Compressing (.tar.gz)";
KnUtils.DeleteFileSafe(zipPath + ".tar.gz");
await KnUtils.DeleteFileSafe(zipPath + ".tar.gz", cancellationTokenSource);
crcAttempt++;
}
}
Expand All @@ -232,7 +232,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.PrepareModPkg()", "Error while compressing the package");
//Disable failing and instead delete the file if it exists
//throw new TaskCanceledException();
KnUtils.DeleteFileSafe(zipPath);
await KnUtils.DeleteFileSafe(zipPath, cancellationTokenSource);
}
else
{
Expand All @@ -252,7 +252,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
ProgressBarMax = 100;
ProgressCurrent = 0;
Info = "Retry: Compressing (7z)";
KnUtils.DeleteFileSafe(zipPath);
await KnUtils.DeleteFileSafe(zipPath, cancellationTokenSource);
crcAttempt++;
}
}
Expand All @@ -267,6 +267,9 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
{
Info = "Waiting for file to be closed";
Log.Add(Log.LogSeverity.Information, "TaskItemViewModel.PrepareModPkg()", "Waiting for file to be closed: " + zipPath);
await Task.Delay(100);
if (cancellationTokenSource.IsCancellationRequested)
throw new TaskCanceledException();
}

Info = "Getting Hash";
Expand Down