private async Task AdvanceExtract() { if (PathProgress >= Path.Count) { //done try { Directory.Delete("PatchFiles/", true); } catch (Exception e) { } Invoke(new Action(() => StartFreeSO())); } else { //extract next zip var path = Path[PathProgress++]; Invoke(new Action(() => { OverallProgress.Value = (100 * (PathProgress - 1)) / Path.Count; OverallNum.Text = PathProgress + "/" + Path.Count; OverallStatus.Text = "Extracting " + path; })); if (File.Exists(path)) { ZipArchive archive; try { archive = ZipFile.OpenRead(path); } catch (Exception) { FileCorrupt(path); return; } var patcher = new ReversiblePatcher(archive); CurrentPatcher = patcher; patcher.OnStatus += Patcher_OnStatus; if (PathProgress == 1) { //first patch try { if (CleanPatch) { foreach (var file in Directory.GetFiles("Content/Patch/")) { //delete any stray patch files. Don't delete user or subfolders (eg. translations) because they might be important try { File.Delete(file); } catch (Exception) { } } } } catch (Exception) { } var worked = await patcher.AttemptRename(8); if (!worked) { PathProgress--; FSONotClosed(); return; } } while (patcher.ToExtract.Count > 0) { await patcher.AttemptExtract(); var remaining = patcher.GetIncompleteFiles(); if (remaining.Count > 0) { //dilemma! var arc = await ShowErrors(remaining); if (arc == 0) { //abort. patcher.Revert(); Cleanup(); Invoke(new Action(() => StartFreeSO())); return; } else if (arc == 1) { //retry } else if (arc == 2) { //ignore patcher.Final(); File.Delete(path); break; } } else { patcher.Final(); File.Delete(path); } } } else { FileMissing(path); } } await AdvanceExtract(); }
private async Task AdvanceExtract() { if (PathProgress >= Path.Count) { //done StartFreeSO(); } else { //extract next zip var path = Path[PathProgress++]; Console.WriteLine($"===== Extracting {path} ({PathProgress}/{Path.Count}) ====="); if (File.Exists(path)) { ZipArchive archive; try { archive = ZipFile.OpenRead(path); } catch (Exception) { FileCorrupt(path); return; } var patcher = new ReversiblePatcher(archive); if (path.Contains("extra") && AllowMonogameMod) { patcher.IgnoreFiles.RemoveWhere(x => x.Contains("MonoGame")); } CurrentPatcher = patcher; patcher.OnStatus += Patcher_OnStatus; if (PathProgress == 1) { //first patch if (CleanPatch) { foreach (var file in Directory.GetFiles("Content/Patch/")) { //delete any stray patch files. Don't delete user or subfolders (eg. translations) because they might be important try { File.Delete(file); } catch (Exception) { } } } var worked = await patcher.AttemptRename(8); if (!worked) { PathProgress--; FSONotClosed(); return; } } while (patcher.ToExtract.Count > 0) { await patcher.AttemptExtract(); var remaining = patcher.GetIncompleteFiles(); if (remaining.Count > 0) { //dilemma! var arc = await ShowErrors(remaining); if (arc == 0) { //abort. patcher.Revert(); Cleanup(); StartFreeSO(); return; } else if (arc == 1) { //retry } else if (arc == 2) { //ignore patcher.Final(); File.Delete(path); break; } } else { Console.WriteLine($"===== Completed {path} ====="); patcher.Final(); File.Delete(path); await AdvanceExtract(); } } } else { FileMissing(path); } } }