ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/AnywhereTS-MSSQL/trunk/TSControlPanel/CPanel.Installer.cs
Revision: 167
Committed: Mon Jul 16 10:40:55 2012 UTC (10 years, 8 months ago) by william
File size: 4773 byte(s)
Log Message:

File Contents

# Content
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.ComponentModel;
5 using System.Configuration.Install;
6 using System.Linq;
7
8
9 namespace AnywhereTS
10 {
11 [RunInstaller(true)]
12 public partial class CPanel : System.Configuration.Install.Installer
13 {
14 public CPanel()
15 {
16 InitializeComponent();
17 }
18 #region install
19 public override void Install(IDictionary stateSaver)
20 {
21 base.Install(stateSaver);
22 string path = this.Context.Parameters["targetdir"];
23 Logging.UpdateLogPath(string.Format(@"{0}\logs", path));
24 using (log4net.NDC.Push("Logged from TSControlPanel.Installer"))
25 {
26 try
27 {
28 CreateRegistryConfigKeys();
29 }
30 catch (Exception ex)
31 {
32 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
33 {
34 Logging.TSControlPanelInstallerLog.Error("Install() failed.");
35 }
36 throw ex;
37 }
38 }
39 }
40 private void CreateRegistryConfigKeys()
41 {
42 try
43 {
44 Microsoft.Win32.RegistryKey key = null;
45 if (IntPtr.Size == 8)
46 { // 64 bit OS
47 //string t = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config";
48 key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\", true);
49 key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config");
50 }
51 else
52 { // 32 bit OS
53 //strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config";
54 key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", true);
55 key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config");
56 }
57
58 // AdminVersion = 2
59 key.SetValue("ControlPanelVersion", 1);
60 // RunFirstTime = 1
61 key.SetValue("RunFirstTime", 1);
62 ATSGlobals.CreateRegistryValues();
63 }
64 catch (Exception ex)
65 {
66 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
67 {
68 Logging.TSControlPanelInstallerLog.Error("CreateRegistryConfigKeys() failed.");
69 }
70 }
71 }
72 #endregion
73 #region uninstall
74 public override void Uninstall(IDictionary savedState)
75 {
76 using (log4net.NDC.Push("Logged from TSControlPanel.Installer"))
77 {
78 try
79 {
80 string path = this.Context.Parameters["targetdir"];
81 Logging.UpdateLogPath(string.Format(@"{0}\logs", path));
82 Logging.TSControlPanelInstallerLog.DebugFormat("Removing TSControlPanel Registry settings");
83 Microsoft.Win32.RegistryKey key = null;
84 if (IntPtr.Size == 8)
85 { // 64 bit OS
86 //string t = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config";
87 key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(string.Format(@"SOFTWARE\Wow6432Node\{0}\{1}", ATSGlobals.ApplicationName,"ts-config"), true);
88 key.DeleteValue("ControlPanelVersion",false);
89 }
90 else
91 { // 32 bit OS
92 //strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config";
93 key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(string.Format(@"Software\{0}\{1}", ATSGlobals.ApplicationName, "ts-config"), true);
94 key.DeleteValue("ControlPanelVersion",false);
95 }
96 Logging.TSControlPanelInstallerLog.DebugFormat("Successfully removed TSControlPanel Registry settings");
97 }
98 catch (Exception ex)
99 {
100 Logging.TSControlPanelInstallerLog.DebugFormat("Failed to remove TSControlPanel Registry settings");
101 throw ex;
102 }
103 }
104 }
105 #endregion
106 }
107 }