/// <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); } }
private static void ImportPrevious_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <object> args = e.Argument as List <object>; bool looseMatching = (bool)args[0]; string[] sourceFullNames = (args[1]) as string[]; //string[] sourceFullNames = e.Argument as string[]; mInvalidAssetNames.Clear(); mNewAssetNames.Clear(); mNewAssetProperties.Clear(); // Check if asset has been previously imported into the system for (int i = 0; i < sourceFullNames.Length && !worker.CancellationPending; i++) { string sourceFullName = sourceFullNames[i]; ArrayList previousSourceFiles = new ArrayList(); string message = "Importing:\n" + " " + Path.GetDirectoryName(sourceFullName) + "\n" + " " + Path.GetFileName(sourceFullName); worker.ReportProgress(i * 100 / sourceFullNames.Length, message); // Check if this is a directory? if (DosUtils.DirectoryExistFast(sourceFullName)) { // Obtain the list of contained files ArrayList containedFiles = DosUtils.FileGetRecursiveList(sourceFullName, "*.*"); if (containedFiles != null) { // Map these filenames to all the possible assetnames previousSourceFiles = MOG_ControllerProject.MapFilenamesToAssetNames(containedFiles, MOG_ControllerProject.GetPlatformName(), null); } } else { // Map this filename to all possible assetnames previousSourceFiles = MOG_ControllerProject.MapFilenameToAssetName(sourceFullName, MOG_ControllerProject.GetPlatformName(), MOG_ControllerProject.GetWorkspaceDirectory()); } // Are we loose matching? if (looseMatching) { // Did we get back only 2 files if (previousSourceFiles.Count == 2) { // Is the second one a blank? MOG_Filename file = previousSourceFiles[1] as MOG_Filename; if (file.GetFullFilename().Length == 0) { // Then remove it! previousSourceFiles.RemoveAt(1); } } } if (previousSourceFiles.Count == 1) { MOG_Filename previousFile = previousSourceFiles[0] as MOG_Filename; if (MogMainForm.MainApp.AssetManagerAutoImportCheckBox.Checked) { // Create the correct controller MOG_ControllerAsset.CreateAsset(sourceFullName, previousFile.GetEncodedFilename(), false); } else { // Create a new invalid name ImportFile invalidName = new ImportFile(sourceFullName); // Add all possible matches to this name foreach (MOG_Filename potentialMatch in previousSourceFiles) { // Make sure we have a valid match? if (potentialMatch != null && potentialMatch.GetOriginalFilename().Length > 0) { invalidName.mPotentialFileMatches.Add(potentialMatch); } } // Add to our invalidNames array mInvalidAssetNames.Add(invalidName); } } else { // Create a new invalid name ImportFile invalidName = new ImportFile(sourceFullName); // Add all possible matches to this name foreach (MOG_Filename potentialMatch in previousSourceFiles) { // Make sure we have a valid match? if (potentialMatch != null && potentialMatch.GetOriginalFilename().Length > 0) { invalidName.mPotentialFileMatches.Add(potentialMatch); } } // Add to our invalidNames array mInvalidAssetNames.Add(invalidName); } } }
private static void ImportAsOne_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <object> args = e.Argument as List <object>; bool looseFileMatching = (bool)args[0]; string[] sourceFilenames = (string[])args[1]; HybridDictionary exactAssetNames = new HybridDictionary(); HybridDictionary looseAssetNames = new HybridDictionary(); for (int i = 0; i < sourceFilenames.Length && !worker.CancellationPending; i++) { string filename = sourceFilenames[i]; ArrayList assetNames = new ArrayList(); string message = "Mapping:\n" + " " + Path.GetDirectoryName(filename) + "\n" + " " + Path.GetFileName(filename); worker.ReportProgress(i * 100 / sourceFilenames.Length, message); if (DosUtils.DirectoryExistFast(filename)) { // Obtain the list of contained files ArrayList containedFiles = DosUtils.FileGetRecursiveList(filename, "*.*"); if (containedFiles != null) { // Map these filenames to all the possible assetnames assetNames = MOG_ControllerProject.MapFilenamesToAssetNames(containedFiles, "", worker); } } else { // Map this filename to all possible assetnames assetNames = MOG_ControllerProject.MapFilenameToAssetName(filename, "", ""); } // Check if we found some assetNames? if (assetNames != null) { // Check if we are allowing loose matches? and // Check if this is a possible loose match? if (looseFileMatching && assetNames.Count == 2) { // Check if this is a blank? MOG_Filename assetName = assetNames[1] as MOG_Filename; if (assetName.GetFullFilename().Length == 0) { // Turn this into an exact match assetNames.RemoveAt(1); } } // Check if we found an exact match? if (assetNames.Count == 1) { // Add this to our list of exactAssetNames if we haven't already found it MOG_Filename assetName = assetNames[0] as MOG_Filename; if (!exactAssetNames.Contains(assetName.GetAssetFullName())) { exactAssetNames[assetName.GetAssetFullName()] = assetName; } } else { // Add all of the assetNames foreach (MOG_Filename assetName in assetNames) { // Check if this is a blank? if (assetName.GetFullFilename().Length == 0) { continue; } // Add this to our list of looseAssetNames if we haven't already found it if (!looseAssetNames.Contains(assetName.GetAssetFullName())) { looseAssetNames[assetName.GetAssetFullName()] = assetName; } } } } } // Check if we have any exact matches? if (exactAssetNames.Count > 0) { e.Result = new ArrayList(exactAssetNames.Values); } else { // Check if are allowing loose matching? if (looseFileMatching) { e.Result = new ArrayList(looseAssetNames.Values); } else { // Add back on the empty entry if it is needed if (looseAssetNames.Count == 1) { looseAssetNames[""] = new MOG_Filename(""); } // Return our list of foundAssets e.Result = new ArrayList(looseAssetNames.Values); } } }
private void InitializeAssetNames(ArrayList sourceFiles) { RenameListView.Items.Clear(); InitializePlatformComboBox(); string listOfBlessedAssets = ""; // Check for presence of wildcards foreach (string fullFilename in sourceFiles) { MOG_Filename asset = new MOG_Filename(fullFilename); // If this Asset has been previously blessed... if (CheckIfAssetHasBeenBlessed(asset)) { listOfBlessedAssets += asset.GetAssetFullName() + "\r\n"; } // Get the imported filenames ArrayList importFiles = DosUtils.FileGetRecursiveList(MOG_ControllerAsset.GetAssetImportedDirectory(MOG_Properties.OpenFileProperties(fullFilename + "\\Properties.info")), "*.*"); if (importFiles.Count > 1) { // If there are more that one, then we cannot rename the files of this asset RenameFiles.Checked = false; RenameFiles.Enabled = false; importFilename = "*Complex asset*"; } else { String importFile = importFiles[0] as string; // Does this asset label match the imported filename? if (string.Compare(DosUtils.PathGetFileNameWithoutExtension(importFile), DosUtils.PathGetFileNameWithoutExtension(asset.GetAssetLabel()), true) == 0) { // All is good then importFilename = DosUtils.PathGetFileName(importFile); } else { // We cannot rename the files of this asset because the label and the imported filename do not match RenameFiles.Checked = false; RenameFiles.Enabled = false; importFilename = string.Format("Asset label({0}) and imported filename({1}) do not match!", DosUtils.PathGetFileNameWithoutExtension(asset.GetAssetLabel()), DosUtils.PathGetFileNameWithoutExtension(importFile)); } } mFullFilename = fullFilename; ListViewItem item = RenameListView.Items.Add(asset.GetAssetFullName()); item.SubItems.Add(asset.GetAssetFullName()); item.SubItems.Add(asset.GetAssetEncodedPath()); item.SubItems.Add(importFilename); item.Selected = true; CheckStringForMatch(ref mCommonClass, asset.GetAssetClassification()); CheckStringForMatch(ref mCommonPlatform, asset.GetAssetPlatform()); CheckStringForMatch(ref mCommonLabel, asset.GetAssetLabel()); } // If we have any Blessed Assets and we don't have privilege to rename them, warn the user if (listOfBlessedAssets.Length > 0 && !CheckPrivilegeToRename()) { MOG_Prompt.PromptMessage("Insufficient privileges to rename already blessed assets", "You do not have permission to rename these previously blessed assets:\r\n" + listOfBlessedAssets); } // Else, If we have any Blessed Assets, warn user about the rename else if (listOfBlessedAssets.Length > 0) { MOG_Prompt.PromptMessage("Inbox renames don't rename previously blessed assets", "The following blessed assets will still exist when renamed assets are blessed:\r\n" + listOfBlessedAssets); } RenameListView.Select(); InitializeTextBoxes(mCommonClass, mCommonPlatform, mCommonLabel); // Make it so that our user will hopefully type over the "*" when assigning a classification... if (mCommonClass == "*") { this.RenameNewClassNameTextBox.SelectAll(); } bInitialized = true; } // end ()