-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
121 lines (104 loc) · 3.45 KB
/
Program.cs
File metadata and controls
121 lines (104 loc) · 3.45 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 DcsBriefop.Forms;
using DcsBriefop.Tools;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace DcsBriefop
{
static class Program
{
[STAThread]
static int Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
InitializeCulture();
ToolsMap.InitializeGMaps();
//GlobalSettings.Default_EagerLoad = new EagerLoad(EagerLoadType.UTM_MGRS);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
OptionsCommon commandLineOptions = ToolsCommandLine.ParseCommandLine(args);
if (commandLineOptions is OptionsBatch optionsBatch)
{
return MainBatch(optionsBatch);
}
else if (commandLineOptions is OptionsApp optionsApp)
{
return MainApp(optionsApp);
}
else
{
return -1;
}
}
private static int MainApp(OptionsApp optionsApp)
{
Log.ApplicationStart();
Log.Info("Starting app verb");
FrmMain f = new FrmMain();
f.Show(null);
f.FormClosed += MainFormClosed;
Application.Run(f);
return 1;
}
private static int MainBatch(OptionsBatch optionsBatch)
{
Log.ApplicationStart();
Log.Info($"Starting batch verb for {optionsBatch.Miz}");
try
{
string sMizFilePath = optionsBatch.Miz;
if (!File.Exists(sMizFilePath) && Directory.Exists(sMizFilePath))
sMizFilePath = Directory.GetFiles(sMizFilePath, "*.miz").FirstOrDefault();
if (!File.Exists(sMizFilePath))
throw new ExceptionBop($"Miz file not found for batch verb [ {optionsBatch.Miz} ]");
Log.Info($"Reading miz file content {sMizFilePath}");
BriefopManager bopManager = new BriefopManager(sMizFilePath);
Log.Info("Saving updated data");
bopManager.MizSave(null);
if (optionsBatch.BriefingOutput.HasFlag(Data.ElementBriefingOutput.Miz))
{
Log.Info($"Generating kneeboard in Miz file");
bopManager.GenerateBriefing(Data.ElementBriefingOutput.Miz);
}
if (optionsBatch.BriefingOutput.HasFlag(Data.ElementBriefingOutput.Miz))
{
Log.Info($"Generating kneeboard in directory");
bopManager.GenerateBriefing(Data.ElementBriefingOutput.Directory);
}
Log.ApplicationEnd();
return 1;
}
catch(Exception ex)
{
Log.Exception(ex);
return -1;
}
}
private static void InitializeCulture()
{
CultureInfo cultureInfo = CultureInfo.InvariantCulture;
//CultureInfo cultureInfo = new CultureInfo("fr-FR"); ;
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = cultureInfo;
}
private static void ManageException(Exception ex, [CallerMemberName] string sMemberName = "", [CallerLineNumber] int iLineNumber = 0)
{
Log.Exception(ex, sMemberName, iLineNumber);
string sMessage = $"Unhandled error.{Environment.NewLine}{ex?.Message}{Environment.NewLine}{Environment.NewLine}{ex?.InnerException}";
ToolsControls.ShowMessageBoxError(sMessage);
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
ManageException(e.ExceptionObject as Exception);
}
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
ManageException(e.Exception);
}
private static void MainFormClosed(object sender, FormClosedEventArgs e)
{
Log.ApplicationEnd();
Application.Exit();
}
}
}