コード例 #1
0
 string GetContent(C1ZipEntry entry)
 {
     using (Stream entryStream = entry.OpenReader())
     {
         using (StreamReader streamReader = new StreamReader(entryStream))
         {
             return(streamReader.ReadToEnd());
         }
     }
 }
コード例 #2
0
        // add a list of files to the Zip file, keeping the specified pathLevels
        void AddFileList(string[] files, int pathLevels)
        {
            // keep track errors and time
            string err   = string.Empty;
            long   start = DateTime.Now.Ticks;

            // add files
            foreach (string file in files)
            {
                // update UI
                UpdateStatusBar("Adding file " + file);
                if (CheckUserCancel())
                {
                    break;
                }

                // add the file
                try
                {
                    _zipFile.Entries.Add(file, pathLevels);
                    Application.DoEvents();
                }
                catch (Exception x)
                {
                    err += "\r\n" + x.Message;
                }
            }

            // cancel? we're done
            if (_cancel)
            {
                return;
            }

            // warn user of any problems
            if (err.Length > 0)
            {
                MessageBox.Show(err, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            // update user interface
            UpdateUI();

            // show how long it took
            double sec = (DateTime.Now.Ticks - start) / (double)TimeSpan.TicksPerSecond;
            double meg = 0;

            if (sec > 1)
            {
                foreach (string file in files)
                {
                    C1ZipEntry ze = _zipFile.Entries[Path.GetFileName(file)];
                    if (ze != null)
                    {
                        meg += ze.SizeCompressedLong;
                    }
                }
                meg /= (1024.0 * 1024.0);
                UpdateStatusBar(string.Format("Compressed in {0:0.00} seconds, {1:0.00} meg/second", sec, meg / sec));
            }
        }