-
Notifications
You must be signed in to change notification settings - Fork 0
/
CatalogChooserForm.cs
408 lines (371 loc) · 13.2 KB
/
CatalogChooserForm.cs
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Windows.Forms;
using Hipparcos_DB.Properties;
using Office2007Rendering;
namespace Hipparcos_DB
{
/// <summary>
/// CatalogChooserForm : Form
/// </summary>
public partial class CatalogChooserForm : Form
{
/// <summary>
/// Settings
/// </summary>
private readonly Settings settings = new Settings();
/// <summary>
/// File names of the Hipparcos catalog
/// </summary>
private readonly string[] filesHipparcosCatalog =
{
"h_dm_com.dat.gz",
"h_dm_cor.dat.gz",
"hd_notes.doc.gz",
"hg_notes.doc.gz",
"h_dm_cor.dat.gz",
"hip_dm_g.dat.gz",
"hip_dm_o.dat.gz",
"hip_dm_v.dat.gz",
"hip_dm_x.dat.gz",
"hip_main.dat.gz",
"hip_va_1.dat.gz",
"hip_va_2.dat.gz",
"hp_auth.doc.gz",
"hp_notes.doc.gz",
"hp_refs.doc.gz",
"solar_ha.dat.gz",
"solar_hp.dat.gz",
"solar_t.dat.gz"
};
/// <summary>
/// File names of the tycho catalog
/// </summary>
private readonly string[] filesTychoCatalog =
{
"h_dm_com.dat.gz",
"h_dm_cor.dat.gz",
"hd_notes.doc.gz",
"hg_notes.doc.gz",
"h_dm_cor.dat.gz",
"hip_dm_g.dat.gz",
"hip_dm_o.dat.gz",
"hip_dm_v.dat.gz",
"hip_dm_x.dat.gz",
"hip_main.dat.gz",
"hip_va_1.dat.gz",
"hip_va_2.dat.gz",
"hp_auth.doc.gz",
"hp_notes.doc.gz",
"hp_refs.doc.gz",
"solar_ha.dat.gz",
"solar_hp.dat.gz",
"solar_t.dat.gz",
"tyc_main.dat"
};
/// <summary>
/// Culture info
/// </summary>
private static readonly CultureInfo culture = CultureInfo.CurrentUICulture;
#region Local methods
/// <summary>
/// Remove the file extension of a file name
/// </summary>
/// <param name="filename">file name</param>
/// <returns>file name without extension</returns>
private static string RemoveFileExtension(string filename) => filename.Substring(startIndex: 0, length: filename.LastIndexOf(value: ".", comparisonType: StringComparison.CurrentCulture));
/// <summary>
/// Check if a file has a specified extension
/// </summary>
/// <param name="filename">file name</param>
/// <param name="extension">file extension</param>
/// <returns>true if the file has a specified extension otherwise false</returns>
private static bool HasFileExtension(string filename, string extension) => Path.GetExtension(path: filename).ToLower(culture: culture) == extension.ToLower(culture: culture);
/// <summary>
/// Open a directory
/// </summary>
/// <param name="path">path of the directory</param>
private static void OpenDirectory(string path)
{
if (Directory.Exists(path: path))
{
Process.Start(fileName: @path);
}
}
/// <summary>
/// Set the information text in the status bar
/// </summary>
/// <param name="text">information text</param>
private void SetStatusbar(string text) => toolStripStatusLabelInfo.Text = text;
/// <summary>
/// Remove the information text in the status bar
/// </summary>
private void ClearStatusbar() => toolStripStatusLabelInfo.Text = string.Empty;
/// <summary>
/// Check if all downloadad files exist
/// </summary>
/// <param name="path">path of the files</param>
/// <param name="files">file names</param>
/// <returns>true if all files exist otherwise false</returns>
private bool CheckIfAllDownloadFilesExist(string path, string[] files)
{
bool checker = true;
foreach (string file in files)
{
if (checker)
{
if (HasFileExtension(filename: file, extension: ".gz"))
{
checker = File.Exists(path: path + RemoveFileExtension(filename: file));
}
else
{
checker = File.Exists(path: path + file);
}
}
}
return checker;
}
/// <summary>
/// Put out a error message about missing downloaded files
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions")]
private void MissingDownloadFiles()
{
MessageBox.Show(
owner: this,
text: Resources.missingDownloadFilesText2,
caption: Resources.missingDownloadFilesTitle,
buttons: MessageBoxButtons.OK,
icon: MessageBoxIcon.Error,
defaultButton: MessageBoxDefaultButton.Button1);
}
#endregion
#region Con- and Destructor
/// <summary>
/// Constructor
/// </summary>
public CatalogChooserForm() => InitializeComponent();
#endregion
#region Form* event handlers
/// <summary>
/// Load the main window
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="sender"/> and <paramref name="e"/> are not needed, but must be indicated.</remarks>
private void CatalogChooserForm_Load(object sender, EventArgs e)
{
ClearStatusbar();
ToolStripManager.Renderer = new Office2007Renderer();
}
#endregion
#region Click event handlers
/// <summary>
/// Open the information window
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="sender"/> and <paramref name="e"/> are not needed, but must be indicated.</remarks>
private void ButtonInfo_Click(object sender, EventArgs e)
{
settings.Reload();
using (AboutBoxForm formAboutBox = new AboutBoxForm())
{
formAboutBox.ShowDialog();
}
}
/// <summary>
/// Open the option window
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="sender"/> and <paramref name="e"/> are not needed, but must be indicated.</remarks>
private void ButtonOptions_Click(object sender, EventArgs e)
{
settings.Reload();
using (OptionsForm formOptions = new OptionsForm())
{
formOptions.ShowDialog();
}
}
/// <summary>
/// Close the main window
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="sender"/> and <paramref name="e"/> are not needed, but must be indicated.</remarks>
private void ButtonExit_Click(object sender, EventArgs e) => Close();
/// <summary>
/// Open the download window and download the Hipparcos catalog
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="sender"/> and <paramref name="e"/> are not needed, but must be indicated.</remarks>
private void ButtonDownloadHipparcosCatalog_Click(object sender, EventArgs e)
{
settings.Reload();
using (DownloaderForm downloaderForm = new DownloaderForm())
{
downloaderForm.SetHost(host: settings.UserHostName);
downloaderForm.SetHostUrls(files: filesHipparcosCatalog);
downloaderForm.SetCatalogDirectory(directory: settings.UserHipparcosCatalogDirectory);
downloaderForm.ShowDialog();
}
}
/// <summary>
/// Open the download window and download the Tycho catalog
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="sender"/> and <paramref name="e"/> are not needed, but must be indicated.</remarks>
private void ButtonDownloadTychoCatalog_Click(object sender, EventArgs e)
{
settings.Reload();
using (DownloaderForm downloaderForm = new DownloaderForm())
{
downloaderForm.SetHost(host: settings.UserHostName);
downloaderForm.SetHostUrls(files: filesTychoCatalog);
downloaderForm.SetCatalogDirectory(directory: settings.UserTychoCatalogDirectory);
downloaderForm.ShowDialog();
}
}
/// <summary>
/// View the Hipparcos catalog
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="sender"/> and <paramref name="e"/> are not needed, but must be indicated.</remarks>
private void ButtonViewHipparcosCatalog_Click(object sender, EventArgs e)
{
settings.Reload();
bool allFilesFound = CheckIfAllDownloadFilesExist(settings.UserHipparcosCatalogDirectory, filesHipparcosCatalog);
if (allFilesFound)
{
using (HipparcosCatalogViewerForm formHipparcosCatalogViewer = new HipparcosCatalogViewerForm())
{
formHipparcosCatalogViewer.ShowDialog();
}
}
else
{
MissingDownloadFiles();
}
}
/// <summary>
/// View the Tycho catalog
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="sender"/> and <paramref name="e"/> are not needed, but must be indicated.</remarks>
private void ButtonViewTychoCatalog_Click(object sender, EventArgs e)
{
settings.Reload();
bool allFilesFound = CheckIfAllDownloadFilesExist(settings.UserTychoCatalogDirectory, filesTychoCatalog);
if (allFilesFound)
{
using (TychoCatalogViewerForm formTychoCatalogViewer = new TychoCatalogViewerForm())
{
formTychoCatalogViewer.ShowDialog();
}
}
else
{
MissingDownloadFiles();
}
}
/// <summary>
/// Open the local directory of the Hipparcos catalog
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="sender"/> and <paramref name="e"/> are not needed, but must be indicated.</remarks>
private void ButtonOpenHipparcosDirectory_Click(object sender, EventArgs e) => OpenDirectory(path: Environment.CurrentDirectory + Path.DirectorySeparatorChar + settings.UserHipparcosCatalogDirectory);
/// <summary>
/// Open the local directory of the Tycho catalog
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="sender"/> and <paramref name="e"/> are not needed, but must be indicated.</remarks>
private void ButtonOpenTychoDirectory_Click(object sender, EventArgs e) => OpenDirectory(path: Environment.CurrentDirectory + Path.DirectorySeparatorChar + settings.UserTychoCatalogDirectory);
#endregion
#region Enter event handlers
/// <summary>
/// Set the information text in the status bar while entering a control
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameter <paramref name="e"/> is not needed, but must be indicated.</remarks>
private void SetStatusbar_Enter(object sender, EventArgs e)
{
if (sender is Control control)
{
SetStatusbar(text: control.AccessibleDescription);
}
else if (sender is ToolStripButton toolStripButton)
{
SetStatusbar(text: toolStripButton.AccessibleDescription);
}
else if (sender is ToolStripMenuItem toolStripMenuItem)
{
SetStatusbar(text: toolStripMenuItem.AccessibleDescription);
}
else if (sender is ToolStripLabel toolStripLabel)
{
SetStatusbar(text: toolStripLabel.AccessibleDescription);
}
else if (sender is ToolStripComboBox toolStripComboBox)
{
SetStatusbar(text: toolStripComboBox.AccessibleDescription);
}
else if (sender is ToolStripDropDown toolStripDropDown)
{
SetStatusbar(text: toolStripDropDown.AccessibleDescription);
}
else if (sender is ToolStripDropDownButton toolStripDropDownButton)
{
SetStatusbar(text: toolStripDropDownButton.AccessibleDescription);
}
else if (sender is ToolStripDropDownItem toolStripDropDownItem)
{
SetStatusbar(text: toolStripDropDownItem.AccessibleDescription);
}
else if (sender is ToolStripDropDownMenu toolStripDropDownMenu)
{
SetStatusbar(text: toolStripDropDownMenu.AccessibleDescription);
}
else if (sender is ToolStripProgressBar toolStripProgressBar)
{
SetStatusbar(text: toolStripProgressBar.AccessibleDescription);
}
else if (sender is ToolStripSplitButton toolStripSplitButton)
{
SetStatusbar(text: toolStripSplitButton.AccessibleDescription);
}
else if (sender is ToolStripSeparator toolStripSeparator)
{
SetStatusbar(text: toolStripSeparator.AccessibleDescription);
}
else if (sender is ToolStripStatusLabel toolStripStatusLabel)
{
SetStatusbar(text: toolStripStatusLabel.AccessibleDescription);
}
else if (sender is ToolStripTextBox toolStripTextBox)
{
SetStatusbar(text: toolStripTextBox.AccessibleDescription);
}
}
#endregion
#region Leave event handlers
/// <summary>
/// Clear the information text in the status bar while leaving a control
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="sender"/> and <paramref name="e"/> are not needed, but must be indicated.</remarks>
private void ClearStatusbar_Leave(object sender, EventArgs e) => ClearStatusbar();
#endregion
}
}