Ejemplo n.º 1
0
 private void btnDuplicate_Click(object sender, EventArgs e)
 {
     if ((lbxLogicTrees.Items.Count > 0) && (lbxLogicTrees.SelectedIndex >= 0))
     {
         //if file exists, rename the file
         string filePath = prntForm._mainDirectory + "\\modules\\" + prntForm.mod.moduleName + "\\logictree";
         string filename = prntForm.mod.moduleLogicTreesList[prntForm._selectedLbxLogicTreeIndex];
         if (File.Exists(filePath + "\\" + filename + ".json"))
         {
             try
             {
                 //rename file
                 File.Copy(filePath + "\\" + filename + ".json", filePath + "\\" + filename + "-Copy.json"); // Try to move
                 try
                 {
                     //load convo
                     LogicTree newConvo = new LogicTree();
                     newConvo = newConvo.GetLogicTree(filePath, "\\" + filename + "-Copy.json");
                     if (newConvo == null)
                     {
                         MessageBox.Show("returned a null LogicTree");
                     }
                     //change convo file name in convo file object properties
                     newConvo.Filename = filename + "-Copy";
                     newConvo.SaveLogicTree(filePath, "\\" + filename + "-Copy.json");
                     prntForm.mod.moduleLogicTreesList.Add(newConvo.Filename);
                     refreshListBoxLogicTrees();
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show("failed to open file: " + ex.ToString());
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.ToString()); // Write error
             }
         }
         else
         {
             MessageBox.Show("File: " + filename + ".json does not exist in the dialog folder");
         }
         refreshListBoxLogicTrees();
     }
 }
Ejemplo n.º 2
0
 private void btnRename_Click(object sender, EventArgs e)
 {
     if ((lbxLogicTrees.Items.Count > 0) && (lbxLogicTrees.SelectedIndex >= 0))
     {
         RenameDialog newName = new RenameDialog();
         DialogResult result = newName.ShowDialog();
         if (result == System.Windows.Forms.DialogResult.OK)
         {
             try
             {
                 #region New Logic Tree
                 if (prntForm.mod.moduleLogicTreesList[prntForm._selectedLbxLogicTreeIndex] == "newLogicTree")
                 {
                     //if file exists, rename the file
                     string filePath = prntForm._mainDirectory + "\\modules\\" + prntForm.mod.moduleName + "\\logictree";
                     if (File.Exists(filePath + "\\" + prntForm.mod.moduleLogicTreesList[prntForm._selectedLbxLogicTreeIndex] + ".json"))
                     {
                         try
                         {
                             //rename file
                             File.Move(filePath + "\\" + prntForm.mod.moduleLogicTreesList[prntForm._selectedLbxLogicTreeIndex] + ".json", filePath + "\\" + newName.RenameText + ".json"); // Try to move
                             try
                             {
                                 //load area
                                 LogicTree newConvo = new LogicTree();
                                 newConvo = newConvo.GetLogicTree(filePath, "\\" + newName.RenameText + ".json");
                                 if (newConvo == null)
                                 {
                                     MessageBox.Show("returned a null LogicTree");
                                 }
                                 //change area file name in area file object properties
                                 newConvo.Filename = newName.RenameText;
                                 newConvo.SaveLogicTree(filePath, "\\" + newName.RenameText + ".json");
                                 prntForm.mod.moduleLogicTreesList[prntForm._selectedLbxLogicTreeIndex] = newName.RenameText;
                             }
                             catch (Exception ex)
                             {
                                 MessageBox.Show("failed to open file: " + ex.ToString());
                             }
                         }
                         catch (Exception ex)
                         {
                             MessageBox.Show(ex.ToString()); // Write error
                         }
                     }
                     else
                     {
                         prntForm.mod.moduleLogicTreesList[prntForm._selectedLbxLogicTreeIndex] = newName.RenameText;
                     }
                     refreshListBoxLogicTrees();
                 }
                 #endregion
                 #region Existing Logic Tree
                 else
                 {
                     DialogResult sure = MessageBox.Show("Are you sure you wish to change the Logic Tree name and the LogicTree file name? (make sure to update any references to this LogicTree name such as script hooks and trigger events)", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
                     if (sure == System.Windows.Forms.DialogResult.Yes)
                     {
                         //if file exists, rename the file
                         string filePath = prntForm._mainDirectory + "\\modules\\" + prntForm.mod.moduleName + "\\logictree";
                         if (File.Exists(filePath + "\\" + prntForm.mod.moduleLogicTreesList[prntForm._selectedLbxLogicTreeIndex] + ".json"))
                         {
                             try
                             {
                                 //rename file
                                 File.Move(filePath + "\\" + prntForm.mod.moduleLogicTreesList[prntForm._selectedLbxLogicTreeIndex] + ".json", filePath + "\\" + newName.RenameText + ".json"); // Try to move
                                 try
                                 {
                                     //load convo
                                     LogicTree newConvo = new LogicTree();
                                     newConvo = newConvo.GetLogicTree(filePath, "\\" + newName.RenameText + ".json");
                                     if (newConvo == null)
                                     {
                                         MessageBox.Show("returned a null LogicTree");
                                     }
                                     //change convo file name in convo file object properties
                                     newConvo.Filename = newName.RenameText;
                                     newConvo.SaveLogicTree(filePath, "\\" + newName.RenameText + ".json");
                                     prntForm.mod.moduleLogicTreesList[prntForm._selectedLbxLogicTreeIndex] = newName.RenameText;
                                 }
                                 catch (Exception ex)
                                 {
                                     MessageBox.Show("failed to open file: " + ex.ToString());
                                 }
                             }
                             catch (Exception ex)
                             {
                                 MessageBox.Show(ex.ToString()); // Write error
                             }
                         }
                         else
                         {
                             prntForm.mod.moduleLogicTreesList[prntForm._selectedLbxLogicTreeIndex] = newName.RenameText;
                         }
                         refreshListBoxLogicTrees();
                     }
                 }
                 #endregion
             }
             catch { }
         }
     }
 }