/// <summary> /// Constructor takes an arraylist of files. We take this files and create a ram tree /// </summary> /// <param name="files"></param> public DirectorySet(ArrayList files) { mBank = new HybridDictionary(true); foreach (string file in files) { try { AddFilename(Path.GetDirectoryName(file), file, false); } catch (Exception e) { if (e.Message == "trying to add empty key") { string message = "Trying to add an asset with an empty key!\n\n" + "Binary Name: " + file + "\n"; MOG_Prompt.PromptMessage("Directory Set", message, e.StackTrace); } else if (e.Message == "duplicate key") { string message = "Two or more duplicate asset files are named the same and are pointing to the same target in your project!\n\n" + "Binary Name: " + file + "\n" + "Asset Name(s):" + "\n\tCan't determine without valid local workspace!\n" + "\nRemove one from the project trees to fix this conflict! Until this is fixed this asset will not be shown in your asset tree."; if (MOG_ControllerProject.GetCurrentSyncDataController() != null) { string duplicateAssets = ""; ArrayList Assets = MOG_ControllerProject.MapFilenameToAssetName(file, MOG_ControllerProject.GetCurrentSyncDataController().GetPlatformName()); if (Assets != null) { foreach (MOG_Filename asset in Assets) { // Make sure we have a valid match? if (asset != null && asset.GetOriginalFilename().Length > 0) { if (duplicateAssets.Length == 0) { duplicateAssets = "Asset Name(s): \n\t" + asset.GetAssetFullName(); } else { duplicateAssets = duplicateAssets + "\n\t" + asset.GetAssetFullName(); } } } } message = "Two or more duplicate asset files are named the same and are pointing to the same target in your project!\n\n" + "Binary Name: " + file + "\n" + duplicateAssets + "\n" + "\nRemove one of the above Assets from the project trees to fix this conflict! Until this is fixed this asset will not be shown in your tree."; } MOG_Prompt.PromptMessage("Directory Set", message, e.StackTrace); } else { string message = "Unhandled exception occurred while trying to add this file.\n" + "FILE: " + file + "\n\n" + e.Message; MOG_Prompt.PromptMessage("Directory Set", message, e.StackTrace); } } } }
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); } } }
public static MOG_Property RepairProperty(MOG_Property propertyObject) { MOG_Property fixedPropertyObject = null; string key = propertyObject.mKey; string section = propertyObject.mSection; string propertySection = propertyObject.mPropertySection; string propertyKey = propertyObject.mPropertyKey; string propertyValue = propertyObject.mPropertyValue; MOG_Property tempProperty = MOG_PropertyFactory.MOG_Relationships.New_RelationshipAssignment("", "", "", ""); MOG_Property tempPackageProperty = MOG_PropertyFactory.MOG_Relationships.New_PackageAssignment("", "", ""); MOG_Property tempSourceFileProperty = MOG_PropertyFactory.MOG_Relationships.New_AssetSourceFile(""); // Check if this property is a package relationship? if (string.Compare(section, tempPackageProperty.mSection, true) == 0) { string assetName = MOG_ControllerPackage.GetPackageName(propertyKey); string groups = MOG_ControllerPackage.GetPackageGroups(propertyKey); string objects = MOG_ControllerPackage.GetPackageObjects(propertyKey); // Remap various properties making sure we correct any problem areas MOG_Filename assetFilename = null; // Check if this property is a SourceFile relationship? if (string.Compare(propertySection, tempSourceFileProperty.mPropertySection, true) == 0) { // Check if the specified file is within the library? if (MOG_ControllerLibrary.IsPathWithinLibrary(propertyKey)) { // Map this library file to a real asset name assetFilename = MOG_ControllerProject.MapFilenameToLibraryAssetName(assetName, MOG_ControllerProject.GetPlatformName()); if (assetFilename != null) { fixedPropertyObject = MOG_PropertyFactory.MOG_Relationships.New_AssetSourceFile(assetFilename.GetFullFilename()); } } } else { // Try to find the assetname for the specified asset ArrayList assets = MOG_ControllerProject.MapFilenameToAssetName(assetName, MOG_ControllerProject.GetPlatformName(), MOG_ControllerProject.GetWorkspaceDirectory()); if (assets == null || assets.Count == 0) { // The package could not be found if (string.Compare(propertySection, tempPackageProperty.mPropertySection, true) == 0) { // Check if we actually had something specified? if (assetName.Length > 0) { // Set the deafult packageFilename info string assetClassification = ""; string assetPlatformName = "All"; string assetLabel = DosUtils.PathGetFileNameWithoutExtension(assetName); string syncTargetPath = DosUtils.PathGetDirectoryPath(assetName); // Check if the assetName was already a valid MOG_Filename? MOG_Filename packageFilename = new MOG_Filename(assetName); if (packageFilename.GetAssetClassification().Length > 0) { assetClassification = MOG_Filename.AppendAdamObjectNameOnClassification(packageFilename.GetAssetClassification()); } if (packageFilename.GetAssetPlatform().Length > 0) { assetPlatformName = packageFilename.GetAssetPlatform(); } if (packageFilename.GetAssetLabel().Length > 0) { assetLabel = packageFilename.GetAssetLabel(); } // Prompt user to complete the unknown information about this packageFile string message = "MOG has detected a new package assignment to a previously non-existing package. Please complete the following red fields so that a proper package can be created in MOG."; PackageCreator creator = new PackageCreator(); creator.Classification = assetClassification; creator.PackageName = assetLabel; creator.SyncTarget = syncTargetPath; creator.Platform = assetPlatformName; if (creator.ShowDialog() == DialogResult.OK) { // Use this newly created packageFilename as our assetFilename to be fixed assetFilename = creator.AssetName; } else { // The PackageName is invalid message = "New Package Not Created.\n" + "The user chose not to create a new package."; MOG_Report.ReportMessage("Package Assignment", message, Environment.StackTrace, MOG_ALERT_LEVEL.ERROR); } } else { // The PackageName is invalid string message = "Invalid PackageName specified.\n" + "The packaged asset was not assigned to a package."; MOG_Report.ReportMessage("Package Assignment", message, Environment.StackTrace, MOG_ALERT_LEVEL.ERROR); } } } else { // Always use the first one assetFilename = assets[0] as MOG_Filename; MOG_ControllerProject.MapFilenameToAssetName_WarnAboutAmbiguousMatches(assetName, assets); } // Now do we finally have a package asset name? if (assetFilename != null) { // Replace the propertyObject with the fixed up one fixedPropertyObject = MOG_PropertyFactory.MOG_Relationships.New_RelationshipAssignment(propertySection, assetFilename.GetAssetFullName(), groups, objects); } } } // Check if we fixed the property? if (fixedPropertyObject != null) { return(fixedPropertyObject); } return(propertyObject); }
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); } } }