Exemple #1
0
        /// <summary>
        /// Overridden project Close function
        /// </summary>
        /// <returns></returns>
        public override bool Close()
        {
            if (Scene != null)
            {
                Scene.Close();
            }
            EditorApp.Project = null;
            EditorApp.Scene   = null;

            //Remove the project directory from the engine base data directory
            EditorApp.EngineManager.File_RemoveDataDirectory(ProjectDir);
            RemoveAllCustomDataDirectories();

            // empty all class managers (before engine.DeInit so that native code can be executed)
            EditorManager.EngineManager.RefreshEntityClassManager();
            EditorManager.EngineManager.RefreshShaderEffectManager();
            EditorManager.EngineManager.RefreshComponentClassManager();

            EditorApp.EngineManager.DeInitEngine();

            // Unload plugins after DeInit (when all references to plugin components/entities are gone)
            EditorManager.EngineManager.Plugins_UnloadAllEnginePlugins();

            // Unload the project specific editor plugins
            PluginManager.UnloadPlugins(EditorPlugins);
            EditorManager.DeInitializeNonStandardPlugins();

            EditorPlugins = null;

            ProjectDir = "";
            FileName   = "";

            // Deactivate RCS system
            UpdateRCSStatus(false);

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Actually load the project
        /// </summary>
        /// <param name="filename"></param>
        public void Load(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("Project file not found.");
            }

            try
            {
                SendProjectLoadingEvent();

                EditorManager.EngineManager.InitFileHandling();
                EditorManager.EngineManager.SetBaseDataPath(EditorManager.BaseDataDir);
                EditorManager.EngineManager.SetEditorDataPath(EditorManager.AppDataDir);

                _deinitStack.Push(() =>
                {
                    //Remove the project directory from the engine base data directory
                    EditorApp.EngineManager.File_RemoveSearchPath(ProjectSearchPath);
                    RemoveAllCustomDataDirectories();

                    EditorApp.EngineManager.File_RemoveFileSystem("workspace");
                });

                m_filename = filename;
                string projectDirNoEndingSlash = Path.GetDirectoryName(filename).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
                ProjectDir = projectDirNoEndingSlash + Path.DirectorySeparatorChar;

                //Nothing to read at the moment...
                //We don't want to put user specific data in the project file anyway
                //Handle file string earlier to use RCS.
                this.FileName = Path.GetFileName(filename);

                _deinitStack.Push(() =>
                {
                    ProjectDir = "";
                    FileName   = "";
                });

                EditorManager.EngineManager.SetProjectPath(ProjectDir);

                // Open MultiUser Editing Dialog
                if (!TestManager.IsRunning && !EditorManager.SilentMode && EditorManager.Settings.OpenMultiUserEditingDialogOnProjectLoad)
                {
                    if (DetectFolderType() != FolderType_e.Local || EditorManager.Settings.OpenMultiUserEditingDialogForLocalProjects)
                    {
                        MultiUserEditingDlg dlg = new MultiUserEditingDlg();
                        dlg.ShowInTaskbar = false;
                        dlg.Project       = this;
                        if (dlg.ShowDialog() != DialogResult.OK)
                        {
                            throw new Exception("No multi-user editing option selected.");
                        }
                    }
                }

                // Select and activate the right RCS system. User cannot abort this operation.
                // If updating the RCS status fails we break up loading the project.
                if (!UpdateRCSStatus(true))
                {
                    throw new Exception("Failed to update RCS status.");
                }

                // Setup RCS changelist
                if (ManagedBase.RCS.GetProvider() != null)
                {
                    string sChangeListDescription = "vForge";
                    if (EditorManager.Settings.CreateSeparateChangelists)
                    {
                        string sDirName = Path.GetFileName(projectDirNoEndingSlash);
                        sChangeListDescription += " - " + sDirName;
                    }
                    string sChangelist = ManagedBase.RCS.GetProvider().GetChangelistByDescription(sChangeListDescription, true);
                    if (sChangelist != null)
                    {
                        ManagedBase.RCS.GetProvider().SetChangelist(sChangelist);
                    }
                }

                _deinitStack.Push(() =>
                {
                    // Deactivate RCS system
                    UpdateRCSStatus(false);
                });

                if (!EnsureValidWorkspace())
                {
                    throw new Exception("No valid workspace found.");
                }

                // optionally load plugins from sub directory
                string additionalPluginDir = AdditionalPluginDir;

                EditorManager.ProfileManager.InitNewProject(ProjectDir);

                // Notify the asset manager of automatically added data directories
                EditorManager.AssetManager.AddDataDirectory(
                    EditorManager.IsCustomBaseDataDir ? ":base_data" : EditorManager.DefaultBaseDataSearchPath, "Base", false, false, true);

                // If a custom simulation data path has been set, add it as a file system.
                if (EditorManager.IsCustomSimulationDataDir)
                {
                    EditorManager.EngineManager.File_AddFileSystem("simulation_data", EditorManager.SimulationDataDir, FileSystemFlags.Writable);
                }
                // Add the search path for simulation data
                this.AddCustomDataDirectory(
                    EditorManager.IsCustomSimulationDataDir ? ":simulation_data" : EditorManager.DefaultSimulationDataSearchPath, "Simulation", true, true);

                // Load the project specific editor plugins (install an assembly resolver to load the
                // assemblies from the project directory)
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ProjectPlugins_AssemblyResolve);
                EditorPlugins = new EditorPluginCollection();
                PluginManager.LoadPlugins(ProjectDir, EditorPlugins);
                if (additionalPluginDir != null)
                {
                    PluginManager.LoadPlugins(additionalPluginDir, EditorPlugins);
                }
                AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(ProjectPlugins_AssemblyResolve);

                //Load the entity plugins (so they can register their application) before engine init
                EditorManager.EngineManager.Plugins_LoadAllEnginePlugins(projectDirNoEndingSlash);
                if (additionalPluginDir != null)
                {
                    EditorManager.EngineManager.Plugins_LoadAllEnginePlugins(additionalPluginDir);
                }

                // load the manifest file which may contain additional engine plugins:
                EditorManager.LoadManifestFile(this, Path.Combine(projectDirNoEndingSlash, "vForgeManifest.txt"));

                // Find out whether the project directory is already added as a search path; i.e., whether we open
                // a project in one of the previously added directories. If yes, set the project search path
                // accordingly and don't add another search path. Otherwise, add a search path for the project.
                String searchPathOfProjectDir = EditorManager.EngineManager.File_GetSearchPathForPath(
                    filename, FileSystemAccessMode.Read, FileSystemElementType.File);
                if (searchPathOfProjectDir != null)
                {
                    ProjectSearchPath = searchPathOfProjectDir;
                }
                else
                {
                    EditorManager.EngineManager.File_AddSearchPath(ProjectSearchPath, SearchPathFlags.Writable | SearchPathFlags.PathMustExist);
                    EditorManager.AssetManager.AddDataDirectory(ProjectSearchPath, new DirectoryInfo(ProjectDir).Name, false, true, true);
                }

                _deinitStack.Push(() =>
                {
                    // Unload plugins after DeInit (when all references to plugin components/entities are gone)
                    EditorManager.EngineManager.Plugins_UnloadAllEnginePlugins();

                    // Unload the project specific editor plugins
                    PluginManager.UnloadPlugins(EditorPlugins);
                    EditorManager.DeInitializeNonStandardPlugins();

                    EditorPlugins = null;
                });

                EditorManager.EngineManager.RefreshEntityClassManager();
                EditorManager.EngineManager.RefreshShaderEffectManager();
                EditorManager.EngineManager.RefreshComponentClassManager();

                //Initialize the engine
                if (!EditorApp.EngineManager.InitEngine())
                {
                    throw new Exception("Failed to initialize engine. Please check the engine log for more details.");
                }

                _deinitStack.Push(() =>
                {
                    // empty all class managers (before engine.DeInit so that native code can be executed)
                    EditorManager.EngineManager.RefreshEntityClassManager();
                    EditorManager.EngineManager.RefreshShaderEffectManager();
                    EditorManager.EngineManager.RefreshComponentClassManager();

                    EditorApp.EngineManager.DeInitEngine();
                });
            }
            catch
            {
                Close();
                throw;
            }
        }