/// <summary> /// /// </summary> /// <param name="local_absolute_path"></param> public override void ExportFile(string local_absolute_path) { ZipFile zipFile = this.OpenZipFile(); string localPath; int pos; local_absolute_path = PathUtils.ToUnixPath(local_absolute_path); try { if (this.IsDirectory) { foreach (ZipEntry entry in zipFile) { if (entry.Name.StartsWith(this.InnerPath.Substring(1) + "/") || this.innerPath == "/") { localPath = PathUtils.AddTrailingSlash(local_absolute_path) + entry.Name; if ((pos = entry.Name.IndexOf('/')) != -1) { localPath = PathUtils.AddTrailingSlash(local_absolute_path) + entry.Name.Substring(pos); } if (entry.IsDirectory) { localPath = localPath.Substring(0, localPath.Length - 1); Directory.CreateDirectory(localPath); } else { IOUtils.StreamFromTo(zipFile.GetInputStream(entry), new FileStream(localPath, FileMode.Create), 1024); } } } } else { ZipEntry entry = zipFile.GetEntry(this.innerPath.Substring(1)); localPath = local_absolute_path; if (entry != null) { IOUtils.StreamFromTo(zipFile.GetInputStream(entry), new FileStream(localPath, FileMode.Create), 1024); } } } finally { zipFile.Close(); } }
private ResultSet CreateZip(ManagerEngine man, Hashtable input) { ResultSet rs = new ResultSet(new string[] { "status", "fromfile", "tofile", "message" }); if (man.GetFile(man.DecryptPath((string)input["topath"]), (string)input["toname"] + ".zip").Exists) { throw new ManagerException("{#error.tofile_exists}"); } for (int i = 0; input["frompath" + i] != null; i++) { IFile fromFile = man.GetFile(man.DecryptPath((string)input["frompath" + i])); IFile toFile = man.GetFile("zip://" + PathUtils.AddTrailingSlash(man.DecryptPath((string)input["topath"])) + input["toname"] + ".zip", fromFile.Name); if (!man.IsToolEnabled("zip", toFile.Config)) { throw new ManagerException("{#error.no_access}"); } if (!fromFile.Exists) { rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.no_from_file}"); continue; } // Zip check if (!man.VerifyFile(fromFile, "zip")) { rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), man.InvalidFileMsg); continue; } if (fromFile.CopyTo(toFile)) { rs.Add("OK", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#message.zip_success}"); } } return(rs); }
/// <summary> /// Delete formats for the specified image based. /// /// Format parameters: /// %f - Filename. /// %e - Extension. /// %w - Image width. /// %h - Image height. /// %tw - Target width. /// %th - Target height. /// %ow - Original width. /// %oh - Original height. /// /// Examples: /// 320x240|gif=%f_%w_%h.gif,320x240=%f_%w_%h.%e /// </summary> /// <param name="path">File name to format.</param> /// <param name="format">Format string to process.</param> public static void DeleteFormatImages(string path, string format) { int targetWidth, targetHeight, newWidth, newHeight; string fileName, extension, outPath; MediaInfo info; double scale; if (!File.Exists(path)) { return; } info = new MediaInfo(path); foreach (string chunk in format.Split(new char[] { ',' })) { Match chunkMatch = Regex.Match(chunk, @"\s?([^=]+)\s?=(.+)\s?"); if (chunkMatch.Success) { fileName = Path.GetFileNameWithoutExtension(path); extension = Path.GetExtension(path).Replace(".", ""); targetWidth = newWidth = info.Width; targetHeight = newHeight = info.Height; // Parse all items foreach (string item in chunkMatch.Groups[1].Value.Split(new char[] { '|' })) { switch (item.ToLower()) { case "gif": case "jpeg": case "jpg": case "png": case "bmp": extension = item; break; default: Match match = Regex.Match(item, @"\s?([0-9\*]+)\s?x([0-9\*]+)\s?"); if (match.Success) { try { targetWidth = Convert.ToInt32(match.Groups[1].Value); } catch { // Ignore } try { targetHeight = Convert.ToInt32(match.Groups[2].Value); } catch { // Ignore } try { if (match.Groups[1].Value == "*") { // Width is omitted targetWidth = (int)Math.Floor((double)info.Width / (info.Height / targetHeight)); } if (match.Groups[2].Value == "*") { // Height is omitted targetHeight = (int)Math.Floor((double)info.Height / (info.Width / targetWidth)); } } catch { // Ignore } } break; } } // Scale it if (targetWidth != info.Width || targetHeight != info.Height) { scale = Math.Min(targetWidth / (double)info.Width, targetHeight / (double)info.Height); newWidth = scale > 1 ? info.Width : (int)Math.Floor((double)info.Width * scale); newHeight = scale > 1 ? info.Height : (int)Math.Floor((double)info.Height * scale); } // Build output path outPath = chunkMatch.Groups[2].Value; outPath = outPath.Replace("%f", fileName); outPath = outPath.Replace("%e", extension); outPath = outPath.Replace("%ow", "" + info.Width); outPath = outPath.Replace("%oh", "" + info.Height); outPath = outPath.Replace("%tw", "" + targetWidth); outPath = outPath.Replace("%th", "" + targetHeight); outPath = outPath.Replace("%w", "" + newWidth); outPath = outPath.Replace("%h", "" + newHeight); outPath = PathUtils.AddTrailingSlash(PathUtils.ToUnixPath(Path.GetDirectoryName(path))) + outPath; if (File.Exists(outPath)) { File.Delete(outPath); } } } }