Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCeRiAl <ikhatib@gmail.com>2017-11-17 01:20:08 +0300
committerCeRiAl <ikhatib@gmail.com>2017-11-21 01:19:21 +0300
commite3c5fbefb6a42483821d395f935b7356e9503872 (patch)
tree6c08b6c812c717d9a1059100ceb8189aa8335f64 /ApplicationDeploymentWrapper.cs
parentdda38610b77156db2604b4b84912b985e0a64337 (diff)
Add new ApplicationDeploymentWrapper class
Load System.Deployment.dll dynamically if possible, otherwise use a dummy implementation (this enables building and running the exact same executable on Windows and Linux)
Diffstat (limited to 'ApplicationDeploymentWrapper.cs')
-rw-r--r--ApplicationDeploymentWrapper.cs77
1 files changed, 77 insertions, 0 deletions
diff --git a/ApplicationDeploymentWrapper.cs b/ApplicationDeploymentWrapper.cs
new file mode 100644
index 00000000..00df6286
--- /dev/null
+++ b/ApplicationDeploymentWrapper.cs
@@ -0,0 +1,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(); }
+ }
+ }
+ }
+}