public DateTime GetUpdateDate(string strFileName) { strFileName = DiskReadZip_FilePacker._getFileLegalLowerDir(strFileName); if (string.IsNullOrEmpty(strFileName)) { throw new ArgumentNullException(strFileName); } this.m_Conn = this.m_Packer.CheckConnection(this.Name); DiskReadZip_ConnectInfo conn = this.m_Conn; conn.Open(); SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null; DateTime updateTime = DateTime.MinValue; foreach (var v in conn.ZipTarget.Entries) { if (v.IsDirectory) { continue; } if (string.Compare(v.Key, strFileName, true) == 0) { findFile = v; updateTime = v.LastModifiedTime ?? DateTime.MinValue; break; } } return(updateTime); }
public DateTime GetUpdateDate(string strFileName) { strFileName = FileEntryInfo.GetDirPathToLowerNorm_STC(strFileName); if (string.IsNullOrEmpty(strFileName)) { throw new ArgumentNullException(strFileName); } DiskZip_ConnectInfo zipConn = _checkFileDataZip(strFileName); zipConn.Open(); SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null; DateTime updateTime = DateTime.MinValue; foreach (var v in zipConn.ZipTarget.Entries) { if (v.IsDirectory) { continue; } if (string.Compare(v.Key, strFileName, true) == 0) { findFile = v; updateTime = v.LastModifiedTime ?? DateTime.MinValue; break; } } return(updateTime); }
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); }
public void DelFile(string strFileName) { strFileName = DiskReadZip_FilePacker._getFileLegalLowerDir(strFileName); if (string.IsNullOrEmpty(strFileName)) { return; } //压缩包文件存储格式 //目录 "a/b/c/" //文件 "a/test.txt" this.m_Conn = this.m_Packer.CheckConnection(this.Name); DiskReadZip_ConnectInfo conn = this.m_Conn; conn.Open(); SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null; foreach (var v in conn.ZipTarget.Entries) { if (v.IsDirectory) { continue; } if (string.Compare(v.Key, strFileName, true) == 0) { findFile = v; break; } } if (findFile != null) { conn.ZipTarget.RemoveEntry(findFile); findFile.Close(); } }
public bool FileExists(string strFileName) { strFileName = DiskReadZip_FilePacker._getFileLegalLowerDir(strFileName); if (string.IsNullOrEmpty(strFileName)) { return(false); } this.m_Conn = this.m_Packer.CheckConnection(this.Name); DiskReadZip_ConnectInfo conn = this.m_Conn; conn.Open(); SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null; foreach (var v in conn.ZipTarget.Entries) { if (v.IsDirectory) { continue; } if (string.Compare(v.Key, strFileName, true) == 0) { findFile = v; break; } } if (findFile != null) { return(true); } return(false); }
public Stream OpenFileAsStream(string strFileName) { strFileName = DiskReadZip_FilePacker._getFileLegalLowerDir(strFileName); if (string.IsNullOrEmpty(strFileName)) { throw new ArgumentNullException(strFileName); } this.m_Conn = this.m_Packer.CheckConnection(this.Name); DiskReadZip_ConnectInfo conn = this.m_Conn; conn.Open(); SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null; foreach (var v in conn.ZipTarget.Entries) { if (v.IsDirectory) { continue; } if (string.Compare(v.Key, strFileName, true) == 0) { findFile = v; break; } } if (findFile != null) { return(conn.GetUnCompressStream(findFile)); } return(null); }
public byte[] OpenFile(string strFileName) { strFileName = DiskReadZip_FilePacker._getFileLegalLowerDir(strFileName); if (string.IsNullOrEmpty(strFileName)) { throw new ArgumentNullException(strFileName); } this.m_Conn = this.m_Packer.CheckConnection(this.Name); DiskReadZip_ConnectInfo conn = this.m_Conn; conn.Open(); SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null; foreach (var v in conn.ZipTarget.Entries) { if (v.IsDirectory) { continue; } if (string.Compare(v.Key, strFileName, true) == 0) { findFile = v; break; } } byte[] buf = null; if (findFile != null) { using (MemoryStream ms = conn.GetUnCompressStream(findFile)) { buf = ms.ToArray(); ms.Close();//关闭流 } } return(buf); }
internal ZipArchiveEntry(ZipArchive archive, SharpCompress.Archive.Zip.ZipArchiveEntry entry) { if (archive == null) throw new ArgumentNullException("archive"); if (entry == null) throw new ArgumentNullException("entry"); Archive = archive; this.entry = entry; }
public void UpdateFile(string strFileName, byte[] fileData, DateTime date) { 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);//获取存储位置 //_checkTopChildDirZipPath(firstDir);//检测ZIP,并创建 FileEntryInfo file = new FileEntryInfo(); file.FileDir = firstDir; file.FileName = childDirFileName; file.FileLen = fileData.Length; file.FileUpdateTime = file.DateTimeToStr(date); // zipConn.Open(); SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null; foreach (var ze in zipConn.ZipTarget.Entries) { if (ze.IsDirectory) { continue; } if (string.Compare(ze.Key, file.FileName, true) == 0) { findFile = ze; break; } } // if (findFile != null) { zipConn.ZipTarget.RemoveEntry(findFile); //findFile.Close();//删除老的 } //修改文件 AddFile(strFileName, fileData, date); if (m_InUpdateState) { m_InUpdateConnZips.Add(zipConn); } else { zipConn.Save(); } }
internal ZipArchiveEntry(ZipArchive archive, SharpCompress.Archive.Zip.ZipArchiveEntry entry) { if (archive == null) { throw new ArgumentNullException("archive"); } if (entry == null) { throw new ArgumentNullException("entry"); } Archive = archive; this.entry = entry; }
public MemoryStream GetUnCompressStream(SharpCompress.Archive.Zip.ZipArchiveEntry entry) { MemoryStream tempStream = new MemoryStream(); //SharpCompress.Archive.IArchiveEntryExtensions.WriteTo(entry, tempStream); using (var entryStream = entry.OpenEntryStream()) { const int bufSize = 1024 * 16;//16k byte[] buf = new byte[bufSize]; int bytesRead = 0; while ((bytesRead = entryStream.Read(buf, 0, bufSize)) > 0) { tempStream.Write(buf, 0, bytesRead); } } tempStream.Position = 0; return(tempStream); }
public void DelFile(string strFileName) { strFileName = FileEntryInfo.GetDirPathToLowerNorm_STC(strFileName); if (string.IsNullOrEmpty(strFileName)) { 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 v in zipConn.ZipTarget.Entries) { if (v.IsDirectory) { continue; } if (string.Compare(v.Key, childDirFileName, true) == 0) { findFile = v; break; } } if (findFile != null) { zipConn.ZipTarget.RemoveEntry(findFile); //findFile.Close(); } if (m_InUpdateState) { m_InUpdateConnZips.Add(zipConn); } else { zipConn.Save(); } }
/// <summary> /// 一般不使用吧,外面判断新文件名是否已经存在,不要'/'开头 /// </summary> /// <param name="strFileName">相对目录路径名</param> /// <param name="strNewFile">相对目录路径名</param> public void RenameFile(string strFileName, string strNewFile) { strFileName = DiskReadZip_FilePacker._getFileLegalLowerDir(strFileName); strNewFile = DiskReadZip_FilePacker._getFileLegalLowerDir(strNewFile); if (string.IsNullOrEmpty(strFileName) || string.IsNullOrEmpty(strNewFile)) { return; //名称不能为空 } if (string.Compare(strFileName, strNewFile) == 0) { return; //没有修改 } this.m_Conn = this.m_Packer.CheckConnection(this.Name); DiskReadZip_ConnectInfo conn = this.m_Conn; //ToDo: conn.Open(); SharpCompress.Archive.Zip.ZipArchiveEntry findfile = null; foreach (var ze in conn.ZipTarget.Entries) { if (ze.IsDirectory) { continue; } if (string.Compare(ze.Key, strFileName, true) == 0) { findfile = ze; break; } } if (findfile != null) { //外面判断新文件是否存在 MemoryStream ms = conn.GetUnCompressStream(findfile); conn.ZipTarget.AddEntry(strNewFile, ms, true, ms.Length, findfile.LastModifiedTime); conn.ZipTarget.RemoveEntry(findfile); findfile.Close(); } }
public bool FileExists(string strFileName) { strFileName = FileEntryInfo.GetDirPathToLowerNorm_STC(strFileName); if (string.IsNullOrEmpty(strFileName)) { return(false); } 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; } } bool find = false; if (findFile != null) { //findFile.Close(); find = true; } return(find); }
public void UpdateFile(string strFileName, byte[] fileData, DateTime date) { strFileName = DiskReadZip_FilePacker._getFileLegalLowerDir(strFileName); if (string.IsNullOrEmpty(strFileName)) { throw new ArgumentNullException(strFileName); } // this.m_Conn = this.m_Packer.CheckConnection(this.Name); DiskReadZip_ConnectInfo conn = this.m_Conn; conn.Open(); SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null; foreach (var ze in conn.ZipTarget.Entries) { if (ze.IsDirectory) { continue; } if (string.Compare(ze.Key, strFileName, true) == 0) { findFile = ze; break; } } // if (findFile != null) { conn.ZipTarget.RemoveEntry(findFile); findFile.Close();//删除老的 AddFile(strFileName, fileData, date); } else { AddFile(strFileName, fileData, date); } }
/// <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(); } } } }