Example #1
0
        private void LoadTGATextures(ZipFile pk3)
        {
            foreach (Texture tex in Textures)
            {
                // The size of the new Texture2D object doesn't matter. It will be replaced (including its size) with the data from the texture that's getting pulled from the pk3 file.
                if (pk3.ContainsEntry(tex.Name + ".tga"))
                {
                    Texture2D readyTex = new Texture2D(4, 4);
                    ZipEntry  entry    = pk3[tex.Name + ".tga"];
                    using (CrcCalculatorStream stream = entry.OpenReader())
                    {
                        MemoryStream ms = new MemoryStream();
                        entry.Extract(ms);
                        readyTex = TGALoader.LoadTGA(ms);
                    }

                    readyTex.name       = tex.Name;
                    readyTex.filterMode = FilterMode.Trilinear;
                    readyTex.Compress(true);

                    if (readyTextures.ContainsKey(tex.Name))
                    {
                        Debug.Log("Updating texture with name " + tex.Name + ".tga");
                        readyTextures[tex.Name] = readyTex;
                    }
                    else
                    {
                        readyTextures.Add(tex.Name, readyTex);
                    }
                }
            }
        }
Example #2
0
        private void copyByteDataFromTemp(Game gameResult)
        {
            var fs = new FileStream(recordDir + "\\" + filename, FileMode.Create);
            var sw = new StreamWriter(fs);

            sw.WriteLine(gameResult.toJsonString());
            sw.Close();
            fs.Close();

            fs = new FileStream(recordDir + "\\" + filename, FileMode.Append);
            var zs = new ZipOutputStream(fs);

            using (var zip = ZipFile.Read(recordDir + "\\" + TEMP_FILENAME))
            {
                foreach (var e in zip)
                {
                    using (CrcCalculatorStream ccs = e.OpenReader())
                    {
                        using (var ms = new MemoryStream())
                        {
                            ccs.CopyTo(ms);
                            var bytes = ms.ToArray();
                            zs.PutNextEntry(e.FileName);
                            zs.Write(bytes, 0, bytes.Length);
                        }
                    }
                }
            }
            zs.Close();
            fs.Close();

            deleteTempFile();
        }
Example #3
0
        public byte[] GetContent()
        {
            byte[] buffer = new byte[e.UncompressedSize];

            using (CrcCalculatorStream s = e.OpenReader())
            {
                int n, totalBytesRead = 0;
                do
                {
                    n = s.Read(buffer, 0, buffer.Length);
                    totalBytesRead += n;
                }while (n > 0);

                if (s.Crc != e.Crc)
                {
                    throw new Exception(string.Format("The Zip Entry failed the CRC Check. (0x{0:X8}!=0x{1:X8})", s.Crc, e.Crc));
                }
                if (totalBytesRead != e.UncompressedSize)
                {
                    throw new Exception(string.Format("We read an unexpected number of bytes. ({0}!={1})", totalBytesRead, e.UncompressedSize));
                }
            }

            return(buffer);
        }
 protected void SetupCRCStream(IWebResponseData responseData, Stream responseStream, long contentLength)
 {
     CrcStream = null;
     if (responseData != null && uint.TryParse(responseData.GetHeaderValue("x-amz-crc32"), out uint result))
     {
         Crc32Result = (int)result;
         CrcStream   = new CrcCalculatorStream(responseStream, contentLength);
     }
 }
Example #5
0
 protected override void Dispose(bool disposing)
 {
     if (internalStream != null)
     {
         internalStream.Dispose();
         internalStream = null;
     }
     base.Dispose(disposing);
 }
Example #6
0
        public static string ReadText(ZipEntry entry)
        {
            CrcCalculatorStream stream = entry.OpenReader();
            StreamReader        reader = new StreamReader(stream);
            string text = reader.ReadToEnd();

            reader.Close();
            stream.Close();
            return(text);
        }
Example #7
0
 public byte[] GetData()
 {
     using (CrcCalculatorStream reader = ZipEntry.OpenReader())
     {
         byte[] data;
         data = new byte[ZipEntry.UncompressedSize];
         reader.Read(data, 0, (int)ZipEntry.UncompressedSize);
         return(data);
     }
 }
Example #8
0
        public BSPMap(string filename, bool loadFromPK3)
        {
            filename = Path.Combine("maps/", filename);

            // Look through all available .pk3 files to find the map.
            // The first map will be used, which doesn't match Q3 behavior, as it would use the last found map, but eh.
            if (loadFromPK3)
            {
                foreach (FileInfo info in new DirectoryInfo(Application.streamingAssetsPath).GetFiles())
                {
                    if (info.Name.EndsWith(".PK3") || info.Name.EndsWith(".pk3"))
                    {
                        using (ZipFile pk3 = ZipFile.Read(info.FullName))
                        {
                            if (pk3.ContainsEntry(filename))
                            {
                                ZipEntry entry = pk3[filename];
                                using (CrcCalculatorStream mapstream = pk3[filename].OpenReader())
                                {
                                    MemoryStream ms = new MemoryStream();
                                    entry.Extract(ms);
                                    BSP = new BinaryReader(ms);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                BSP = new BinaryReader(File.Open(filename, FileMode.Open));
            }


            // Read our header and lumps
            ReadHeader();
            ReadEntities();
            ReadTextures();
            ReadVertexes();
            ReadFaces();
            ReadMeshVerts();
            ReadLightmaps();

            // Comb through all of the available .pk3 files and load in any textures needed by the current map.
            // Textures in higher numbered .pk3 files will be used over ones in lower ones.
            foreach (FileInfo info in new DirectoryInfo(Application.streamingAssetsPath).GetFiles())
            {
                if (info.Name.EndsWith(".pk3") || info.Name.EndsWith(".PK3"))
                {
                    textureLump.PullInTextures(info.Name);
                }
            }

            BSP.Close();
        }
Example #9
0
        private static string ZipEntryRead(ZipEntry entry)
        {
            CrcCalculatorStream reader = entry.OpenReader();
            string content             = "";

            while (reader.Position < reader.Length)
            {
                content += (char)reader.ReadByte();
            }
            return(content);
        }
Example #10
0
 private byte[] GetDataFromZip(ZipEntry zipEntry)
 {
     byte[] array = new byte[zipEntry.UncompressedSize];
     using (CrcCalculatorStream crcCalculatorStream = zipEntry.OpenReader())
     {
         if (crcCalculatorStream.Read(array, 0, array.Length) != array.Length)
         {
             Heluo.Logger.LogError("Zip file size not equal !! " + zipEntry.FileName, "GetDataFromZip", "C:\\PathOfWuxia\\PathOfWuxia\\Assets\\Scripts\\Resource\\Provider\\ExternalResourceProvider.cs", 119);
         }
     }
     return(array);
 }
        protected void SetupCRCStream(NameValueCollection headers, Stream responseStream, long contentLength)
        {
            this.crcStream = null;

            UInt32 parsed;

            if (UInt32.TryParse(headers["x-amz-crc32"], out parsed))
            {
                this.crc32Result = (int)parsed;
                this.crcStream   = new CrcCalculatorStream(responseStream, contentLength);
            }
        }
Example #12
0
        public void ZipFileCloseFake(ulong fileOffset, out byte[] centralDir)
        {
            centralDir = null;
            if (ZipOpen != ZipOpenType.OpenFakeWrite)
            {
                return;
            }

            _zip64 = false;
            bool lTrrntzip = true;

            _zipFs = new MemoryStream();

            _centerDirStart = fileOffset;
            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;

            _fileComment = lTrrntzip ? ZipUtils.GetBytes("TORRENTZIPPED-" + crcCs.Crc.ToString("X8")) : new byte[0];
            ZipStatus    = lTrrntzip ? ZipStatus.TrrntZip : ZipStatus.None;

            crcCs.Dispose();

            if (_zip64)
            {
                _endOfCenterDir64 = fileOffset + (ulong)_zipFs.Position;
                Zip64EndOfCentralDirWrite();
                Zip64EndOfCentralDirectoryLocatorWrite();
            }
            EndOfCentralDirWrite();

            centralDir = ((MemoryStream)_zipFs).ToArray();
            _zipFs.Close();
            _zipFs.Dispose();
            ZipOpen = ZipOpenType.Closed;
        }
        private int Start(byte[] data, int offset, int length)
        {
            _workingMessage  = null;
            _amountBytesRead = 0;

            if (_runningChecksumStream != null)
            {
                _runningChecksumStream.Dispose();
            }

            _runningChecksumStream = new CrcCalculatorStream(new NullStream());
            _currentMessageLength  = 0;
            _state = DecoderState.ReadPrelude;
            return(0);
        }
Example #14
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            if (origin == SeekOrigin.Begin)
            {
                m_currentStream.Close();
                m_currentStream = m_entry.OpenReader();
            }

            for (int i = 0; i < offset; i++)
            {
                ReadByte();
            }

            return(Position);
        }
Example #15
0
        public async Task <MemoryStream> GetEntry(string name)
        {
            if (file.ContainsEntry(name))
            {
                ZipEntry entry = file[name];

                CrcCalculatorStream s = entry.OpenReader();
                byte[] bytes          = new byte[s.Length];
                int    i = await s.ReadAsync(bytes, 0, bytes.Length);

                MemoryStream m = new MemoryStream(bytes);
                return(m);
            }
            return(null);
        }
Example #16
0
        private bool OpenPart(PartialFile part)
        {
            if (!File.Exists(part.Filename))
            {
                return(false);
            }

            currentPart.Crc = (uint)internalStream.Crc;
            internalStream.Close();
            internalStream.Dispose();

            internalStream = new CrcCalculatorStream(new FileStream(part.Filename, mode, access), false);
            currentPart    = part;
            positionInPart = 0;
            return(true);
        }
Example #17
0
 /// <summary>
 /// ゲームのリプレイデータをロードする
 /// </summary>
 public void loadPlayData()
 {
     using (var zip = ZipFile.Read(recordDir + "\\" + filename))
     {
         foreach (var e in zip)
         {
             using (CrcCalculatorStream ccs = e.OpenReader())
             {
                 using (var ms = new MemoryStream())
                 {
                     ccs.CopyTo(ms);
                     buildReplay(e.FileName, ms.ToArray());
                 }
             }
         }
     }
 }
Example #18
0
        /// <summary> Get all activity samples for a gt3x file. </summary>
        /// <returns>Activity samples.</returns>
        public IEnumerable <AccelerationSample> ActivityEnumerator()
        {
            if (TypeOfDevice == DeviceType.Unknown)
            {
                yield break;
            }

            //zipdotnet let's us access the activity.bin file without extracting it to the filesystem.
            using (ZipFile zip = ZipFile.Read(FileName))
            {
                ZipEntry activity = zip["activity.bin"];
                using (CrcCalculatorStream activityStream = activity.OpenReader())
                    foreach (var sample in ParseAcceleration(activityStream))
                    {
                        yield return(sample);
                    }
            }
        }
Example #19
0
        /// <summary> Get all lux samples for a gt3x file. </summary>
        /// <returns>Lux samples.</returns>
        public IEnumerable <LuxSample> LuxEnumerator()
        {
            if (TypeOfDevice == DeviceType.Unknown)
            {
                yield break;
            }

            //zipdotnet let's us access the activity.bin file without extracting it to the filesystem.
            using (ZipFile zip = ZipFile.Read(FileName))
            {
                ZipEntry luxZip = zip["lux.bin"];
                using (CrcCalculatorStream luxStream = luxZip.OpenReader())
                    foreach (var lux in ParseLux(luxStream))
                    {
                        yield return(lux);
                    }
            }
        }
Example #20
0
 private void _FinishCurrentEntry()
 {
     if (this._currentEntry != null)
     {
         if (this._needToWriteEntryHeader)
         {
             this._InitiateCurrentEntry(true);
         }
         this._currentEntry.FinishOutputStream(this._outputStream, this._outputCounter, this._encryptor, this._deflater, this._entryOutputStream);
         this._currentEntry.PostProcessOutput(this._outputStream);
         if (this._currentEntry.OutputUsedZip64.HasValue)
         {
             this._anyEntriesUsedZip64 |= this._currentEntry.OutputUsedZip64.Value;
         }
         this._outputCounter     = null;
         this._encryptor         = (this._deflater = null);
         this._entryOutputStream = null;
     }
 }
Example #21
0
        private void zipFileCloseWrite()
        {
            _zip64 = false;
            bool lTrrntzip = true;

            _centerDirStart = (ulong)_zipFs.Position;

            using (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 ? ZipUtils.GetBytes("TORRENTZIPPED-" + crcCs.Crc.ToString("X8")) : new byte[0];
                ZipStatus    = lTrrntzip ? ZipStatus.TrrntZip : ZipStatus.None;
            }
            _zip64 |= _centerDirStart >= 0xffffffff;
            _zip64 |= _centerDirSize >= 0xffffffff;
            _zip64 |= _localFiles.Count >= 0xffff;

            if (_zip64)
            {
                _endOfCenterDir64 = (ulong)_zipFs.Position;
                Zip64EndOfCentralDirWrite();
                Zip64EndOfCentralDirectoryLocatorWrite();
            }
            EndOfCentralDirWrite();

            _zipFs.SetLength(_zipFs.Position);
            _zipFs.Flush();
            _zipFs.Close();
            _zipFs.Dispose();
            _zipFileInfo = new FileInfo(_zipFileInfo.FullName);
            ZipOpen      = ZipOpenType.Closed;
        }
Example #22
0
        private void Initialize()
        {
            Parts = new List <PartialFile>();

            // Check if file .z01 exists
            if (isReading)
            {
                FindParts();
                currentPart = Parts.First();
                string path = currentPart.Filename;
                isMultipart    = amountOfParts > 1;
                internalStream = new CrcCalculatorStream(new FileStream(path, mode, access), false);
            }
            else
            {
                isMultipart    = Interaction.Instance.MultiPart;
                internalStream = CreatePart(1);
            }
        }
Example #23
0
        bool LoadMod(string path)
        {
            try
            {
                ZipFile zf = ZipFile.Read(path);
                string  modInfoJsonText = "";
                Image   modIcon         = null;

                if (zf.ContainsEntry("modinfo.json"))
                {
                    modInfoJsonText = Zip.ReadText(zf["modinfo.json"]);
                }

                if (zf.ContainsEntry("modicon.png"))
                {
                    CrcCalculatorStream crc = zf["modicon.png"].OpenReader();
                    modIcon = Image.FromStream(crc);
                    crc.Close();
                }
                zf.Dispose();

                ModInfo modInfo = new ModInfo(path, modInfoJsonText, modIcon);

                if (!ModIDs.Contains(modInfo.ToString()))
                {
                    Mods.Add(modInfo);
                    ModIDs.Add(modInfo.ToString());
                    LF_ModList();
                    return(true);
                }
                else
                {
                    this.latestException = new Exception("This mod is already loaded. If you want to update it, remove the old version first.");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                this.latestException = ex;
                return(false);
            }
        }
        private static void WriteChunk(Stream outputStream, string type, byte[] data)
        {
            var length = data != null ? data.Length : 0;

            outputStream.Write(CreateChunkFromInt(length), 0, 4);

            using (var crc32 = new CrcCalculatorStream(outputStream, true))
            {
                crc32.Write(CreateChunkFromString(type), 0, 4);

                if (data != null)
                {
                    crc32.Write(data, 0, length);
                }

                crc32.Flush();

                outputStream.Write(CreateChunkFromUint((uint)crc32.Crc), 0, 4);
            }
        }
Example #25
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (!isMultipart || partSize > positionInPart + (count - offset))
            {
                // Just write
                internalStream.Write(buffer, offset, count);
                positionInPart += count;
                _position      += count;
                return;
            }

            // Else, write what we can
            int sizeLeft = (int)(partSize - positionInPart);

            internalStream.Write(buffer, offset, sizeLeft);
            positionInPart += sizeLeft;
            _position      += sizeLeft;

            internalStream = CreatePart(++amountOfParts);
            Write(buffer, offset + sizeLeft, count - sizeLeft);
        }
Example #26
0
 private int _ExtractOne(Stream output)
 {
     lock (_streamLock)
     {
         Stream input = this.ArchiveStream;
         input.Seek(this.__FileDataPosition, SeekOrigin.Begin);
         byte[] bytes      = new byte[0x2200];
         int    LeftToRead = (this.CompressionMethod == 8) ? this.UncompressedSize : this._CompressedFileDataSize;
         Stream input3     = (this.CompressionMethod == 8) ? new DeflateStream(input, CompressionMode.Decompress, true) : input;
         using (CrcCalculatorStream s1 = new CrcCalculatorStream(input3))
         {
             while (LeftToRead > 0)
             {
                 int len = (LeftToRead > bytes.Length) ? bytes.Length : LeftToRead;
                 int n   = s1.Read(bytes, 0, len);
                 this._CheckRead(n);
                 output.Write(bytes, 0, n);
                 LeftToRead -= n;
             }
             return(s1.Crc32);
         }
     }
 }
Example #27
0
        private void sortID_TextChanged(object sender, EventArgs e)
        {
            int spellId;

            if (int.TryParse(sortID.Text, out spellId))
            {
                string zippath = "clientVersion\\" + Form1.clientVersion + ".zip";

                using (ZipFile zip = ZipFile.Read(zippath))
                {
                    bool found = false;
                    foreach (ZipEntry e1 in zip)
                    {
                        if (e1.FileName == spellId + ".png")
                        {
                            CrcCalculatorStream reader    = e1.OpenReader();
                            MemoryStream        memstream = new MemoryStream();
                            reader.CopyTo(memstream);
                            byte[] bytes = memstream.ToArray();
                            SpellPicture.Image = Image.FromStream(memstream);
                            found = true;
                            SpellPicture.Visible = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        SpellPicture.Visible = false;
                    }
                }
            }
            else
            {
                SpellPicture.Image = null;
            }
        }
Example #28
0
        public static TrrntZipStatus ReZipFiles(List <ZippedFile> zippedFiles, ICompress originalZipFile, byte[] buffer, StatusCallback StatusCallBack, LogCallback LogCallback, int ThreadID)
        {
            int bufferSize = buffer.Length;

            string filename    = originalZipFile.ZipFilename;
            string tmpFilename = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(filename) + ".tmp";

            string outfilename = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(filename) + ".zip";

            if (Path.GetExtension(filename) == ".7z")
            {
                if (File.Exists(outfilename))
                {
                    LogCallback?.Invoke(ThreadID, "Error output .zip file already exists");
                    return(TrrntZipStatus.RepeatFilesFound);
                }
            }

            if (IO.File.Exists(tmpFilename))
            {
                IO.File.Delete(tmpFilename);
            }

            ICompress zipFileOut = new ZipFile();

            try
            {
                zipFileOut.ZipFileCreate(tmpFilename);

                // by now the zippedFiles have been sorted so just loop over them
                for (int i = 0; i < zippedFiles.Count; i++)
                {
                    StatusCallBack?.Invoke(ThreadID, (int)((double)(i + 1) / (zippedFiles.Count) * 100));

                    ZippedFile t = zippedFiles[i];

                    if (Program.VerboseLogging)
                    {
                        LogCallback?.Invoke(ThreadID, $"{t.Size,15}  {t.StringCRC}   {t.Name}");
                    }

                    Stream readStream = null;
                    ulong  streamSize = 0;
                    ushort compMethod;

                    ZipFile   z       = originalZipFile as ZipFile;
                    ZipReturn zrInput = ZipReturn.ZipUntested;
                    if (z != null)
                    {
                        zrInput = z.ZipFileOpenReadStream(t.Index, false, out readStream, out streamSize, out compMethod);
                    }
                    SevenZ z7 = originalZipFile as SevenZ;
                    if (z7 != null)
                    {
                        zrInput = z7.ZipFileOpenReadStream(t.Index, out readStream, out streamSize);
                    }

                    Stream    writeStream;
                    ZipReturn zrOutput = zipFileOut.ZipFileOpenWriteStream(false, true, t.Name, streamSize, 8, out writeStream);

                    if (zrInput != ZipReturn.ZipGood || zrOutput != ZipReturn.ZipGood)
                    {
                        //Error writing local File.
                        zipFileOut.ZipFileClose();
                        originalZipFile.ZipFileClose();
                        IO.File.Delete(tmpFilename);
                        return(TrrntZipStatus.CorruptZip);
                    }

                    Stream crcCs = new CrcCalculatorStream(readStream, true);

                    ulong sizetogo = streamSize;
                    while (sizetogo > 0)
                    {
                        int sizenow = sizetogo > (ulong)bufferSize ? bufferSize : (int)sizetogo;

                        crcCs.Read(buffer, 0, sizenow);
                        writeStream.Write(buffer, 0, sizenow);
                        sizetogo = sizetogo - (ulong)sizenow;
                    }
                    writeStream.Flush();

                    crcCs.Close();
                    if (z != null)
                    {
                        originalZipFile.ZipFileCloseReadStream();
                    }

                    uint crc = (uint)((CrcCalculatorStream)crcCs).Crc;

                    if (crc != t.CRC)
                    {
                        return(TrrntZipStatus.CorruptZip);
                    }

                    zipFileOut.ZipFileCloseWriteStream(t.ByteCRC);
                }

                zipFileOut.ZipFileClose();
                originalZipFile.ZipFileClose();
                IO.File.Delete(filename);
                IO.File.Move(tmpFilename, outfilename);

                return(TrrntZipStatus.ValidTrrntzip);
            }
            catch (Exception)
            {
                zipFileOut?.ZipFileCloseFailed();
                originalZipFile?.ZipFileClose();
                return(TrrntZipStatus.CorruptZip);
            }
        }
Example #29
0
        // These two data types are supported in DotNetZip, but only if .NET Framework is targeted.
        //private SelfExtractorFlavor _selfExtractorFlavor;
        //private SelfExtractorSaveOptions _selfExtractorSaveOptions;

        public void CallAll()
        {
            // These two apis are supported in DotNetZip, but only if .NET Framework is targeted.
            //_zipFile.SaveSelfExtractor(_string, _selfExtractorFlavor);
            //_zipFile.SaveSelfExtractor(_string, _selfExtractorSaveOptions);

            //Project: Ionic.Zip
            _bZip2InputStream.Close();
            _bZip2InputStream.Flush();
            _int  = _bZip2InputStream.Read(_bytes, _int, _int);
            _int  = _bZip2InputStream.ReadByte();
            _long = _bZip2InputStream.Seek(_long, _seekOrigin);
            _bZip2InputStream.SetLength(_long);
            _bZip2InputStream.Write(_bytes, _int, _int);
            _bZip2OutputStream.Close();
            _bZip2OutputStream.Flush();
            _int  = _bZip2OutputStream.Read(_bytes, _int, _int);
            _long = _bZip2OutputStream.Seek(_long, _seekOrigin);
            _bZip2OutputStream.SetLength(_long);
            _bZip2OutputStream.Write(_bytes, _int, _int);
            _parallelBZip2OutputStream.Close();
            _parallelBZip2OutputStream.Flush();
            _int  = _parallelBZip2OutputStream.Read(_bytes, _int, _int);
            _long = _parallelBZip2OutputStream.Seek(_long, _seekOrigin);
            _parallelBZip2OutputStream.SetLength(_long);
            _parallelBZip2OutputStream.Write(_bytes, _int, _int);
            _crc32.Combine(_int, _int);
            _int = _crc32.ComputeCrc32(_int, _byte);
            _int = _crc32.GetCrc32(_stream);
            _int = _crc32.GetCrc32AndCopy(_stream, _stream);
            _crc32.Reset();
            _crc32.SlurpBlock(_bytes, _int, _int);
            _crc32.UpdateCRC(_byte);
            _crc32.UpdateCRC(_byte, _int);
            _crcCalculatorStream.Close();
            _crcCalculatorStream.Flush();
            _int  = _crcCalculatorStream.Read(_bytes, _int, _int);
            _long = _crcCalculatorStream.Seek(_long, _seekOrigin);
            _crcCalculatorStream.SetLength(_long);
            _crcCalculatorStream.Write(_bytes, _int, _int);
            _zipEntriesCollection = _fileSelector.SelectEntries(_zipFile);
            _zipEntriesCollection = _fileSelector.SelectEntries(_zipFile, _string);
            _stringsCollection    = _fileSelector.SelectFiles(_string);
            _stringsReadOnly      = _fileSelector.SelectFiles(_string, _bool);
            _string = _fileSelector.ToString();
            _bool   = _comHelper.CheckZip(_string);
            _bool   = _comHelper.CheckZipPassword(_string, _string);
            _comHelper.FixZipDirectory(_string);
            _string = _comHelper.GetZipLibraryVersion();
            _bool   = _comHelper.IsZipFile(_string);
            _bool   = _comHelper.IsZipFileWithExtract(_string);
            _countingStream.Adjust(_long);
            _countingStream.Flush();
            _int  = _countingStream.Read(_bytes, _int, _int);
            _long = _countingStream.Seek(_long, _seekOrigin);
            _countingStream.SetLength(_long);
            _countingStream.Write(_bytes, _int, _int);
            _zipEntry.Extract();
            _zipEntry.Extract(_extractExistingFileAction);
            _zipEntry.Extract(_string);
            _zipEntry.Extract(_string, _extractExistingFileAction);
            _zipEntry.Extract(_stream);
            _zipEntry.ExtractWithPassword(_extractExistingFileAction, _string);
            _zipEntry.ExtractWithPassword(_string);
            _zipEntry.ExtractWithPassword(_string, _extractExistingFileAction, _string);
            _zipEntry.ExtractWithPassword(_string, _string);
            _zipEntry.ExtractWithPassword(_stream, _string);
            _crcCalculatorStream = _zipEntry.OpenReader();
            _crcCalculatorStream = _zipEntry.OpenReader(_string);
            _zipEntry.SetEntryTimes(_datetime, _datetime, _datetime);
            _string   = _zipEntry.ToString();
            _zipEntry = _zipFile.AddDirectory(_string);
            _zipEntry = _zipFile.AddDirectory(_string, _string);
            _zipEntry = _zipFile.AddDirectoryByName(_string);
            _zipEntry = _zipFile.AddEntry(_string, _bytes);
            _zipEntry = _zipFile.AddEntry(_string, _openDelegate, _closeDelegate);
            _zipEntry = _zipFile.AddEntry(_string, _writeDelegate);
            _zipEntry = _zipFile.AddEntry(_string, _string);
            _zipEntry = _zipFile.AddEntry(_string, _string, _encoding);
            _zipEntry = _zipFile.AddEntry(_string, _stream);
            _zipEntry = _zipFile.AddFile(_string);
            _zipEntry = _zipFile.AddFile(_string, _string);
            _zipFile.AddFiles(_strings);
            _zipFile.AddFiles(_strings, _bool, _string);
            _zipFile.AddFiles(_strings, _string);
            _zipEntry = _zipFile.AddItem(_string);
            _zipEntry = _zipFile.AddItem(_string, _string);
            _zipFile.AddSelectedFiles(_string);
            _zipFile.AddSelectedFiles(_string, _bool);
            _zipFile.AddSelectedFiles(_string, _string);
            _zipFile.AddSelectedFiles(_string, _string, _bool);
            _zipFile.AddSelectedFiles(_string, _string, _string);
            _zipFile.AddSelectedFiles(_string, _string, _string, _bool);
            _bool = _zipFile.ContainsEntry(_string);
            _zipFile.Dispose();
            _zipFile.ExtractAll(_string);
            _zipFile.ExtractAll(_string, _extractExistingFileAction);
            _zipFile.ExtractSelectedEntries(_string);
            _zipFile.ExtractSelectedEntries(_string, _extractExistingFileAction);
            _zipFile.ExtractSelectedEntries(_string, _string);
            _zipFile.ExtractSelectedEntries(_string, _string, _string);
            _zipFile.ExtractSelectedEntries(_string, _string, _string, _extractExistingFileAction);
            _enumerator = _zipFile.GetNewEnum();
            _zipFile.Initialize(_string);
            _zipFile.RemoveEntries(_zipEntriesCollection);
            _zipFile.RemoveEntries(_stringsCollection);
            _zipFile.RemoveEntry(_zipEntry);
            _zipFile.RemoveEntry(_string);
            _int = _zipFile.RemoveSelectedEntries(_string);
            _int = _zipFile.RemoveSelectedEntries(_string, _string);
            _zipFile.Save();
            _zipFile.Save(_string);
            _zipFile.Save(_stream);
            _zipEntriesCollection = _zipFile.SelectEntries(_string);
            _zipEntriesCollection = _zipFile.SelectEntries(_string, _string);
            _string   = _zipFile.ToString();
            _zipEntry = _zipFile.UpdateDirectory(_string);
            _zipEntry = _zipFile.UpdateDirectory(_string, _string);
            _zipEntry = _zipFile.UpdateEntry(_string, _bytes);
            _zipEntry = _zipFile.UpdateEntry(_string, _openDelegate, _closeDelegate);
            _zipEntry = _zipFile.UpdateEntry(_string, _writeDelegate);
            _zipEntry = _zipFile.UpdateEntry(_string, _string);
            _zipEntry = _zipFile.UpdateEntry(_string, _string, _encoding);
            _zipEntry = _zipFile.UpdateEntry(_string, _stream);
            _zipEntry = _zipFile.UpdateFile(_string);
            _zipFile.UpdateFile(_string, _string);
            _zipFile.UpdateFiles(_strings);
            _zipFile.UpdateFiles(_strings, _string);
            _zipFile.UpdateItem(_string);
            _zipFile.UpdateItem(_string, _string);
            _zipFile.UpdateSelectedFiles(_string, _string, _string, _bool);
            _zipInputStream.Flush();
            _zipEntry = _zipInputStream.GetNextEntry();
            _int      = _zipInputStream.Read(_bytes, _int, _int);
            _long     = _zipInputStream.Seek(_long, _seekOrigin);
            _zipInputStream.SetLength(_long);
            _string = _zipInputStream.ToString();
            _zipInputStream.Write(_bytes, _int, _int);
            _bool = _zipOutputStream.ContainsEntry(_string);
            _zipOutputStream.Flush();
            _zipEntry = _zipOutputStream.PutNextEntry(_string);
            _int      = _zipOutputStream.Read(_bytes, _int, _int);
            _long     = _zipOutputStream.Seek(_long, _seekOrigin);
            _zipOutputStream.SetLength(_long);
            _string = _zipOutputStream.ToString();
            _zipOutputStream.Write(_bytes, _int, _int);
            _deflateStream.Flush();
            _int  = _deflateStream.Read(_bytes, _int, _int);
            _long = _deflateStream.Seek(_long, _seekOrigin);
            _deflateStream.SetLength(_long);
            _deflateStream.Write(_bytes, _int, _int);
            _gZipStream.Flush();
            _int  = _gZipStream.Read(_bytes, _int, _int);
            _long = _gZipStream.Seek(_long, _seekOrigin);
            _gZipStream.SetLength(_long);
            _gZipStream.Write(_bytes, _int, _int);
            _parallelDeflateOutputStream.Close();
            _parallelDeflateOutputStream.Flush();
            _int = _parallelDeflateOutputStream.Read(_bytes, _int, _int);
            _parallelDeflateOutputStream.Reset(_stream);
            _long = _parallelDeflateOutputStream.Seek(_long, _seekOrigin);
            _parallelDeflateOutputStream.SetLength(_long);
            _parallelDeflateOutputStream.Write(_bytes, _int, _int);

            // Static
            _bool = ZipFile.CheckZip(_string);
            _bool = ZipFile.CheckZip(_string, _bool, _textWriter);
            _bool = ZipFile.CheckZipPassword(_string, _string);
            ZipFile.FixZipDirectory(_string);
            _bool    = ZipFile.IsZipFile(_string);
            _bool    = ZipFile.IsZipFile(_string, _bool);
            _bool    = ZipFile.IsZipFile(_stream, _bool);
            _zipFile = ZipFile.Read(_string);
            _zipFile = ZipFile.Read(_string, _readOptions);
            _zipFile = ZipFile.Read(_stream);
            _zipFile = ZipFile.Read(_stream, _readOptions);
            _uint    = Adler.Adler32(_uint, _bytes, _int, _int);
            _bytes   = DeflateStream.CompressBuffer(_bytes);
            _bytes   = DeflateStream.CompressString(_string);
            _bytes   = DeflateStream.UncompressBuffer(_bytes);
            _string  = DeflateStream.UncompressString(_bytes);
            _bytes   = GZipStream.CompressBuffer(_bytes);
            _bytes   = GZipStream.CompressString(_string);
            _bytes   = GZipStream.UncompressBuffer(_bytes);
            _string  = GZipStream.UncompressString(_bytes);
            _bytes   = ZlibStream.CompressBuffer(_bytes);
            _bytes   = ZlibStream.CompressString(_string);
            _bytes   = ZlibStream.UncompressBuffer(_bytes);
            _string  = ZlibStream.UncompressString(_bytes);
        }
Example #30
0
        public override void ProcessFile(string fileName, object logControl)
        {
            // Open epud in Zip utility
            ZipFile _epub = new ZipFile(fileName);

            _epub.TempFileFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            //Get collection of *.opf file (should be only one)

            List <ZipEntry> _opfs = _epub.SelectEntries("*.opf", "OEBPS") as List <ZipEntry>;



            if (_opfs.Count > 0)
            {
                // Get first opf file
                ZipEntry _opf = _opfs[0];

                // Get opf file stream
                CrcCalculatorStream _t = _opf.OpenReader();

                // Create XmlDocument and load it with opf file content
                XmlDocument         _xdoc  = new XmlDocument();
                XmlNamespaceManager _nsMan = new XmlNamespaceManager(_xdoc.NameTable);
                _xdoc.Load(_t);
                _nsMan.AddNamespace("opf", "http://www.idpf.org/2007/opf");
                _nsMan.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");

                // Get book title node
                XmlNode _metadata = _xdoc.DocumentElement.SelectSingleNode("opf:metadata", _nsMan);
                // Replace children text with translited version
                foreach (XmlNode _metaDataNode in _metadata.ChildNodes)
                {
                    if (Program.EPUBSettings.GetConfigKey(_metaDataNode.LocalName, false).Value.ToUpper() == "TRUE")
                    {
                        _metaDataNode.InnerText = Transliterate(_metaDataNode.InnerText);
                    }
                }

                //Create MemoryStream for modified file
                MemoryStream _opfFile = new MemoryStream();

                //Write modified XmlDocument into MemoryStream
                XmlWriterSettings _xmSet = new XmlWriterSettings();
                _xmSet.Indent             = true;
                _xmSet.ConformanceLevel   = ConformanceLevel.Auto;
                _xmSet.OmitXmlDeclaration = false;

                XmlWriter _xwrite = XmlWriter.Create(_opfFile, _xmSet);
                _xdoc.Save(_xwrite);
                _opfFile.Flush();
                _opfFile.Position = 0;


                // Update opf file within epub archive
                _epub.UpdateEntry(_opf.FileName, _opfFile);
                // Save changes in epub
                _epub.Save();



                WriteLog(logControl, " - SUCCESS \n");
            }
        }