Skip to content

Commit

Permalink
Merge pull request stevencohn#828 from stevencohn/823-show-error-on-a…
Browse files Browse the repository at this point in the history
…rchive-failure

Show error box when Archive fails
  • Loading branch information
stevencohn authored Jan 21, 2023
2 parents 77be7bb + 929c885 commit 9b9af9a
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions OneMore/Commands/File/ArchiveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Models;
using River.OneMoreAddIn.UI;
using System;
using System.IO;
using System.IO.Compression;
Expand Down Expand Up @@ -35,6 +36,8 @@ internal class ArchiveCommand : Command
private int pageCount = 0;
private bool bookScope;

private Exception exception = null;


public ArchiveCommand()
{
Expand Down Expand Up @@ -75,8 +78,12 @@ public override async Task Execute(params object[] args)
}

var progressDialog = new UI.ProgressDialog(Execute);
await progressDialog.RunModeless();

// report result is needed to show UI after Execute is completed on another thread
await progressDialog.RunModeless(ReportResult);
}

logger.WriteLine("done");
}


Expand All @@ -103,13 +110,19 @@ await archivist.BuildHyperlinkMap(
progress.SetMaximum(totalCount);
progress.SetMessage($"Archiving {totalCount} pages");

using (var stream = new FileStream(zipPath, FileMode.Create))
try
{
using var stream = new FileStream(zipPath, FileMode.Create);
using (archive = new ZipArchive(stream, ZipArchiveMode.Create))
{
await Archive(progress, hierarchy, hierarchy.Attribute("name").Value);
}
}
catch (Exception exc)
{
logger.WriteLine($"cannot create archive", exc);
exception = exc;
}

try
{
Expand All @@ -121,13 +134,27 @@ await archivist.BuildHyperlinkMap(
}

progress.Close();
UIHelper.ShowMessage(string.Format(Resx.ArchiveCommand_archived, pageCount, zipPath));

logger.WriteTime("archive complete");
logger.End();
}


private void ReportResult(object sender, EventArgs e)
{
// report results back on the main UI thread...

if (exception == null)
{
UIHelper.ShowMessage(string.Format(Resx.ArchiveCommand_archived, pageCount, zipPath));
}
else
{
MoreMessageBox.ShowErrorWithLogLink(owner, exception.Message);
}
}


private string ChooseLocation(string name)
{
string path;
Expand Down

0 comments on commit 9b9af9a

Please sign in to comment.