public static async Task ExtractZipForInstall(string zipFilePath, string outFolder) { var zf = new ZipFile(zipFilePath); var entries = zf.OfType <ZipEntry>().ToArray(); var re = new Regex(@"lib[\\\/][^\\\/]*[\\\/]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); try { await Utility.ForEachAsync(entries, (zipEntry) => { if (!zipEntry.IsFile) { return; } var entryFileName = Uri.UnescapeDataString(zipEntry.Name); if (!re.Match(entryFileName).Success) { return; } var fullZipToPath = Path.Combine(outFolder, re.Replace(entryFileName, "", 1)); var directoryName = Path.GetDirectoryName(fullZipToPath); var buffer = new byte[64 * 1024]; if (directoryName.Length > 0) { Utility.Retry(() => Directory.CreateDirectory(directoryName), 2); } Utility.Retry(() => { using (var zipStream = zf.GetInputStream(zipEntry)) using (FileStream streamWriter = File.Create(fullZipToPath)) { StreamUtils.Copy(zipStream, streamWriter, buffer); } }, 5); }, 4); } finally { zf.Close(); } }
public static async Task ExtractZipForInstall(string zipFilePath, string outFolder) { var zf = new ZipFile(zipFilePath); var entries = zf.OfType <ZipEntry>().ToArray(); var re = new Regex(@"lib[\\\/][^\\\/]*[\\\/]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); try { await Utility.ForEachAsync(entries, (zipEntry) => { if (!zipEntry.IsFile) { return; } var entryFileName = Uri.UnescapeDataString(zipEntry.Name); if (!re.Match(entryFileName).Success) { return; } var fullZipToPath = Path.Combine(outFolder, re.Replace(entryFileName, "", 1)); var failureIsOkay = false; if (entryFileName.Contains("_ExecutionStub.exe")) { // NB: On upgrade, many of these stubs will be in-use, nbd tho. failureIsOkay = true; fullZipToPath = Path.Combine( Directory.GetParent(Path.GetDirectoryName(fullZipToPath)).FullName, Path.GetFileName(fullZipToPath).Replace("_ExecutionStub.exe", ".exe")); LogHost.Default.Info("Rigging execution stub for {0} to {1}", entryFileName, fullZipToPath); } var directoryName = Path.GetDirectoryName(fullZipToPath); var buffer = new byte[64 * 1024]; if (directoryName.Length > 0) { Utility.Retry(() => Directory.CreateDirectory(directoryName), 2); } try { Utility.Retry(() => { using (var zipStream = zf.GetInputStream(zipEntry)) using (FileStream streamWriter = File.Create(fullZipToPath)) { StreamUtils.Copy(zipStream, streamWriter, buffer); } }, 5); } catch (Exception e) { if (!failureIsOkay) { LogHost.Default.WarnException("Can't write execution stub, probably in use", e); throw e; } } }, 4); } finally { zf.Close(); } }