/// <summary> /// 构造函数,根据完整文件名生成适应于ZipEntry的文件名 /// </summary> /// <param name="aFileName"></param> /// <param name="aBasePath"></param> /// <param name="isDirctory"></param> public I3SharpZipFileInfo(string aFullName, string aBaseDir, bool isDirctory, I3SZFileInfoMode aMode) { string aFileName; if (string.IsNullOrEmpty(aBaseDir)) { aFileName = Path.GetFileName(aFullName); } else { aBaseDir = I3DirectoryUtil.CheckDirctoryLastChar(aBaseDir); aFileName = aFullName.Replace(aBaseDir, string.Empty); } if (isDirctory) { aFileName = I3DirectoryUtil.CheckDirctoryLastChar(aFileName); } aFileName = aFileName.Replace(@"\", "/"); if (isDirctory) { fileName = aFileName; fullName = aFullName; fileSize = 0; mode = aMode; } else { using (FileStream fileStream = new FileStream(aFullName, FileMode.Open, FileAccess.Read)) { fileName = aFileName; fullName = aFullName; fileSize = fileStream.Length; mode = aMode; } } }
/// <summary> /// 压缩整个目录,包含子目录和文件 /// </summary> /// <param name="aDir"></param> /// <param name="destFileName"></param> /// <returns></returns> public I3MsgInfo CompressADir(string aDir, string destFileName) { #region 先删除目的文件 if (!I3FileUtil.CheckFileNotExists(destFileName)) { return(new I3MsgInfo(false, "")); } #endregion if (!string.IsNullOrEmpty(aDir)) { aDir = I3DirectoryUtil.CheckDirctoryLastChar(aDir); aDir = aDir + "*"; } string cmdLine = " a -ep1 -r -Y "; if (!string.IsNullOrEmpty(passWord)) { cmdLine = cmdLine + " -p" + I3StringUtil.AppendDoubleQuotes(passWord) + " "; } cmdLine = cmdLine + I3StringUtil.AppendDoubleQuotes(destFileName) + " " + I3StringUtil.AppendDoubleQuotes(aDir); return(RunCmdLine(cmdLine)); }