-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSettings.cs
131 lines (120 loc) · 4.33 KB
/
Settings.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Drawing;
using System.IO;
using System.Xml.Serialization;
namespace EventHandlerExplorer
{
/// <summary>
/// Application settings
/// </summary>
public class Settings
{
#pragma warning disable 1591
[XmlElement("LoadWebsOnStart")]
public bool LoadWebsOnStart { get; set; }
[XmlElement("AutoIisReset")]
public bool AutoIisReset { get; set; }
[XmlElement("ScriptGacInstall")]
public string ScriptGacInstall { get; set; }
[XmlElement("ScriptGacRemove")]
public string ScriptGacRemove { get; set; }
[XmlIgnore]
public string ScriptIisReset { get; set; }
#pragma warning restore 1591
private readonly FormMain parent;
/// <summary>
/// Default settings
/// </summary>
public Settings()
{
// Default settings
LoadWebsOnStart = false;
AutoIisReset = false;
ScriptGacInstall= @"[System.Reflection.Assembly]::Load('System.EnterpriseServices, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a');$publish = New-Object System.EnterpriseServices.Internal.Publish;$publish.GacInstall('$fullpath');";
ScriptGacRemove = @"[System.Reflection.Assembly]::Load('System.EnterpriseServices, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a');$publish = New-Object System.EnterpriseServices.Internal.Publish;$publish.GacRemove('$fullpath');";
ScriptIisReset = @"iisreset /noforce";
}
/// <summary>
/// Initialize parent to log to listview
/// </summary>
public Settings(FormMain form) : this()
{
this.parent = form;
}
/// <summary>
/// Settings Folder, static property
/// </summary>
private static string SettingsFolder
{
get
{
string folder = string.Empty;
try
{
folder = Environment.CurrentDirectory;
}
catch
{
// Just in case, handle permissions issue. "User\ApplicationData" will have permissions in any case
folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
}
return folder;
}
}
/// <summary>
/// Settings File, static property
/// </summary>
private static string SettingsFile
{
get
{
return Path.Combine(SettingsFolder, "EventHandlerExplorerSettings.xml");
}
}
/// <summary>
/// Deserialize settings
/// </summary>
public void LoadSettings()
{
try
{
if (File.Exists(SettingsFile))
{
using (Stream stream = File.OpenRead(SettingsFile))
{
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
Settings settings = new Settings();
settings = (Settings)serializer.Deserialize(stream);
this.LoadWebsOnStart = settings.LoadWebsOnStart;
this.AutoIisReset = settings.AutoIisReset;
this.ScriptGacInstall = settings.ScriptGacInstall;
this.ScriptGacRemove = settings.ScriptGacRemove;
}
}
}
catch (Exception ex)
{
parent.Logger("Exception loading settings, will use standard options.", Color.LightBlue);
parent.Logger("Exception: " + ex.ToString(), Color.LightBlue);
}
}
/// <summary>
/// Serialize settings
/// </summary>
public void SaveSettings()
{
try
{
using (Stream stream = File.Create(SettingsFile))
{
XmlSerializer s = new XmlSerializer(this.GetType());
s.Serialize(stream, this);
}
}
catch (Exception ex)
{
parent.Logger("Exception from Settings, Saving: " + ex.ToString(), Color.LightBlue);
}
}
}
}