-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriver.cs
57 lines (51 loc) · 2.11 KB
/
Driver.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
using System;
using System.IO;
using System.Windows.Forms;
using System.Threading;
using System.Deployment.Application;
namespace gutenberg.collect
{
public class Driver
{
[STAThread]
public static void Main(String[] args)
{
AppDomain.CurrentDomain.UnhandledException
+= delegate(object sender, UnhandledExceptionEventArgs evArgs)
{
Exception e = (Exception) evArgs.ExceptionObject;
Console.WriteLine("Unhandled exception: " + e);
Environment.Exit(1);
};
bool createdNew;
using (new Mutex(true, "Gradians.com founded in Nov 2012", out createdNew))
{
if (!createdNew) return;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
bool isNetwork = ApplicationDeployment.IsNetworkDeployed;
ApplicationContext scanbotContext =
new ScanbotContext(GetVersion(isNetwork));
if (isNetwork) ConfigureAutoStart();
Application.Run(scanbotContext);
}
}
public static string GetVersion(bool network)
{
return (network)? ApplicationDeployment.CurrentDeployment.
CurrentVersion.ToString(): Application.ProductVersion;
}
public static void ConfigureAutoStart()
{
string shortCutPath = Path.Combine(Path.Combine(Environment.GetFolderPath(
System.Environment.SpecialFolder.Programs),
PUBLISHER), PRODUCT) + ".appref-ms";
string startUpPath = Path.Combine(Environment.GetFolderPath(
System.Environment.SpecialFolder.Startup),
PRODUCT) + ".appref-ms";
File.Copy(shortCutPath, startUpPath, true);
}
private const string PUBLISHER = "Gradians Educational Services";
private const string PRODUCT = "Scanbot";
}
}