static void Main(string[] args) { Boot booter = null; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { InitApplicationUserDirectory(); InitializeLogging(args); booter = new Boot(); booter.BootStrap(); GorgonApplication.Run(booter); } catch (Exception ex) { ex.Catch(_ => GorgonDialogs.ErrorBox(null, Resources.GOREDIT_ERR_GENERAL_ERROR, Resources.GOREDIT_ERR_ERROR, ex), Log); } finally { Log?.LogEnd(); booter?.Dispose(); EditorCommonResources.UnloadResources(); } }
/// <summary> /// Function to perform the boot strapping operation. /// </summary> /// <returns>The main application window.</returns> public async void BootStrap() { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; try { // Get our initial context. SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext()); Program.Log.Print("Booting application...", LoggingLevel.All); Cursor.Current = Cursors.WaitCursor; await ShowSplashAsync(); // Initalize the common resources. EditorCommonResources.LoadResources(); _folderBrowser = new FileSystemFolderBrowseService(); _commonServices = new ViewModelInjection(Program.Log, new WaitCursorBusyState(), new MessageBoxService()); _pluginCache = new GorgonMefPlugInCache(Program.Log); _graphicsContext = GraphicsContext.Create(Program.Log); _plugInLocation = new DirectoryInfo(Path.Combine(GorgonApplication.StartupPath.FullName, "PlugIns")); if (!_plugInLocation.Exists) { Program.Log.Print($"[ERROR] Plug in path '{_plugInLocation.FullName}' was not found. No plug ins will be loaded.", LoggingLevel.Simple); GorgonDialogs.ErrorBox(null, Resources.GOREDIT_ERR_LOADING_PLUGINS); } // Get any application settings we might have. _settings = LoadSettings(); // Load our file system import/export plugins. FileSystemProviders fileSystemProviders = LoadFileSystemPlugIns(); // Load our tool plug ins. _toolPlugIns = LoadToolPlugIns(); // Load our content service plugins. _contentPlugIns = LoadContentPlugIns(); // Create the project manager for the application _projectManager = new ProjectManager(fileSystemProviders); _mainForm = new FormMain { Location = new Point(_settings.WindowBounds.Value.X, _settings.WindowBounds.Value.Y), Size = new Size(_settings.WindowBounds.Value.Width, _settings.WindowBounds.Value.Height), WindowState = FormWindowState.Normal }; await HideSplashAsync(); MainForm = _mainForm; var factory = new ViewModelFactory(_settings, fileSystemProviders, _contentPlugIns, _toolPlugIns, _projectManager, _commonServices, new ClipboardService(), new DirectoryLocateService(), new FileScanService(_contentPlugIns), _folderBrowser); FormWindowState windowState; // Ensure the window state values fall into an acceptable range. if (!Enum.IsDefined(typeof(FormWindowState), _settings.WindowState)) { windowState = FormWindowState.Maximized; } else { windowState = (FormWindowState)_settings.WindowState; } _mainForm.GraphicsContext = _graphicsContext; _mainForm.SetDataContext(factory.CreateMainViewModel(_graphicsContext.Graphics.VideoAdapter.Name)); _mainForm.Show(); _mainForm.WindowState = windowState; } finally { Cursor.Current = Cursors.Default; } }