コード例 #1
0
        /// <summary>
        /// Remove an entry from the archive
        /// </summary>
        /// <param name="index">
        /// The index of the entry that is to be removed
        /// </param>
        private void DeleteEntryFromFile(int index)
        {
            long jump = XyzConstants.SuperHeaderSize;

            for (int i = 0; i < index; ++i)
            {
                jump += XyzConstants.FixedHeaderSize +
                        zipEntries[i].NameLength
                        //+zipEntries[i].CompressedSize
                ;
            }
            XyzEntry entry    = zipEntries[index];
            long     fileJump = XyzConstants.FixedHeaderSize +
                                entry.NameLength
                                //+entry.CompressedSize
            ;

            baseStream.Seek(jump + fileJump, SeekOrigin.Begin);
            long length = baseStream.Length - fileJump - jump;

            byte[] b = new byte[length];
            baseStream.Read(b, 0, (int)length);
            baseStream.Seek(jump, SeekOrigin.Begin);
            baseStream.Write(b, 0, (int)length);
            baseStream.SetLength(baseStream.Length - fileJump);
            //CompressionForm.statusMessage = "Removed successfully";
        }
コード例 #2
0
 /// <summary>
 /// Remove an entry from the archive
 /// </summary>
 /// <param name="jump">
 /// The offset of the file to be removed
 /// </param>
 public void Remove(long jump, XyzEntry entry)
 {
     try
     {
         //long fileJump = XyzConstants.FixedHeaderSize +
         //        entry.NameLength
         //        +entry.CompressedLength;
         //baseStream.Seek( jump + fileJump, SeekOrigin.Begin );
         //long length = baseStream.Length - fileJump - jump;
         //byte[] b = new byte[length];
         //baseStream.Read( b, 0, (int)length );
         //baseStream.Seek( jump, SeekOrigin.Begin );
         //baseStream.Write( b, 0, (int)length );
         //baseStream.SetLength( baseStream.Length - fileJump );
         //CompressionForm.statusMessage = "Removed successfully";
     }
     catch (ArgumentException)
     {
         XyzConstants.ShowError(XyzConstants.FileError);
     }
     catch (IOException)
     {
         XyzConstants.ShowError(XyzConstants.IOError);
     }
 }
コード例 #3
0
        /// <summary>
        /// Add a new entry to the zip
        /// </summary>
        /// <param name="entry">
        /// The details about the header of the entry
        /// </param>
        public void Add(XyzEntry entry)
        {
            FileStream fs = null;

            try
            {
                fs = File.OpenRead(entry.Name);
                //entry.Size = (Int32)fs.Length;
                entry.DateTime = File.GetLastWriteTime(entry.Name);
                PutNextHeader(entry);
                WriteCompressedFile(fs, entry);
                //CompressionForm.statusMessage = XyzConstants.AddMessage;
            }
            catch (ArgumentOutOfRangeException)
            {
                XyzConstants.ShowError(XyzConstants.ArgumentError);
            }
            catch (ArgumentException)
            {
                XyzConstants.ShowError(XyzConstants.FileError);
            }
            catch (FileNotFoundException)
            {
                XyzConstants.ShowError(XyzConstants.FileNotFoundError);
            }
            catch (IOException)
            {
                XyzConstants.ShowError(XyzConstants.IOError);
            }
            catch (OutOfMemoryException)
            {
                XyzConstants.ShowError(XyzConstants.MemoryError);
            }
        }
コード例 #4
0
        /// <summary>
        /// Writes the compressed data into the basestream
        /// It instantiates a memory stream which will serve
        /// as a temp store and then compresses it using Gzip Stream or
        /// Deflate stream and writes it to the base stream
        /// </summary>
        private void WriteCompressedFile(FileStream fStream, XyzEntry entry)
        {
            MemoryStream ms = new MemoryStream();

            try
            {
                if (method == XyzConstants.DEFLATE)
                {
                    zipStream = new DeflateStream(ms, CompressionMode.Compress,
                                                  true);
                }
                else if (method == XyzConstants.GZIP)
                {
                    zipStream = new GZipStream(ms, CompressionMode.Compress,
                                               true);
                }

                byte[] buffer = new byte[fStream.Length];
                fStream.Read(buffer, 0, buffer.Length);
                zipStream.Write(buffer, 0, buffer.Length);
                zipStream.Close();

                byte[] b = new byte[ms.Length];
                ms.Seek(0, SeekOrigin.Begin);
                ms.Read(b, 0, b.Length);
                baseStream.Write(b, 0, b.Length);
                //Go back and write the length and the CRC
                WriteCompressedLengthCRC((int)ms.Length, ComputeMD5(b), entry);
            }
            catch (IOException)
            {
                XyzConstants.ShowError(XyzConstants.IOError);
            }
            catch (ArgumentException)
            {
                XyzConstants.ShowError(XyzConstants.SeekError);
            }
            finally
            {
                ms.Close();
            }
        }
コード例 #5
0
        public void Add(string fileName)
        {
            System.Globalization.CultureInfo ci =
                System.Threading.Thread.CurrentThread.CurrentUICulture;
            if (fileName.ToLower(ci).Equals(zipName.ToLower(ci)))
            {
                XyzConstants.ShowError("Cannot add the current xip file");
                //CompressionForm.statusMessage = String.Empty;
                return;
            }
            XyzEntry entry = new XyzEntry(fileName);

            thisWriter.Add(entry);

            //if (CompressionForm.statusMessage.Length != 0)
            //{
            //    zipEntries.Add(entry);
            //    thisWriter.CloseHeaders((Int16)zipEntries.Count);
            //}
        }
コード例 #6
0
 private void WriteCompressedLengthCRC(Int32 value, byte[] crc,
                                       XyzEntry entry)
 {
     try{
         //entry.CompressedLength = value;
         entry.SetCrc(crc);
         baseStream.Seek(offset, SeekOrigin.Begin);
         //WriteLeInt32(entry.CompressedLength);
         WriteBytes(crc);
         //Remove the recorded offset
         offset = -1;
         baseStream.Seek(0, SeekOrigin.End);
     }
     catch (IOException)
     {
         XyzConstants.ShowError(XyzConstants.IOError);
     }
     catch (ArgumentException)
     {
         XyzConstants.ShowError(XyzConstants.ArgumentError);
     }
 }
コード例 #7
0
 /// <summary>
 /// Puts the next header in a predefined order
 /// </summary>
 /// <param name="entry">
 /// the XyzEntry which contains all the information
 /// </param>
 private void PutNextHeader(XyzEntry entry)
 {
     try{
         //WriteLeInt32(entry.Size);
         ////REcord the offset to write proper CRC and compressed size
         //offset = baseStream.Position;
         //WriteLeInt32(entry.CompressedLength);
         //WriteBytes(entry.GetCrc());
         //WriteLeInt32(entry.DosTime);
         //WriteLeInt16(entry.NameLength);
         //byte[] names = ConvertToArray(entry.Name);
         //baseStream.Write(names, 0, names.Length);
     }
     catch (IOException)
     {
         XyzConstants.ShowError(XyzConstants.IOError);
     }
     catch (ArgumentException)
     {
         XyzConstants.ShowError(XyzConstants.SeekError);
     }
 }
コード例 #8
0
 public bool DeleteEntry(XyzEntry entry)
 {
     return(false);
 }