Ejemplo n.º 1
0
        /// <summary>
        /// Opens a Zip file with the given name.
        /// </summary>
        /// <param name="name"> Zip name</param>
        public ZipFile(string name)
        {
            try
            {
                zipName    = name;
                baseStream = new FileStream(zipName, FileMode.Open);
                thisWriter = new ZipWriter(baseStream);

                int index1 = zipName.IndexOf(ZipConstants.Dot);
                int index2 = zipName.LastIndexOf(ZipConstants.BackSlash);
                thisReader = new ZipReader(baseStream, zipName.Substring(index2,
                                                                         index1 - index2));

                zipEntries        = thisReader.GetAllEntries();
                thisWriter.Method = thisReader.Method;
                if (CompressionForm.statusMessage != String.Empty)
                {
                    CompressionForm.statusMessage =
                        String.Format(
                            System.Threading.Thread.CurrentThread.CurrentUICulture,
                            ZipConstants.OpenMessage, name);
                }
            }
            catch (IOException)
            {
                ZipConstants.ShowError("Error opening the file");
            }
            catch (ArgumentOutOfRangeException)
            {
                ZipConstants.ShowError(ZipConstants.CorruptedError);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Created a new Zip file with the given name.
        /// </summary>
        /// <param name="method"> Gzip or deflate</param>
        /// <param name="name"> Zip name</param>
        public ZipFile(string name, byte method, FileMode mode)
        {
            try
            {
                zipName = name;

                baseStream        = new FileStream(zipName, mode);
                thisWriter        = new ZipWriter(baseStream);
                thisWriter.Method = method;

                //New File
                thisWriter.WriteSuperHeader(0, method);

                int index1 = zipName.IndexOf(ZipConstants.Dot);
                int index2 = zipName.LastIndexOf(ZipConstants.BackSlash);
                thisReader = new ZipReader(baseStream, zipName.Substring(index2,
                                                                         index1 - index2));

                zipEntries = thisReader.GetAllEntries();
                CompressionForm.statusMessage =
                    String.Format(
                        System.Threading.Thread.CurrentThread.CurrentUICulture,
                        ZipConstants.NewMessage, name);
            }
            catch (System.IO.IOException)
            {
                ZipConstants.ShowError(ZipConstants.IOError);
            }
        }