/// <summary> /// After rename, fixup the directory and update the MOG_ControllerSyncData /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GameDataTreeView_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e) { try { guiAssetTreeTag tag = (guiAssetTreeTag)e.Node.Tag; string targetDirectoryName = tag.FullFilename.Replace(e.Node.Text, e.Label); if (!Directory.Exists(targetDirectoryName)) { DirectoryInfo dir = new DirectoryInfo(tag.FullFilename); dir.MoveTo(targetDirectoryName); e.Node.Tag = new guiAssetTreeTag(targetDirectoryName, e.Node); GameDataTreeView.LabelEdit = false; } else { MOG_Report.ReportMessage("Rename Directory", "A name of that directory already exist", Environment.StackTrace, MOG_ALERT_LEVEL.ERROR); e.CancelEdit = true; return; } } catch { } }
/// <summary> /// Find a node within a nodes children based on its Text value /// </summary> /// <param name="parentNode"></param> /// <param name="title"></param> /// <returns></returns> private TreeNode FindNode(TreeNode parentNode, string title) { try { if (parentNode == null) { if (this.GameDataTreeView.Nodes != null && this.GameDataTreeView.Nodes.Count > 0) { parentNode = this.GameDataTreeView.Nodes[0]; } } if (parentNode != null) { foreach (TreeNode node in parentNode.Nodes) { guiAssetTreeTag tag = (guiAssetTreeTag)node.Tag; if (string.Compare(tag.FullFilename, title, true) == 0) { return(node); } } } } catch { } return(null); }
/// <summary> /// Go to the drive and get all the files and directories directly under it /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GameDataTreeView_BeforeExpand(object sender, System.Windows.Forms.TreeViewCancelEventArgs e) { // Get our initial root path from our treeView Tag // string rootPath = (string)e.Node.TreeView.Tag; if (e.Node.Nodes[0].Text == "BLANK") { try { guiAssetTreeTag dirTag = (guiAssetTreeTag)e.Node.Tag; MOG_ControllerSyncData targetGamdeData = null; // Check if this directory has a targetGamdeData if (dirTag.Object != null) { targetGamdeData = (MOG_ControllerSyncData)dirTag.Object; } if (Path.IsPathRooted(dirTag.FullFilename)) { FillDirectory(e.Node, dirTag.FullFilename, targetGamdeData); } } catch { } } }
/// <summary> /// Event for when the explorer contextmenu is opened. /// We do some validation for each of the menu items /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LocalDirectoryCommandsContextMenu_Popup(object sender, System.EventArgs e) { try { if (MOGAllowDirectoryOpperations == false) { throw new Exception("All directory opperations are disabled"); } // Check to see if the selected node is a mog target guiAssetTreeTag tag = (guiAssetTreeTag)GameDataTreeView.SelectedNode.Tag; // All tags with objects are MOG_ControllerSyncData's // So is this a MOG_ControllerSyncData node? if (tag.Object != null) { // If it is... Disable something? } else { // If its not... Enable something? try { // Make sure this path is a valid path not a drive root if (Path.GetDirectoryName(tag.FullFilename).Length > 0) { this.LocalDirectoryCreateMenuItem.Enabled = true; this.LocalDirectoryDeleteMenuItem.Enabled = true; this.LocalDirectoryRenameMenuItem.Enabled = true; } } catch { // We do not allow delete or rename from root paths like 'c:\' this.LocalDirectoryDeleteMenuItem.Enabled = false; this.LocalDirectoryRenameMenuItem.Enabled = false; try { if (Path.GetDirectoryName(tag.FullFilename + "\\NewFolder").Length > 0) { this.LocalDirectoryCreateMenuItem.Enabled = true; } } catch { } } } } catch { this.LocalDirectoryCreateMenuItem.Enabled = false; this.LocalDirectoryDeleteMenuItem.Enabled = false; this.LocalDirectoryRenameMenuItem.Enabled = false; } }
/// <summary> /// Delete directory /// </summary> private void LocalDirectoryDeleteMenuItem_Click(object sender, System.EventArgs e) { try { guiAssetTreeTag tag = (guiAssetTreeTag)GameDataTreeView.SelectedNode.Tag; if (MOG_Prompt.PromptResponse("Delete Directory", "Are you sure you wan to delete this directory with all its contents?\n\nDirectory:\n\n" + tag.FullFilename, MOGPromptButtons.YesNo) == MOGPromptResult.Yes) { if (tag.Object != null) { // Get our gameData handle from the item's tag MOG_ControllerSyncData gameDataHandle = (MOG_ControllerSyncData)tag.Object; if (gameDataHandle != null) { MOG_Report.ReportMessage("Delete Directory", "Cannot delete a directory that is a MOG Local Workspace! Remove this Workspace first then try again.", Environment.StackTrace, MOG_ALERT_LEVEL.ERROR); return; // // Remove the synced location // if (!MOG_DBSyncedDataAPI.RemoveSyncedLocation(MOG_ControllerSystem.GetComputerName(), gameDataHandle.GetProjectName(), gameDataHandle.GetPlatformName(), gameDataHandle.GetGameDataPath())) // { // throw new Exception("Database could not remove this synced location!"); // } // // // Remove all the updated records // string filter = gameDataHandle.GetGameDataPath() + "\\*"; // if (!MOG_DBInboxAPI.InboxRemoveAllAssets("Local", null, null, filter)) // { // throw new Exception("Database inbox could not remove this synced location!"); // } } } // Now, actually delete the directory ArrayList FilesToDelete = DosUtils.FileGetRecursiveList(tag.FullFilename, "*.*"); ProgressDialog progress = new ProgressDialog("Delete Directory", "Deleting...", LocalDirectoryDelete_Worker, FilesToDelete, true); if (progress.ShowDialog() == DialogResult.OK) { // Now delete all the files left behind Directory.Delete(tag.FullFilename, true); // Remove the node GameDataTreeView.SelectedNode.Remove(); } } } catch (Exception ex) { MOG_Report.ReportMessage("Delete Directory", "Could not delete this directory!\n\nMessage:" + ex.Message, ex.StackTrace, MOG_ALERT_LEVEL.CRITICAL); } }