private void create_zip_directory(QueryPanelInfoEventArgs e_current) { ZipDirectory zd = (ZipDirectory)e_current.ItemCollection; //prepare dialog CreateDirectoryDialog dialog = new CreateDirectoryDialog(); dialog.Text = CommandMenu.Text; dialog.labelParentDir.Text = zd.CurrentZipDirectory + "/"; dialog.checkBoxUseTemplate.Checked = false; dialog.checkBoxUseTemplate.Enabled = false; dialog.textBoxTemplateDirectory.Enabled = false; if (dialog.ShowDialog() != DialogResult.OK) { return; } if (dialog.textBoxDirectoryName.Text.Length == 0) { Messages.ShowMessage("directory name cannot be empty"); return; } string new_directory_name = string.Empty; if (zd.CurrentZipDirectory == string.Empty) { new_directory_name = dialog.textBoxDirectoryName.Text; } else { new_directory_name = zd.CurrentZipDirectory + "/" + dialog.textBoxDirectoryName.Text; } if (!new_directory_name.EndsWith("/")) { new_directory_name = new_directory_name + "/"; } try { ZipEntry dir_entry = zd.ZipFile.EntryFactory.MakeDirectoryEntry(new_directory_name); dir_entry.Size = 0; dir_entry.CompressedSize = 0; //required, else exception throws zd.ZipFile.BeginUpdate(); zd.ZipFile.Add(dir_entry); zd.ZipFile.CommitUpdate(); zd.Refill(); } catch (Exception ex) { Messages.ShowException(ex); } }
protected override void internal_command_proc() { QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs(); OnQueryCurrentPanel(e); if (!(e.ItemCollection is ZipDirectory)) { return; } ZipDirectory zd = (ZipDirectory)e.ItemCollection; List <string> initial_sources = new List <string>(); string initial_zip_dir = zd.CurrentZipDirectory; if (initial_zip_dir.StartsWith("/")) { initial_zip_dir = initial_zip_dir.Substring(1); } if ((!initial_zip_dir.EndsWith("/")) && (initial_zip_dir != string.Empty)) { initial_zip_dir = initial_zip_dir + "/"; } if (e.SelectedIndices.Length == 0) { if (zd.GetItemDisplayName(e.FocusedIndex) == "..") { return; } initial_sources.Add(initial_zip_dir + zd.GetItemDisplayName(e.FocusedIndex)); } else { for (int i = 0; i < e.SelectedIndices.Length; i++) { initial_sources.Add(initial_zip_dir + zd.GetItemDisplayName(e.SelectedIndices[i])); } } //show dialog DeleteFileDialog dialog = new DeleteFileDialog(); dialog.Text = Options.GetLiteral(Options.LANG_DELETE); dialog.DeleteFileOptions = DeleteFileOptions.DeleteEmptyDirectories | DeleteFileOptions.DeleteReadonly | DeleteFileOptions.RecursiveDeleteFiles; dialog.textBoxMask.Text = "*"; dialog.checkBoxForceReadonly.Enabled = false; dialog.checkBoxRecursive.Enabled = false; dialog.checkBoxRemoveEmptyDirs.Enabled = false; if (dialog.ShowDialog() != DialogResult.OK) { return; } List <ZipEntry> del_list = new List <ZipEntry>(); create_delete_list(del_list, initial_sources, dialog.textBoxMask.Text, zd.ZipFile); mainForm main_win = (mainForm)Program.MainWindow; try { zd.ZipFile.BeginUpdate(); for (int i = 0; i < del_list.Count; i++) { main_win.NotifyLongOperation (string.Format (Options.GetLiteral(Options.LANG_DELETE_NOW_0), del_list[i].Name), true); zd.ZipFile.Delete(del_list[i]); } main_win.NotifyLongOperation(Options.GetLiteral(Options.LANG_COMMIT_ARCHIVE_UPDATES), true); zd.ZipFile.CommitUpdate(); zd.Refill(); } catch (Exception ex) { Messages.ShowException(ex); } finally { main_win.NotifyLongOperation("Done", false); } }
private void add_to_zip(QueryPanelInfoEventArgs e_current, QueryPanelInfoEventArgs e_other) { mainForm main_window = (mainForm)Program.MainWindow; try { //this is sync operation ZipDirectory zd = (ZipDirectory)e_other.ItemCollection; DirectoryList dl = (DirectoryList)e_current.ItemCollection; //show add zip dialog ArchiveAddDialog dialog = new ArchiveAddDialog(); dialog.Text = Options.GetLiteral(Options.LANG_ARCHIVE_ADD); dialog.textBoxSourceMask.Text = "*"; dialog.ArchiveAddOptions = Options.ArchiveAddOptions; if (dialog.ShowDialog() != DialogResult.OK) { return; } ArchiveAddOptions options = dialog.ArchiveAddOptions; Options.ArchiveAddOptions = options; //notify main window main_window.NotifyLongOperation(Options.GetLiteral(Options.LANG_CREATING_FILE_LIST_TO_ARCHIVE), true); //create file list to add (only files with path) string[] one_file_list = new string[0]; List <string> root_paths = new List <string>(); List <string> file_list = new List <string>(); if (e_current.SelectedIndices.Length == 0) { if (dl[e_current.FocusedIndex].FileName == "..") { Messages.ShowMessage(Options.GetLiteral(Options.LANG_WRONG_SOURCE)); return; } root_paths.Add(dl[e_current.FocusedIndex].FullName); } else { for (int i = 0; i < e_current.SelectedIndices.Length; i++) { root_paths.Add(dl[e_current.SelectedIndices[i]].FullName); } } foreach (string one_path in root_paths) { if ((Directory.Exists(one_path)) && ((options & ArchiveAddOptions.Recursive) == ArchiveAddOptions.Recursive)) { one_file_list = Directory.GetFiles(one_path, dialog.textBoxSourceMask.Text, SearchOption.AllDirectories); } else if ((File.Exists(one_path)) && (Wildcard.Match(dialog.textBoxSourceMask.Text, one_path))) { one_file_list = new string[] { one_path }; } else { one_file_list = new string[0]; } file_list.AddRange(one_file_list); } //call ZipFile.BeginUpdate ZipFile zf = zd.ZipFile; //for each source list item: //create zip file name from real file path, trimmed from dl current directory //call ZipFile.Add //notify main window string current_dir = dl.DirectoryPath; string zip_path = string.Empty; int zip_index = 0; foreach (string one_file in file_list) { try { zip_path = one_file.Substring(current_dir.Length); if (zd.CurrentZipDirectory != string.Empty) { zip_path = zd.CurrentZipDirectory + "/" + zip_path; } zip_path = ZipEntry.CleanName(zip_path); //check for exist zip_index = zf.FindEntry(zip_path, true); if (zip_index != -1) { //entry with same name already exists if ((options & ArchiveAddOptions.NeverRewrite) == ArchiveAddOptions.NeverRewrite) { //skip continue; } if ((options & ArchiveAddOptions.RewriteIfSourceNewer) == ArchiveAddOptions.RewriteIfSourceNewer) { //check mod date if (File.GetLastWriteTime(one_file) < zf[zip_index].DateTime) { continue; } else { //remove entry zf.BeginUpdate(); zf.Delete(zf[zip_index]); zf.CommitUpdate(); } } if ((options & ArchiveAddOptions.RewriteAlways) == ArchiveAddOptions.RewriteAlways) { zf.BeginUpdate(); zf.Delete(zf[zip_index]); zf.CommitUpdate(); } } //open source file main_window.NotifyLongOperation (string.Format (Options.GetLiteral(Options.LANG_ARCHIVING_0_1), one_file, zip_path), true); InternalStreamSource static_source = null; try { //TODO избавиться от флага SaveAttributes //будем всегда сохранять - DONE zf.BeginUpdate(); zf.Add(one_file, zip_path); main_window.NotifyLongOperation(Options.GetLiteral(Options.LANG_COMMIT_ARCHIVE_UPDATES), true); zf.CommitUpdate(); } catch (Exception ex) { if ((options & ArchiveAddOptions.SupressErrors) != ArchiveAddOptions.SupressErrors) { string err_message = string.Format (Options.GetLiteral(Options.LANG_FAILED_ARCHIVE_0), zip_path); if (Messages.ShowExceptionContinue(ex, err_message)) { continue; } else { break; } } } finally { if (static_source != null) { static_source.Close(); } } } catch (Exception ex) { if ((options & ArchiveAddOptions.SupressErrors) != ArchiveAddOptions.SupressErrors) { string err_message = string.Format (Options.GetLiteral(Options.LANG_FAILED_ARCHIVE_0), zip_path); if (Messages.ShowExceptionContinue(ex, err_message)) { continue; } else { break; } } } }//end of foreach //Refill zd zd.Refill(); //notify main window when done } catch (Exception ex) { Messages.ShowException(ex); } finally { main_window.NotifyLongOperation("Done", false); } }