public Stream OpenFileAsStream(string strFileName) { strFileName = FileEntryInfo.GetDirPathToLowerNorm_STC(strFileName); if (string.IsNullOrEmpty(strFileName)) { throw new ArgumentNullException(strFileName); } string firstDir = ""; string childDirFileName = ""; firstDir = FileEntryInfo.GetFirstDir_STC(strFileName, out childDirFileName); DiskZip_ConnectInfo zipConn = _checkFileDataZip(strFileName);//获取存储位置 zipConn.Open(); SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null; foreach (var v in zipConn.ZipTarget.Entries) { if (v.IsDirectory) { continue; } if (string.Compare(v.Key, childDirFileName, true) == 0) { findFile = v; break; } } if (findFile != null) { return(zipConn.GetUnCompressStream(findFile)); } return(null); }
/// <summary> /// /// </summary> /// <param name="strFileName"></param> /// <param name="strNewFile"></param> public void RenameFile(string strFileName, string strNewFile) { strFileName = FileEntryInfo.GetDirPathToLowerNorm_STC(strFileName); strNewFile = FileEntryInfo.GetDirPathToLowerNorm_STC(strNewFile); if (string.IsNullOrEmpty(strFileName) || string.IsNullOrEmpty(strNewFile)) { return; //名称不能为空 } if (string.Compare(strFileName, strNewFile) == 0) { return; //没有修改 } string firstDir = ""; string childDirFileName = ""; firstDir = FileEntryInfo.GetFirstDir_STC(strFileName, out childDirFileName); DiskZip_ConnectInfo zipConn = _checkFileDataZip(strFileName);//获取存储位置 zipConn.Open(); SharpCompress.Archive.Zip.ZipArchiveEntry findfile = null; foreach (var ze in zipConn.ZipTarget.Entries) { if (ze.IsDirectory) { continue; } if (string.Compare(ze.Key, childDirFileName, true) == 0) { findfile = ze; break; } } if (findfile != null) { MemoryStream ms = zipConn.GetUnCompressStream(findfile); zipConn.ZipTarget.RemoveEntry(findfile); //findfile.Close(); // string firstDir2 = ""; string childDirFileName2 = ""; firstDir2 = FileEntryInfo.GetFirstDir_STC(strNewFile, out childDirFileName2); DiskZip_ConnectInfo zipConn2 = _checkFileDataZip(strNewFile);//获取存储位置 zipConn2.Open(); zipConn2.ZipTarget.AddEntry(strNewFile, ms, true, ms.Length, findfile.LastModifiedTime); if (m_InUpdateState) { m_InUpdateConnZips.Add(zipConn); if (string.Compare(firstDir2, firstDir) != 0) { m_InUpdateConnZips.Add(zipConn2); } } else { zipConn.Save(); if (string.Compare(firstDir2, firstDir) != 0) { zipConn2.Save(); } } } }