public bool Swap(ref CMacroFile src) { CMacro tmp = new CMacro(); String text = String.Empty; if ((this.Macros != null) && (src.Macros != null)) { for (int i = 0; i < this.Macros.Length; i++) { this.Macros[i].Swap(ref src.Macros[i]); } } uint version = src.version; src.version = this.version; this.version = version; this.Changed = true; src.Changed = true; return(true); }
public bool Swap(ref CMacroFile src) { CMacro tmp = new CMacro(); String text = String.Empty; if ((this.Macros != null) && (src.Macros != null)) { for (int i = 0; i < this.Macros.Length; i++) { this.Macros[i].Swap(ref src.Macros[i]); } } uint version = src.version; src.version = this.version; this.version = version; this.Changed = true; src.Changed = true; return true; }
public bool CopyFrom(CMacroFile src) { bool reset = false; if (this.Macros == null) { this.Macros = new CMacro[20]; for (int i = 0; i < this.Macros.Length; i++) this.Macros[i] = new CMacro(); reset = true; } if (src != null) { this.version = src.version; if (src.Macros == null) { // if we haven't already reassigned for this.Macros == null if (reset == false) { for (int i = 0; i < this.Macros.Length; i++) { if (this.Macros[i] == null) this.Macros[i] = new CMacro(); } } } else { for (int i = 0; i < this.Macros.Length; i++) { // if we haven't already reassigned for this.Macros == null if (reset == false) { if (this.Macros[i] == null) this.Macros[i] = new CMacro(); } this.Macros[i].CopyFrom(src.Macros[i]); } } } //TreeNode tmpaltNode = src.altNode; //TreeNode tmpctrlNode = src.ctrlNode; //this.altNode = src.altNode; //this.ctrlNode = src.ctrlNode; //this.thisNode = src.thisNode; // do not modify this. // NEVER COPY fNames because we are // copying file information, not where it's at. // this.fName = src.fName; this.Changed = true; return true; }
public bool CopyFrom(CMacroFile src) { bool reset = false; if (this.Macros == null) { this.Macros = new CMacro[20]; for (int i = 0; i < this.Macros.Length; i++) { this.Macros[i] = new CMacro(); } reset = true; } if (src != null) { this.version = src.version; if (src.Macros == null) { // if we haven't already reassigned for this.Macros == null if (reset == false) { for (int i = 0; i < this.Macros.Length; i++) { if (this.Macros[i] == null) { this.Macros[i] = new CMacro(); } } } } else { for (int i = 0; i < this.Macros.Length; i++) { // if we haven't already reassigned for this.Macros == null if (reset == false) { if (this.Macros[i] == null) { this.Macros[i] = new CMacro(); } } this.Macros[i].CopyFrom(src.Macros[i]); } } } //TreeNode tmpaltNode = src.altNode; //TreeNode tmpctrlNode = src.ctrlNode; //this.altNode = src.altNode; //this.ctrlNode = src.ctrlNode; //this.thisNode = src.thisNode; // do not modify this. // NEVER COPY fNames because we are // copying file information, not where it's at. // this.fName = src.fName; this.Changed = true; return(true); }
private void HandleCharOrFolder(TreeNode dragNode, TreeNode dropNode) { #region Handle copying files from char to folder Thread notifyThread = new Thread(new ParameterizedThreadStart(ShowNotifyForm)); TagInfo ti = new TagInfo(String.Empty, "Processing book..."); TagInfo tIdrop = dropNode.Tag as TagInfo; TagInfo tIdrag = dragNode.Tag as TagInfo; CMacroFile[] draglist = new CMacroFile[0]; LogMessage.Log("DragDrop: Creating list of valid files"); for (int i = 0; i < MacroFiles.Count; i++) { #region Locate all files matching the dragNode's folder path if ((MacroFiles[i] != null) && (MacroFiles[i].fName != null) && (MacroFiles[i].fName.Contains(tIdrag.Text))) { Array.Resize(ref draglist, draglist.Length + 1); draglist[draglist.Length - 1] = MacroFiles[i]; } #endregion } if (draglist.Length > 0) { #region If there are valid files for dragging CMacroFile tmp_drop = null; exitLoop = false; List<TagInfo> ttlFileList = new List<TagInfo>(); for (int i = 0; i < draglist.Length; i++) { // remove the common directory, to merge and create a path String PathToRemove = String.Empty; String FileWithFolder = draglist[i].fName; String newpath = String.Empty; try { // draglist[i].fName PathToRemove = Path.GetDirectoryName(tIdrag.Text.Trim('\\')); FileWithFolder = FileWithFolder.Remove(0, PathToRemove.Length); // Attempt to throw an error here. newpath = Path.GetFullPath(tIdrop.Text.Trim('\\') + "\\" + FileWithFolder.Trim('\\')); #region Check for valid TTL files here String newttlfile = String.Empty; String oldttlfile = String.Empty; try { newttlfile = Path.GetDirectoryName(newpath) + "\\mcr.ttl"; // (tIdrop.Text.Trim('\\') + "\\mcr.ttl"); oldttlfile = Path.GetDirectoryName(draglist[i].fName) + "\\mcr.ttl"; } catch (PathTooLongException e) { // File.Exists(String.Empty) always returns false // This will catch an PathTooLongException errors and ignore transfer LogMessage.LogF("..HandleCharOrFolder(): TTL file path is too long {0}, skipping", e.Message); } catch (Exception e) { LogMessage.LogF("..HandleCharOrFolder(): Unknown exception {0}, ignoring", e.Message); } if (newttlfile != oldttlfile) { #region If future ttlfile is within system limits on Path Length and is not the SAME FILE int oldcnt = 0; for (oldcnt = 0; oldcnt < ttlFileList.Count; oldcnt++) { TagInfo tmpTTL = ttlFileList[oldcnt]; CBook cbTTL = tmpTTL.Object1 as CBook; if (cbTTL.fName == oldttlfile) break; } if (oldcnt >= ttlFileList.Count) // not been handled yet { #region If not handled yet CBook cbold = null, cbnew = null; for (int bcnt = 0; bcnt < BookList.Count; bcnt++) { #region Locate any existing book for either file if (BookList[bcnt].fName == oldttlfile) { BookList[bcnt].Restore(); cbold = BookList[bcnt]; } else if (BookList[bcnt].fName == newttlfile) { BookList[bcnt].Restore(); cbnew = BookList[bcnt]; } #endregion } if ((cbold == null) && (File.Exists(oldttlfile))) { #region If didn't find the drag mcr.ttl file and it does exist, Load it cbold = new CBook(oldttlfile); BookList.Add(cbold); #endregion } if ((cbnew == null) && (File.Exists(newttlfile))) { #region If didn't find the drop mcr.ttl file and it does exist, Load it cbnew = new CBook(newttlfile); BookList.Add(cbnew); #endregion } if ((cbold != null) && (cbnew != null)) { #region If old ttl file and new ttlfile info was found in memory ttlFileList.Add(new TagInfo("Overwrite_TTL", cbold, cbnew)); #endregion } else if ((cbold != null) && (cbnew == null)) { #region If old ttl file was found but new ttl file was not cbnew = new CBook(cbold, newttlfile); ttlFileList.Add(new TagInfo("Copy_TTL", Path.GetDirectoryName(newttlfile), cbold, cbnew)); #endregion } #endregion } #endregion } #endregion } catch (PathTooLongException error) { LogMessage.Log("While processing book files, encountered Path Too Long error -- {0}", error.Message); } catch (Exception error) { LogMessage.Log("While processing book files, encountered Unexpected error -- {0}", error.Message); } } // end for loop #region Test for list if (ttlFileList.Count != 0) { if (ttlFileList.Count == 1) { #region If only one book file is being processed, show generic MessageBox instead String path = ttlFileList[0].Text; CBook cbold = ttlFileList[0].Object1 as CBook; CBook cbnew = ttlFileList[0].Object2 as CBook; if (ttlFileList[0].Type == "Overwrite_TTL") { DialogResult dr = MessageBox.Show( String.Format("Book name file found in both directories,\r\nSource: {0}\r\nDestination: {1}\r\n\r\nOverwite the destination Book File?", Utilities.EllipsifyPath(cbold.fName, 60), Utilities.EllipsifyPath(cbnew.fName, 60)), "Overwrite?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (dr == DialogResult.Yes) { cbnew.CopyFrom(cbold); } else if (dr == DialogResult.Cancel) { LogMessage.Log("..Cancelled drop"); return; } } else if (ttlFileList[0].Type == "Copy_TTL") { DialogResult dr = MessageBox.Show( String.Format("Book name file found in source directory:\r\n'{0}',\r\n\r\nCopy to the destination directory:\r\n'{1}'?", Utilities.EllipsifyPath(cbold.fName, 60), Utilities.EllipsifyPath(path, 60)), "Copy?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (dr == DialogResult.Yes) { BookList.Add(cbnew); } else if (dr == DialogResult.Cancel) { LogMessage.Log("..Cancelled drop"); return; } } #endregion } else { #region Else go with the CheckedListBox ExitAndSaveBox esb = new ExitAndSaveBox("Confirmation box...", "Select what actions to take:", "Confirm", "No To All", "Cancel Operation"); esb.checkedListBox1.Items.Clear(); foreach (TagInfo x in ttlFileList) esb.checkedListBox1.Items.Add(x, true); bool ExitTTLLoop = false; do { DialogResult dr = esb.ShowDialog(this); if (dr == DialogResult.Cancel) { LogMessage.Log("..HandleSwapOrCopy(): Copy cancelled"); return; } else if (dr == DialogResult.No) ExitTTLLoop = true; else if (dr == DialogResult.Yes) { if (esb.checkedListBox1.CheckedItems.Count == 0) MessageBox.Show("If you're going to select to save, you must select something!", "Select 'No To All' to ignore this."); else { foreach (TagInfo x in esb.checkedListBox1.CheckedItems) { CBook cbold = x.Object1 as CBook; CBook cbnew = x.Object2 as CBook; String type = x.Type; if (type == "Copy_TTL") { BookList.Add(cbnew); } else if (type == "Overwrite_TTL") { cbnew.CopyFrom(cbold); } } ExitTTLLoop = true; } } } while (ExitTTLLoop == false); #endregion } } #endregion #region Show Notify Form if (draglist.Length > FILES_TO_HIDE) { ti.Object1 = draglist.Length as Object; notifyThread.Start((object)ti); } #endregion String[] errorFiles = new String[0]; String errorString = String.Empty; for (int i = 0; (i < draglist.Length) && (exitLoop == false); i++) { #region Loop through draglist Copying files #region Update NotifyForm UI if (draglist.Length > FILES_TO_HIDE) { UpdateNotifyUI(Utilities.EllipsifyPath(draglist[i].fName), i); Thread.Sleep(25); } #endregion String PathToRemove = String.Empty; String FileWithFolder = draglist[i].fName; String newpath = String.Empty; try { #region Copy files or Create new files here // draglist[i].fName PathToRemove = Path.GetDirectoryName(tIdrag.Text.Trim('\\')); FileWithFolder = FileWithFolder.Remove(0, PathToRemove.Length); // Attempt to throw an error here. newpath = Path.GetFullPath(tIdrop.Text.Trim('\\') + "\\" + FileWithFolder.Trim('\\')); tmp_drop = FindMacroFileExactByFileName(newpath); if (tmp_drop != null) { tmp_drop.CopyFrom(draglist[i]); } else { NewFileInMemory(draglist[i], newpath); } #endregion } catch (PathTooLongException e) { #region Setup for error processing for Too long filenames LogMessage.Log("..HandleCharOrFolder(): Path is too long, could not copy: {0}, skipping -- Error: {1}", newpath, e.Message); Array.Resize(ref errorFiles, errorFiles.Length + 1); errorFiles[errorFiles.Length - 1] = Utilities.EllipsifyPath(newpath); errorString += errorFiles[errorFiles.Length - 1] + "\r\n"; #endregion } catch (Exception e) { #region Generic Error LogMessage.LogF("..HandleCharOrFolder(): Unexpected error -- {0}, ignoring.", e.Message); Array.Resize(ref errorFiles, errorFiles.Length + 1); errorFiles[errorFiles.Length - 1] = Utilities.EllipsifyPath(newpath); errorString += errorFiles[errorFiles.Length - 1] + "\r\n"; #endregion } #endregion } #region Close Notify Form if (draglist.Length > FILES_TO_HIDE) { UpdateNotifyProgress(notifyForm.NotifyBarMax); Thread.Sleep(200); CloseNotifyForm(); } #endregion #region Notify of any errors encountered if ((errorFiles.Length > 0) && (errorString != String.Empty)) { MessageBox.Show("The following " + errorFiles.Length + " files can not be saved (Path to file is TOO long):\r\n" + errorString, "Error: Path(s) too long on " + errorFiles.Length + " files!", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endregion #endregion } else { LogMessage.Log("...Unable to determine list of files in char directory {0}", tIdrag.Text); MessageBox.Show("Unable to complete the request, I'm sorry.", "Drag & Drop Error!"); } #endregion }
private void HandleBookToOthers(TreeNode dragNode, TreeNode dropNode) { Thread notifyThread = new Thread(new ParameterizedThreadStart(ShowNotifyForm)); TagInfo ti = new TagInfo(String.Empty, "Processing book..."); TreeNode dragchildren = dragNode.FirstNode; TagInfo tIdrag = dragNode.Tag as TagInfo; TagInfo tIdrop = dropNode.Tag as TagInfo; if ((tIdrop.Type == "folder") || (tIdrop.Type == "template") || (tIdrop.Type == "main") || (tIdrop.Type == "char")) { TagInfo tIp = dragNode.Parent.Tag as TagInfo; String newttlfile = tIdrop.Text.Trim('\\') + "\\mcr.ttl"; String oldttlfile = tIp.Text.Trim('\\') + "\\mcr.ttl"; #region Catch any error with TTL file manipulation try { newttlfile = Path.GetFullPath(newttlfile); oldttlfile = Path.GetFullPath(oldttlfile); } catch (PathTooLongException e) { LogMessage.LogF("..HandleBookToOthers(): TTL file path is too long {0}, skipping", e.Message); newttlfile = String.Empty; oldttlfile = String.Empty; } catch (Exception e) { LogMessage.LogF("..HandleBookToOthers(): Unknown Exception {0}, ignoring", e.Message); } #endregion if (newttlfile != oldttlfile) { #region If future ttlfile is within system limits on Path Length and is not the SAME FILE CBook cbold = null, cbnew = null; for (int i = 0; i < BookList.Count; i++) { #region Locate any existing book for either file if (BookList[i].fName == oldttlfile) { BookList[i].Restore(); cbold = BookList[i]; } else if (BookList[i].fName == newttlfile) { BookList[i].Restore(); cbnew = BookList[i]; } #endregion } if ((cbold == null) && (File.Exists(oldttlfile))) { #region If didn't find the drag mcr.ttl file and it does exist, Load it cbold = new CBook(oldttlfile); BookList.Add(cbold); #endregion } if ((cbnew == null) && (File.Exists(newttlfile))) { #region If didn't find the drop mcr.ttl file and it does exist, Load it cbnew = new CBook(newttlfile); BookList.Add(cbnew); #endregion } if ((cbold != null) && (cbnew != null)) { #region If old ttl file and new ttlfile info was found in memory DialogResult dr = MessageBox.Show("Book name file found in both directories, Yes to overwite the destination Book File.", "Overwrite?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (dr == DialogResult.Yes) { cbnew.CopyFrom(cbold); } else if (dr == DialogResult.Cancel) return; #endregion } else if ((cbold != null) && (cbnew == null)) { #region If old ttl file info was found, but newttlfile was not DialogResult dr = MessageBox.Show("Book name file found in source directory, Yes to copy to the destination directory.", "Copy?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (dr == DialogResult.Yes) { cbnew = new CBook(cbold, newttlfile); BookList.Add(cbnew); } else if (dr == DialogResult.Cancel) return; #endregion } #endregion } #region Loop through the dragnode's children (macro files) doing copy as necessary CMacroFile[] draglist = new CMacroFile[0]; for (dragchildren = dragNode.FirstNode; dragchildren != null; dragchildren = dragchildren.NextNode) { CMacroFile cmf_drag = FindMacroFileExactByNode(dragchildren); if (cmf_drag != null) { Array.Resize(ref draglist, draglist.Length + 1); draglist[draglist.Length - 1] = cmf_drag; } } if (draglist.Length <= 0) { #region If no files to transfer, return LogMessage.Log("..HandleBookToOthers: No valid files to drag, returning"); return; #endregion } #region Show Notify Form if (draglist.Length > FILES_TO_HIDE) { ti.Object1 = (Object)draglist.Length; notifyThread.Start((object)ti); } #endregion exitLoop = false; String[] errorFiles = new String[0]; String errorString = String.Empty; String oldName = String.Empty; String newName = String.Empty; for (int x = 0; (x < draglist.Length) && (exitLoop == false); x++) { #region Loop through draglist attempting to create new files if necessary oldName = Path.GetFileName(draglist[x].fName); if ((oldName != null) && (oldName != String.Empty)) { newName = String.Format("{0}\\{1}", tIdrop.Text.Trim('\\'), oldName); try { #region Catch an error if FullPath to newName is too long, otherwise Copy file // if too long this should kick it out automatically newName = Path.GetFullPath(newName); if (draglist.Length > FILES_TO_HIDE) { UpdateNotifyUI(Utilities.EllipsifyPath(newName), x); Thread.Sleep(25); } CMacroFile cmf_drop = FindMacroFileExactByFileName(newName); if (cmf_drop != null) { cmf_drop.CopyFrom(draglist[x]); } else { NewFileInMemory(draglist[x], newName); } #endregion } catch (PathTooLongException e) { LogMessage.Log("HandleBookToOthers(): Filename {0} Error -- {1}", newName, e.Message); Array.Resize(ref errorFiles, errorFiles.Length + 1); errorFiles[errorFiles.Length - 1] = Utilities.EllipsifyPath(newName); errorString += errorFiles[errorFiles.Length - 1] + "\r\n"; } catch (Exception e) { LogMessage.Log("HandleBookToOthers(): Filename {0} Error -- {1}", newName, e.Message); } } #endregion } #region Close Notify Form if (draglist.Length > FILES_TO_HIDE) { UpdateNotifyProgress(notifyForm.NotifyBarMax); Thread.Sleep(200); CloseNotifyForm(); } #endregion #region Notify of any errors due to long path names if ((errorFiles.Length > 0) && (errorString != String.Empty)) { MessageBox.Show("The following " + errorFiles.Length + " files can not be copied (Path to file is TOO long):\r\n" + errorString, "Error: Path(s) to " + errorFiles.Length + " files are too long!", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endregion #endregion } }
/// <summary> /// Designed for specifically handling book to book copy and swap. /// </summary> /// <param name="dragNode">TreeNode that initiated the original Drag and Drop operation.</param> /// <param name="dropNode">TreeNode the drag and drop operation was dropped to.</param> /// <param name="SwapOrCopy">1 for Swap, 2 for Copy</param> private void HandleBookToBook(TreeNode dragNode, TreeNode dropNode, int SwapOrCopy) { if ((SwapOrCopy != 1) && (SwapOrCopy != 2)) return; #region Setup Variables for BookToBook Swap/Copy // Setup Thread for the NotifyForm Thread notifyThread = new Thread(new ParameterizedThreadStart(ShowNotifyForm)); // Information for the notifyForm TagInfo ti = new TagInfo(String.Empty, "Processing book..."); // the actual char|folder of the book location TreeNode dP = dropNode.Parent; // ... to get the Tag Info TagInfo tIdrop = dP.Tag as TagInfo; // ... to get the foldername String folderName = tIdrop.Text.Trim('\\'); // Go to the macro sets within the book specifically TreeNode dragchildren = dragNode.FirstNode; // go to the MacroSets within the book TreeNode dropchildren = dropNode.FirstNode; // list variables for storing the drag file and dropfile // this should be a 1-1 list. CMacroFile[] draglist = new CMacroFile[0]; CMacroFile[] droplist = new CMacroFile[0]; #endregion for (dragchildren = dragNode.FirstNode; dragchildren != null; dragchildren = dragchildren.NextNode) { #region Loop through the dragged nodes to setup the list CMacroFile cmf_drag = FindMacroFileExactByNode(dragchildren); // If not a file to drag, skip it if (cmf_drag == null) continue; CMacroFile cmf_drop = null; if (SwapOrCopy == 1) { #region Go through each drop node looking for a file that matches position // go through each drop node looking // for a matching file to swap with // if it exists, add it to the droplist to match // with the draglist for (dropchildren = dropNode.FirstNode; dropchildren != null; dropchildren = dropchildren.NextNode) { cmf_drop = FindMacroFileExactByNode(dropchildren); if (cmf_drop != null) { if ((cmf_drop.FileNumber % 10) == (cmf_drag.FileNumber % 10)) { Array.Resize(ref draglist, draglist.Length + 1); draglist[draglist.Length - 1] = cmf_drag; Array.Resize(ref droplist, droplist.Length + 1); droplist[droplist.Length - 1] = cmf_drop; break; } } } #endregion } else if (SwapOrCopy == 2) // Copy { #region Or just parse the location it should go if Copying to make it quicker // booknumber * 10 + matching file number (0-9) int fNumber = ((Int32.Parse(dropNode.Name) - 1) * 10) + (cmf_drag.FileNumber % 10); // format the macrofile name based on this number String name = String.Format("mcr{0}.dat", (fNumber == 0) ? "" : fNumber.ToString()); // create the potential filename for the drop file String fName = String.Format("{0}\\{1}", tIdrop.Text.Trim('\\'), name); try { // if it's too long, this should throw an error // and go to the CATCH statement fName = Path.GetFullPath(fName); Array.Resize(ref draglist, draglist.Length + 1); Array.Resize(ref droplist, droplist.Length + 1); draglist[draglist.Length - 1] = cmf_drag; cmf_drop = FindMacroFileExactByFileName(fName); // doesn't matter if the file exists, it could // just be in memory. if (cmf_drop != null) { droplist[droplist.Length - 1] = cmf_drop; } else { droplist[droplist.Length - 1] = NewFileInMemory(fName); } } catch (PathTooLongException e) { LogMessage.LogF("...HandleBookToBook(): Path {0} Error -- {1}", fName, e.Message); } catch (Exception e) { LogMessage.LogF("...HandleBookToBook(): Unexpected error {1} on Path {0}", fName, e.Message); } #endregion } #endregion } if ((draglist.Length == 0) || (droplist.Length == 0) || (draglist.Length != droplist.Length)) { #region If the list is NOT 1-1 or there's no list at all, quit with error message. if (SwapOrCopy == 1) MessageBox.Show("You can only swap between books for the same number Macro Set!\r\nFor Example: Macro Set #1 and Macro Set #1", "Drag & Drop Error!"); else if (SwapOrCopy == 2) MessageBox.Show("I would be unable to copy ANY of those files, possibly the path would be too long is my guess", "Drag & Drop Error"); return; #endregion } DialogResult dr = MessageBox.Show( String.Format("{0} Book name As Well?", (SwapOrCopy == 1) ? "Swap" : "Copy"), String.Format("{0} book names?", (SwapOrCopy == 1) ? "Swap" : "Copy"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (dr == DialogResult.Yes) { #region Request if we want to copy/swap the booknames as well TagInfo tIdrag = dragNode.Parent.Tag as TagInfo; String oldttlfile = String.Empty; String newttlfile = String.Empty; try { oldttlfile = Path.GetFullPath(tIdrag.Text.Trim('\\') + "\\mcr.ttl"); newttlfile = Path.GetFullPath(tIdrop.Text.Trim('\\') + "\\mcr.ttl"); CBook cbold = null, cbnew = null; for (int i = 0; (i < BookList.Count) && (cbold == null) && (cbnew == null); i++) { if (BookList[i].fName == oldttlfile) { BookList[i].Restore(); cbold = BookList[i]; } if (BookList[i].fName == newttlfile) { BookList[i].Restore(); cbnew = BookList[i]; } } if ((cbold != null) && (cbnew != null)) { int oldindex = Int32.Parse(dragNode.Name) - 1; int newindex = Int32.Parse(dropNode.Name) - 1; if (SwapOrCopy == 1) { String tmp = cbold.GetBookName(oldindex); cbold.SetBookName(oldindex, cbnew.GetBookName(newindex)); cbnew.SetBookName(newindex, tmp); tmp = dragNode.Text; dragNode.Text = dropNode.Text; dropNode.Text = tmp; } else if (SwapOrCopy == 2) { cbnew.SetBookName(newindex, cbold.GetBookName(oldindex)); dropNode.Text = dragNode.Text; } } } catch (PathTooLongException e) { MessageBox.Show("Unable to comply due to the path length involved is too long", "Path too long error!", MessageBoxButtons.OK, MessageBoxIcon.Error); LogMessage.LogF("..HandleBookToBook(): TTL File: Path too long error -- {0}", e.Message); } catch (Exception e) { MessageBox.Show("Unable to complete the request", "Unexpected error"); LogMessage.LogF("..HandleBookToBook(): TTL File: Unexpected error {0}", e.Message); } #endregion } else if (dr == DialogResult.Cancel) return; exitLoop = false; #region Show Notify Form if (draglist.Length > FILES_TO_HIDE) { ti.Object1 = draglist.Length as Object; notifyThread.Start((object)ti); Thread.Sleep(200); } #endregion for (int i = 0; (i < draglist.Length) && (exitLoop == false); i++) { #region For each item in the draglist, Swap/Copy it with/to the corresponding droplist if (draglist.Length > FILES_TO_HIDE) { UpdateNotifyUI(Utilities.EllipsifyPath(draglist[i].fName), i); Thread.Sleep(25); } if (SwapOrCopy == 1) { Swap(ref draglist[i], ref droplist[i]); } else if (SwapOrCopy == 2) { droplist[i].CopyFrom(draglist[i]); } #endregion } #region Close Notify Form if ((exitLoop == false) && (draglist.Length > FILES_TO_HIDE)) { UpdateNotifyProgress(notifyForm.NotifyBarMax); Thread.Sleep(200); CloseNotifyForm(); } #endregion }
private void ChangeButtonNames(CMacroFile cmf) { if ((cmf == null) || (cmf.Macros == null)) for (int i = 0; i < 20; i++) buttons[i].Text = String.Format("{0}{1}", (i < 10) ? "Ctrl-" : "Alt-", (i + 1) % 10); // this should be 1 - 9 & 0, not 0 - 9 //radiobuttons[i].Text = String.Format("{0}{1}", (i < 10) ? "Ctrl-" : "Alt-", // (i + 1) % 10); else for (int i = 0; i < 20; i++) buttons[i].Text = cmf.Macros[i].DisplayName(); //radiobuttons[i].Text = cmf.Macros[i].DisplayName(); }
/// <summary> /// Determines if a given node is the "Alt Macros" node of a Macro File. /// </summary> /// <param name="node">The TreeNode to check.</param> /// <param name="cmf">The Macro File whose "Ctrl Macros" node we'll compare to.</param> /// <returns>Returns true if TreeNode is the "Ctrl Macros" node of the given MacroFile. Returns false if not.</returns> private bool is_ctrlnode(TreeNode node, CMacroFile cmf) { if ((cmf == null) || (node == null)) return false; return (node == cmf.ctrlNode); }
private void Modify(ref CMacroFile cmf_drag, ref CMacroFile cmf_drop, DragEventArgs e) { #region Swap/Copy Drag & Drop MacroFiles and update if ((cmf_drag != null) && (cmf_drop != null)) { if (e.Effect == DragDropEffects.Link) { Swap(ref cmf_drop, ref cmf_drag); } else if (e.Effect == DragDropEffects.Copy) cmf_drop.CopyFrom(cmf_drag); } else LogMessage.Log("....Modify(): cmf_drag: {0} cmf_drop: {1}", (cmf_drag == null) ? "<NULL>" : cmf_drag.thisNode.Text, (cmf_drop == null) ? "<NULL>" : cmf_drop.thisNode.Text); #endregion }
/// <summary> /// Gets the currently edited Macro for the given Macro File. /// </summary> /// <param name="cmf">Macro File whose Macro we want to return.</param> /// <returns>Returns a Macro assuming the given Macro File is the currently edited one.</returns> private CMacro GetCurrentMacro(CMacroFile cmf) { if (cmf == null) return null; for (int i = 0; i < buttons.Length; i++) if (buttons[i].Enabled == false) return (cmf.Macros[i]); return null; }
private bool Swap(ref CMacroFile cmfe_drop, ref CMacroFile cmfe_drag) { if ((cmfe_drop == null) || (cmfe_drag == null)) return false; CMacroFile tmp = new CMacroFile(this._ATPhraseLoader); tmp.CopyFrom(cmfe_drop); cmfe_drop.CopyFrom(cmfe_drag); cmfe_drag.CopyFrom(tmp); return true; }
private CMacroFile NewFileInMemory(FileInfo fi) { // Search for one with same filename that may be deleted CMacroFile cmf = FindMacroFileExactByFileName(fi.FullName, true); // if not found if (cmf == null) { cmf = new CMacroFile(this._ATPhraseLoader); MacroFiles.Add(cmf); } cmf.fName = fi.FullName; int first_index = -1, last_index = -1; first_index = fi.FullName.LastIndexOf('r'); last_index = fi.FullName.LastIndexOf('.'); cmf.FileNumber = -1; if (fi.FullName.Contains("\\mcr") && fi.FullName.Contains(".dat")) { if ((first_index != -1) && (last_index != -1)) { string number = fi.FullName.Substring(first_index + 1, last_index - (first_index + 1)); if (number == String.Empty) cmf.FileNumber = 0; else { try { cmf.FileNumber = Int32.Parse(number); } catch { cmf.FileNumber = -1; } } } } if (cmf.FileNumber >= Preferences.Max_Macro_Sets) cmf.FileNumber = -1; LogMessage.Log("..Created a new file '" + fi.FullName + "' in memory"); int index = this.treeView.Nodes.IndexOfKey("Templates <x_ffxi_me_x>"); BuildMacroFileNodes(cmf, this.treeView.Nodes, (index > -1) ? this.treeView.Nodes[index] : null); cmf.Changed = true; if (cmf.IsDeleted) cmf.Restore(); return cmf; }
private CMacroFile NewFileInMemory(CMacroFile src, String s) { FileInfo fi = new FileInfo(s); CMacroFile ret = NewFileInMemory(fi); ret.CopyFrom(src); return (ret); }
private CMacroFile NewFileInMemory(CMacroFile src, FileInfo fi) { CMacroFile ret = NewFileInMemory(fi); ret.CopyFrom(src); return (ret); }
private void BuildMacroFileNodes(CMacroFile cmf, TreeNodeCollection maintreeviewNodes, TreeNode templateNode) { if ((cmf == null) || (cmf.fName == null)) return; // mainpath is C:\Program Files\blahblah // fName is C:\Program Files\blahblah\filename.dat TreeNode tempTreeNode = null; bool Found = false; string s = String.Empty; string temppath = String.Empty; if (templateNode != null) { TagInfo tItemp = templateNode.Tag as TagInfo; temppath = tItemp.Text; } foreach (TreeNode mainNode in maintreeviewNodes) { if (mainNode == templateNode) { continue; } TagInfo tI = mainNode.Tag as TagInfo; string mainpath = tI.Text; if ((mainpath != String.Empty) && cmf.fName.Contains(mainpath)) { s = cmf.fName.Remove(0, mainpath.Length); // remove the common start path tempTreeNode = mainNode; if (s.Trim('\\') == String.Empty) s = mainpath; Found = true; } if (Found) break; } if (!Found && (temppath != String.Empty) && cmf.fName.Contains(temppath)) { s = cmf.fName.Remove(0, temppath.Length); tempTreeNode = templateNode; if (s.Trim('\\') == String.Empty) s = temppath; } if (tempTreeNode != null) { cmf.thisNode = BuildTreeRecursive(tempTreeNode, s.Trim('\\'), cmf.FileNumber, cmf.fName); TagInfo xTag = new TagInfo("macrofile"); cmf.thisNode.Tag = xTag; cmf.ctrlNode = cmf.thisNode.Nodes.Add("Ctrl Macros", "Ctrl Macros", "Bars", "Bars"); xTag = new TagInfo("ctrlmacro"); cmf.ctrlNode.Tag = xTag; cmf.altNode = cmf.thisNode.Nodes.Add("Alt Macros", "Alt Macros", "Bars", "Bars"); xTag = new TagInfo("altmacro"); cmf.altNode.Tag = xTag; for (int x = 0; x < 20; x++) { if (x < 10) BuildMacroNode(ref cmf.Macros[x], cmf.ctrlNode); else if (x >= 10) BuildMacroNode(ref cmf.Macros[x], cmf.altNode); } } }