Skip to content

Commit

Permalink
Now ZipExtractor will retry copying file in case of failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
ravibpatel committed Aug 22, 2020
1 parent a6b7f74 commit 113501e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion ZipExtractor/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using ZipExtractor.Properties;

namespace ZipExtractor
{
public partial class FormMain : Form
{
private const int _maxRetries = 2;
private BackgroundWorker _backgroundWorker;
readonly StringBuilder _logBuilder = new StringBuilder();

Expand Down Expand Up @@ -88,8 +90,26 @@ private void FormMain_Shown(object sender, EventArgs e)
}

ZipStorer.ZipFileEntry entry = dir[index];
zip.ExtractFile(entry, Path.Combine(path, entry.FilenameInZip));
string currentFile = string.Format(Resources.CurrentFileExtracting, entry.FilenameInZip);
int retries = 0;
bool notCopied = true;
while (notCopied)
{
try
{
zip.ExtractFile(entry, Path.Combine(path, entry.FilenameInZip));
notCopied = false;
}
catch (IOException)
{
Thread.Sleep(5000);
retries++;
if (retries > _maxRetries)
{
throw;
}
}
}
int progress = (index + 1) * 100 / dir.Count;
_backgroundWorker.ReportProgress(progress, currentFile);

Expand Down
2 changes: 1 addition & 1 deletion ZipExtractor/ZipExtractor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<ApplicationVersion>1.1.0.0</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down

0 comments on commit 113501e

Please sign in to comment.