using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security; using System.Text; using System.Threading; [assembly: CompilationRelaxations(8)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: ComVisible(false)] [assembly: CLSCompliant(true)] [assembly: SecurityTransparent] [assembly: SecurityRules(SecurityRuleSet.Level2, SkipVerificationInFullTrust = true)] [assembly: AssemblyTitle("System.IO.Compression.FileSystem.dll")] [assembly: AssemblyDescription("System.IO.Compression.FileSystem.dll")] [assembly: AssemblyDefaultAlias("System.IO.Compression.FileSystem.dll")] [assembly: AssemblyCompany("Microsoft Corporation")] [assembly: AssemblyProduct("Microsoft® .NET Framework")] [assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")] [assembly: AssemblyFileVersion("4.8.9032.0")] [assembly: AssemblyInformationalVersion("4.8.9032.0")] [assembly: SatelliteContractVersion("4.0.0.0")] [assembly: NeutralResourcesLanguage("en-US")] [assembly: AssemblyDelaySign(true)] [assembly: AssemblyKeyFile("f:\\dd\\tools\\devdiv\\EcmaPublicKey.snk")] [assembly: AssemblySignatureKey("002400000c800000140100000602000000240000525341310008000001000100613399aff18ef1a2c2514a273a42d9042b72321f1757102df9ebada69923e2738406c21e5b801552ab8d200a65a235e001ac9adc25f2d811eb09496a4c6a59d4619589c69f5baf0c4179a47311d92555cd006acc8b5959f2bd6e10e360c34537a1d266da8085856583c85d81da7f3ec01ed9564c58d93d713cd0172c8e23a10f0239b80c96b07736f5d8b022542a4e74251a5f432824318b3539a5a087f8e53d2f135f9ca47f3bb2e10aff0af0849504fb7cea3ff192dc8de0edad64c68efde34c56d302ad55fd6e80f302d5efcdeae953658d3452561b5f36c542efdbdd9f888538d374cef106acf7d93a4445c3c73cd911f0571aaf3d54da12b11ddec375b3", "a5a866e1ee186f807668209f3b11236ace5e21f117803a3143abb126dd035d7d2f876b6938aaf2ee3414d5420d753621400db44a49c486ce134300a2106adb6bdb433590fef8ad5c43cba82290dc49530effd86523d9483c00f458af46890036b0e2c61d077d7fbac467a506eba29e467a87198b053c749aa2a4d2840c784e6d")] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: DefaultDllImportSearchPaths(DllImportSearchPath.System32 | DllImportSearchPath.AssemblyDirectory)] [assembly: AssemblyVersion("4.0.0.0")] namespace System { internal static class AppContextDefaultValues { public static void PopulateDefaultValues() { ParseTargetFrameworkName(out var identifier, out var profile, out var version); PopulateDefaultValuesPartial(identifier, profile, version); } private static void ParseTargetFrameworkName(out string identifier, out string profile, out int version) { string targetFrameworkName = AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName; if (!TryParseFrameworkName(targetFrameworkName, out identifier, out version, out profile)) { identifier = ".NETFramework"; version = 40000; profile = string.Empty; } } private static bool TryParseFrameworkName(string frameworkName, out string identifier, out int version, out string profile) { identifier = (profile = string.Empty); version = 0; if (frameworkName == null || frameworkName.Length == 0) { return false; } string[] array = frameworkName.Split(new char[1] { ',' }); version = 0; if (array.Length < 2 || array.Length > 3) { return false; } identifier = array[0].Trim(); if (identifier.Length == 0) { return false; } bool flag = false; profile = null; for (int i = 1; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { '=' }); if (array2.Length != 2) { return false; } string text = array2[0].Trim(); string text2 = array2[1].Trim(); if (text.Equals("Version", StringComparison.OrdinalIgnoreCase)) { flag = true; if (text2.Length > 0 && (text2[0] == 'v' || text2[0] == 'V')) { text2 = text2.Substring(1); } Version version2 = new Version(text2); version = version2.Major * 10000; if (version2.Minor > 0) { version += version2.Minor * 100; } if (version2.Build > 0) { version += version2.Build; } } else { if (!text.Equals("Profile", StringComparison.OrdinalIgnoreCase)) { return false; } if (!string.IsNullOrEmpty(text2)) { profile = text2; } } } if (!flag) { return false; } return true; } private static void PopulateDefaultValuesPartial(string platformIdentifier, string profile, int version) { switch (platformIdentifier) { case ".NETCore": case ".NETFramework": if (version <= 40600) { LocalAppContext.DefineSwitchDefault("Switch.System.IO.Compression.ZipFile.UseBackslash", initialValue: true); } break; case "WindowsPhone": case "WindowsPhoneApp": if (version <= 80100) { LocalAppContext.DefineSwitchDefault("Switch.System.IO.Compression.ZipFile.UseBackslash", initialValue: true); } break; } } } internal static class LocalAppContextSwitches { private static int _zipFileUseBackslash; private static int _doNotAddTrailingSeparator; internal const string ZipFileUseBackslashName = "Switch.System.IO.Compression.ZipFile.UseBackslash"; internal const string DoNotAddTrailingSeparatorString = "Switch.System.IO.Compression.DoNotAddTrailingSeparator"; public static bool ZipFileUseBackslash { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return LocalAppContext.GetCachedSwitchValue("Switch.System.IO.Compression.ZipFile.UseBackslash", ref _zipFileUseBackslash); } } public static bool DoNotAddTrailingSeparator { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return LocalAppContext.GetCachedSwitchValue("Switch.System.IO.Compression.DoNotAddTrailingSeparator", ref _doNotAddTrailingSeparator); } } } internal static class LocalAppContext { private delegate bool TryGetSwitchDelegate(string switchName, out bool value); private static TryGetSwitchDelegate TryGetSwitchFromCentralAppContext; private static bool s_canForwardCalls; private static Dictionary s_switchMap; private static readonly object s_syncLock; private static bool DisableCaching { get; set; } static LocalAppContext() { s_switchMap = new Dictionary(); s_syncLock = new object(); s_canForwardCalls = SetupDelegate(); AppContextDefaultValues.PopulateDefaultValues(); DisableCaching = IsSwitchEnabled("TestSwitch.LocalAppContext.DisableCaching"); } public static bool IsSwitchEnabled(string switchName) { if (s_canForwardCalls && TryGetSwitchFromCentralAppContext(switchName, out var value)) { return value; } return IsSwitchEnabledLocal(switchName); } private static bool IsSwitchEnabledLocal(string switchName) { bool flag; bool value; lock (s_switchMap) { flag = s_switchMap.TryGetValue(switchName, out value); } if (flag) { return value; } return false; } private static bool SetupDelegate() { Type type = typeof(object).Assembly.GetType("System.AppContext"); if (type == null) { return false; } MethodInfo method = type.GetMethod("TryGetSwitch", BindingFlags.Static | BindingFlags.Public, null, new Type[2] { typeof(string), typeof(bool).MakeByRefType() }, null); if (method == null) { return false; } TryGetSwitchFromCentralAppContext = (TryGetSwitchDelegate)Delegate.CreateDelegate(typeof(TryGetSwitchDelegate), method); return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool GetCachedSwitchValue(string switchName, ref int switchValue) { if (switchValue < 0) { return false; } if (switchValue > 0) { return true; } return GetCachedSwitchValueInternal(switchName, ref switchValue); } private static bool GetCachedSwitchValueInternal(string switchName, ref int switchValue) { if (DisableCaching) { return IsSwitchEnabled(switchName); } bool flag = IsSwitchEnabled(switchName); switchValue = (flag ? 1 : (-1)); return flag; } internal static void DefineSwitchDefault(string switchName, bool initialValue) { s_switchMap[switchName] = initialValue; } } } namespace System.IO.Compression { public static class ZipFile { private static readonly char s_pathSeperator = (System.LocalAppContextSwitches.ZipFileUseBackslash ? '\\' : '/'); public static ZipArchive OpenRead(string archiveFileName) { return Open(archiveFileName, ZipArchiveMode.Read); } public static ZipArchive Open(string archiveFileName, ZipArchiveMode mode) { return Open(archiveFileName, mode, null); } public static ZipArchive Open(string archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding) { FileMode mode2; FileAccess access; FileShare share; switch (mode) { case ZipArchiveMode.Read: mode2 = FileMode.Open; access = FileAccess.Read; share = FileShare.Read; break; case ZipArchiveMode.Create: mode2 = FileMode.CreateNew; access = FileAccess.Write; share = FileShare.None; break; case ZipArchiveMode.Update: mode2 = FileMode.OpenOrCreate; access = FileAccess.ReadWrite; share = FileShare.None; break; default: throw new ArgumentOutOfRangeException("mode"); } FileStream fileStream = null; try { fileStream = File.Open(archiveFileName, mode2, access, share); return new ZipArchive(fileStream, mode, leaveOpen: false, entryNameEncoding); } catch { fileStream?.Dispose(); throw; } } public static void CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName) { DoCreateFromDirectory(sourceDirectoryName, destinationArchiveFileName, null, includeBaseDirectory: false, null); } public static void CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName, CompressionLevel compressionLevel, bool includeBaseDirectory) { DoCreateFromDirectory(sourceDirectoryName, destinationArchiveFileName, compressionLevel, includeBaseDirectory, null); } public static void CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName, CompressionLevel compressionLevel, bool includeBaseDirectory, Encoding entryNameEncoding) { DoCreateFromDirectory(sourceDirectoryName, destinationArchiveFileName, compressionLevel, includeBaseDirectory, entryNameEncoding); } public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName) { ExtractToDirectory(sourceArchiveFileName, destinationDirectoryName, null); } public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName, Encoding entryNameEncoding) { if (sourceArchiveFileName == null) { throw new ArgumentNullException("sourceArchiveFileName"); } using ZipArchive source = Open(sourceArchiveFileName, ZipArchiveMode.Read, entryNameEncoding); source.ExtractToDirectory(destinationDirectoryName); } private static void DoCreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName, CompressionLevel? compressionLevel, bool includeBaseDirectory, Encoding entryNameEncoding) { sourceDirectoryName = Path.GetFullPath(sourceDirectoryName); destinationArchiveFileName = Path.GetFullPath(destinationArchiveFileName); using ZipArchive zipArchive = Open(destinationArchiveFileName, ZipArchiveMode.Create, entryNameEncoding); bool flag = true; DirectoryInfo directoryInfo = new DirectoryInfo(sourceDirectoryName); string fullName = directoryInfo.FullName; if (includeBaseDirectory && directoryInfo.Parent != null) { fullName = directoryInfo.Parent.FullName; } foreach (FileSystemInfo item in directoryInfo.EnumerateFileSystemInfos("*", SearchOption.AllDirectories)) { flag = false; int length = item.FullName.Length - fullName.Length; string text; if (System.LocalAppContextSwitches.ZipFileUseBackslash) { text = item.FullName.Substring(fullName.Length, length); text = text.TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); } else { text = EntryFromPath(item.FullName, fullName.Length, length); } if (item is FileInfo) { ZipFileExtensions.DoCreateEntryFromFile(zipArchive, item.FullName, text, compressionLevel); } else if (item is DirectoryInfo possiblyEmptyDir && IsDirEmpty(possiblyEmptyDir)) { string text2 = text; char c = s_pathSeperator; zipArchive.CreateEntry(text2 + c); } } if (includeBaseDirectory && flag) { string text = (System.LocalAppContextSwitches.ZipFileUseBackslash ? directoryInfo.Name : EntryFromPath(directoryInfo.Name, 0, directoryInfo.Name.Length)); string text3 = text; char c = s_pathSeperator; zipArchive.CreateEntry(text3 + c); } } private static string EntryFromPath(string entry, int offset, int length) { while (length > 0 && (entry[offset] == Path.DirectorySeparatorChar || entry[offset] == Path.AltDirectorySeparatorChar)) { offset++; length--; } if (length == 0) { return string.Empty; } char[] array = entry.ToCharArray(offset, length); for (int i = 0; i < array.Length; i++) { if (array[i] == Path.DirectorySeparatorChar || array[i] == Path.AltDirectorySeparatorChar) { array[i] = s_pathSeperator; } } return new string(array); } private static bool IsDirEmpty(DirectoryInfo possiblyEmptyDir) { using (IEnumerator enumerator = possiblyEmptyDir.EnumerateFileSystemInfos("*", SearchOption.AllDirectories).GetEnumerator()) { if (enumerator.MoveNext()) { FileSystemInfo current = enumerator.Current; return false; } } return true; } } [EditorBrowsable(EditorBrowsableState.Never)] public static class ZipFileExtensions { public static ZipArchiveEntry CreateEntryFromFile(this ZipArchive destination, string sourceFileName, string entryName) { return DoCreateEntryFromFile(destination, sourceFileName, entryName, null); } public static ZipArchiveEntry CreateEntryFromFile(this ZipArchive destination, string sourceFileName, string entryName, CompressionLevel compressionLevel) { return DoCreateEntryFromFile(destination, sourceFileName, entryName, compressionLevel); } public static void ExtractToDirectory(this ZipArchive source, string destinationDirectoryName) { if (source == null) { throw new ArgumentNullException("source"); } if (destinationDirectoryName == null) { throw new ArgumentNullException("destinationDirectoryName"); } DirectoryInfo directoryInfo = Directory.CreateDirectory(destinationDirectoryName); string text = directoryInfo.FullName; if (!System.LocalAppContextSwitches.DoNotAddTrailingSeparator) { int length = text.Length; if (length != 0 && text[length - 1] != Path.DirectorySeparatorChar) { string text2 = text; char directorySeparatorChar = Path.DirectorySeparatorChar; text = text2 + directorySeparatorChar; } } foreach (ZipArchiveEntry entry in source.Entries) { string fullPath = Path.GetFullPath(Path.Combine(text, entry.FullName)); if (!fullPath.StartsWith(text, StringComparison.OrdinalIgnoreCase)) { throw new IOException(SR.GetString("IO_ExtractingResultsInOutside")); } if (Path.GetFileName(fullPath).Length == 0) { if (entry.Length != 0L) { throw new IOException(SR.GetString("IO_DirectoryNameWithData")); } Directory.CreateDirectory(fullPath); } else { Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); entry.ExtractToFile(fullPath, overwrite: false); } } } internal static ZipArchiveEntry DoCreateEntryFromFile(ZipArchive destination, string sourceFileName, string entryName, CompressionLevel? compressionLevel) { if (destination == null) { throw new ArgumentNullException("destination"); } if (sourceFileName == null) { throw new ArgumentNullException("sourceFileName"); } if (entryName == null) { throw new ArgumentNullException("entryName"); } using Stream stream = File.Open(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.Read); ZipArchiveEntry zipArchiveEntry = (compressionLevel.HasValue ? destination.CreateEntry(entryName, compressionLevel.Value) : destination.CreateEntry(entryName)); DateTime dateTime = File.GetLastWriteTime(sourceFileName); if (dateTime.Year < 1980 || dateTime.Year > 2107) { dateTime = new DateTime(1980, 1, 1, 0, 0, 0); } zipArchiveEntry.LastWriteTime = dateTime; using (Stream destination2 = zipArchiveEntry.Open()) { stream.CopyTo(destination2); } return zipArchiveEntry; } public static void ExtractToFile(this ZipArchiveEntry source, string destinationFileName) { source.ExtractToFile(destinationFileName, overwrite: false); } public static void ExtractToFile(this ZipArchiveEntry source, string destinationFileName, bool overwrite) { if (source == null) { throw new ArgumentNullException("source"); } if (destinationFileName == null) { throw new ArgumentNullException("destinationFileName"); } FileMode mode = ((!overwrite) ? FileMode.CreateNew : FileMode.Create); using (Stream destination = File.Open(destinationFileName, mode, FileAccess.Write, FileShare.None)) { using Stream stream = source.Open(); stream.CopyTo(destination); } File.SetLastWriteTime(destinationFileName, source.LastWriteTime.DateTime); } } internal sealed class SR { internal const string IO_DirectoryNameWithData = "IO_DirectoryNameWithData"; internal const string IO_ExtractingResultsInOutside = "IO_ExtractingResultsInOutside"; private static SR loader; private ResourceManager resources; private static CultureInfo Culture => null; public static ResourceManager Resources => GetLoader().resources; internal SR() { resources = new ResourceManager("System.IO.Compression.FileSystem", GetType().Assembly); } private static SR GetLoader() { if (loader == null) { SR value = new SR(); Interlocked.CompareExchange(ref loader, value, null); } return loader; } public static string GetString(string name, params object[] args) { SR sR = GetLoader(); if (sR == null) { return null; } string @string = sR.resources.GetString(name, Culture); if (args != null && args.Length != 0) { for (int i = 0; i < args.Length; i++) { if (args[i] is string text && text.Length > 1024) { args[i] = text.Substring(0, 1021) + "..."; } } return string.Format(CultureInfo.CurrentCulture, @string, args); } return @string; } public static string GetString(string name) { return GetLoader()?.resources.GetString(name, Culture); } public static string GetString(string name, out bool usedFallback) { usedFallback = false; return GetString(name); } public static object GetObject(string name) { return GetLoader()?.resources.GetObject(name, Culture); } } }