1 using System;
2 using System.Reactive.Concurrency;
3 using System.Windows.Forms;
4 using OpenBveApi.FileSystem;
5 using OpenBveApi.Interface;
6 using Reactive.Bindings;
7 using SoundManager;
8 using TrainEditor2.Audio;
9 using TrainEditor2.Graphics;
10 using TrainEditor2.Systems;
11 using TrainEditor2.Views;
12 
13 namespace TrainEditor2
14 {
15 	internal static class Program
16 	{
17 		/// <summary>The host API used by this program.</summary>
18 		internal static Host CurrentHost;
19 
20 		/// <summary>Information about the file system organization.</summary>
21 		internal static FileSystem FileSystem;
22 
23 		internal static NewRenderer Renderer;
24 
25 		internal static SoundApi SoundApi;
26 
27 		/// <summary>
28 		/// アプリケーションのメイン エントリ ポイントです。
29 		/// </summary>
30 		[STAThread]
Main()31 		private static void Main()
32 		{
33 			ReactivePropertyScheduler.SetDefault(ImmediateScheduler.Instance);
34 
35 			CurrentHost = new Host();
36 
37 			try
38 			{
39 				FileSystem = FileSystem.FromCommandLineArgs(new string[0], null);
40 				FileSystem.CreateFileSystem();
41 			}
42 			catch (Exception ex)
43 			{
44 				MessageBox.Show(Translations.GetInterfaceString("errors_filesystem_invalid") + Environment.NewLine + Environment.NewLine + ex.Message, Translations.GetInterfaceString("program_title"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
45 				return;
46 			}
47 
48 			Interface.LoadOptions();
49 
50 			Renderer = new NewRenderer(CurrentHost, Interface.CurrentOptions, FileSystem);
51 
52 			SoundApi = new SoundApi();
53 			SoundApi.Initialize(CurrentHost, SoundRange.Medium);
54 
55 			string error;
56 			if (!CurrentHost.LoadPlugins(FileSystem, Interface.CurrentOptions, out error, null, Renderer))
57 			{
58 				SoundApi.Deinitialize();
59 				MessageBox.Show(error, @"OpenBVE", MessageBoxButtons.OK, MessageBoxIcon.Error);
60 				return;
61 			}
62 
63 			Application.EnableVisualStyles();
64 			Application.SetCompatibleTextRenderingDefault(false);
65 			Application.Run(new FormEditor());
66 
67 			CurrentHost.UnloadPlugins(out error);
68 			SoundApi.Deinitialize();
69 
70 			Interface.SaveOptions();
71 		}
72 	}
73 }
74