-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
67 lines (62 loc) · 2.21 KB
/
Program.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
using NeoFlyExport.Properties;
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace NeoFlyExport
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
if (CommandLine.Arguments.Count == 0)
{
SearchExternalViewers();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
else
{
try
{
NeoFlyData neoFlyData = new NeoFlyData();
neoFlyData.Load();
neoFlyData.ExportToGPXFile(CommandLine.Arguments);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "NeoFlyExport error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
/// <summary>
/// Search for installed GPX viewers and add them automatically
/// </summary>
static void SearchExternalViewers()
{
string[] regKeys = new string[] {
@"HKEY_CLASSES_ROOT\Applications\GPXSee.exe\shell\open\command",
@"HKEY_CLASSES_ROOT\Viking File\shell\edit\command"
};
foreach (string regKey in regKeys)
{
// Registry command
string commandLine = (string)Microsoft.Win32.Registry.GetValue(regKey, "", null);
if (commandLine == null)
continue;
// Exe file
commandLine = commandLine.Substring(0, commandLine.IndexOf(".exe", StringComparison.InvariantCultureIgnoreCase) + 4).Trim('"');
if (!File.Exists(commandLine))
continue;
// Add the viewer to user settings
if (!Settings.Default.ExternalViewers.Contains(commandLine, StringComparer.InvariantCultureIgnoreCase))
Settings.Default.ExternalViewers.Add(commandLine);
}
}
}
}