public ZipReturn ZipFileOpen(Stream inStream) { ZipFileClose(); _zipFileInfo = null; _zipFs = inStream; ZipOpen = ZipOpenType.OpenRead; ZipStatus = ZipStatus.None; return(ZipFileReadHeaders()); }
public ZipReturn ZipFileOpen(byte[] zipFileBytes) { ZipFileClose(); _zipFileInfo = null; _memoryZipFile = zipFileBytes; _zipFs = new MemoryStream(_memoryZipFile, 0, zipFileBytes.Length); ZipOpen = ZipOpenType.OpenRead; ZipStatus = ZipStatus.None; return(ZipFileReadHeaders()); }
public ZipReturn ZipFileOpen(byte[] zipBytes) { ZipFileClose(); ZipStatus = ZipStatus.None; _fileInfo = null; _inStream = new MemoryStream(zipBytes); ZipOpen = ZipOpenType.OpenRead; //return ZipFileReadHeaders(); return(ZipReturn.ZipGood); }
public ZipReturn ZipFileOpen(Stream inStream) { ZipFileClose(); ZipStatus = ZipStatus.None; _fileInfo = null; _inStream = inStream; ZipOpen = ZipOpenType.OpenRead; //return ZipFileReadHeaders(); return(ZipReturn.ZipGood); }
public ZipReturn ZipFileOpen(string newFilename, long timestamp, bool readHeaders) { ZipFileClose(); ZipStatus = ZipStatus.None; _fileInfo = null; try { if (!RVIO.File.Exists(newFilename)) { ZipFileClose(); return(ZipReturn.ZipErrorFileNotFound); } _fileInfo = new FileInfo(newFilename); if (timestamp != -1 && _fileInfo.LastWriteTime != timestamp) { ZipFileClose(); return(ZipReturn.ZipErrorTimeStamp); } int errorCode = FileStream.OpenFileRead(newFilename, out _inStream); if (errorCode != 0) { ZipFileClose(); if (errorCode == 32) { return(ZipReturn.ZipFileLocked); } return(ZipReturn.ZipErrorOpeningFile); } } catch (PathTooLongException) { ZipFileClose(); return(ZipReturn.ZipFileNameToLong); } catch (IOException) { ZipFileClose(); return(ZipReturn.ZipErrorOpeningFile); } ZipOpen = ZipOpenType.OpenRead; if (!readHeaders) { return(ZipReturn.ZipGood); } //return ZipFileReadHeaders(); return(ZipReturn.ZipGood); }
/// <summary> /// Read the end of the central directory /// </summary> /// <returns>Status of the given stream</returns> private ZipReturn ReadEndOfCentralDir() { // Open the stream for reading BinaryReader br = new BinaryReader(_zipstream); // If the stream doesn't start with the correct signature, return uint thisSignature = br.ReadUInt32(); if (thisSignature != Constants.EndOfCentralDirSignature) { return(ZipReturn.ZipEndOfCentralDirectoryError); } // If this is part of a spanned archive, return ushort tushort = br.ReadUInt16(); // NumberOfThisDisk if (tushort != 0) { return(ZipReturn.ZipEndOfCentralDirectoryError); } tushort = br.ReadUInt16(); // NumberOfThisDiskCenterDir if (tushort != 0) { return(ZipReturn.ZipEndOfCentralDirectoryError); } // If the number of entries in the current disk doesn't match up with the total entries, return _entriesCount = br.ReadUInt16(); // TotalNumberOfEntriesDisk tushort = br.ReadUInt16(); // TotalNumber of entries in the central directory if (tushort != _entriesCount) { return(ZipReturn.ZipEndOfCentralDirectoryError); } _centerDirSize = br.ReadUInt32(); // SizeOfCenteralDir _centerDirStart = br.ReadUInt32(); // Offset // Get the file comment ushort zipFileCommentLength = br.ReadUInt16(); _fileComment = br.ReadBytes(zipFileCommentLength); // If there's extra data past the comment, flag that we have extra data if (_zipstream.Position != _zipstream.Length) { _zipStatus |= ZipStatus.ExtraData; } return(ZipReturn.ZipGood); }
public ZipReturn ZipFileOpen(string filename, long timestamp, bool readHeaders) { ZipFileClose(); _memoryZipFile = null; Debug.WriteLine(filename); #region open file stream try { if (!RVIO.File.Exists(filename)) { ZipFileClose(); return(ZipReturn.ZipErrorFileNotFound); } _zipFileInfo = new FileInfo(filename); if ((timestamp != -1) && (_zipFileInfo.LastWriteTime != timestamp)) { ZipFileClose(); return(ZipReturn.ZipErrorTimeStamp); } int errorCode = FileStream.OpenFileRead(filename, out _zipFs); if (errorCode != 0) { ZipFileClose(); return(ZipReturn.ZipErrorOpeningFile); } } catch (PathTooLongException) { ZipFileClose(); return(ZipReturn.ZipFileNameToLong); } catch (IOException) { ZipFileClose(); return(ZipReturn.ZipErrorOpeningFile); } #endregion ZipOpen = ZipOpenType.OpenRead; ZipStatus = ZipStatus.None; return(ZipFileReadHeaders()); }
private ZipReturn ZipFileReadHeaders() { try { SignatureHeader signatureHeader = new SignatureHeader(); if (!signatureHeader.Read(new BinaryReader(_zipFs))) { return(ZipReturn.ZipSignatureError); } _baseOffset = _zipFs.Position; //_zipFs.Seek(_baseOffset + (long)signatureHeader.NextHeaderOffset, SeekOrigin.Begin); //byte[] mainHeader = new byte[signatureHeader.NextHeaderSize]; //_zipFs.Read(mainHeader, 0, (int)signatureHeader.NextHeaderSize); //if (!CRC.VerifyDigest(signatureHeader.NextHeaderCRC, mainHeader, 0, (uint)signatureHeader.NextHeaderSize)) // return ZipReturn.Zip64EndOfCentralDirError; if (signatureHeader.NextHeaderSize != 0) { _zipFs.Seek(_baseOffset + (long)signatureHeader.NextHeaderOffset, SeekOrigin.Begin); ZipReturn zr = Header.ReadHeaderOrPackedHeader(_zipFs, _baseOffset, out _header); if (zr != ZipReturn.ZipGood) { return(zr); } } _zipFs.Seek(_baseOffset + (long)(signatureHeader.NextHeaderOffset + signatureHeader.NextHeaderSize), SeekOrigin.Begin); ZipStatus = ZipStatus.None; ZipStatus |= IsRomVault7Z() ? ZipStatus.TrrntZip : ZipStatus.None; ZipStatus |= Istorrent7Z() ? ZipStatus.Trrnt7Zip : ZipStatus.None; PopulateLocalFiles(out _localFiles); return(ZipReturn.ZipGood); } catch { ZipFileClose(); return(ZipReturn.ZipErrorReadingFile); } }
// not finalized yet, so do not use private void WriteRomVault7Zip(BinaryWriter bw, ulong headerPos, ulong headerLength, uint headerCRC) { const string sig = "RomVault7Z01"; byte[] RV7Zid = Util.Enc.GetBytes(sig); // RomVault 7Zip torrent header // 12 bytes : RomVault7Zip // 4 bytes : HeaderCRC // 8 bytes : HeaderPos // 8 bytes : HeaderLength bw.Write(RV7Zid); bw.Write(headerCRC); bw.Write(headerPos); bw.Write(headerLength); ZipStatus = ZipStatus.TrrntZip; }
public ZipReturn ZipFileOpen(string newFilename, long timestamp, bool readHeaders) { ZipFileClose(); _pZipStatus = ZipStatus.None; _zip64 = false; _centerDirStart = 0; _centerDirSize = 0; _zipFileInfo = null; try { if (!IO.File.Exists(newFilename)) { ZipFileClose(); return ZipReturn.ZipErrorFileNotFound; } _zipFileInfo = new IO.FileInfo(newFilename); if (_zipFileInfo.LastWriteTime != timestamp) { ZipFileClose(); return ZipReturn.ZipErrorTimeStamp; } int errorCode = IO.FileStream.OpenFileRead(newFilename, out _zipFs); if (errorCode != 0) { ZipFileClose(); if (errorCode == 32) return ZipReturn.ZipFileLocked; return ZipReturn.ZipErrorOpeningFile; } } catch (PathTooLongException) { ZipFileClose(); return ZipReturn.ZipFileNameToLong; } catch (IOException) { ZipFileClose(); return ZipReturn.ZipErrorOpeningFile; } ZipOpen = ZipOpenType.OpenRead; if (!readHeaders) return ZipReturn.ZipGood; try { ZipReturn zRet = FindEndOfCentralDirSignature(); if (zRet != ZipReturn.ZipGood) { ZipFileClose(); return zRet; } long endOfCentralDir = _zipFs.Position; zRet = EndOfCentralDirRead(); if (zRet != ZipReturn.ZipGood) { ZipFileClose(); return zRet; } // check if this is a ZIP64 zip and if it is read the Zip64 End Of Central Dir Info if (_centerDirStart == 0xffffffff || _centerDirSize == 0xffffffff || _localFilesCount == 0xffff) { _zip64 = true; _zipFs.Position = endOfCentralDir - 20; zRet = Zip64EndOfCentralDirectoryLocatorRead(); if (zRet != ZipReturn.ZipGood) { ZipFileClose(); return zRet; } _zipFs.Position = (long)_endOfCenterDir64; zRet = Zip64EndOfCentralDirRead(); if (zRet != ZipReturn.ZipGood) { ZipFileClose(); return zRet; } } bool trrntzip = false; // check if the ZIP has a valid TorrentZip file comment if (_fileComment.Length == 22) { if (GetString(_fileComment).Substring(0, 14) == "TORRENTZIPPED-") { CrcCalculatorStream crcCs = new CrcCalculatorStream(_zipFs, true); byte[] buffer = new byte[_centerDirSize]; _zipFs.Position = (long)_centerDirStart; crcCs.Read(buffer, 0, (int)_centerDirSize); crcCs.Flush(); crcCs.Close(); uint r = (uint)crcCs.Crc; crcCs.Dispose(); string tcrc = GetString(_fileComment).Substring(14, 8); string zcrc = r.ToString("X8"); if (String.Compare(tcrc, zcrc, StringComparison.Ordinal) == 0) trrntzip = true; } } // now read the central directory _zipFs.Position = (long)_centerDirStart; _localFiles.Clear(); _localFiles.Capacity = (int)_localFilesCount; for (int i = 0; i < _localFilesCount; i++) { LocalFile lc = new LocalFile(_zipFs); zRet = lc.CenteralDirectoryRead(); if (zRet != ZipReturn.ZipGood) { ZipFileClose(); return zRet; } _zip64 |= lc.Zip64; _localFiles.Add(lc); } for (int i = 0; i < _localFilesCount; i++) { zRet = _localFiles[i].LocalFileHeaderRead(); if (zRet != ZipReturn.ZipGood) { ZipFileClose(); return zRet; } trrntzip &= _localFiles[i].TrrntZip; } // check trrntzip file order if (trrntzip) for (int i = 0; i < _localFilesCount - 1; i++) { if (TrrntZipStringCompare(_localFiles[i].FileName, _localFiles[i + 1].FileName) < 0) continue; trrntzip = false; break; } // check trrntzip directories if (trrntzip) for (int i = 0; i < _localFilesCount - 1; i++) { // see if we found a directory string filename0 = _localFiles[i].FileName; if (filename0.Substring(filename0.Length - 1, 1) != "/") continue; // see if the next file is in that directory string filename1 = _localFiles[i + 1].FileName; if (filename1.Length <= filename0.Length) continue; if (TrrntZipStringCompare(filename0, filename1.Substring(0, filename0.Length)) != 0) continue; // if we found a file in the directory then we do not need the directory entry trrntzip = false; break; } if (trrntzip) _pZipStatus |= ZipStatus.TrrntZip; return ZipReturn.ZipGood; } catch { ZipFileClose(); return ZipReturn.ZipErrorReadingFile; } }
/// <summary> /// Close the file that the stream refers to /// </summary> public void Close() { // If the stream is already closed, then just return if (_zipOpen == ZipOpenType.Closed) { return; } // If the stream is opened for read, close it if (_zipOpen == ZipOpenType.OpenRead) { Dispose(); _zipOpen = ZipOpenType.Closed; return; } // Now, the only other choice is open for writing so we check everything is correct _zip64 = false; bool torrentZip = true; // Check the central directory _centerDirStart = (ulong)_zipstream.Position; if (_centerDirStart >= 0xffffffff) { _zip64 = true; } // Now loop through and add all of the central directory entries foreach (ZipFileEntry zfe in _entries) { zfe.WriteCentralDirectory(_zipstream); _zip64 |= zfe.Zip64; torrentZip &= zfe.TorrentZip; } _centerDirSize = (ulong)_zipstream.Position - _centerDirStart; // Then get the central directory hash OptimizedCRC ocrc = new OptimizedCRC(); byte[] buffer = new byte[_centerDirSize]; long currentPosition = _zipstream.Position; _zipstream.Position = (long)_centerDirStart; // Then read in the central directory and hash BinaryReader br = new BinaryReader(_zipstream); buffer = br.ReadBytes((int)_centerDirSize); ocrc.Update(buffer, 0, (int)_centerDirSize); string calculatedCrc = ocrc.Value.ToString("X8"); // Finally get back to the original position _zipstream.Position = currentPosition; // Now set more of the information _fileComment = (torrentZip ? Encoding.ASCII.GetBytes(("TORRENTZIPPED-" + calculatedCrc).ToCharArray()) : new byte[0]); _zipStatus = (torrentZip ? ZipStatus.TorrentZip : ZipStatus.None); // If we have a Zip64 archive, write the correct information if (_zip64) { _endOfCenterDir64 = (ulong)_zipstream.Position; WriteZip64EndOfCentralDir(); WriteZip64EndOfCentralDirectoryLocator(); } // Now write out the end of the central directory WriteEndOfCentralDir(); // Finally, close and dispose of the stream _zipstream.SetLength(_zipstream.Position); _zipstream.Flush(); _zipstream.Close(); _zipstream.Dispose(); // Get the new file information _zipFileInfo = new FileInfo(_zipFileInfo.FullName); // And set the stream to closed _zipOpen = ZipOpenType.Closed; }
public ZipReturn ZipFileOpen(string filename, long timestamp, bool readHeaders) { Debug.WriteLine(filename); #region open file stream try { if (!IO.File.Exists(filename)) { ZipFileClose(); return(ZipReturn.ZipErrorFileNotFound); } _zipFileInfo = new IO.FileInfo(filename); if (timestamp != -1 && _zipFileInfo.LastWriteTime != timestamp) { ZipFileClose(); return(ZipReturn.ZipErrorTimeStamp); } int errorCode = IO.FileStream.OpenFileRead(filename, out _zipFs); if (errorCode != 0) { ZipFileClose(); return(ZipReturn.ZipErrorOpeningFile); } } catch (PathTooLongException) { ZipFileClose(); return(ZipReturn.ZipFileNameToLong); } catch (IOException) { ZipFileClose(); return(ZipReturn.ZipErrorOpeningFile); } #endregion _zipOpen = ZipOpenType.OpenRead; _pZipStatus = ZipStatus.None; try { SignatureHeader signatureHeader = new SignatureHeader(); if (!signatureHeader.Read(new BinaryReader(_zipFs))) { return(ZipReturn.ZipSignatureError); } _baseOffset = _zipFs.Position; //_zipFs.Seek(_baseOffset + (long)signatureHeader.NextHeaderOffset, SeekOrigin.Begin); //byte[] mainHeader = new byte[signatureHeader.NextHeaderSize]; //_zipFs.Read(mainHeader, 0, (int)signatureHeader.NextHeaderSize); //if (!CRC.VerifyDigest(signatureHeader.NextHeaderCRC, mainHeader, 0, (uint)signatureHeader.NextHeaderSize)) // return ZipReturn.Zip64EndOfCentralDirError; _zipFs.Seek(_baseOffset + (long)signatureHeader.NextHeaderOffset, SeekOrigin.Begin); ZipReturn zr = Header.ReadHeaderOrPackedHeader(_zipFs, _baseOffset, out _header); if (zr != ZipReturn.ZipGood) { return(zr); } _zipFs.Seek(_baseOffset + (long)(signatureHeader.NextHeaderOffset + signatureHeader.NextHeaderSize), SeekOrigin.Begin); _pZipStatus = ZipStatus.None; //_pZipStatus = IsRomVault7Z() ? ZipStatus.TrrntZip : ZipStatus.None; //_pZipStatus = Istorrent7Z() ? ZipStatus.TrrntZip : ZipStatus.None; PopulateLocalFiles(out _localFiles); return(ZipReturn.ZipGood); } catch { ZipFileClose(); return(ZipReturn.ZipErrorReadingFile); } }
public override void Read(BinaryReader br, List<RvDat> parentDirDats) { base.Read(br, parentDirDats); bool foundTree = br.ReadBoolean(); if (foundTree) { Tree = new RvTreeRow(); Tree.Read(br); } else Tree = null; bool foundGame = br.ReadBoolean(); if (foundGame) { Game = new RvGame(); Game.Read(br); } else Game = null; int count = br.ReadInt32(); _dirDats.Clear(); for (int i = 0; i < count; i++) { RvDat dat = new RvDat { DatIndex = i }; dat.Read(br); _dirDats.Add(dat); string datname = TreeFullName + @"\" + dat.GetData(RvDat.DatData.DatName); if (datname.Length >= 9 && datname.Substring(0, 9) == @"ROMVault\") datname = datname.Substring(9); DB.Bgw.ReportProgress(0, new bgwText("Loading: " + datname)); DB.Bgw.ReportProgress((int)br.BaseStream.Position); } if (_dirDats.Count > 0) parentDirDats = _dirDats; count = br.ReadInt32(); _children.Clear(); for (int i = 0; i < count; i++) { RvBase tChild = DBTypeGet.GetRvType((FileType)br.ReadByte()); tChild.Parent = this; tChild.Read(br, parentDirDats); _children.Add(tChild); } if (DBTypeGet.isCompressedDir(FileType)) ZipStatus = (ZipStatus)br.ReadByte(); }
public override EFile FileRemove() { ZipStatus = ZipStatus.None; return base.FileRemove(); }
private ZipReturn EndOfCentralDirRead() { BinaryReader zipBr = new BinaryReader(_zipFs); uint thisSignature = zipBr.ReadUInt32(); if (thisSignature != EndOfCentralDirSignature) return ZipReturn.ZipEndOfCentralDirectoryError; ushort tushort = zipBr.ReadUInt16(); // NumberOfThisDisk if (tushort != 0) return ZipReturn.ZipEndOfCentralDirectoryError; tushort = zipBr.ReadUInt16(); // NumberOfThisDiskCenterDir if (tushort != 0) return ZipReturn.ZipEndOfCentralDirectoryError; _localFilesCount = zipBr.ReadUInt16(); // TotalNumberOfEnteriesDisk tushort = zipBr.ReadUInt16(); // TotalNumber of enteries in the central directory if (tushort != _localFilesCount) return ZipReturn.ZipEndOfCentralDirectoryError; _centerDirSize = zipBr.ReadUInt32(); // SizeOfCenteralDir _centerDirStart = zipBr.ReadUInt32(); // Offset ushort zipFileCommentLength = zipBr.ReadUInt16(); _fileComment = zipBr.ReadBytes(zipFileCommentLength); if (_zipFs.Position != _zipFs.Length) _pZipStatus |= ZipStatus.ExtraData; return ZipReturn.ZipGood; }
/// <summary> /// Open a new file as an archive /// </summary> /// <param name="filename">Name of the new file to open</param> /// <param name="timestamp">Timestamp the file should have</param> /// <param name="readHeaders">True if file headers should be read, false otherwise</param> /// <returns>Status of the underlying stream</returns> public ZipReturn Open(string filename, long timestamp, bool readHeaders) { // If a stream already exists, close it Close(); // Now, reset the archive information _zipStatus = ZipStatus.None; _zip64 = false; _centerDirStart = 0; _centerDirSize = 0; _zipFileInfo = null; // Then, attempt to open the file and get information from it try { // If the input file doesn't exist, close the stream and return if (!File.Exists(filename)) { Close(); return(ZipReturn.ZipErrorFileNotFound); } // Get the fileinfo object _zipFileInfo = new FileInfo(filename); // If the timestamps don't match, close the stream and return if (_zipFileInfo.LastWriteTime.Ticks != timestamp) { Close(); return(ZipReturn.ZipErrorTimeStamp); } // Now try to open the file for reading _zipstream = Utilities.TryOpenRead(filename); int read = _zipstream.Read(new byte[1], 0, 1); if (read != 1) { Close(); return(ZipReturn.ZipErrorOpeningFile); } _zipstream.Position = 0; } catch (PathTooLongException) { Close(); return(ZipReturn.ZipFileNameToLong); } catch (IOException) { Close(); return(ZipReturn.ZipErrorOpeningFile); } // If we succeeded, set the flag for read _zipOpen = ZipOpenType.OpenRead; // If we're not reading the headers, return if (!readHeaders) { return(ZipReturn.ZipGood); } //Otherwise, we want to get all of the archive information try { // First, try to get the end of the central directory ZipReturn zr = FindEndOfCentralDirSignature(); if (zr != ZipReturn.ZipGood) { Close(); return(zr); } // Now read the end of the central directory long eocd = _zipstream.Position; zr = ReadEndOfCentralDir(); if (zr != ZipReturn.ZipGood) { Close(); return(zr); } // If we have any indicators of Zip64, check for the Zip64 EOCD if (_centerDirStart == 0xffffffff || _centerDirSize == 0xffffffff || _entriesCount == 0xffff) { _zip64 = true; // Check for the Zip64 EOCD locator _zipstream.Position = eocd - 20; zr = ReadZip64EndOfCentralDirectoryLocator(); if (zr != ZipReturn.ZipGood) { Close(); return(zr); } // If it was found, read the Zip64 EOCD _zipstream.Position = (long)_endOfCenterDir64; zr = ReadZip64EndOfCentralDir(); if (zr != ZipReturn.ZipGood) { Close(); return(zr); } } // Now that we have the rest of the information, check for TorrentZip bool torrentZip = false; if (_fileComment.Length == 22) { if (Encoding.ASCII.GetString(_fileComment).Substring(0, 14) == "TORRENTZIPPED-") { // First get to the right part of the stream OptimizedCRC ocrc = new OptimizedCRC(); byte[] buffer = new byte[_centerDirSize]; _zipstream.Position = (long)_centerDirStart; // Then read in the central directory and hash BinaryReader br = new BinaryReader(_zipstream); buffer = br.ReadBytes((int)_centerDirSize); ocrc.Update(buffer, 0, (int)_centerDirSize); string calculatedCrc = ocrc.Value.ToString("X8"); // If the hashes match, then we have a torrentzip file string extractedCrc = Encoding.ASCII.GetString(_fileComment).Substring(14, 8); if (String.Equals(calculatedCrc, extractedCrc, StringComparison.Ordinal)) { torrentZip = true; } } } // With potential torrentzip out of the way, read the central directory _zipstream.Position = (long)_centerDirStart; // Remove any entries already listed in the archive _entries.Clear(); _entries.Capacity = (int)_entriesCount; // Now populate the entries from the central directory for (int i = 0; i < _entriesCount; i++) { ZipFileEntry zfe = new ZipFileEntry(_zipstream); zr = zfe.ReadCentralDirectory(); // If we get any errors, close and return if (zr != ZipReturn.ZipGood) { Close(); return(zr); } // If we have a Zip64 entry, make sure the archive is _zip64 |= zfe.Zip64; // Now add the entry to the archive _entries.Add(zfe); } // Now that the entries are populated, verify against the actual headers for (int i = 0; i < _entriesCount; i++) { zr = _entries[i].ReadHeader(); // If we get any errors, close and return if (zr != ZipReturn.ZipGood) { Close(); return(zr); } // If we have a torrentzipped entry, make sure the archive is torrentZip &= _entries[i].TorrentZip; } // If we have a torrentzipped file, check the file order if (torrentZip) { for (int i = 0; i < _entriesCount - 1; i++) { if (TorrentZipStringCompare(_entries[i].FileName, _entries[i + 1].FileName) < 0) { continue; } torrentZip = false; break; } } // Now check for torrentzipped directories if we still have a torrentZip file if (torrentZip) { for (int i = 0; i < _entriesCount - 1; i++) { // See if we found a directory string filename0 = _entries[i].FileName; if (filename0.Substring(filename0.Length - 1, 1) != "/") { continue; } // See if the next file is in that directory string filename1 = _entries[i + 1].FileName; if (filename1.Length <= filename0.Length) { continue; } if (TorrentZipStringCompare(filename0, filename1.Substring(0, filename0.Length)) == 0) { continue; } // If we found a file in the directory, then we don't need the directory entry torrentZip = false; break; } } // If we still have torrentzip, say the archive is too if (torrentZip) { _zipStatus |= ZipStatus.TorrentZip; } return(ZipReturn.ZipGood); } catch { Close(); return(ZipReturn.ZipErrorReadingFile); } }
public void ZipFileClose() { if (ZipOpen == ZipOpenType.Closed) { return; } if (ZipOpen == ZipOpenType.OpenRead) { if (_zipFs != null) { _zipFs.Close(); _zipFs.Dispose(); } ZipOpen = ZipOpenType.Closed; return; } _zip64 = false; bool lTrrntzip = true; _centerDirStart = (ulong)_zipFs.Position; if (_centerDirStart >= 0xffffffff) _zip64 = true; CrcCalculatorStream crcCs = new CrcCalculatorStream(_zipFs, true); foreach (LocalFile t in _localFiles) { t.CenteralDirectoryWrite(crcCs); _zip64 |= t.Zip64; lTrrntzip &= t.TrrntZip; } crcCs.Flush(); crcCs.Close(); _centerDirSize = (ulong)_zipFs.Position - _centerDirStart; _fileComment = lTrrntzip ? GetBytes("TORRENTZIPPED-" + crcCs.Crc.ToString("X8")) : new byte[0]; _pZipStatus = lTrrntzip ? ZipStatus.TrrntZip : ZipStatus.None; crcCs.Dispose(); if (_zip64) { _endOfCenterDir64 = (ulong)_zipFs.Position; Zip64EndOfCentralDirWrite(); Zip64EndOfCentralDirectoryLocatorWrite(); } EndOfCentralDirWrite(); _zipFs.SetLength(_zipFs.Position); _zipFs.Flush(); _zipFs.Close(); _zipFs.Dispose(); _zipFileInfo = new IO.FileInfo(_zipFileInfo.FullName); ZipOpen = ZipOpenType.Closed; }
public override void Read(BinaryReader br, List <RvDat> parentDirDats) { base.Read(br, parentDirDats); bool foundTree = br.ReadBoolean(); if (foundTree) { Tree = new RvTreeRow(); Tree.Read(br); } else { Tree = null; } bool foundGame = br.ReadBoolean(); if (foundGame) { Game = new RvGame(); Game.Read(br); } else { Game = null; } int count = br.ReadInt32(); _dirDats.Clear(); for (int i = 0; i < count; i++) { RvDat dat = new RvDat { DatIndex = i }; dat.Read(br); _dirDats.Add(dat); string datname = TreeFullName + @"\" + dat.GetData(RvDat.DatData.DatName); if ((datname.Length >= 9) && (datname.Substring(0, 9) == @"RomVault\")) { datname = datname.Substring(9); } DB.Bgw.ReportProgress(0, new bgwText("Loading: " + datname)); DB.Bgw.ReportProgress((int)br.BaseStream.Position); } if (_dirDats.Count > 0) { parentDirDats = _dirDats; } count = br.ReadInt32(); _children.Clear(); for (int i = 0; i < count; i++) { RvBase tChild = DBTypeGet.GetRvType((FileType)br.ReadByte()); tChild.Parent = this; tChild.Read(br, parentDirDats); _children.Add(tChild); } if (DBTypeGet.isCompressedDir(FileType)) { ZipStatus = (ZipStatus)br.ReadByte(); } }
public override EFile FileRemove() { ZipStatus = ZipStatus.None; return(base.FileRemove()); }