コード例 #1
0
        public static void Decompress(Stream sourceStream, string targetDir)
        {
            if (sourceStream == null)
            {
                throw new ArgumentException("sourceStream");
            }

            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }

            using (sourceStream) {
                InternalZipFileCollection zipFiles = InternalZipArchive.Open(sourceStream);
                foreach (InternalZipFile zipFile in zipFiles)
                {
                    byte[] buffer = new byte[zipFile.UncompressedSize];
                    zipFile.FileDataStream.Read(buffer, 0, buffer.Length);

                    string targetPath = Path.Combine(targetDir, zipFile.FileName);
                    var    dirname    = Path.GetDirectoryName(targetPath);
                    if (!Directory.Exists(dirname))
                    {
                        Directory.CreateDirectory(dirname);
                    }
                    if (zipFile.CompressedSize == 0)
                    {
                        continue;
                    }
                    using (FileStream ws = new FileStream(targetPath, FileMode.Create, FileAccess.Write)) {
                        ws.Write(buffer, 0, buffer.Length);
                    }
                }
            }
        }
 public ZipFilesHelper(string path)
 {
     if (File.Exists(path))
     {
         stream   = File.OpenRead(path);
         zipFiles = InternalZipArchive.Open(stream);
     }
 }
コード例 #3
0
 void UnpackUpgradeToWorkingFolder(string upgradeFileName, string workingFolder)
 {
     using (FileStream stream = new FileStream(upgradeFileName, FileMode.Open)) {
         InternalZipFileCollection files = InternalZipArchive.Open(stream);
         foreach (InternalZipFile file in files)
         {
             SaveFile(Path.Combine(workingFolder, Path.GetFileName(file.FileName)), file);
         }
     }
 }
コード例 #4
0
        public static void CompressDir(string sourceDir, string targetFile)
        {
            if (!Directory.Exists(sourceDir))
            {
                throw new ArgumentException("sourceDir");
            }

            using (InternalZipArchive zipper = new InternalZipArchive(targetFile)) {
                DirectoryInfo di = new DirectoryInfo(sourceDir);
                foreach (FileInfo fi in di.GetFiles())
                {
                    using (FileStream fs = fi.OpenRead()) {
                        zipper.Add(fi.Name, DateTime.Now, fs);
                    }
                }
            }
        }
コード例 #5
0
        static DevExpress.XtraRichEdit.DocumentFormat CheckZippedFileContent(Stream stream)
        {
            stream.Seek(0, SeekOrigin.Begin);
            InternalZipFileCollection files = InternalZipArchive.Open(stream);

            foreach (InternalZipFile entry in files)
            {
                if (entry.FileName.Contains(".rels") || entry.FileName.Contains("document.xml"))
                {
                    return(DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
                }
                if (entry.FileName.Contains("content.xml"))
                {
                    return(DevExpress.XtraRichEdit.DocumentFormat.OpenDocument);
                }
            }
            return(DevExpress.XtraRichEdit.DocumentFormat.PlainText);
        }
コード例 #6
0
        static ISpellCheckerDictionary GetDefaultDictionary()
        {
            SpellCheckerISpellDictionary dic = new SpellCheckerISpellDictionary();
            Stream zipFileStream             = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("DevExpress.MailClient.Win.Dictionaries.default.zip");
            InternalZipFileCollection files  = InternalZipArchive.Open(zipFileStream);
            Stream alphabetStream            = GetFileStream(files, "EnglishAlphabet.txt");
            Stream dictionaryStream          = GetFileStream(files, "american.xlg");
            Stream grammarStream             = GetFileStream(files, "english.aff");

            try {
                dic.LoadFromStream(dictionaryStream, grammarStream, alphabetStream);
            } catch {
            } finally {
                dictionaryStream.Dispose();
                grammarStream.Dispose();
                zipFileStream.Dispose();
                alphabetStream.Dispose();
                DisposeZipFileStreams(files);
            }
            dic.Culture = new CultureInfo("en-US");
            return(dic);
        }
コード例 #7
0
        static ISpellCheckerDictionary GetDefaultDictionary()
        {
            SpellCheckerISpellDictionary dic = new SpellCheckerISpellDictionary();

            using (Stream stream = DemoUtils.GetDataStream(DemoUtils.PathToDictionaries, "default.zip")) {
                InternalZipFileCollection files = InternalZipArchive.Open(stream);
                Stream dictionaryStream         = GetFileStream(files, "american.xlg");
                Stream grammarStream            = GetFileStream(files, "english.aff");
                Stream alphabetStream           = DemoUtils.GetDataStream(DemoUtils.PathToDictionaries, "EnglishAlphabet.txt");
                try {
                    dic.LoadFromStream(dictionaryStream, grammarStream, alphabetStream);
                }
                catch {
                }
                finally {
                    dictionaryStream.Close();
                    grammarStream.Close();
                    alphabetStream.Close();
                }
            }
            dic.Culture = new CultureInfo("en-US");
            return(dic);
        }
        void SaveArchive(string url, byte[] buffer)
        {
            string tempPath = Path.ChangeExtension(StoragePath, "tmp");

            // Create a new ZIP archive.
            using (InternalZipArchive arch = new InternalZipArchive(tempPath)) {
                // Open a ZIP archive where report files are stored.
                using (ZipFilesHelper helper = new ZipFilesHelper(StoragePath)) {
                    bool added = false;
                    // Copy all report files to a new archive.
                    // Update a file with a specified URL.
                    // If the file does not exist, create it.
                    foreach (InternalZipFile item in helper.ZipFiles)
                    {
                        if (StringsEgual(item.FileName, url))
                        {
                            arch.Add(item.FileName, DateTime.Now, buffer);
                            added = true;
                        }
                        else
                        {
                            arch.Add(item.FileName, DateTime.Now, GetBytes(item));
                        }
                    }
                    if (!added)
                    {
                        arch.Add(url, DateTime.Now, buffer);
                    }
                }
            }
            // Replace the old ZIP archive with the new one.
            if (File.Exists(StoragePath))
            {
                File.Delete(StoragePath);
            }
            File.Move(tempPath, StoragePath);
        }