forked from gw2scratch/evtc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadingForm.cs
More file actions
183 lines (166 loc) · 4.35 KB
/
LoadingForm.cs
File metadata and controls
183 lines (166 loc) · 4.35 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
using System.Linq;
using System.Threading.Tasks;
using Eto.Drawing;
using Eto.Forms;
using GW2Scratch.ArcdpsLogManager.Configuration;
using GW2Scratch.ArcdpsLogManager.Gw2Api;
using GW2Scratch.ArcdpsLogManager.Logs;
using GW2Scratch.ArcdpsLogManager.Logs.Caching;
namespace GW2Scratch.ArcdpsLogManager
{
public sealed class LoadingForm : Form
{
public LoadingForm()
{
var layout = new DynamicLayout();
Icon = Resources.GetProgramIcon();
Title = "Loading - arcdps Log Manager";
ClientSize = new Size(200, 80);
Resizable = false;
Content = layout;
layout.BeginCentered(spacing: new Size(5, 5));
{
layout.Add(null, yscale: true);
layout.AddCentered("Loading the cache");
layout.AddCentered(new ProgressBar {Indeterminate = true});
layout.Add(null, yscale: true);
}
layout.EndCentered();
if (!Settings.LogRootPaths.Any())
{
LoadComplete += (sender, args) => Task.Run(ShowInitialConfiguration);
}
else
{
LoadComplete += (sender, args) => Task.Run(LoadManager);
}
}
private void ShowInitialConfiguration()
{
Application.Instance.Invoke(() =>
{
var form = new SettingsForm();
form.Show();
Visible = false;
form.SettingsSaved += (sender, args) =>
{
Visible = true;
Task.Run(LoadManager);
};
form.Closed += (sender, args) =>
{
// If the form was closed without saving, this form is still invisible, and we want to close
// the whole program
if (!Visible)
{
Close();
}
};
});
}
private void LoadManager()
{
LogCache cache = null;
ApiData apiData = null;
do
{
try
{
cache = LogCache.LoadFromFile();
}
catch (CacheLockedException)
{
Application.Instance.Invoke(() =>
{
MessageBox.Show("Only one instance of the log manager can be running at a time.", MessageBoxType.Error);
Close();
});
return;
}
catch (Exception e)
{
bool abort = false;
Application.Instance.Invoke(() =>
{
var result = MessageBox.Show("An error has occured while loading the stored log data. " +
"This can be automatically resolved by deleting the cache file, " +
"however, all logs will have to be processed again. Delete the cache?" +
$"\n\nError: {e.Message}.", "Error loading the log cache.",
MessageBoxButtons.YesNo, MessageBoxType.Error);
if (result != DialogResult.Yes)
{
abort = true;
}
else
{
try
{
LogCache.DeleteFile();
}
catch (Exception deletionException)
{
MessageBox.Show("An error has occured while deleting the log cache. " +
$"\nError: {deletionException.Message}.", "Error deleting the log cache.", MessageBoxType.Error);
abort = true;
}
}
});
if (abort)
{
Application.Instance.Invoke(Close);
return;
}
}
} while (cache == null);
do
{
try
{
apiData = ApiData.LoadFromFile();
}
catch (Exception e)
{
bool abort = false;
Application.Instance.Invoke(() =>
{
var result = MessageBox.Show("An error has occured while loading the stored API data. " +
"This can be automatically resolved by deleting the API cache file. " +
" Delete the cache?" +
$"\n\nError: {e.Message}.", "Error loading the API cache.",
MessageBoxButtons.YesNo, MessageBoxType.Error);
if (result != DialogResult.Yes)
{
abort = true;
}
else
{
try
{
ApiData.DeleteFile();
}
catch (Exception deletionException)
{
MessageBox.Show("An error has occured while deleting the API cache. " +
$"\nError: {deletionException.Message}.", "Error deleting the API cache.", MessageBoxType.Error);
abort = true;
}
}
});
if (abort)
{
Application.Instance.Invoke(Close);
return;
}
}
} while (apiData == null);
Application.Instance.Invoke(() =>
{
var managerForm = new ManagerForm(cache, apiData);
Application.Instance.MainForm = managerForm;
managerForm.Show();
Close();
});
}
}
}