private void _startBtn_Click(object sender, EventArgs e) { ThreadStart a = delegate { putToList(); if (!Directory.Exists(SelectedPath)) { Directory.CreateDirectory(SelectedPath); } string listFile = DescriptionPath + "/list.zip"; if (File.Exists(listFile)) { File.Delete(listFile); } var list = new FileInfo(listFile); var listStream = new ZipOutputStream(list.Create()); var listEntry = new ZipEntry("list.lst") {DateTime = DateTime.Now}; listStream.PutNextEntry(listEntry); onStart(); writeString(listStream, "#Version: " + Version + "\n"); for (var i = 0; i < _files.Count; i++) //листаем { var item = _files[i]; item.validateDirectoryes(); FileStream sourceStream = item.CreateSource(); FileStream descriptionStream = item.CreateDescription(); var zipDescriptionStream = new ZipOutputStream(descriptionStream); //открываем стрим zipDescriptionStream.SetLevel(9); // zipDescriptionStream.Password = PASSWORD; var entry = new ZipEntry(item.EntryName.Replace(".zip", "")) {DateTime = item.SourceTime()}; zipDescriptionStream.PutNextEntry(entry); var bytes = new byte[sourceStream.Length]; int readLen = sourceStream.Read(bytes, 0, bytes.Length); sourceStream.Close(); if (readLen != bytes.Length) { continue; } zipDescriptionStream.Write(bytes, 0, readLen); zipDescriptionStream.Finish(); zipDescriptionStream.Close(); writeString(listStream, item.FileName + "\t" + item.MD5 + "\n"); var p = ((100*i)/_files.Count); if (p > 100) p = 100; setValue(p); } listStream.Finish(); listStream.Close(); onEnd(); }; new Thread(a).Start(); }
/// <summary> /// Create a zip archive sending output to the <paramref name="outputStream"/> passed. /// </summary> /// <param name="outputStream">The stream to write archive data to.</param> /// <param name="sourceDirectory">The directory to source files from.</param> /// <param name="recurse">True to recurse directories, false for no recursion.</param> /// <param name="fileFilter">The <see cref="PathFilter">file filter</see> to apply.</param> /// <param name="directoryFilter">The <see cref="PathFilter">directory filter</see> to apply.</param> public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, string fileFilter, string directoryFilter) { NameTransform = new ZipNameTransform(sourceDirectory); sourceDirectory_ = sourceDirectory; using ( outputStream_ = new ZipOutputStream(outputStream) ) { #if !NETCF_1_0 if ( password_ != null ) { outputStream_.Password = password_; } #endif outputStream_.UseZip64 = UseZip64; FileSystemScanner scanner = new FileSystemScanner(fileFilter, directoryFilter); scanner.ProcessFile += new ProcessFileHandler(ProcessFile); if ( this.CreateEmptyDirectories ) { scanner.ProcessDirectory += new ProcessDirectoryHandler(ProcessDirectory); } if (events_ != null) { if ( events_.FileFailure != null ) { scanner.FileFailure += events_.FileFailure; } if ( events_.DirectoryFailure != null ) { scanner.DirectoryFailure += events_.DirectoryFailure; } } scanner.Scan(sourceDirectory, recurse); } }
public void make() { if (_files.Count == 0) { _log.Info("Files == 0"); MessageBox.Show("Files is none", "Premaker", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (!Directory.Exists(DescriptionDirectory)) { Directory.CreateDirectory(DescriptionDirectory); } FileInfo listZIP = new FileInfo(DescriptionDirectory + "/list.zip"); ZipOutputStream zipListStream = new ZipOutputStream(listZIP.Create()); zipListStream.SetLevel(COMPRESS_LEVEL); //уровень компресии zipListStream.Password = PASSWORD; //пароль ZipEntry listEntry = new ZipEntry("list.lst"); listEntry.DateTime = DateTime.Now; zipListStream.PutNextEntry(listEntry); writeString(zipListStream, "#Revision:" + REVISION + "\n"); //пишем номер ревизии ChooseForm.Instance.FormAsGameFiles.onStart(); //прогресс бар включаем ChooseForm.Instance.FormAsGameFiles.disableItems(false); //отключаем что б не изменилось for (int i = 0; i < Items.Count; i++) //листаем { if (Break) { ChooseForm.Instance.FormAsGameFiles.setStatus("Break"); ChooseForm.Instance.FormAsGameFiles.setValue(0); return; } lock (zipListStream) { ListFile item = Items[i]; try { if (!item.Exists()) { _log.Info("WTF source file is deleted ??. File: " + item.SourceDirectoryName + item.FileName); continue; } if (item.FileType != ListFileType.DELETE) { item.validateDirectoryes(); FileStream sourceStream = item.CreateSource(); FileStream descriptionStream = item.CreateDescription(); if (sourceStream == null || descriptionStream == null) { _log.Info("WTF streams NULL???. File: " + item.FileName); } ChooseForm.Instance.FormAsGameFiles.setStatus("Compressing " + item.FileName); ZipOutputStream zipDescriptionStream = new ZipOutputStream(descriptionStream); //открываем стрим zipDescriptionStream.SetLevel(COMPRESS_LEVEL); zipDescriptionStream.Password = PASSWORD; ZipEntry entry = new ZipEntry(item.EntryName.Replace(".zip", "")); entry.DateTime = item.SourceTime(); zipDescriptionStream.PutNextEntry(entry); byte[] bytes = new byte[sourceStream.Length]; int readLen = sourceStream.Read(bytes, 0, bytes.Length); sourceStream.Close(); if (readLen != bytes.Length) { _log.Info("WTF source file is not compled read??. File: " + item.FileName); continue; } zipDescriptionStream.Write(bytes, 0, readLen); zipDescriptionStream.Finish(); zipDescriptionStream.Close(); } writeString(zipListStream, item.FileName + "\t" + item.FileType + "\t" + item.MD5 + "\n"); } catch (Exception e) { _log.Info("Exception: file - " + item.FileName, e); } finally { int p = ((100 * i) / Items.Count); if (p > 100) p = 100; ChooseForm.Instance.FormAsGameFiles.setValue(p); } } } zipListStream.Finish(); zipListStream.Close(); ChooseForm.Instance.FormAsGameFiles.setStatus("Done"); ChooseForm.Instance.FormAsGameFiles.disableItems(true); ChooseForm.Instance.FormAsGameFiles.onEnd(); }