public virtual bool Zip(ZipOprationInfo zipOprationInfo) { using (var zip = zipOprationInfo.IsNew ? new ZipFile() : ZipFile.Read(zipOprationInfo.DestinationPath)) { if (!string.IsNullOrEmpty(zipOprationInfo.Password)) { zip.Password = zipOprationInfo.Password; var encryption = EncryptionAlgorithm.PkzipWeak; if (zipOprationInfo.Encryption != null) { Enum.TryParse(zipOprationInfo.Encryption, true, out encryption); } zip.Encryption = encryption; } if (zipOprationInfo.CompressionLevel != null) { var compressionLevel = Ionic.Zlib.CompressionLevel.Default; Enum.TryParse(zipOprationInfo.CompressionLevel, true, out compressionLevel); zip.CompressionLevel = compressionLevel; } if (zipOprationInfo.Files != null) { foreach (var file in zipOprationInfo.Files) { zip.UpdateFile(zipOprationInfo.SourcePath.EndsWith(@"\") ? zipOprationInfo.SourcePath + file : zipOprationInfo.SourcePath + @"\" + file); } } if (zipOprationInfo.Folders != null) { foreach (var folder in zipOprationInfo.Folders) { var currentFolder = folder; if (folder == "/" || folder == @"\") { currentFolder = ""; } zip.UpdateDirectory(zipOprationInfo.SourcePath.EndsWith(@"\") ? zipOprationInfo.SourcePath + currentFolder : zipOprationInfo.SourcePath + @"\" + currentFolder); } } zip.Save(zipOprationInfo.DestinationPath.ToLower().IndexOf(".zip", StringComparison.Ordinal) > -1 ? zipOprationInfo.DestinationPath : zipOprationInfo.DestinationPath + ".zip"); } return(true); }
public bool Zip(ZipOprationInfo zipOprationInfo) { //if (zipOprationInfo.DestinationPath[0] != '~') // zipOprationInfo.DestinationPath = zipOprationInfo.DestinationPath[0] == '/' ? "~" + // zipOprationInfo.DestinationPath : "~/" + zipOprationInfo.DestinationPath; //if (zipOprationInfo.SourcePath[0] != '~') // zipOprationInfo.SourcePath = zipOprationInfo.SourcePath[0] == '/' ? "~" + // zipOprationInfo.SourcePath : "~/" + zipOprationInfo.SourcePath; var temp = zipOprationInfo.DestinationPath; zipOprationInfo.DestinationPath = _fileSystemManager.RelativeToAbsolutePath(AuthorizeManager.AuthorizeActionOnPath(zipOprationInfo.DestinationPath, ActionKey.WriteToDisk)); if (zipOprationInfo.DestinationPath == null) { throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.PathNotFound, temp)); } zipOprationInfo.SourcePath = _fileSystemManager.RelativeToAbsolutePath(AuthorizeManager.AuthorizeActionOnPath(zipOprationInfo.SourcePath, ActionKey.ReadFromDisk)); if (!zipOprationInfo.OverWrite) { if (_fileSystemManager.FileExist(zipOprationInfo.DestinationPath.ToLower().IndexOf(".zip", StringComparison.Ordinal) > -1 ? zipOprationInfo.DestinationPath : zipOprationInfo.DestinationPath + ".zip")) { throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.RepeatedPath, zipOprationInfo.DestinationPath)); } } var path = zipOprationInfo.DestinationPath.Remove(zipOprationInfo.DestinationPath.ToLower() .LastIndexOf("\\", StringComparison.Ordinal)); if (!_fileSystemManager.DirectoryExists(path)) { throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.PathNotFound, path)); } return(_zipManager.Zip(zipOprationInfo)); }
public bool Zip(ZipOprationInfo zipOprationInfo) { return(_fileSystemBiz.Zip(zipOprationInfo)); }