static void DisposeZipFileStreams(InternalZipFileCollection files) { foreach (InternalZipFile file in files) { file.FileDataStream.Dispose(); } }
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); } }
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); } } }
static InternalZipFile GetZipFile(InternalZipFileCollection zipFiles, string url) { foreach (InternalZipFile item in zipFiles) { if (StringsEgual(item.FileName, url)) { return(item); } } return(null); }
static Stream GetFileStream(InternalZipFileCollection files, string name) { Stream stream = files.Find(delegate(InternalZipFile file) { return(file.FileName.IndexOf(name) >= 0); }).FileDataStream; try { return(CreateMemoryStream(stream)); } finally { stream.Close(); } }
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); }
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); }
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); }
static Stream GetFileStream(InternalZipFileCollection files, string name) { Stream stream = files.Find(delegate(InternalZipFile file) { return file.FileName.IndexOf(name) >= 0; }).FileDataStream; try { return CreateMemoryStream(stream); } finally { stream.Close(); } }
static void DisposeZipFileStreams(InternalZipFileCollection files) { foreach(InternalZipFile file in files) file.FileDataStream.Dispose(); }