Repository navigation
Expand file tree
/
Copy pathApplication.cs
More file actions
121 lines (96 loc) · 2.87 KB
/
Copy pathApplication.cs
File metadata and controls
121 lines (96 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Data;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using SqlNado;
using SyslogLogging;
namespace Mhora;
internal static class Application
{
private static string _workingDir;
private static LoggingModule _log;
private static DataTable _countryCodes;
internal static bool Running
{
get;
private set;
}
internal static Assembly ActiveAssembly => Running ? Assembly.GetEntryAssembly() : Assembly.GetExecutingAssembly();
internal static string WorkingDir => _workingDir ??= Path.GetDirectoryName(ActiveAssembly.Location);
internal static Version Version => Assembly.GetExecutingAssembly().GetName().Version;
internal static LoggingModule Log => _log ??= new LoggingModule();
internal static string VersionString
{
get
{
var versionString = Version.ToString();
switch (Version.Build)
{
case 0:
{
versionString += " (beta)";
}
break;
case 1:
{
versionString += " (release candidate)";
}
break;
case 2:
{
}
break;
default:
{
versionString += " (?)";
}
break;
}
return versionString;
}
}
private static SQLiteDatabase _worldDb;
public static SQLiteDatabase WorldDb => _worldDb;
public static async Task InitDb()
{
_worldDb = new SQLiteDatabase("world.db");
}
private const string LogFile = "debug.txt";
public static MainForm MainForm => new MainForm();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
private static void Main(string[] args)
{
Running = true;
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionEventRaised;
System.Windows.Forms.Application.ThreadException += ThreadExceptionRaised;
System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
if (File.Exists(LogFile))
{
File.Delete(LogFile);
}
Log.Settings.LogFilename = Path.Combine(WorkingDir, LogFile);
Log.Settings.FileLogging = FileLoggingMode.SingleLogFile;
System.Windows.Forms.Application.Run(MainForm);
_worldDb.Dispose();
AppDomain.CurrentDomain.UnhandledException -= UnhandledExceptionEventRaised;
System.Windows.Forms.Application.ThreadException -= ThreadExceptionRaised;
Running = false;
}
private static void ThreadExceptionRaised(object sender, ThreadExceptionEventArgs e)
{
Log.Exception(e.Exception);
}
private static void UnhandledExceptionEventRaised(object sender, UnhandledExceptionEventArgs e)
{
var exception = (Exception) e.ExceptionObject;
Log.Exception(exception);
}
}