Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }