Skip to content

Commit

Permalink
Fix progress reporting on import export
Browse files Browse the repository at this point in the history
  • Loading branch information
DSPaul committed May 4, 2024
1 parent b0c60a5 commit 04deebf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Services/IOService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static async Task<string> UnZipCollection(string path)
progressVM.TotalAmount = 1;

//extract
await Task.Run(() => archive.ExtractToDirectory(tmpCollectionPath)); //TODO add cancelation and progress reporting
await Task.Run(() => archive.ExtractToDirectory(tmpCollectionPath, progressReport: new Action<double>(progressVM.UpdateFromPercentage)));

progressVM.IncrementCounter();
return tmpCollectionPath;
Expand Down
11 changes: 7 additions & 4 deletions src/ViewModels/ExportCollectionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,21 @@ public async Task ExportToFile(string targetPath)
//Now add xml files
archive.AddAllFromDirectory(ContentSelectorVM.CuratedCollection.FullDataPath);

//Add version so we can check compatibility when importing
SatchelInfo info = new();
archive.AddEntry(Constants.SatchelInfoFileName, new MemoryStream(JsonSerializer.SerializeToUtf8Bytes(info)));

//Progress reporting
progressVM.Text = "Exporting Collection";
progressVM.ShowCount = false;
progressVM.ResetCounter();
progressVM.TotalAmount = 1;
//TODO find new way to track progress

//Add version so we can check compatibility when importing
SatchelInfo info = new();
archive.AddEntry(Constants.SatchelInfoFileName, new MemoryStream(JsonSerializer.SerializeToUtf8Bytes(info)));

//Export
await Task.Run(() => archive.SaveTo(targetPath, CompressionType.None));

progressVM.IncrementCounter();
Logger.Info($"Exported {CollectionToExport.DirectoryName} to {targetPath}");
}
catch (Exception ex)
Expand Down
6 changes: 6 additions & 0 deletions src/ViewModels/ProgressViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public void IncrementCounter()
_progressMutex.ReleaseMutex();
}

public void UpdateFromPercentage(double percentage)
{
TotalAmount = 100;
Counter = (int)(percentage * 100);
}

public void ResetCounter()
{
_progressMutex.WaitOne();
Expand Down

0 comments on commit 04deebf

Please sign in to comment.