-
-
Notifications
You must be signed in to change notification settings - Fork 460
/
ApplicationDeploymentWrapper.cs
77 lines (67 loc) · 2.6 KB
/
ApplicationDeploymentWrapper.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
using System;
using System.IO;
using System.Reflection;
namespace com.clusterrr.hakchi_gui
{
public class ApplicationDeployment
{
private static bool inited = false;
private static Type applicationDeploymentType;
public static bool IsNetworkDeployed
{
get
{
if (!inited) init();
if (applicationDeploymentType == null) return false;
ExternalPropertyHelper<bool> IsNetworkDeployedProp = new ExternalPropertyHelper<bool>(applicationDeploymentType.GetProperty("IsNetworkDeployed"));
return IsNetworkDeployedProp.Value;
}
}
public static ApplicationDeployment CurrentDeployment
{
get { return new ApplicationDeployment(); }
}
public bool IsFirstRun
{
get
{
if (applicationDeploymentType == null) return false;
ExternalPropertyHelper<object> CurrentDeploymentProp = new ExternalPropertyHelper<object>(applicationDeploymentType.GetProperty("CurrentDeployment"));
object CurrentDeployment = CurrentDeploymentProp.Value;
return (bool)CurrentDeployment.GetType().GetProperty("IsFirstRun").GetValue(CurrentDeployment, null);
}
}
private static void init()
{
try
{
string runtimeDirectory = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
Assembly systemDeploymentAssembly = Assembly.LoadFrom(Path.Combine(runtimeDirectory, "System.Deployment.dll"));
applicationDeploymentType = systemDeploymentAssembly.GetType("System.Deployment.Application.ApplicationDeployment");
}
catch (FileNotFoundException e)
{
Console.WriteLine("Could not load System.Deployment.dll dynamically: {0}", e.Message);
}
finally
{
inited = true;
}
}
private class ExternalPropertyHelper<PropertyType>
{
delegate PropertyType GetFunction();
GetFunction GetValue;
public ExternalPropertyHelper(PropertyInfo externalProperty)
{
MethodInfo getMethod = externalProperty.GetGetMethod();
GetFunction getter = (GetFunction)Delegate.CreateDelegate(typeof(GetFunction), getMethod);
GetValue = getter;
}
public PropertyType Value
{
get { return GetValue(); }
}
}
}
}