public static GZipResult Compress(FileInfo[] files, string lpBaseFolder, string lpDestFolder, string zipFileName, bool deleteTempFile) { GZipResult result = new GZipResult(); try { if (!lpDestFolder.EndsWith(@"\")) { lpDestFolder = lpDestFolder + @"\"; } string str = lpDestFolder + zipFileName + ".tmp"; string str2 = lpDestFolder + zipFileName; result.TempFile = str; result.ZipFile = str2; if ((files == null) || (files.Length <= 0)) { return(result); } smethod_3(files, lpBaseFolder, str, result); if (result.FileCount > 0) { smethod_2(str, str2, result); } if (deleteTempFile) { File.Delete(str); result.TempFileDeleted = true; } } catch { result.Errors = true; } return(result); }
private static void smethod_2(string string_0, string string_1, GZipResult gzipResult_0) { FileStream stream = null; FileStream stream2 = null; GZipStream stream3 = null; try { stream = new FileStream(string_1, FileMode.Create, FileAccess.Write, FileShare.None); stream3 = new GZipStream(stream, CompressionMode.Compress, true); stream2 = new FileStream(string_0, FileMode.Open, FileAccess.Read, FileShare.Read); byte[] buffer = new byte[stream2.Length]; stream2.Read(buffer, 0, buffer.Length); stream2.Close(); stream2 = null; stream3.Write(buffer, 0, buffer.Length); gzipResult_0.ZipFileSize = stream.Length; gzipResult_0.CompressionPercent = smethod_8(gzipResult_0.TempFileSize, gzipResult_0.ZipFileSize); } catch { gzipResult_0.Errors = true; } finally { if (stream3 != null) { stream3.Close(); stream3 = null; } if (stream != null) { stream.Close(); stream = null; } if (stream2 != null) { stream2.Close(); stream2 = null; } } }
private static FileStream smethod_7(string string_0, string string_1, GZipResult gzipResult_0) { FileStream stream = null; GZipStream stream2 = null; FileStream stream3 = null; FileStream stream4 = null; byte[] buffer = new byte[0x1000]; int count = 0; try { stream = new FileStream(string_0, FileMode.Open, FileAccess.Read, FileShare.Read); gzipResult_0.ZipFileSize = stream.Length; stream3 = new FileStream(string_1, FileMode.Create, FileAccess.Write, FileShare.None); stream2 = new GZipStream(stream, CompressionMode.Decompress, true); goto Label_005C; Label_0042: if (count == 0x1000) { goto Label_005C; } goto Label_00AE; Label_004F: stream3.Write(buffer, 0, count); goto Label_0042; Label_005C: count = stream2.Read(buffer, 0, 0x1000); if (count == 0) { goto Label_0042; } goto Label_004F; } catch { gzipResult_0.Errors = true; } finally { if (stream2 != null) { stream2.Close(); stream2 = null; } if (stream3 != null) { stream3.Close(); stream3 = null; } if (stream != null) { stream.Close(); stream = null; } } Label_00AE: stream4 = new FileStream(string_1, FileMode.Open, FileAccess.Read, FileShare.None); if (stream4 != null) { gzipResult_0.TempFileSize = stream4.Length; } return(stream4); }
public static GZipResult Decompress(string lpSrcFolder, string lpDestFolder, string zipFileName, bool deleteTempFile, bool writeFiles, string addExtension, Hashtable htFiles, int bufferSize) { // This item is obfuscated and can not be translated. GZipResult result = new GZipResult(); if (!lpSrcFolder.EndsWith(@"\")) { lpSrcFolder = lpSrcFolder + @"\"; } if (!lpDestFolder.EndsWith(@"\")) { lpDestFolder = lpDestFolder + @"\"; } string str = lpSrcFolder + zipFileName + ".tmp"; string str2 = lpSrcFolder + zipFileName; result.TempFile = str; result.ZipFile = str2; string str3 = null; string str4 = null; string path = null; GZipFileInfo info = null; FileStream stream = null; ArrayList list = new ArrayList(); bool flag = false; if (string.IsNullOrEmpty(addExtension)) { addExtension = string.Empty; } else if (!addExtension.StartsWith(".")) { addExtension = "." + addExtension; } try { stream = smethod_7(str2, str, result); if (stream != null) { while (stream.Position != stream.Length) { str3 = null; while (!string.IsNullOrEmpty(str3)) { if (0 == 0) { goto Label_00EF; } str3 = smethod_4(stream); } goto Label_00C4; Label_00EF: if (!string.IsNullOrEmpty(str3)) { info = new GZipFileInfo(); if (!info.ParseFileInfo(str3) || (info.Length <= 0)) { continue; } list.Add(info); str4 = lpDestFolder + info.RelativePath; path = smethod_6(str4); info.LocalPath = str4; flag = false; if ((htFiles == null) || htFiles.ContainsKey(info.RelativePath)) { info.RestoreRequested = true; flag = writeFiles; } if (flag) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } info.Restored = smethod_5(stream, info.Length, str4 + addExtension, bufferSize); continue; } stream.Position += info.Length; } } } } catch { result.Errors = true; } finally { if (stream != null) { stream.Close(); stream = null; } } try { if (deleteTempFile) { File.Delete(str); result.TempFileDeleted = true; } } catch { result.Errors = true; } result.FileCount = list.Count; result.Files = new GZipFileInfo[list.Count]; list.CopyTo(result.Files); return(result); }