private static EntryFromPath ( string entry, int offset, int length, char &buffer, bool appendPathSeparator = false ) : string | ||
entry | string | |
offset | int | |
length | int | |
buffer | char | |
appendPathSeparator | bool | |
return | string |
private static void DoCreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName, CompressionLevel?compressionLevel, bool includeBaseDirectory, Encoding entryNameEncoding) { string str; char sPathSeperator; sourceDirectoryName = Path.GetFullPath(sourceDirectoryName); destinationArchiveFileName = Path.GetFullPath(destinationArchiveFileName); using (ZipArchive zipArchive = ZipFile.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 fileSystemInfo in directoryInfo.EnumerateFileSystemInfos("*", SearchOption.AllDirectories)) { flag = false; int length = fileSystemInfo.FullName.Length - fullName.Length; if (!LocalAppContextSwitches.ZipFileUseBackslash) { str = ZipFile.EntryFromPath(fileSystemInfo.FullName, fullName.Length, length); } else { str = fileSystemInfo.FullName.Substring(fullName.Length, length); str = str.TrimStart(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }); } if (!(fileSystemInfo is FileInfo)) { DirectoryInfo directoryInfo1 = fileSystemInfo as DirectoryInfo; if (directoryInfo1 == null || !ZipFile.IsDirEmpty(directoryInfo1)) { continue; } sPathSeperator = ZipFile.s_pathSeperator; zipArchive.CreateEntry(string.Concat(str, sPathSeperator.ToString())); } else { ZipFileExtensions.DoCreateEntryFromFile(zipArchive, fileSystemInfo.FullName, str, compressionLevel); } } if (includeBaseDirectory & flag) { str = (LocalAppContextSwitches.ZipFileUseBackslash ? directoryInfo.Name : ZipFile.EntryFromPath(directoryInfo.Name, 0, directoryInfo.Name.Length)); sPathSeperator = ZipFile.s_pathSeperator; zipArchive.CreateEntry(string.Concat(str, sPathSeperator.ToString())); } } }