-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathCustomAction.cs
230 lines (188 loc) · 9.08 KB
/
CustomAction.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
using System;
using System.IO;
using System.Linq;
using System.Xml;
using Microsoft.Deployment.WindowsInstaller;
namespace SettingsInstallerParameters
{
public class CustomActions
{
[CustomAction]
public static ActionResult UpdateConfigXml(Session session)
{
session.Log("Starting UpdateConfigXml");
try
{
updateConfigXml(session);
session.Log("Successfully finished UpdateConfigXml");
return ActionResult.Success;
}
catch (Exception err)
{
session.Log("An issue was encountered in UpdateConfigXml:\n" + err);
return ActionResult.Failure;
}
}
private static void updateConfigXml(Session session)
{
// Write install path to config file
string xmlPath = Path.Combine(getInstallDir(session), "JitsiMeetOutlookAddIn.dll.config");
session.Log($"Executing on file: {xmlPath}");
if (!File.Exists(xmlPath))
{
session.Log($"File to patch does not exist: {xmlPath}");
return;
}
// TODO: Implement new settings
XmlDocument document = new XmlDocument();
document.Load(xmlPath);
System.Xml.XPath.XPathNavigator navigator = document.CreateNavigator();
if (getDomain(session).Length != 0)
{
session.Log($"Setting custom domain: {getDomain(session)}");
navigator.SelectSingleNode(@"/configuration/userSettings/JitsiMeetOutlook.Properties.Settings/setting[@name='Domain']/value").SetValue(getDomain(session));
}
if (getRoomID(session).Length != 0)
{
session.Log($"Setting custom room ID: {getRoomID(session)}");
navigator.SelectSingleNode(@"/configuration/userSettings/JitsiMeetOutlook.Properties.Settings/setting[@name='roomID']/value").SetValue(getRoomID(session));
}
session.Log($"Setting require name option: {getRequireDisplayName(session)}");
navigator.SelectSingleNode(@"/configuration/userSettings/JitsiMeetOutlook.Properties.Settings/setting[@name='requireDisplayName']/value").SetValue(getRequireDisplayName(session));
session.Log($"Setting audio muted option: {getStartWithAudioMuted(session)}");
navigator.SelectSingleNode(@"/configuration/userSettings/JitsiMeetOutlook.Properties.Settings/setting[@name='startWithAudioMuted']/value").SetValue(getStartWithAudioMuted(session));
session.Log($"Setting video muted option: {getStartWithVideoMuted(session)}");
navigator.SelectSingleNode(@"/configuration/userSettings/JitsiMeetOutlook.Properties.Settings/setting[@name='startWithVideoMuted']/value").SetValue(getStartWithVideoMuted(session));
session.Log($"Setting install directory: {getInstallDir(session)}");
navigator.SelectSingleNode(@"/configuration/userSettings/JitsiMeetOutlook.Properties.Settings/setting[@name='installDirectory']/value").SetValue(getInstallDir(session));
session.Log($"Setting display language: {getLanguage(session)}");
navigator.SelectSingleNode(@"/configuration/userSettings/JitsiMeetOutlook.Properties.Settings/setting[@name='language']/value").SetValue(getLanguage(session));
session.Log($"Setting random ID generator mode: {getLanguage(session)}");
navigator.SelectSingleNode(@"/configuration/userSettings/JitsiMeetOutlook.Properties.Settings/setting[@name='randomRoomIdGeneratorMode']/value").SetValue(getRandomRoomIdGeneratorMode(session));
if (getConferenceMapperEndpoint(session).Length != 0)
{
session.Log($"Setting custom ConferenceMapperEndpoint: {getConferenceMapperEndpoint(session)}");
navigator.SelectSingleNode(@"/configuration/userSettings/JitsiMeetOutlook.Properties.Settings/setting[@name='conferenceMapperEndpoint']/value").SetValue(getConferenceMapperEndpoint(session));
}
if (getPhoneNumberListEndpoint(session).Length != 0)
{
session.Log($"Setting custom phoneNumberListEndpoint: {getPhoneNumberListEndpoint(session)}");
navigator.SelectSingleNode(@"/configuration/userSettings/JitsiMeetOutlook.Properties.Settings/setting[@name='phoneNumberListEndpoint']/value").SetValue(getPhoneNumberListEndpoint(session));
}
if (getConferenceSchedulerEndpoint(session).Length != 0)
{
session.Log($"Setting custom conferenceSchedulerEndpoint: {getConferenceSchedulerEndpoint(session)}");
navigator.SelectSingleNode(@"/configuration/userSettings/JitsiMeetOutlook.Properties.Settings/setting[@name='conferenceSchedulerEndpoint']/value").SetValue(getConferenceSchedulerEndpoint(session));
}
if (getConferenceSchedulerEndpointSecret(session).Length != 0)
{
if (getConferenceSchedulerEndpointSecret(session).Length < 8)
{
session.Log($"WARNING: The secret is to short. This will throw errors in the application.");
}
session.Log($"Setting custom conferenceSchedulerEndpointSecret: {getConferenceSchedulerEndpointSecret(session)}");
navigator.SelectSingleNode(@"/configuration/userSettings/JitsiMeetOutlook.Properties.Settings/setting[@name='conferenceSchedulerEndpointSecret']/value").SetValue(getConferenceSchedulerEndpointSecret(session));
}
session.Log($"Saving settings to: {xmlPath}");
document.Save(xmlPath);
}
private static string getInstallDir(Session session)
{
return Path.GetDirectoryName(session.CustomActionData["InstallDir"]);
}
private static string getDomain(Session session)
{
return session.CustomActionData["Domain"];
}
private static string getRoomID(Session session)
{
return session.CustomActionData["roomID"];
}
private static string getConferenceMapperEndpoint(Session session)
{
return session.CustomActionData["conferenceMapperEndpoint"];
}
private static string getPhoneNumberListEndpoint(Session session)
{
return session.CustomActionData["phoneNumberListEndpoint"];
}
private static string getConferenceSchedulerEndpoint(Session session)
{
return session.CustomActionData["conferenceSchedulerEndpoint"];
}
private static string getConferenceSchedulerEndpointSecret(Session session)
{
return session.CustomActionData["conferenceSchedulerEndpointSecret"];
}
private static string getRequireDisplayName(Session session)
{
return getBooleanParameter(session, "requireDisplayName");
}
private static string getStartWithAudioMuted(Session session)
{
return getBooleanParameter(session, "startWithAudioMuted");
}
private static string getStartWithVideoMuted(Session session)
{
return getBooleanParameter(session, "startWithVideoMuted");
}
private static string getLanguage(Session session)
{
string[] availableLanguages = { "en", "cz", "de", "es", "fr", "ru" };
string userLanguageInput = session.CustomActionData["language"];
if (availableLanguages.Contains(userLanguageInput))
{
return userLanguageInput;
}
else
{
return "en";
}
}
private static string getRandomRoomIdGeneratorMode(Session session)
{
string[] availableModes = { "phrase", "string" };
string userModeInput = session.CustomActionData["randomRoomIdGeneratorMode"];
if (availableModes.Contains(userModeInput))
{
return userModeInput;
}
else
{
return "phrase";
}
}
private static string getBooleanParameter(Session session, string parameter)
{
string userInput = session.CustomActionData[parameter];
if (userInput == null)
{
return "False";
}
else if (validBoolSettingInput(userInput))
{
return ToTitleCase(userInput);
}
else
{
return "False";
}
}
private static bool validBoolSettingInput(string input)
{
String[] xmlBoolean = { "true", "false" };
if (xmlBoolean.Contains(input.ToLower()))
{
return true;
}
else
{
return false;
}
}
private static string ToTitleCase(string input)
{
return System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(input.ToLower());
}
}
}