void DoExisting(List<CLKsFATXLib.Structs.ExistingEntry> Existing) { if (Existing.Count == 0) { return; } List<CLKsFATXLib.Structs.ExistingEntry> FilesWithFolders = new List<CLKsFATXLib.Structs.ExistingEntry>(); List<CLKsFATXLib.Structs.ExistingEntry> FoldersWithFiles = new List<CLKsFATXLib.Structs.ExistingEntry>(); List<CLKsFATXLib.Structs.ExistingEntry> Folders = new List<CLKsFATXLib.Structs.ExistingEntry>(); List<CLKsFATXLib.Structs.ExistingEntry> Files = new List<CLKsFATXLib.Structs.ExistingEntry>(); MergedPaths = new List<CLKsFATXLib.Structs.ExistingEntry>(); goto _Sort; _Sort: { foreach (CLKsFATXLib.Structs.ExistingEntry ex in Existing) { if (ex.Existing.IsFolder && VariousFunctions.IsFolder(ex.NewPath)) { Folders.Add(ex); } else if (ex.Existing.IsFolder && !VariousFunctions.IsFolder(ex.NewPath)) { FilesWithFolders.Add(ex); } else if (!ex.Existing.IsFolder && VariousFunctions.IsFolder(ex.NewPath)) { FoldersWithFiles.Add(ex); } else { Files.Add(ex); } } Existing = new List<CLKsFATXLib.Structs.ExistingEntry>(); } bool Delete = false; for (int i = 0; i < Folders.Count; i++) { if (Cancel) { return; } if (Windows7) { tm.SetProgressValue(1, 1); tm.SetProgressState(TaskbarProgressBarState.Error); } DialogResult dr = DialogResult.Ignore; bool Checked = false; if (!Aero) { Forms.InjectDialog id = new InjectDialog(Folders[i], Folders.Count - 1); CheckForIllegalCrossThreadCalls = false; id.ShowDialog(this.Owner); Checked = id.checkBox1.Checked; CheckForIllegalCrossThreadCalls = true; } else { this.Invoke((MethodInvoker)delegate { td.Caption = "Entry Already Exists"; td.InstructionText = "Cannot Write Folder \"" + Folders[i].NewPath + "\""; td.Text = "A " + ((Folders[i].Existing.IsFolder) ? "folder " : "file ") + "named \"" + Folders[i].Existing.Name + "\" already exists in the directory \"" + Folders[i].Existing.Parent.FullPath + "\". Would you like to " + ((Folders[i].Existing.IsFolder) ? "merge the already existing folder with the new one?" : "overwrite the currently existing file to write the new folder?"); td.FooterCheckBoxChecked = false; td.FooterCheckBoxText = "Do this for all current items? (" + Folders.Count + ")"; td.Icon = TaskDialogStandardIcon.Error; td.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No; if (td.ShowDialog(this.Handle) == TaskDialogResult.Yes) { dr = DialogResult.Yes; } Checked = (bool)td.FooterCheckBoxChecked; }); } // If they want to merge the folders if (dr == DialogResult.Yes) { if (Windows7) { tm.SetProgressState(TaskbarProgressBarState.Normal); } // If they want to do all of them... if (Checked) { foreach (var existing in Folders) { Existing.AddRange(((Folder)existing.Existing).Parent.InjectFolder(existing.NewPath, true, Delete)); MergedPaths.Add(existing); } Folders = new List<CLKsFATXLib.Structs.ExistingEntry>(); break; } else { foreach (System.IO.DirectoryInfo di in new System.IO.DirectoryInfo(Folders[i].NewPath).GetDirectories()) { Existing.AddRange(((Folder)Folders[i].Existing).InjectFolder(di.FullName, false, Delete)); } foreach (System.IO.FileInfo fi in new System.IO.DirectoryInfo(Folders[i].NewPath).GetFiles()) { CLKsFATXLib.Structs.WriteResult wr = ((Folder)Folders[i].Existing).CreateNewFile(fi.FullName); CLKsFATXLib.Structs.ExistingEntry exe = new CLKsFATXLib.Structs.ExistingEntry(); exe.Existing = wr.Entry; exe.NewPath = fi.FullName; Existing.Add(exe); } //Existing.AddRange(((Folder)Folders[i].Existing).Parent.InjectFolder(Folders[i].NewPath, false, Delete)); MergedPaths.Add(Folders[i]); Folders.RemoveAt(i); i--; } } else if (Checked) { Folders = new List<CLKsFATXLib.Structs.ExistingEntry>(); } } if (Existing.Count != 0) { goto _Sort; } for (int i = 0; i < Files.Count; i++) { if (Cancel) { return; } // If we don't even have to show a dialog... if (Delete) { Files[i].Existing.Parent.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); ((File)Files[i].Existing).Delete(); Files[i].Existing.Parent.CreateNewFile(Files[i].NewPath); } else { if (Windows7) { tm.SetProgressValue(1, 1); tm.SetProgressState(TaskbarProgressBarState.Error); } DialogResult dr = DialogResult.Ignore; bool Checked = false; if (!Aero) { Forms.InjectDialog id = new InjectDialog(Files[i], Files.Count - 1); CheckForIllegalCrossThreadCalls = false; id.ShowDialog(this.Owner); Checked = id.checkBox1.Checked; CheckForIllegalCrossThreadCalls = true; } else { this.Invoke((MethodInvoker)delegate { td.Caption = "File Already Exists"; td.InstructionText = "Cannot Write File \"" + Files[i].NewPath + "\""; td.Text = "A file named \"" + Files[i].Existing.Name + "\" already exists in the directory \"" + Files[i].Existing.Parent.FullPath + "\". Would you like to overwrite the currently existing file to write the new file?"; td.FooterCheckBoxChecked = false; td.FooterCheckBoxText = "Do this for all current items (" + Files.Count + ")"; td.Icon = TaskDialogStandardIcon.Error; td.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No; if (td.ShowDialog(this.Handle) == TaskDialogResult.Yes) { dr = DialogResult.Yes; } Checked = (bool)td.FooterCheckBoxChecked; }); } if (dr == DialogResult.Yes) { if (Windows7) { tm.SetProgressState(TaskbarProgressBarState.Normal); } if (Checked) { Delete = true; Files[i].Existing.Parent.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); ((File)Files[i].Existing).Delete(); Files[i].Existing.Parent.CreateNewFile(Files[i].NewPath); Files.RemoveAt(i); i--; } else { ((File)Files[i].Existing).Delete(); Files[i].Existing.Parent.CreateNewFile(Files[i].NewPath); Files.RemoveAt(i); i--; } } else if (Checked) { Files = new List<CLKsFATXLib.Structs.ExistingEntry>(); } } } if (Existing.Count != 0) { goto _Sort; } if (FilesWithFolders.Count > 0 || FoldersWithFiles.Count > 0) { Forms.Existing exForm = new Existing(FilesWithFolders, FoldersWithFiles); CheckForIllegalCrossThreadCalls = false; exForm.Show(this.Owner); CheckForIllegalCrossThreadCalls = true; } }
void DoExisting(List <CLKsFATXLib.Structs.ExistingEntry> Existing) { if (Existing.Count == 0) { return; } List <CLKsFATXLib.Structs.ExistingEntry> FilesWithFolders = new List <CLKsFATXLib.Structs.ExistingEntry>(); List <CLKsFATXLib.Structs.ExistingEntry> FoldersWithFiles = new List <CLKsFATXLib.Structs.ExistingEntry>(); List <CLKsFATXLib.Structs.ExistingEntry> Folders = new List <CLKsFATXLib.Structs.ExistingEntry>(); List <CLKsFATXLib.Structs.ExistingEntry> Files = new List <CLKsFATXLib.Structs.ExistingEntry>(); MergedPaths = new List <CLKsFATXLib.Structs.ExistingEntry>(); goto _Sort; _Sort: { foreach (CLKsFATXLib.Structs.ExistingEntry ex in Existing) { if (ex.Existing.IsFolder && VariousFunctions.IsFolder(ex.NewPath)) { Folders.Add(ex); } else if (ex.Existing.IsFolder && !VariousFunctions.IsFolder(ex.NewPath)) { FilesWithFolders.Add(ex); } else if (!ex.Existing.IsFolder && VariousFunctions.IsFolder(ex.NewPath)) { FoldersWithFiles.Add(ex); } else { Files.Add(ex); } } Existing = new List <CLKsFATXLib.Structs.ExistingEntry>(); } bool Delete = false; for (int i = 0; i < Folders.Count; i++) { if (Cancel) { return; } if (Windows7) { tm.SetProgressValue(1, 1); tm.SetProgressState(TaskbarProgressBarState.Error); } DialogResult dr = DialogResult.Ignore; bool Checked = false; if (!Aero) { Forms.InjectDialog id = new InjectDialog(Folders[i], Folders.Count - 1); CheckForIllegalCrossThreadCalls = false; id.ShowDialog(this.Owner); Checked = id.checkBox1.Checked; CheckForIllegalCrossThreadCalls = true; } else { this.Invoke((MethodInvoker) delegate { td.Caption = "Entry Already Exists"; td.InstructionText = "Cannot Write Folder \"" + Folders[i].NewPath + "\""; td.Text = "A " + ((Folders[i].Existing.IsFolder) ? "folder " : "file ") + "named \"" + Folders[i].Existing.Name + "\" already exists in the directory \"" + Folders[i].Existing.Parent.FullPath + "\". Would you like to " + ((Folders[i].Existing.IsFolder) ? "merge the already existing folder with the new one?" : "overwrite the currently existing file to write the new folder?"); td.FooterCheckBoxChecked = false; td.FooterCheckBoxText = "Do this for all current items? (" + Folders.Count + ")"; td.Icon = TaskDialogStandardIcon.Error; td.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No; if (td.ShowDialog(this.Handle) == TaskDialogResult.Yes) { dr = DialogResult.Yes; } Checked = (bool)td.FooterCheckBoxChecked; }); } // If they want to merge the folders if (dr == DialogResult.Yes) { if (Windows7) { tm.SetProgressState(TaskbarProgressBarState.Normal); } // If they want to do all of them... if (Checked) { foreach (var existing in Folders) { Existing.AddRange(((Folder)existing.Existing).Parent.InjectFolder(existing.NewPath, true, Delete)); MergedPaths.Add(existing); } Folders = new List <CLKsFATXLib.Structs.ExistingEntry>(); break; } else { foreach (System.IO.DirectoryInfo di in new System.IO.DirectoryInfo(Folders[i].NewPath).GetDirectories()) { Existing.AddRange(((Folder)Folders[i].Existing).InjectFolder(di.FullName, false, Delete)); } foreach (System.IO.FileInfo fi in new System.IO.DirectoryInfo(Folders[i].NewPath).GetFiles()) { CLKsFATXLib.Structs.WriteResult wr = ((Folder)Folders[i].Existing).CreateNewFile(fi.FullName); CLKsFATXLib.Structs.ExistingEntry exe = new CLKsFATXLib.Structs.ExistingEntry(); exe.Existing = wr.Entry; exe.NewPath = fi.FullName; Existing.Add(exe); } //Existing.AddRange(((Folder)Folders[i].Existing).Parent.InjectFolder(Folders[i].NewPath, false, Delete)); MergedPaths.Add(Folders[i]); Folders.RemoveAt(i); i--; } } else if (Checked) { Folders = new List <CLKsFATXLib.Structs.ExistingEntry>(); } } if (Existing.Count != 0) { goto _Sort; } for (int i = 0; i < Files.Count; i++) { if (Cancel) { return; } // If we don't even have to show a dialog... if (Delete) { Files[i].Existing.Parent.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); ((File)Files[i].Existing).Delete(); Files[i].Existing.Parent.CreateNewFile(Files[i].NewPath); } else { if (Windows7) { tm.SetProgressValue(1, 1); tm.SetProgressState(TaskbarProgressBarState.Error); } DialogResult dr = DialogResult.Ignore; bool Checked = false; if (!Aero) { Forms.InjectDialog id = new InjectDialog(Files[i], Files.Count - 1); CheckForIllegalCrossThreadCalls = false; id.ShowDialog(this.Owner); Checked = id.checkBox1.Checked; CheckForIllegalCrossThreadCalls = true; } else { this.Invoke((MethodInvoker) delegate { td.Caption = "File Already Exists"; td.InstructionText = "Cannot Write File \"" + Files[i].NewPath + "\""; td.Text = "A file named \"" + Files[i].Existing.Name + "\" already exists in the directory \"" + Files[i].Existing.Parent.FullPath + "\". Would you like to overwrite the currently existing file to write the new file?"; td.FooterCheckBoxChecked = false; td.FooterCheckBoxText = "Do this for all current items (" + Files.Count + ")"; td.Icon = TaskDialogStandardIcon.Error; td.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No; if (td.ShowDialog(this.Handle) == TaskDialogResult.Yes) { dr = DialogResult.Yes; } Checked = (bool)td.FooterCheckBoxChecked; }); } if (dr == DialogResult.Yes) { if (Windows7) { tm.SetProgressState(TaskbarProgressBarState.Normal); } if (Checked) { Delete = true; Files[i].Existing.Parent.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); ((File)Files[i].Existing).Delete(); Files[i].Existing.Parent.CreateNewFile(Files[i].NewPath); Files.RemoveAt(i); i--; } else { ((File)Files[i].Existing).Delete(); Files[i].Existing.Parent.CreateNewFile(Files[i].NewPath); Files.RemoveAt(i); i--; } } else if (Checked) { Files = new List <CLKsFATXLib.Structs.ExistingEntry>(); } } } if (Existing.Count != 0) { goto _Sort; } if (FilesWithFolders.Count > 0 || FoldersWithFiles.Count > 0) { Forms.Existing exForm = new Existing(FilesWithFolders, FoldersWithFiles); CheckForIllegalCrossThreadCalls = false; exForm.Show(this.Owner); CheckForIllegalCrossThreadCalls = true; } }
private void DoExisting(List <ParrotLibs.Structs.ExistingEntry> aExistList) { if (aExistList.Count == 0) { return; } // 文件、文件夹、文件包含文件夹、文件夹包含文件 List <ParrotLibs.Structs.ExistingEntry> sFiles = new List <ParrotLibs.Structs.ExistingEntry>(); List <ParrotLibs.Structs.ExistingEntry> sFolders = new List <ParrotLibs.Structs.ExistingEntry>(); List <ParrotLibs.Structs.ExistingEntry> sFilesWithFolders = new List <ParrotLibs.Structs.ExistingEntry>(); List <ParrotLibs.Structs.ExistingEntry> sFoldersWithFiles = new List <ParrotLibs.Structs.ExistingEntry>(); MergedPaths = new List <ParrotLibs.Structs.ExistingEntry>(); goto _Sort; _Sort: { // 对ExistList中的元素进行分类 foreach (ParrotLibs.Structs.ExistingEntry sEntry in aExistList) { // 元素中的内容是文件夹,并且该元素是文件夹 if (sEntry.Existing.IsFolder && VariousFunctions.IsFolder(sEntry.NewPath)) { sFolders.Add(sEntry); } // 元素中的内容是文件夹,并且该元素是文件 else if (sEntry.Existing.IsFolder && !VariousFunctions.IsFolder(sEntry.NewPath)) { sFilesWithFolders.Add(sEntry); } // 元素中的内容是文件,并且该元素是文件夹 else if (!sEntry.Existing.IsFolder && VariousFunctions.IsFolder(sEntry.NewPath)) { sFoldersWithFiles.Add(sEntry); } // 文件 else { sFiles.Add(sEntry); } } // 分类后,对ExistList进行初始化 aExistList = new List <ParrotLibs.Structs.ExistingEntry>(); } bool Delete = false; for (int i = 0; i < sFolders.Count; i++) { if (Cancel) { return; } if (Windows7) { tm.SetProgressValue(1, 1); tm.SetProgressState(TaskbarProgressBarState.Error); } DialogResult dr = DialogResult.Ignore; bool Checked = false; // VISTA 之前版本 if (Aero == false) { InjectDialog sInjectDialog = new InjectDialog(sFolders[i], sFolders.Count - 1); CheckForIllegalCrossThreadCalls = false; sInjectDialog.ShowDialog(this.Owner); Checked = sInjectDialog.checkBox1.Checked; CheckForIllegalCrossThreadCalls = true; } else { this.Invoke((MethodInvoker) delegate { mTaskDialog.Caption = "该内容已存在"; mTaskDialog.InstructionText = "无法对下列路径进行写操作 \"" + sFolders[i].NewPath + "\""; if (sFolders[i].Existing.IsFolder == true) { mTaskDialog.Text = "因为在 \"" + sFolders[i].Existing.Parent.FullPath + "\" 路径下,"; mTaskDialog.Text += "有相同的 \"" + sFolders[i].Existing.Name + "\" 文件夹存在!"; mTaskDialog.Text += "是否合并该文件夹?"; } else { mTaskDialog.Text = "因为在 \"" + sFolders[i].Existing.Parent.FullPath + "\" 路径下,"; mTaskDialog.Text += "有相同的 \"" + sFolders[i].Existing.Name + "\" 文件存在!"; mTaskDialog.Text += "是否将旧文件覆盖?"; } mTaskDialog.Icon = TaskDialogStandardIcon.Warning; mTaskDialog.FooterCheckBoxChecked = false; mTaskDialog.FooterCheckBoxText = "全部应用? (目标数:" + sFolders.Count + ")"; mTaskDialog.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No; if (mTaskDialog.ShowDialog(this.Handle) == TaskDialogResult.Yes) { dr = DialogResult.Yes; } Checked = (bool)mTaskDialog.FooterCheckBoxChecked; }); } // If they want to merge the folders if (dr == DialogResult.Yes) { if (Windows7) { tm.SetProgressState(TaskbarProgressBarState.Normal); } // If they want to do all of them... if (Checked) { foreach (var existing in sFolders) { aExistList.AddRange(((Folder)existing.Existing).Parent.InjectFolder(existing.NewPath, true, Delete)); MergedPaths.Add(existing); } sFolders = new List <ParrotLibs.Structs.ExistingEntry>(); break; } else { foreach (System.IO.DirectoryInfo di in new System.IO.DirectoryInfo(sFolders[i].NewPath).GetDirectories()) { aExistList.AddRange(((Folder)sFolders[i].Existing).InjectFolder(di.FullName, false, Delete)); } foreach (System.IO.FileInfo fi in new System.IO.DirectoryInfo(sFolders[i].NewPath).GetFiles()) { ParrotLibs.Structs.WriteResult wr = ((Folder)sFolders[i].Existing).CreateNewFile(fi.FullName); ParrotLibs.Structs.ExistingEntry exe = new ParrotLibs.Structs.ExistingEntry(); exe.Existing = wr.Entry; exe.NewPath = fi.FullName; aExistList.Add(exe); } //Existing.AddRange(((Folder)Folders[i].Existing).Parent.InjectFolder(Folders[i].NewPath, false, Delete)); MergedPaths.Add(sFolders[i]); sFolders.RemoveAt(i); i--; } } else if (Checked) { sFolders = new List <ParrotLibs.Structs.ExistingEntry>(); } } if (aExistList.Count != 0) { goto _Sort; } for (int i = 0; i < sFiles.Count; i++) { if (Cancel) { return; } // If we don't even have to show a dialog... if (Delete) { sFiles[i].Existing.Parent.FolderAction += new ParrotLibs.Structs.FolderActionChanged(EntryAction_FolderAction); ((File)sFiles[i].Existing).Delete(); sFiles[i].Existing.Parent.CreateNewFile(sFiles[i].NewPath); } else { if (Windows7) { tm.SetProgressValue(1, 1); tm.SetProgressState(TaskbarProgressBarState.Error); } DialogResult dr = DialogResult.Ignore; bool Checked = false; if (!Aero) { Forms.InjectDialog id = new InjectDialog(sFiles[i], sFiles.Count - 1); CheckForIllegalCrossThreadCalls = false; id.ShowDialog(this.Owner); Checked = id.checkBox1.Checked; CheckForIllegalCrossThreadCalls = true; } else { this.Invoke((MethodInvoker) delegate { mTaskDialog.Caption = "File Already Exists"; mTaskDialog.InstructionText = "Cannot Write File \"" + sFiles[i].NewPath + "\""; mTaskDialog.Text = "A file named \"" + sFiles[i].Existing.Name + "\" already exists in the directory \"" + sFiles[i].Existing.Parent.FullPath + "\". Would you like to overwrite the currently existing file to write the new file?"; mTaskDialog.FooterCheckBoxChecked = false; mTaskDialog.FooterCheckBoxText = "Do this for all current items (" + sFiles.Count + ")"; mTaskDialog.Icon = TaskDialogStandardIcon.Error; mTaskDialog.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No; if (mTaskDialog.ShowDialog(this.Handle) == TaskDialogResult.Yes) { dr = DialogResult.Yes; } Checked = (bool)mTaskDialog.FooterCheckBoxChecked; }); } if (dr == DialogResult.Yes) { if (Windows7) { tm.SetProgressState(TaskbarProgressBarState.Normal); } if (Checked) { Delete = true; sFiles[i].Existing.Parent.FolderAction += new ParrotLibs.Structs.FolderActionChanged(EntryAction_FolderAction); ((File)sFiles[i].Existing).Delete(); sFiles[i].Existing.Parent.CreateNewFile(sFiles[i].NewPath); sFiles.RemoveAt(i); i--; } else { ((File)sFiles[i].Existing).Delete(); sFiles[i].Existing.Parent.CreateNewFile(sFiles[i].NewPath); sFiles.RemoveAt(i); i--; } } else if (Checked) { sFiles = new List <ParrotLibs.Structs.ExistingEntry>(); } } } if (aExistList.Count != 0) { goto _Sort; } if (sFilesWithFolders.Count > 0 || sFoldersWithFiles.Count > 0) { Forms.Existing exForm = new Existing(sFilesWithFolders, sFoldersWithFiles); CheckForIllegalCrossThreadCalls = false; exForm.Show(this.Owner); CheckForIllegalCrossThreadCalls = true; } }