public String ExtractFileToString(ZipStorer.ZipFileEntry zipFileEntry) { String rv = null; MemoryStream ms = new MemoryStream(); if (Zip.ExtractFile(zipFileEntry, ms)) { ms.Position = 0; rv = new StreamReader(ms).ReadToEnd().Trim(); } ms.Close(); ms.Dispose(); return rv; }
/// <summary> /// Method to open an existing storage from stream /// </summary> /// <param name="_stream">Already opened stream with zip contents</param> /// <param name="_access">File access mode for stream operations</param> /// <returns>A valid ZipStorer object</returns> public static ZipStorer Open(Stream _stream, FileAccess _access) { if (!_stream.CanSeek && _access != FileAccess.Read) { throw new InvalidOperationException("Stream cannot seek"); } ZipStorer zip = new ZipStorer(); //zip.FileName = _filename; zip.ZipFileStream = _stream; zip.Access = _access; if (zip.ReadFileInfo()) { return(zip); } throw new System.IO.InvalidDataException(); }
/// <summary> /// Method to open an existing storage from stream /// </summary> /// <param name="stream">Already opened stream with zip contents</param> /// <param name="access">File access mode for stream operations</param> /// <returns>A valid ZipStorer object</returns> public static ZipStorer Open(Stream stream, FileAccess access) { if (!stream.CanSeek && access != FileAccess.Read) { throw new InvalidOperationException("Stream cannot seek"); } var zip = new ZipStorer(); //zip.FileName = _filename; zip._zipFileStream = stream; zip._access = access; if (zip.ReadFileInfo()) { return(zip); } throw new InvalidDataException(); }
public void AddStream(ZipStorer.CompressionMethod compressionMethod, Stream sourceStream, string fileNameInZip, DateTime modificationTimeStamp, string fileEntryComment) { if (this.access == FileAccess.Read) { throw new InvalidOperationException("Writing is not allowed"); } ZipStorer.ZipFileEntry item = default(ZipStorer.ZipFileEntry); item.Method = compressionMethod; item.EncodeUTF8 = this.EncodeUtf8; item.FilenameInZip = ZipStorer.NormalizeFileName(fileNameInZip); item.Comment = ((fileEntryComment == null) ? string.Empty : fileEntryComment); item.Crc32 = 0u; item.HeaderOffset = (uint)this.zipFileStream.Position; item.ModifyTime = modificationTimeStamp; this.WriteLocalHeader(ref item); item.FileOffset = (uint)this.zipFileStream.Position; this.Store(ref item, sourceStream); sourceStream.Close(); this.UpdateCrcAndSizes(ref item); this.files.Add(item); }
/// <summary> /// Method to open an existing storage from stream /// </summary> /// <param name="_stream">Already opened stream with zip contents</param> /// <param name="_access">File access mode for stream operations</param> /// <returns>A valid ZipStorer object</returns> public static ZipStorer Open(Stream _stream, FileAccess _access) { if (!_stream.CanSeek && _access != FileAccess.Read) { throw new InvalidOperationException("Stream cannot seek"); } ZipStorer zip = new ZipStorer(); //zip.FileName = _filename; zip.ZipFileStream = _stream; zip.Access = _access; if (zip.ReadFileInfo()) { return(zip); } //throw new System.IO.InvalidDataException(); return(null); // TODO Unity had an issue with the above line so returning null }
/// <summary> /// Method to open an existing storage from stream /// </summary> /// <param name="stream">Already opened stream with zip contents</param> /// <param name="fileFileAccess">File access mode for stream operations</param> /// <returns>A valid ZipStorer object</returns> public static ZipStorer Open([NotNull] Stream stream, FileAccess fileFileAccess) { if (stream == null) { throw new ArgumentNullException("stream"); } if (!stream.CanSeek && fileFileAccess != FileAccess.Read) { throw new InvalidOperationException("Stream cannot seek"); } ZipStorer zip = new ZipStorer { zipFileStream = stream, access = fileFileAccess }; if (zip.ReadFileInfo()) { return(zip); } throw new InvalidDataException(); }
/// <summary> /// Method to open an existing storage from stream /// </summary> /// <param name="_stream">Already opened stream with zip contents</param> /// <param name="_access">File access mode for stream operations</param> /// <param name="_leaveOpen">true to leave the stream open after the ZipStorer object is disposed; otherwise, false (default).</param> /// <returns>A valid ZipStorer object</returns> public static ZipStorer Open(Stream _stream, FileAccess _access, Boolean _leaveOpen = false) { if (!_stream.CanSeek && _access != FileAccess.Read) { throw new InvalidOperationException("Stream cannot seek"); } ZipStorer zip = new ZipStorer { ZipFileStream = _stream, Access = _access, leaveOpen = _leaveOpen }; //zip.FileName = _filename; if (zip.ReadFileInfo()) { return(zip); } throw new InvalidDataException(); }
//ディレクトリをzipファイルに書き込む private static void WriteDirToZip(ZipStorer zip, DirectoryInfo srcDir, string pathInZip) { var files = srcDir.EnumerateFiles(); files = files.Where(e => e.Name != "mimetype"); //mimetypeファイルを除く foreach (var file in files) { var ext = file.Extension; ZipStorer.Compression compression; //ファイル形式によって圧縮形式を変える switch (ext) { case "jpg": //画像ファイルは圧縮しない(時間の無駄なので) case "JPEG": case "png": case "PNG": case "gif": case "GIF": compression = ZipStorer.Compression.Store; break; case "EPUB": case "epub": continue; //EPUBファイルは格納しない default: compression = ZipStorer.Compression.Deflate; //通常のファイルは圧縮する break; } WriteFileToZip(zip,file, pathInZip + file.Name, compression); } //残りのディレクトリを再帰的に書き込む var dirs = srcDir.EnumerateDirectories(); foreach (var dir in dirs) { WriteDirToZip(zip, dir, pathInZip + dir.Name + "/"); } }
void PrepareUpdate() { updatePackage = ZipStorer.Open(updateLocation, System.IO.FileAccess.Read); updatePackageCatalog = updatePackage.ReadCentralDir(); }
/// <summary> /// Method to create a new zip storage in a stream /// </summary> /// <param name="stream"></param> /// <param name="fileComment"></param> /// <returns>A valid ZipStorer object</returns> public static ZipStorer Create(Stream stream, string fileComment) { ZipStorer zip = new ZipStorer { comment = fileComment, zipFileStream = stream, access = FileAccess.Write }; return zip; }
public bool ExtractFileToStream(ZipStorer.ZipFileEntry zipFileEntry, ref MemoryStream s) { if (Zip.ExtractFile(zipFileEntry, s)) return true; return false; }
/// <summary> /// Method to create a new storage file /// </summary> /// <param name="_filename">Full path of Zip file to create</param> /// <param name="_comment">General comment for Zip file</param> /// <returns></returns> public static ZipStorer Create(string _filename, string _comment) { ZipStorer zip = new ZipStorer(); zip.FileName = _filename; zip.Comment = _comment; zip.ZipFileStream = new FileStream(_filename, FileMode.Create, FileAccess.ReadWrite); zip.Access = FileAccess.Write; return zip; }
/// <summary> /// Create a new zip storage in a stream. /// </summary> /// <param name="zipStream">The stream to use to create the Zip file.</param> /// <param name="fileComment">General comment for Zip file.</param> /// <returns>A valid ZipStorer object.</returns> public static ZipStorer Create(Stream zipStream, string fileComment) { ZipStorer zip = new ZipStorer(); zip.comment = fileComment; zip.zipFileStream = zipStream; zip.access = FileAccess.Write; return zip; }
public List<string> words = new List<string>(); // The XLSX dictionary public OoXml(string template_filename) // Constructor from a file name { zip = ZipStorer.Open(template_filename, FileAccess.Read); // Open the template foreach (ZipStorer.ZipFileEntry l in zip.ReadCentralDir()) streams.Add(new gStream(this, zip, l)); // Get the streams that make up the template and add them SetStructure(); // Analyzes the Sheets structure }
//Epubにファイルを追加する(mimetypeを除く) private static void WriteEpubFilesToZip(ZipStorer zip,string srcDir) { var files = Directory.GetFiles(srcDir, "*", SearchOption.AllDirectories); //全ファイル var targetFiles = files.Where(e => Path.GetFileName(e).Equals("mimetype") != true) //mimetypeを除く .Select(e => new FileInfo(e)); foreach (var targetFile in targetFiles) { var ext = targetFile.Extension; var compression = new ZipStorer.Compression(); switch (ext) { case "jpg": //画像ファイルは圧縮しない(時間の無駄なので) case "JPEG": case "png": case "PNG": case "gif": case "GIF": compression = ZipStorer.Compression.Store; break; case "EPUB": case "epub": continue; //EPUBファイルは格納しない default: compression = ZipStorer.Compression.Deflate; //通常のファイルは圧縮する break; } //対象を書き込む using (var ms = new MemoryStream(File.ReadAllBytes(targetFile.FullName))) { ms.Position = 0; //ファイルの先頭からコピー var fileNameInZip = GetRelPath(targetFile.FullName, srcDir); //zip内でのファイル名 zip.AddStream(compression, fileNameInZip, ms, DateTime.Now, string.Empty); } } }
/// <summary> Removes one of many files in storage. It creates a new Zip file. </summary> /// <param name="zip"> Reference to the current Zip object. </param> /// <param name="zfes"> List of Entries to remove from storage. </param> /// <returns> True if success, false if not. </returns> /// <remarks> This method only works for storage of type FileStream. </remarks> public static bool RemoveEntries([NotNull] ref ZipStorer zip, [NotNull] List <ZipFileEntry> zfes) { if (zip == null) { throw new ArgumentNullException("zip"); } if (zfes == null) { throw new ArgumentNullException("zfes"); } if (!(zip.zipFileStream is FileStream)) { throw new InvalidOperationException("RemoveEntries is allowed just over streams of type FileStream"); } //Get full list of entries List <ZipFileEntry> fullList = zip.ReadCentralDir(); //In order to delete we need to create a copy of the zip file excluding the selected items string tempZipName = Path.GetTempFileName(); string tempEntryName = Path.GetTempFileName(); try { ZipStorer tempZip = Create(tempZipName, string.Empty); foreach (ZipFileEntry zfe in fullList) { if (!zfes.Contains(zfe)) { if (zip.ExtractFile(zfe, tempEntryName)) { tempZip.AddFile(zfe.Method, tempEntryName, zfe.FileNameInZip, zfe.Comment); } } } zip.Close(); tempZip.Close(); if (File.Exists(zip.fileName)) { File.Replace(tempZipName, zip.fileName, null, true); } else { File.Move(tempZipName, zip.fileName); } zip = Open(zip.fileName, zip.access); } catch { return(false); } finally { if (File.Exists(tempZipName)) { File.Delete(tempZipName); } if (File.Exists(tempEntryName)) { File.Delete(tempEntryName); } } return(true); }
public PakkedFile(string name, string handle, int index, ZipStorer.ZipFileEntry entry) { Name = name; Handle = handle; IsPakked = true; PakIndex = index; Entry = entry; }
/// <summary> /// /// </summary> private void SyncToDisk() { //[i] Sync file to disk and check zix lot size if (_zixLots.Count > 0) { var zlLatest = _zixLots.Last(); //[i] Need to get new file storage. var zlFileSize = (int)new FileInfo(zlLatest.FilePath ).Length; zlLatest.FileSize = zlFileSize; //[i] Check zix lot file size if (zlLatest.FileSize < (ZixSizeMax * 1024 * 1000)) { var zlFstream = new FileStream(zlLatest.FilePath,FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.ReadWrite ); _zixStorer = ZipStorer.Open(zlFstream, FileAccess.ReadWrite); _zixLot = zlLatest; } else { var zlNewSeq = _zixLots.Count + 1; var zlNewFileName = _zixStorageName + "." + ZixLotFileExt + "." + zlNewSeq ; var zlNew = new ZixLot { FileName = zlNewFileName, FilePath = _zixStoragePath + zlNewFileName, FileSize = 0, LotSequence = _zixLots.Count + 1 }; _zixStorer = ZipStorer.Create(_zixStoragePath + zlNew.FileName, "engine:db:zix"); _zixLots.Add(zlNew); _zixLot = zlNew; } } else { var zlNewFileName = _zixStorageName + "." + ZixLotFileExt + ".1"; var zlNew = new ZixLot { FileName = zlNewFileName, FilePath = _zixStoragePath + zlNewFileName, FileSize = 0, LotSequence = 1 }; _zixStorer = ZipStorer.Create(zlNew.FilePath, "engine:db:zix"); _zixLots.Add(zlNew); _zixLot = zlNew; } }
public PakFile(string name, string handle) { Handle = handle; Name = name; Storer = ZipStorer.Open(handle, FileAccess.Read); }
public void Open() { Zip = ZipStorer.Open(zipFile, FileAccess.Read); }
public void Save() { Zip = ZipStorer.Create(zipFile, "GamePower Package"); Zip.EncodeUTF8 = false; foreach (String file in Files) Zip.AddFile(ZipStorer.Compression.Store, file, Path.GetFileName(file), String.Empty); }
/// <summary> /// Method to open an existing storage from stream /// </summary> /// <param name="stream">Already opened stream with zip contents</param> /// <param name="fileFileAccess">File access mode for stream operations</param> /// <returns>A valid ZipStorer object</returns> public static ZipStorer Open( [NotNull] Stream stream, FileAccess fileFileAccess ) { if( stream == null ) throw new ArgumentNullException( "stream" ); if( !stream.CanSeek && fileFileAccess != FileAccess.Read ) throw new InvalidOperationException( "Stream cannot seek" ); ZipStorer zip = new ZipStorer { zipFileStream = stream, access = fileFileAccess }; if( zip.ReadFileInfo() ) return zip; throw new InvalidDataException(); }
/// <summary> /// Method to open an existing storage from stream /// </summary> /// <param name="_stream">Already opened stream with zip contents</param> /// <param name="_access">File access mode for stream operations</param> /// <returns>A valid ZipStorer object</returns> public static ZipStorer Open(Stream _stream, FileAccess _access) { if (!_stream.CanSeek && _access != FileAccess.Read) throw new InvalidOperationException("Stream cannot seek"); ZipStorer zip = new ZipStorer(); //zip.FileName = _filename; zip.ZipFileStream = _stream; zip.Access = _access; if (zip.ReadFileInfo()) return zip; throw new System.IO.InvalidDataException(); }
/// <summary> /// Removes one of many files in storage. It creates a new Zip file. /// </summary> /// <param name="zip">Reference to the current Zip object</param> /// <param name="zfes">List of Entries to remove from storage</param> /// <returns>True if success, false if not</returns> /// <remarks>This method only works for storage of type FileStream</remarks> public static bool RemoveEntries( ref ZipStorer zip, [NotNull] List<ZipFileEntry> zfes ) { if( zfes == null ) throw new ArgumentNullException( "zfes" ); if( !(zip.zipFileStream is FileStream) ) throw new InvalidOperationException( "RemoveEntries is allowed just over streams of type FileStream" ); //Get full list of entries List<ZipFileEntry> fullList = zip.ReadCentralDir(); //In order to delete we need to create a copy of the zip file excluding the selected items string tempZipName = Path.GetTempFileName(); string tempEntryName = Path.GetTempFileName(); try { ZipStorer tempZip = Create( tempZipName, string.Empty ); foreach( ZipFileEntry zfe in fullList ) { if( !zfes.Contains( zfe ) ) { if( zip.ExtractFile( zfe, tempEntryName ) ) { tempZip.AddFile( zfe.Method, tempEntryName, zfe.FileNameInZip, zfe.Comment ); } } } zip.Close(); tempZip.Close(); if( File.Exists( zip.fileName ) ) { File.Replace( tempZipName, zip.fileName, null, true ); } else { File.Move( tempZipName, zip.fileName ); } zip = Open( zip.fileName, zip.access ); } catch { return false; } finally { if( File.Exists( tempZipName ) ) File.Delete( tempZipName ); if( File.Exists( tempEntryName ) ) File.Delete( tempEntryName ); } return true; }
void AddCritterType( ZipStorer zip, CritterType crType ) { object datafile = null; if( !OpenCurrentDatafile( ref datafile ) ) return; List<CritterAnimationPacked> zipFiles = new List<CritterAnimationPacked>(); foreach( CritterAnimation crAnim in crType.Animations ) { List<string> nameList = new List<string>(); List<byte[]> bytesList = new List<byte[]>(); List<DateTime> dateList = new List<DateTime>(); string crName = crType.Name + crAnim.Name; for( int d = 0; d <= 5; d++ ) { if( crAnim.Dir[d] == CritterAnimationDir.None ) continue; string ext = ".FR" + (crAnim.Full ? "M" : d.ToString()); switch( LoadedMode ) { case LoadModeType.Directory: string filename = openDirectory.SelectedPath + Path.DirectorySeparatorChar + crName + ext; if( File.Exists( filename ) ) { zipFiles.Add( new CritterAnimationPacked( ArtCrittersZip + crName + ext, File.ReadAllBytes( filename ), File.GetLastWriteTime( filename ) ) ); } break; case LoadModeType.Zip: ZipStorer zipDatafile = (ZipStorer)datafile; MemoryStream stream = new MemoryStream(); zipDatafile.ExtractFile( crAnim.ZipData[d], stream ); zipFiles.Add( new CritterAnimationPacked( ArtCrittersZip + crName + ext, stream.ToArray(), crAnim.ZipData[d].ModifyTime ) ); break; case LoadModeType.Dat: DAT dat = (DAT)datafile; zipFiles.Add( new CritterAnimationPacked( ArtCrittersZip + crName + ext, dat.FileList[crAnim.DatData[d]].GetData(), DateTime.Now ) ); break; } if( crAnim.Full ) break; } } CloseCurrentDatafile( ref datafile ); foreach( CritterAnimationPacked crAnimPacked in zipFiles ) { MemoryStream stream = new MemoryStream( crAnimPacked.Bytes, false ); zip.AddStream( ZipStorer.Compression.Deflate, crAnimPacked.Filename, stream, crAnimPacked.Date, "" ); } }
public static ZipStorer Open(Stream stream, FileAccess access) { if (!stream.CanSeek && access != FileAccess.Read) { throw new InvalidOperationException("Stream cannot seek"); } ZipStorer zip = new ZipStorer(); zip.zipFileStream = stream; zip.access = access; if (zip.ReadFileInfo()) { return zip; } throw new System.IO.InvalidDataException(); }
public static ZipStorer Create([NotNull] Stream stream, [NotNull] string fileComment) { if (stream == null) throw new ArgumentNullException("stream"); if (fileComment == null) throw new ArgumentNullException("fileComment"); ZipStorer zip = new ZipStorer { comment = fileComment, zipFileStream = stream, access = FileAccess.Write }; return zip; }
public gSheet Sheet = null; // This links to a data sheet if his stream implements a data sheet public gStream(OoXml doc, ZipStorer zip, ZipStorer.ZipFileEntry z) // This constructor is called when creating the stream from the source template { Document = doc; // Save a reference to the document zfe = z; // Store the ZipFileEntry }
/// <summary> /// Method to open an existing storage /// </summary> /// <param name="_filename">Full path of Zip file to open</param> /// <param name="_access">File access mode as used in FileStream constructor</param> /// <returns></returns> public static ZipStorer Open(string _filename, FileAccess _access) { ZipStorer zip = new ZipStorer(); zip.FileName = _filename; zip.ZipFileStream = new FileStream(_filename, FileMode.Open, _access == FileAccess.Read ? FileAccess.Read : FileAccess.ReadWrite); zip.Access = _access; if (zip.ReadFileInfo()) return zip; throw new System.IO.InvalidDataException(); }
public void Close() // Close the excel file { if (zip != null) { zip.Close(); zip = null; } }
public bool ExtractFile(ZipStorer.ZipFileEntry zipFileEntry, String filename) { return Zip.ExtractFile(zipFileEntry, filename); }
/// <summary> /// Method to create a new zip storage in a stream /// </summary> /// <param name="_stream"></param> /// <param name="_comment"></param> /// <returns>A valid ZipStorer object</returns> public static ZipStorer Create(Stream _stream, string _comment) { ZipStorer zip = new ZipStorer(); zip.Comment = _comment; zip.ZipFileStream = _stream; zip.Access = FileAccess.Write; return zip; }
//ファイルをzipファイルに書き込む private static void WriteFileToZip(ZipStorer zip, FileInfo file, string fileNameInZip, ZipStorer.Compression compression) { using(var m =new MemoryStream(File.ReadAllBytes(file.FullName))) //対象をファイルから読み出す { m.Position = 0; //先頭からコピー zip.AddStream(compression, fileNameInZip, m, DateTime.Now, String.Empty); //zipファイルに格納する } }
/// <summary> /// Removes one of many files in storage. It creates a new Zip file. /// </summary> /// <param name="_zip">Reference to the current Zip object</param> /// <param name="_zfes">List of Entries to remove from storage</param> /// <returns>True if success, false if not</returns> /// <remarks>This method only works for storage of type FileStream</remarks> public static bool RemoveEntries(ref ZipStorer _zip, List<ZipFileEntry> _zfes) { if (!(_zip.ZipFileStream is FileStream)) throw new InvalidOperationException("RemoveEntries is allowed just over streams of type FileStream"); //Get full list of entries List<ZipFileEntry> fullList = _zip.ReadCentralDir(); //In order to delete we need to create a copy of the zip file excluding the selected items string tempZipName = Path.GetTempFileName(); string tempEntryName = Path.GetTempFileName(); try { ZipStorer tempZip = ZipStorer.Create(tempZipName, string.Empty); foreach (ZipFileEntry zfe in fullList) { if (!_zfes.Contains(zfe)) { if (_zip.ExtractFile(zfe, tempEntryName)) { tempZip.AddFile(zfe.Method, tempEntryName, zfe.FilenameInZip, zfe.Comment); } } } _zip.Close(); tempZip.Close(); File.Delete(_zip.FileName); File.Move(tempZipName, _zip.FileName); _zip = ZipStorer.Open(_zip.FileName, _zip.Access); } catch { return false; } finally { if (File.Exists(tempZipName)) File.Delete(tempZipName); if (File.Exists(tempEntryName)) File.Delete(tempEntryName); } return true; }
void AddCritterType( ZipStorer zip, string crTypeName ) { CritterType crType = CritterTypes.Find( cr => crTypeName.ToUpper() == cr.Name ); if( crType == null ) { return; } AddCritterType( zip, crType ); }