internal static ICloneSurrogate GetSurrogateFor(TypeInfo type) { if (surrogates == null) { surrogates = CoheeApp.GetAvailCoheeTypes(typeof(ICloneSurrogate)) .Select(t => t.CreateInstanceOf()) .OfType <ICloneSurrogate>() .NotNull() .ToList(); surrogates.StableSort((s1, s2) => s1.Priority - s2.Priority); } for (int i = 0; i < surrogates.Count; i++) { if (surrogates[i].MatchesType(type)) { return(surrogates[i]); } } return(null); }
private static void GatherAvailable() { availableCodecs = new List <IImageCodec>(); foreach (TypeInfo imageCodecType in CoheeApp.GetAvailCoheeTypes(typeof(IImageCodec))) { if (imageCodecType.IsAbstract) { continue; } if (imageCodecType.IsInterface) { continue; } IImageCodec codec = imageCodecType.CreateInstanceOf() as IImageCodec; if (codec != null) { availableCodecs.Add(codec); } } availableCodecs.StableSort((a, b) => b.Priority > a.Priority ? 1 : -1); }
private static object EditorHintImageResolver(string manifestResourceName) { Assembly[] allAssemblies = CoheeApp.GetCoheeAssemblies().Concat(GetCoheeEditorAssemblies()).Distinct().ToArray(); foreach (Assembly assembly in allAssemblies) { string[] resourceNames = assembly.GetManifestResourceNames(); if (resourceNames.Contains(manifestResourceName)) { // Since images require to keep their origin stream open, we'll need to copy it to gain independence. using (Stream stream = assembly.GetManifestResourceStream(manifestResourceName)) using (Bitmap bitmap = Bitmap.FromStream(stream) as Bitmap) { Bitmap independentBitmap = new Bitmap(bitmap.Width, bitmap.Height); independentBitmap.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution); using (Graphics graphics = Graphics.FromImage(independentBitmap)) { graphics.DrawImageUnscaled(bitmap, 0, 0); } return(independentBitmap); } } } return(null); }
public static void Init(MainWindow mainWindow) { CoheeEditorApp.mainWindow = mainWindow; // Set up an in-memory data log so plugins can access the log history when needed editorLogOutput = new EditorLogOutput(); Logs.AddGlobalOutput(editorLogOutput); // Create working directories, if not existing yet. if (!Directory.Exists(CoheeApp.DataDirectory)) { Directory.CreateDirectory(CoheeApp.DataDirectory); using (FileStream s = File.OpenWrite(Path.Combine(CoheeApp.DataDirectory, "WorkingFolderIcon.ico"))) { Properties.GeneralRes.IconWorkingFolder.Save(s); } using (StreamWriter w = new StreamWriter(Path.Combine(CoheeApp.DataDirectory, "desktop.ini"))) { w.WriteLine("[.ShellClassInfo]"); w.WriteLine("ConfirmFileOp=0"); w.WriteLine("NoSharing=0"); w.WriteLine("IconFile=WorkingFolderIcon.ico"); w.WriteLine("IconIndex=0"); w.WriteLine("InfoTip=This is Dualitors working folder"); } DirectoryInfo dirInfo = new DirectoryInfo(CoheeApp.DataDirectory); dirInfo.Attributes |= FileAttributes.System; FileInfo fileInfoDesktop = new FileInfo(Path.Combine(CoheeApp.DataDirectory, "desktop.ini")); fileInfoDesktop.Attributes |= FileAttributes.Hidden; FileInfo fileInfoIcon = new FileInfo(Path.Combine(CoheeApp.DataDirectory, "WorkingFolderIcon.ico")); fileInfoIcon.Attributes |= FileAttributes.Hidden; } if (!Directory.Exists(CoheeApp.PluginDirectory)) { Directory.CreateDirectory(CoheeApp.PluginDirectory); } if (!Directory.Exists(EditorHelper.SourceDirectory)) { Directory.CreateDirectory(EditorHelper.SourceDirectory); } if (!Directory.Exists(EditorHelper.SourceMediaDirectory)) { Directory.CreateDirectory(EditorHelper.SourceMediaDirectory); } if (!Directory.Exists(EditorHelper.SourceCodeDirectory)) { Directory.CreateDirectory(EditorHelper.SourceCodeDirectory); } //// Initialize Package Management system //packageManager = new PackageManager(); // Initialize Cohee Core EditorHintImageAttribute.ImageResolvers += EditorHintImageResolver; CoheeApp.CorePluginManager.PluginsReady += CoheeApp_CorePluginsReady; CoheeApp.Init(CoheeApp.ExecutionEnvironment.Editor, CoheeApp.ExecutionContext.Editor, new DefaultAssemblyLoader(), null); // Initialize the plugin manager for the editor. We'll use the same loader as the core. editorPluginManager.Init(CoheeApp.CorePluginManager.AssemblyLoader); // Need to load editor plugins before initializing the graphics context, so the backend is available editorPluginManager.LoadPlugins(); // Need to initialize graphics context and default content before instantiating anything that could require any of them InitMainGraphicsContext(); CoheeApp.InitPostWindow(); //LoadUserData(); editorPluginManager.InitPlugins(); // Allow the engine to run appSuspended = false; }
public static bool Terminate(bool byUser) { bool cancel = false; //// Display safety message boxes if the close operation is triggered by the user. //if (byUser) //{ // var unsavedResTemp = CoheeEditorApp.UnsavedResources.ToArray(); // if (unsavedResTemp.Any()) // { // string unsavedResText = unsavedResTemp.Take(5).ToString(r => r.GetType().GetTypeCSCodeName(true) + ":\t" + r.FullName, "\n"); // if (unsavedResTemp.Count() > 5) // unsavedResText += "\n" + string.Format(Properties.GeneralRes.Msg_ConfirmQuitUnsaved_Desc_More, unsavedResTemp.Count() - 5); // MessageBoxResult result = MessageBox.Show( // string.Format(Properties.GeneralRes.Msg_ConfirmQuitUnsaved_Desc, "\n\n" + unsavedResText + "\n\n"), // Properties.GeneralRes.Msg_ConfirmQuitUnsaved_Caption, // MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation); // if (result == MessageBoxResult.Yes) // { // Sandbox.Stop(); // CoheeEditorApp.SaveAllProjectData(); // } // else if (result == MessageBoxResult.Cancel) // cancel = true; // } //} // Did we cancel it? Return false. if (cancel) { return(false); } // Otherwise, actually start terminating. // From this point on, there's no return - need to re-init the editor afterwards. if (Terminating != null) { Terminating(null, EventArgs.Empty); } // Unregister events EditorHintImageAttribute.ImageResolvers -= EditorHintImageResolver; CoheeApp.CorePluginManager.PluginsReady -= CoheeApp_CorePluginsReady; //mainForm.Activated -= mainForm_Activated; //mainForm.Deactivate -= mainForm_Deactivate; //Scene.Leaving -= Scene_Leaving; //Scene.Entered -= Scene_Entered; //Application.Idle -= Application_Idle; //Resource.ResourceSaved -= Resource_ResourceSaved; //Resource.ResourceSaving -= Resource_ResourceSaving; //Resource.ResourceDisposing -= Resource_ResourceDisposing; //FileEventManager.PluginsChanged -= FileEventManager_PluginsChanged; //editorObjects.GameObjectsAdded -= editorObjects_GameObjectsAdded; //editorObjects.GameObjectsRemoved -= editorObjects_GameObjectsRemoved; //editorObjects.ComponentAdded -= editorObjects_ComponentAdded; //editorObjects.ComponentRemoving -= editorObjects_ComponentRemoved; //// Terminate editor actions //editorActions.Clear(); //// Terminate secondary editor components //UndoRedoManager.Terminate(); //FileEventManager.Terminate(); //HelpSystem.Terminate(); //Sandbox.Terminate(); //PreviewProvider.Terminate(); //ConvertOperation.Terminate(); //AssetManager.Terminate(); //DesignTimeObjectData.Terminate(); //// Shut down the editor backend //CoheeApp.ShutdownBackend(ref graphicsBack); // Shut down the plugin manager editorPluginManager.Terminate(); // Terminate Cohee CoheeApp.Terminate(); // Remove the global in-memory log if (editorLogOutput != null) { Logs.RemoveGlobalOutput(editorLogOutput); editorLogOutput = null; } return(true); }