Ejemplo n.º 1
0
        private static bool IsUsingSourceFile(IFileImporter importer, ContentRef <Resource> resourceRef, string srcFilePath, string srcFileExt)
        {
            // Does the Resource or Importer recall to use this file?
            if (importer.IsUsingSrcFile(resourceRef, srcFilePath))
            {
                return(true);
            }

            // Does the system suggest that the Resource would use that file if it was opened for editing?
            string resourceSourcePath = SelectSourceFilePath(resourceRef, srcFileExt);

            if (PathHelper.ArePathsEqual(resourceSourcePath, srcFilePath))
            {
                return(true);
            }

            // Nope.
            return(false);
        }
Ejemplo n.º 2
0
        public static void NotifyFileRenamed(string filePathOld, string filePathNew)
        {
            if (string.IsNullOrEmpty(filePathOld))
            {
                return;
            }

            // Find an importer to handle the file rename
            IFileImporter importer = importers.FirstOrDefault(i => i.CanImportFile(filePathOld));

            if (importer == null)
            {
                return;
            }

            // Guess which Resources are affected and check them first
            string fileBaseName = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(filePathOld));
            List <ContentRef <Resource> > checkContent = ContentProvider.GetAvailableContent <Resource>();

            for (int i = 0; i < checkContent.Count; ++i)
            {
                ContentRef <Resource> resRef = checkContent[i];
                if (resRef.Name == fileBaseName)
                {
                    checkContent.RemoveAt(i);
                    checkContent.Insert(0, resRef);
                }
            }

            // Iterate over all existing Resources to find out which one to modify.
            List <Resource> touchedResources = null;

            foreach (ContentRef <Resource> resRef in checkContent)
            {
                if (resRef.IsDefaultContent)
                {
                    continue;
                }
                if (!importer.IsUsingSrcFile(resRef, filePathOld))
                {
                    continue;
                }
                try
                {
                    Resource res = resRef.Res;
                    if (res.SourcePath == filePathOld)
                    {
                        res.SourcePath = filePathNew;
                        if (touchedResources == null)
                        {
                            touchedResources = new List <Resource>();
                        }
                        touchedResources.Add(res);
                        // Multiple Resources referring to a single source file shouldn't happen
                        // in the current implementation of FileImport and Resource system.
                        // Might change later.
                        break;
                    }
                }
                catch (Exception)
                {
                    Log.Editor.WriteError("There was an error internally renaming a source file '{0}' to '{1}'", filePathOld, filePathNew);
                }
            }

            if (touchedResources != null)
            {
                DualityEditorApp.FlagResourceUnsaved(touchedResources);
            }
        }
Ejemplo n.º 3
0
        public static void ReimportFile(string filePath)
        {
            // Find an importer to handle the file import
            IFileImporter importer = importers.FirstOrDefault(i => i.CanImportFile(filePath));

            if (importer == null)
            {
                return;
            }

            // Guess which Resources are affected and check them first
            string fileBaseName = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(filePath));
            List <ContentRef <Resource> > checkContent = ContentProvider.GetAvailableContent <Resource>();

            for (int i = 0; i < checkContent.Count; ++i)
            {
                ContentRef <Resource> resRef = checkContent[i];
                if (resRef.Name == fileBaseName)
                {
                    checkContent.RemoveAt(i);
                    checkContent.Insert(0, resRef);
                }
            }

            // Iterate over all existing Resources to find out which one to ReImport.
            List <Resource> touchedResources = null;

            foreach (ContentRef <Resource> resRef in checkContent)
            {
                if (resRef.IsDefaultContent)
                {
                    continue;
                }
                if (!importer.IsUsingSrcFile(resRef, filePath))
                {
                    continue;
                }
                try
                {
                    importer.ReimportFile(resRef, filePath);
                    if (resRef.IsLoaded)
                    {
                        if (touchedResources == null)
                        {
                            touchedResources = new List <Resource>();
                        }
                        touchedResources.Add(resRef.Res);
                    }
                    // Multiple Resources referring to a single source file shouldn't happen
                    // in the current implementation of FileImport and Resource system.
                    // Might change later.
                    break;
                }
                catch (Exception)
                {
                    Log.Editor.WriteError("Can't re-import file '{0}'", filePath);
                }
            }

            if (touchedResources != null)
            {
                DualityEditorApp.NotifyObjPropChanged(null, new ObjectSelection((IEnumerable <object>)touchedResources));
            }
        }
Ejemplo n.º 4
0
        private static bool IsUsingSourceFile(IFileImporter importer, ContentRef<Resource> resourceRef, string srcFilePath, string srcFileExt)
        {
            // Does the Resource or Importer recall to use this file?
            if (importer.IsUsingSrcFile(resourceRef, srcFilePath))
                return true;

            // Does the system suggest that the Resource would use that file if it was opened for editing?
            string resourceSourcePath = SelectSourceFilePath(resourceRef, srcFileExt);
            if (PathOp.ArePathsEqual(resourceSourcePath, srcFilePath))
                return true;

            // Nope.
            return false;
        }