protected TreeNode CreateSyncTargetTreeNode(MOG_DBSyncTargetInfo info, string platform) { bool ableToGetSourceFileAssetLinks = false; string currentVersionStamp = info.mVersion; MOG_Filename tempFilename = MOG_Filename.CreateAssetName(info.mAssetClassification, info.mAssetPlatform, info.mAssetLabel); MOG_Filename assetRealFile = MOG_ControllerRepository.GetAssetBlessedVersionPath(tempFilename, currentVersionStamp); // Create node with FocusLevel that does not plug into the BaseLeafTreeView TreeNode node = new TreeNode(info.FilenameOnly, new TreeNode[] { new TreeNode(Blank_Node_Text) }); Mog_BaseTag tag = new Mog_BaseTag(node, assetRealFile.GetEncodedFilename(), RepositoryFocusLevel.Classification, true); node.Name = tempFilename.GetAssetFullName(); tag.AttachedSyncTargetInfo = info; node.Tag = tag; string gamedataFilePath; if (ableToGetSourceFileAssetLinks) { gamedataFilePath = assetRealFile.GetEncodedFilename() + "\\Files.Imported\\" + info.mSyncTargetFile; } else { gamedataFilePath = assetRealFile.GetEncodedFilename() + "\\Files.Imported\\" + info.FilenameOnly; } //This is either a file or an asset SetImageIndices(node, base.GetAssetFileImageIndex(gamedataFilePath)); return(node); }
/// <summary> /// Add group or object to the database /// </summary> private bool AddGroupToDatabase(string addCandidate, MOG_Filename packageAsset) { // Are we platform generic? bool success = true; if (packageAsset.GetAssetPlatform() == "All") { string packageVersion = MOG_DBAssetAPI.GetAssetVersion(packageAsset); if (packageVersion.Length > 0) { success = MOG_DBPackageAPI.AddPackageGroupName(packageAsset, packageVersion, addCandidate, MOG_ControllerProject.GetUser().GetUserName()); } } // We are platform generic, loop through all platforms then ArrayList platforms = MOG_ControllerProject.GetProject().GetPlatforms(); for (int p = 0; p < platforms.Count && success; p++) { MOG_Platform platform = (MOG_Platform)platforms[p]; // Set this package to be platform specific for this platform name packageAsset = MOG_Filename.CreateAssetName(packageAsset.GetAssetClassification(), platform.mPlatformName, packageAsset.GetAssetLabel()); string packageVersion = MOG_DBAssetAPI.GetAssetVersion(packageAsset); if (packageVersion.Length > 0) { // Add to the database success &= MOG_DBPackageAPI.AddPackageGroupName(packageAsset, packageVersion, addCandidate, MOG_ControllerProject.GetUser().GetUserName()); } } return success; }
/// <summary> /// Prepare a drag object to recieve any driped items from the package tree /// </summary> private DataObject PrepareDragObject(TreeView tree, TreeNode node) { // failsafe for unpopulated package lists if (tree.Nodes.Count <= 0) { return(null); } // Create our list holders ArrayList packages = new ArrayList(); MOG_Filename package = new MOG_Filename(node.Text); // Get the package names if (package.GetAssetPlatform().Length == 0) { // We need to make a new MOG_Filename with a valid platform // To do this we need to get to the class, label and desired platform string classification = FindClassification(node); string packgePath = IsolatePackagePath(node.FullPath, classification); if (packgePath.Length > 0) { package = MOG_Filename.CreateAssetName(classification, "All", packgePath); // Add the platforms foreach (MOG_Platform platform in MOG_ControllerProject.GetProject().GetPlatforms()) { package = MOG_Filename.CreateAssetName(classification, platform.mPlatformName, packgePath); packages.Add(package.GetAssetFullName()); } } else { MOG_Prompt.PromptMessage("Create package name", "Could not locate pachage path in package(" + node.FullPath + ")"); return(null); } } else { packages.Add(package.GetAssetFullName()); } if (packages.Count > 0) { // Create a new Data object for the send return(new DataObject("Package", packages)); } return(null); }
private bool IsInformationValid() { if (this.PackageNameTextBox.BackColor == Color.Tomato) { MOG_Prompt.PromptResponse("Package name missing", "Please specify a name for the new package."); return(false); } if (MOG_ControllerProject.DoesAssetExists(MOG_Filename.CreateAssetName(Classification, Platform, PackageName))) { MOG_Prompt.PromptResponse("Package name not unique", "This package already exists, please specify a unique package name and try again."); return(false); } if (this.ClassificationTextBox.BackColor == Color.Tomato) { MOG_Prompt.PromptResponse("Classification missing", "Please select a classification for the new package."); return(false); } if (SyncTargetTextBox.Enabled && SyncTargetTextBox.BackColor == Color.Tomato) { MOG_Prompt.PromptResponse("Sync target missing", "Please select a sync target for the new package."); return(false); } // Check if this package is missing an extension? if (Path.GetExtension(PackageName).Length == 0) { // Check if we are also missing a defined DefaultPackageFileExtension? MOG_Properties tempProperties = new MOG_Properties(Classification); if (tempProperties.DefaultPackageFileExtension.Length == 0) { if (MOG_Prompt.PromptResponse("Warning - Missing extension", "This package does not have an extension. Most eninges require extensions on packages.\n\nDo you want to continue without and extenstion?", "", MOG.PROMPT.MOGPromptButtons.YesNo, MOG.PROMPT.MOG_ALERT_LEVEL.ALERT) == MOG.PROMPT.MOGPromptResult.No) { return(false); } } } if (this.PlatformCombo.BackColor == Color.Tomato) { MOG_Prompt.PromptResponse("Invalid Platform", "Please select a valid platform for the new package."); return(false); } return(true); }
private void ExpandSyncTargetAssetNode(TreeNode gamedataNode, string platform) { Mog_BaseTag gamedataTag = (Mog_BaseTag)gamedataNode.Tag; // If we have valid data... if (gamedataTag.AttachedSyncTargetInfo != null) { // Key is gamedataFilename, Value is gamedataFilenameOnly MOG_DBSyncTargetInfo gamedataInfo = gamedataTag.AttachedSyncTargetInfo; string currentVersionStamp = gamedataInfo.mVersion; MOG_Filename tempFilename = MOG_Filename.CreateAssetName(gamedataInfo.mAssetClassification, gamedataInfo.mAssetPlatform, gamedataInfo.mAssetLabel); MOG_Filename assetRealFile = MOG_ControllerRepository.GetAssetBlessedVersionPath(tempFilename, currentVersionStamp); // Add the asset this gamedata file is associated with under the oldGamedataNode TreeNode assetNode = new TreeNode(assetRealFile.GetAssetFullName(), new TreeNode[] { new TreeNode(Blank_Node_Text) }); assetNode.Tag = new Mog_BaseTag(assetNode, assetRealFile.GetEncodedFilename(), LeafFocusLevel.RepositoryItems, true); assetNode.Name = assetRealFile.GetAssetFullName(); gamedataNode.Nodes.Add(assetNode); SetImageIndices(assetNode, GetAssetFileImageIndex(assetRealFile.GetEncodedFilename())); } }
private static void ImportRemainingItems_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <Object> args = e.Argument as List <Object>; List <ImportFile> remainingItems = args[0] as List <ImportFile>; bool useExtension = (bool)args[1]; string classification = args[2] as string; string platform = args[3] as string; ArrayList propertyArray = args[4] as ArrayList; int itemCount = 0; foreach (ImportFile remainingItem in remainingItems) { // Create the MOG asset name string assetLabel = useExtension ? DosUtils.PathGetFileName(remainingItem.mImportFilename) : DosUtils.PathGetFileNameWithoutExtension(remainingItem.mImportFilename); MOG_Filename multiFile = MOG_Filename.CreateAssetName(classification, platform, assetLabel); // Create our import file list ArrayList multiInFiles = new ArrayList(); multiInFiles.Add(remainingItem.mImportFilename); string message = "Importing:\n" + " " + classification + "\n" + " " + Path.GetFileName(remainingItem.mImportFilename); worker.ReportProgress(itemCount++ *100 / remainingItems.Count, message); // Import the asset MOG_ControllerAsset.CreateAsset(multiFile, "", multiInFiles, null, propertyArray, false, false); // Check if the user canceled things? if (worker.CancellationPending) { break; } } }
private void btnCreate_Click(object sender, EventArgs e) { if (IsInformationValid()) { string[] platforms = Platform.Split(",".ToCharArray()); // Make sure there was something specified before we do anything if (platforms.Length > 0) { bool bPromptUser = true; bool bCreatePackage = true; bool bRebuildPackage = false; foreach (string platform in platforms) { // Create the new package name MOG_Filename assetName = MOG_Filename.CreateAssetName(Classification, platform.Trim(), PackageName); // Check if we should prompt the user? if (bPromptUser) { // Don't bother the user again bPromptUser = false; // Check if this was a platform specific package? if (assetName.IsPlatformSpecific()) { // Check if there are ANY assiciated assets with this new platform-specific package? if (MOG_ControllerPackage.GetAssociatedAssetsForPackage(assetName).Count > 0) { // Prompt the user if they wish to automatically populate this new platform-specific packages? string message = "Whenever new platform-specific packages are created, they sometimes need to be populated if existing package assignments exist.\n\n" + "MOG has detected this to be the case and recommends you to automatically populated this package."; MOGPromptResult result = MOG_Prompt.PromptResponse("Automatically populate this new platform-specific package?", message, MOGPromptButtons.YesNo); switch (result) { case MOGPromptResult.Yes: bCreatePackage = true; bRebuildPackage = true; break; case MOGPromptResult.No: bCreatePackage = true; bRebuildPackage = false; break; case MOGPromptResult.Cancel: bCreatePackage = false; bRebuildPackage = false; break; } } } } // Check if we should create the package? if (bCreatePackage) { MOG_Filename newPackage = MOG_ControllerProject.CreatePackage(assetName, SyncTarget); if (newPackage != null) { // Post the new package into the project mAssetName = newPackage; string jobLabel = "NewPackageCreated." + MOG_ControllerSystem.GetComputerName() + "." + MOG_Time.GetVersionTimestamp(); MOG_ControllerProject.PostAssets(MOG_ControllerProject.GetProjectName(), MOG_ControllerProject.GetBranchName(), jobLabel); // Check if we should rebuild the package? if (bRebuildPackage) { jobLabel = "PopulateNewPackage." + MOG_ControllerSystem.GetComputerName() + "." + MOG_Time.GetVersionTimestamp(); // Schedule the rebuild command MOG_ControllerPackage.RebuildPackage(assetName, jobLabel); // Start the job MOG_ControllerProject.StartJob(jobLabel); } // Well, this is a bit of a hack but was the easiest and safest way to ensure unique JobIDs... // JobIDs are only accurate to the microsecond so lets sleep for a very short time. Thread.Sleep(10); // Setting the dialog's result will automatically close the dialog since we proceeded to create the package DialogResult = DialogResult.OK; } } } } } }
private void MogControl_PackageTreeView_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e) { // Encapsulate all of this in a try-catch, since we don't want to crash MOG try { if (!CheckLabelEdit(e)) { return; } // Disable further label editing e.Node.TreeView.LabelEdit = false; // Find our parent package TreeNode package = FindPackage(e.Node); TreeNode parent = e.Node.Parent; string nodeText = e.Node.Text.ToLower(); ArrayList packagePlatforms = GetPackageLabelEditPlatforms(e, ref nodeText); // Switch base on what our nodeText was before the user editted it switch (nodeText.ToLower()) { case "newgroup": #region new-group if (package != null) { // Get the new edited label name //string groupName = e.Label; MOG_Filename packageAsset = new MOG_Filename(((Mog_BaseTag)package.Tag).FullFilename); string groupName = GetQualifiedGroupName(e, package); // If we have a duplicate, do not add it if (ValidateNodeIsNotDuplicate(e.Node.Parent, groupName) == true) { MOG_Prompt.PromptResponse("Duplicate Entry!", "The group, " + groupName + ", " + "already exists! Group not added."); e.Node.Remove(); return; } // Add group to Database if (!AddGroupToDatabase(groupName, packageAsset)) { // We need to clean up the unsuccessfull add to the database e.Node.Remove(); // Show error MOG_Prompt.PromptMessage("Create group", "We were unable to add this group to the database. Aborting"); } AttachValidatedTagToNewObjectOrGroup(package, e.Node, PackageNodeTypes.Group); // Go ahead and select our node e.Node.TreeView.SelectedNode = e.Node; } #endregion newgroup break; case "(newpackageobject)": #region new-package-object if (package != null) { // Get the new edited label name string objectName = e.Label; e.Node.Text = "(" + objectName + ")"; // If we have a duplicate, do not add it if (ValidateNodeIsNotDuplicate(e.Node.Parent, e.Node.Text) == true) { MOG_Prompt.PromptResponse("Duplicate Entry!", "The object, (" + objectName + "), " + "already exists! Package object not added."); e.Node.Remove(); return; } MOG_Filename packageAsset = new MOG_Filename(((Mog_BaseTag)package.Tag).FullFilename); string groupPath = GetQualifiedGroupName(e, package); // Add group to Database if (!AddGroupToDatabase(groupPath, packageAsset)) { // We need to clean up the unsuccessfull add to the database e.Node.Remove(); // Show error MOG_Prompt.PromptMessage("Create object", "We were unable to add this object to the database. Aborting"); } else { e.CancelEdit = true; AttachValidatedTagToNewObjectOrGroup(package, e.Node, PackageNodeTypes.Object); // Go ahead and select our node e.Node.TreeView.SelectedNode = e.Node; } } #endregion new-package-object break; case "newpackage": #region new-package // Get the new package name string nodeFullname = MOG_Filename.JoinClassificationString(e.Node.FullPath, e.Label); // Construct a valid filename MOG_Filename[] packages = new MOG_Filename[packagePlatforms.Count]; bool duplicateExists = false; string duplicates = ""; for (int i = 0; i < packages.Length && i < packagePlatforms.Count; ++i) { MOG_Filename packageName = MOG_Filename.CreateAssetName(e.Node.Parent.FullPath, (string)packagePlatforms[i], e.Label); packages[i] = packageName; // If we have a duplicate package, store if ((duplicateExists |= ValidateNodeIsNotDuplicate(e.Node.Parent, packageName.GetAssetName())) == true) { duplicates += packageName + "\r\n"; } } // If we had duplicates, warn user and exit if (duplicateExists) { MOG_Prompt.PromptResponse("Duplicate Entry(ies) Detected!", "The following were already exist:\r\n\r\n" + duplicates); e.Node.Remove(); return; } // If we did not get a ValidPackageName (or the user decided to abort...) foreach (MOG_Filename packageName in packages) { if (!ValidatePackageExtension(e, packageName)) { return; } } bool problemAdding = false; string packageErrorPrompt = "Did not complete package add for the following: \r\n"; // Go backwards through our packages (so we can get the right platforms. for (int i = packages.Length - 1; i > -1; --i) { MOG_Filename packageName = packages[i]; // Did we get a valid package name? if (packageName != null) { // Create the package MOG_Filename createdPackage = CreatePackageForPlatform(e, packageName, parent); // If the user cancelled some part of the process or we had an error... if (createdPackage == null) { // Remove the node packageErrorPrompt += "\t" + packageName + "."; problemAdding = true; break; } TreeNode newPackageNode; // For our first platform, we've already got a node, use it... if (i == 0) { e.Node.Text = createdPackage.GetAssetName(); e.Label.ToString(); newPackageNode = e.Node; } // For subsequent platforms, add a new node... else { newPackageNode = e.Node.Parent.Nodes.Add(createdPackage.GetAssetName()); } // Now that we've got our initial information, add our tag newPackageNode.Tag = new Mog_BaseTag(newPackageNode, createdPackage.GetEncodedFilename(), this.FocusForAssetNodes, true); ((Mog_BaseTag)newPackageNode.Tag).PackageNodeType = PackageNodeTypes.Package; ((Mog_BaseTag)newPackageNode.Tag).PackageFullName = createdPackage.GetAssetFullName(); SetImageIndices(newPackageNode, GetAssetFileImageIndex(createdPackage.GetEncodedFilename())); } } // If we had a problem, let the user know and remove our package if (problemAdding) { MOG_Prompt.PromptMessage("Unable to Add Package(s)", packageErrorPrompt); e.Node.Remove(); foreach (MOG_Filename packageName in packages) { RemovePackage(packageName); } } else // Else, we were OK, so go ahead and select this node... { e.Node.TreeView.SelectedNode = e.Node; foreach (MOG_Filename packageName in packages) { // Add this package to the list of newly added packages this.CreatedPackages.Add(packageName); } // Fire the after package create event if (AfterPackageCreate != null) { AfterPackageCreate(this, EventArgs.Empty); } } #endregion new-package break; } } catch (Exception ex) { MOG_Report.ReportMessage("TreeNode Error!", "Error committing change to package, group, or package object label:\n" + ex.Message, ex.StackTrace, MOG.PROMPT.MOG_ALERT_LEVEL.ERROR); if (e.Node != null) { e.Node.Remove(); } } }
/// <summary> /// Remove a Group or Package Object from the database /// </summary> /// <param name="removeCandidate">Full path of Group or Object with /// '/' as delimiter, starting from package name.</param> /// <param name="packageAsset">The Asset that is the Package</param> /// <param name="platformGeneric"> /// Whether or not this is a platform Generic operation. /// /// This is where the "Show Platform Specific" checkbox would /// plug in from the PackageManagementTreeView /// </param> /// <returns>Bool indicating success/failure</returns> public bool RemoveGroupFromDatabase(string removeCandidate, MOG_Filename packageAsset) { try { bool success = true; // Get the current version of this package string packageVersion = MOG_DBAssetAPI.GetAssetVersion(packageAsset); // Check to see if any assets reference this if (MOG_DBPackageAPI.GetAllAssetsInPackageGroup(packageAsset, packageVersion, removeCandidate).Count == 0) { // If all is ok, remove it from the database success &= MOG_DBPackageAPI.RemovePackageGroupName(packageAsset, packageVersion, removeCandidate, MOG_ControllerProject.GetUser().GetUserName()); } else { throw (new Exception("Cannot remove object or group that is used by active assets!")); } // Are we platform generic? if (String.Compare(packageAsset.GetAssetPlatform(), "All", true) == 0) { // We are platform generic, loop through all platforms then ArrayList platforms = MOG_ControllerProject.GetProject().GetPlatforms(); for (int p = 0; p < platforms.Count; p++) { MOG_Platform platform = (MOG_Platform)platforms[p]; // Set this package to be platform specific for this platform name packageAsset = MOG_Filename.CreateAssetName(packageAsset.GetAssetClassification(), platform.mPlatformName, packageAsset.GetAssetLabel()); packageVersion = MOG_DBAssetAPI.GetAssetVersion(packageAsset); if (packageVersion.Length > 0) { // Check to see if any assets reference this if (MOG_DBPackageAPI.GetAllAssetsInPackageGroup(packageAsset, packageVersion, removeCandidate).Count == 0) { // If all is ok, remove it from the database success &= MOG_DBPackageAPI.RemovePackageGroupName(packageAsset, packageVersion, removeCandidate, MOG_ControllerProject.GetUser().GetUserName()); } else { throw (new Exception("Cannot remove object or group that is used by active assets!")); } } } } return success; } catch (Exception e) { // Get the current version of this package string packageVersion = MOG_DBAssetAPI.GetAssetVersion(packageAsset); // See if we can report to the user about why this node could not be deleted ArrayList assignedAssets = MOG_DBPackageAPI.GetAllAssetsInPackageGroup(packageAsset, packageVersion, removeCandidate); if (assignedAssets != null) { // Walk all associated assets and make a list string assets = ""; foreach (MOG_Filename assetName in assignedAssets) { if (assets.Length == 0) { assets = assetName.GetEncodedFilename(); } else { assets = assets + "\n" + assetName.GetEncodedFilename(); } } // Tell the user MOG_Prompt.PromptMessage("Remove node", "Cannot remove this node because the following assets are assigned to it:\n\n" + assets); } else { // This must have been another problem MOG_Prompt.PromptMessage("Remove node", "Cannot remove this node.\nMessage\n" + e.Message); } } return false; }
private string FixName(string name, ImportFile fullFilename, ref ArrayList properties) { string newName = null; bool succeed = false; bool cancel = false; // Have we previously specified whether or not to apply changes to all names? if (mOkToAll == false) { // Looks like we need to fix up the name... ImportAssetTreeForm mImportForm = new ImportAssetTreeForm(fullFilename); // Keep trying until we either fix the name or we cancel. while (!succeed && !cancel) { // Show BlessDialog as a modal dialog and determine if DialogResult = OK. mImportForm.ShowDialog(MogMainForm.MainApp); DialogResult rc = mImportForm.DialogResult; // Save our extension settings for multi import mShowExtensions = mImportForm.MOGShowExtensions; // Check dialog results if (rc == DialogResult.Cancel) { // This means the user clicked cancel cancel = true; } else { if (rc == DialogResult.Yes) { // This is the OkToAll button mOkToAll = true; } // Construct the new name based on the dialog fields newName = mImportForm.GetFixedAssetName(); // Always check each name to make sure it worked... succeed = CheckName(newName); if (succeed) { properties.AddRange(mImportForm.MOGPropertyArray); // Set previous settings for future imports mPreviousProperties = new ArrayList(); mPreviousProperties.AddRange(mImportForm.MOGPropertyArray); mPreviousClassifiaton = mImportForm.FinalAssetName.GetAssetClassification(); mPreviousPlatform = mImportForm.FinalAssetName.GetAssetPlatform(); } } } } else { // Since the OkToAll button was previously selected, just fix this name the same way w/o asking // Make sure to create mog names that match our previous settings of 'Extension' or 'No Extension' if (mShowExtensions) { name = DosUtils.PathGetFileName(fullFilename.mImportFilename); } else { name = DosUtils.PathGetFileNameWithoutExtension(fullFilename.mImportFilename); } MOG_Filename newAssetName = MOG_Filename.CreateAssetName(mPreviousClassifiaton, mPreviousPlatform, name); newName = newAssetName.GetAssetFullName(); // Always check each name to make sure it worked... succeed = CheckName(newName); if (succeed == false) { // Wow, this current name failed after a previous one succeeded...force the dialog to display agian. mOkToAll = false; newName = FixName(name, fullFilename, ref properties); } else { // Load previous properties set on earlier imports properties.AddRange(mPreviousProperties); } } return(newName); }