Skip to content

Commit 7cf6493

Browse files
authored
Merge pull request #7 from FlashpointProject/dev
Dev
2 parents 8073496 + eea4fb4 commit 7cf6493

File tree

101 files changed

+1334
-990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1334
-990
lines changed

FlashpointSecurePlayer/ActiveXControl.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,46 @@ public class ActiveXControl {
2626
[DllImport("KERNEL32.DLL", CallingConvention = CallingConvention.StdCall)]
2727
private static extern IntPtr GetProcAddress(IntPtr moduleHandle, [MarshalAs(UnmanagedType.LPStr)] string procName);
2828

29-
private IntPtr ModuleHandle = IntPtr.Zero;
29+
private IntPtr moduleHandle = IntPtr.Zero;
30+
3031
private readonly DllRegisterServerDelegate DllRegisterServer;
3132
private readonly DllRegisterServerDelegate DllUnregisterServer;
3233

3334
public ActiveXControl(string libFileName) {
34-
ModuleHandle = LoadLibrary(libFileName);
35+
moduleHandle = LoadLibrary(libFileName);
3536

36-
if (ModuleHandle == IntPtr.Zero) {
37-
throw new DllNotFoundException();
37+
if (moduleHandle == IntPtr.Zero) {
38+
throw new DllNotFoundException("The library " + libFileName + " could not be found.");
3839
}
3940

4041
IntPtr dllRegisterServerProcAddress = IntPtr.Zero;
41-
dllRegisterServerProcAddress = GetProcAddress(ModuleHandle, "DllRegisterServer");
42+
dllRegisterServerProcAddress = GetProcAddress(moduleHandle, "DllRegisterServer");
4243

4344
if (dllRegisterServerProcAddress == IntPtr.Zero) {
44-
throw new InvalidActiveXControlException();
45+
throw new InvalidActiveXControlException("The library does not have a DllRegisterServer export.");
4546
}
4647

4748
IntPtr dllUnregisterServerProcAddress = IntPtr.Zero;
48-
dllUnregisterServerProcAddress = GetProcAddress(ModuleHandle, "DllUnregisterServer");
49+
dllUnregisterServerProcAddress = GetProcAddress(moduleHandle, "DllUnregisterServer");
4950

5051
if (dllUnregisterServerProcAddress == IntPtr.Zero) {
51-
throw new InvalidActiveXControlException();
52+
throw new InvalidActiveXControlException("The library does not have a DllUnregisterServer export.");
5253
}
5354

5455
DllRegisterServer = Marshal.GetDelegateForFunctionPointer(dllRegisterServerProcAddress, typeof(DllRegisterServerDelegate)) as DllRegisterServerDelegate;
5556
DllUnregisterServer = Marshal.GetDelegateForFunctionPointer(dllUnregisterServerProcAddress, typeof(DllRegisterServerDelegate)) as DllRegisterServerDelegate;
5657
}
5758

5859
~ActiveXControl() {
59-
if (ModuleHandle != IntPtr.Zero) {
60-
FreeLibrary(ModuleHandle);
61-
ModuleHandle = IntPtr.Zero;
60+
if (moduleHandle != IntPtr.Zero) {
61+
FreeLibrary(moduleHandle);
62+
moduleHandle = IntPtr.Zero;
6263
}
6364
}
6465

6566
private void RegisterServer(DllRegisterServerDelegate DllRegisterServer) {
6667
if (DllRegisterServer() != 0) {
67-
throw new Win32Exception();
68+
throw new Win32Exception("Failed to register the DLL Server.");
6869
}
6970
}
7071

FlashpointSecurePlayer/CustomSecurityManager.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,22 @@ public CustomSecurityManager(WebBrowser _WebBrowser) {
2222
int err = webBrowserServiceProviderInterface.QueryService(ref InternetInterfaces.SID_SProfferService, ref InternetInterfaces.IID_IProfferService, out profferServiceInterfacePointer);
2323

2424
if (err != S_OK) {
25-
throw new Win32Exception();
25+
throw new Win32Exception("Failed to query the Web Browser Service.");
2626
}
27-
28-
InternetInterfaces.IProfferService profferServiceInterface = Marshal.GetObjectForIUnknown(profferServiceInterfacePointer) as InternetInterfaces.IProfferService;
29-
30-
if (profferServiceInterface == null) {
31-
throw new Win32Exception();
27+
28+
if (!(Marshal.GetObjectForIUnknown(profferServiceInterfacePointer) is InternetInterfaces.IProfferService profferServiceInterface)) {
29+
throw new Win32Exception("Failed to get the Proffer Service Interface.");
3230
}
3331

3432
err = profferServiceInterface.ProfferService(ref InternetInterfaces.IID_IInternetSecurityManager, this, out int cookie);
3533

3634
if (err != S_OK) {
37-
throw new Win32Exception();
35+
throw new Win32Exception("Failed to proffer the Internet Security Manager Service.");
3836
}
3937
} catch (SEHException) {
40-
throw new Win32Exception();
38+
throw new Win32Exception("An SEH Exception was encountered while creating the Custom Security Manager.");
4139
} catch (ExternalException) {
42-
throw new Win32Exception();
40+
throw new Win32Exception("An External Exception was encountered while creating the Custom Security Manager.");
4341
}
4442
}
4543

FlashpointSecurePlayer/DownloadsBefore.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace FlashpointSecurePlayer {
1414
class DownloadsBefore : Modifications {
15-
public DownloadsBefore(Form Form) : base(Form) { }
15+
public DownloadsBefore(Form form) : base(form) { }
1616

1717
private void Activate() { }
1818

@@ -28,13 +28,21 @@ public async Task ActivateAsync(string name, List<string> downloadsBeforeNames)
2828
// we know the file downloaded all the way before the
2929
// server/software starts
3030
//DownloadBeforeElement downloadBeforeElement = null;
31-
List<Task> downloadTasks = new List<Task>();
31+
ProgressManager.CurrentGoal.Start(downloadsBeforeNames.Count);
3232

33-
for (int i = 0;i < downloadsBeforeNames.Count;i++) {
34-
downloadTasks.Add(DownloadAsync(downloadsBeforeNames[i]));
35-
}
33+
try {
34+
Task[] downloadTasks = new Task[downloadsBeforeNames.Count];
35+
36+
for (int i = 0;i < downloadsBeforeNames.Count;i++) {
37+
downloadTasks[i] = DownloadAsync(downloadsBeforeNames[i]).ContinueWith(delegate (Task task) {
38+
ProgressManager.CurrentGoal.Steps++;
39+
}, TaskScheduler.FromCurrentSynchronizationContext());
40+
}
3641

37-
await Task.WhenAll(downloadTasks.ToArray()).ConfigureAwait(false);
42+
await Task.WhenAll(downloadTasks).ConfigureAwait(false);
43+
} finally {
44+
ProgressManager.CurrentGoal.Stop();
45+
}
3846
}
3947
}
4048
}

FlashpointSecurePlayer/EnvironmentVariables.cs

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace FlashpointSecurePlayer {
1515
class EnvironmentVariables : Modifications {
1616
const string COMPATIBILITY_LAYER_NAME = "__COMPAT_LAYER";
1717

18-
public EnvironmentVariables(Form Form) : base(Form) { }
18+
public EnvironmentVariables(Form form) : base(form) { }
1919

2020
public void Activate(string name, string server, string applicationMutexName) {
2121
base.Activate(name);
@@ -28,48 +28,56 @@ public void Activate(string name, string server, string applicationMutexName) {
2828
try {
2929
compatibilityLayerValue = Environment.GetEnvironmentVariable(COMPATIBILITY_LAYER_NAME);
3030
} catch (ArgumentException) {
31-
throw new EnvironmentVariablesFailedException();
31+
throw new EnvironmentVariablesFailedException("Failed to get the " + COMPATIBILITY_LAYER_NAME + " Environment Variable.");
3232
} catch (SecurityException) {
33-
throw new TaskRequiresElevationException();
33+
throw new TaskRequiresElevationException("Getting the " + COMPATIBILITY_LAYER_NAME + " Environment Variable requires elevation.");
3434
}
3535

36-
EnvironmentVariablesElement environmentVariablesElement = null;
36+
ProgressManager.CurrentGoal.Start(modificationsElement.EnvironmentVariables.Count);
3737

38-
for (int i = 0;i < modificationsElement.EnvironmentVariables.Count;i++) {
39-
environmentVariablesElement = modificationsElement.EnvironmentVariables.Get(i) as EnvironmentVariablesElement;
40-
41-
if (environmentVariablesElement == null) {
42-
throw new EnvironmentVariablesFailedException();
43-
}
38+
try {
39+
EnvironmentVariablesElement environmentVariablesElement = null;
4440

45-
value = environmentVariablesElement.Value;
41+
for (int i = 0;i < modificationsElement.EnvironmentVariables.Count;i++) {
42+
environmentVariablesElement = modificationsElement.EnvironmentVariables.Get(i) as EnvironmentVariablesElement;
4643

47-
try {
48-
Environment.SetEnvironmentVariable(environmentVariablesElement.Name, RemoveVariablesFromLengthenedValue(value) as string);
49-
} catch (ArgumentException) {
50-
throw new EnvironmentVariablesFailedException();
51-
} catch (SecurityException) {
52-
throw new TaskRequiresElevationException();
53-
}
44+
if (environmentVariablesElement == null) {
45+
throw new System.Configuration.ConfigurationErrorsException("The Environment Variables Element (" + i + ") is null.");
46+
}
5447

55-
// if this is the compatibility layer variable
56-
// and the value is not what we want to set it to
57-
// and we're in server mode...
58-
if (environmentVariablesElement.Name == COMPATIBILITY_LAYER_NAME && !String.IsNullOrEmpty(server)) {
59-
values = new List<string>();
48+
value = environmentVariablesElement.Value;
6049

61-
if (compatibilityLayerValue != null) {
62-
compatibilityLayerValues = compatibilityLayerValue.ToUpper().Split(' ').ToList();
50+
try {
51+
Environment.SetEnvironmentVariable(environmentVariablesElement.Name, RemoveVariablesFromLengthenedValue(value) as string);
52+
} catch (ArgumentException) {
53+
throw new EnvironmentVariablesFailedException("Failed to set the " + environmentVariablesElement.Name + " Environment Variable.");
54+
} catch (SecurityException) {
55+
throw new TaskRequiresElevationException("Setting the " + environmentVariablesElement.Name + " Environment Variable requires elevation.");
6356
}
6457

65-
if (value != null) {
66-
values = value.ToUpper().Split(' ').ToList();
67-
}
68-
69-
if (values.Except(compatibilityLayerValues).Any()) {
70-
throw new CompatibilityLayersException();
58+
// if this is the compatibility layer variable
59+
// and the value is not what we want to set it to
60+
// and we're in server mode...
61+
if (environmentVariablesElement.Name == COMPATIBILITY_LAYER_NAME && !String.IsNullOrEmpty(server)) {
62+
values = new List<string>();
63+
64+
if (compatibilityLayerValue != null) {
65+
compatibilityLayerValues = compatibilityLayerValue.ToUpper().Split(' ').ToList();
66+
}
67+
68+
if (value != null) {
69+
values = value.ToUpper().Split(' ').ToList();
70+
}
71+
72+
if (values.Except(compatibilityLayerValues).Any()) {
73+
throw new CompatibilityLayersException("The Compatibility Layers (" + String.Join(", ", compatibilityLayerValues) + ") cannot be set.");
74+
}
7175
}
76+
77+
ProgressManager.CurrentGoal.Steps++;
7278
}
79+
} finally {
80+
ProgressManager.CurrentGoal.Stop();
7381
}
7482
}
7583

@@ -94,43 +102,51 @@ public void Deactivate(string server) {
94102
try {
95103
compatibilityLayerValue = Environment.GetEnvironmentVariable(COMPATIBILITY_LAYER_NAME);
96104
} catch (ArgumentException) {
97-
throw new EnvironmentVariablesFailedException();
105+
throw new EnvironmentVariablesFailedException("Failed to get the " + COMPATIBILITY_LAYER_NAME + " Environment Variable.");
98106
} catch (SecurityException) {
99-
throw new TaskRequiresElevationException();
107+
throw new TaskRequiresElevationException("Getting the " + COMPATIBILITY_LAYER_NAME + " Environment Variable requires elevation.");
100108
}
101109

102110
if (compatibilityLayerValue != null) {
103111
compatibilityLayerValues = compatibilityLayerValue.ToUpper().Split(' ').ToList();
104112
}
105113

106-
EnvironmentVariablesElement environmentVariablesElement = null;
114+
ProgressManager.CurrentGoal.Start(modificationsElement.EnvironmentVariables.Count);
107115

108-
for (int i = 0;i < modificationsElement.EnvironmentVariables.Count;i++) {
109-
environmentVariablesElement = modificationsElement.EnvironmentVariables.Get(i) as EnvironmentVariablesElement;
116+
try {
117+
EnvironmentVariablesElement environmentVariablesElement = null;
110118

111-
if (environmentVariablesElement == null) {
112-
throw new EnvironmentVariablesFailedException();
113-
}
119+
for (int i = 0;i < modificationsElement.EnvironmentVariables.Count;i++) {
120+
environmentVariablesElement = modificationsElement.EnvironmentVariables.Get(i) as EnvironmentVariablesElement;
114121

115-
value = environmentVariablesElement.Value;
116-
values = new List<string>();
122+
if (environmentVariablesElement == null) {
123+
throw new System.Configuration.ConfigurationErrorsException("The Environment Variables Element (" + i + ") is null.");
124+
}
117125

118-
if (value != null) {
119-
values = value.ToUpper().Split(' ').ToList();
120-
}
126+
value = environmentVariablesElement.Value;
127+
values = new List<string>();
121128

122-
// if this isn't the compatibility layer variable
123-
// or the value isn't what we want to set it to
124-
// or we're not in server mode...
125-
if (environmentVariablesElement.Name != COMPATIBILITY_LAYER_NAME || values.Except(compatibilityLayerValues).Any() || String.IsNullOrEmpty(server)) {
126-
try {
127-
Environment.SetEnvironmentVariable(environmentVariablesElement.Name, null);
128-
} catch (ArgumentException) {
129-
throw new EnvironmentVariablesFailedException();
130-
} catch (SecurityException) {
131-
throw new TaskRequiresElevationException();
129+
if (value != null) {
130+
values = value.ToUpper().Split(' ').ToList();
132131
}
132+
133+
// if this isn't the compatibility layer variable
134+
// or the value isn't what we want to set it to
135+
// or we're not in server mode...
136+
if (environmentVariablesElement.Name != COMPATIBILITY_LAYER_NAME || values.Except(compatibilityLayerValues).Any() || String.IsNullOrEmpty(server)) {
137+
try {
138+
Environment.SetEnvironmentVariable(environmentVariablesElement.Name, null);
139+
} catch (ArgumentException) {
140+
throw new EnvironmentVariablesFailedException("Failed to set the " + environmentVariablesElement.Name + " Environment Variable.");
141+
} catch (SecurityException) {
142+
throw new TaskRequiresElevationException("Getting the " + COMPATIBILITY_LAYER_NAME + " Environment Variable requires elevation.");
143+
}
144+
}
145+
146+
ProgressManager.CurrentGoal.Steps++;
133147
}
148+
} finally {
149+
ProgressManager.CurrentGoal.Stop();
134150
}
135151
}
136152
}

FlashpointSecurePlayer/FlashpointProxy.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private static void GetSystemProxy(ref INTERNET_PER_CONN_OPTION_LIST internetPer
117117
int internetPerConnOptionListSize = Marshal.SizeOf(internetPerConnOptionList);
118118

119119
if (internetPerConnOptionListOptions.Length < 2) {
120-
throw new ArgumentException();
120+
throw new ArgumentException("The Internet Per Connection Option List Options cannot have a Length of less than two.");
121121
}
122122

123123
// set flags
@@ -152,7 +152,7 @@ private static void GetSystemProxy(ref INTERNET_PER_CONN_OPTION_LIST internetPer
152152
bool result = InternetQueryOption(IntPtr.Zero, INTERNET_OPTION.INTERNET_OPTION_PER_CONNECTION_OPTION, ref internetPerConnOptionList, ref internetPerConnOptionListSize);
153153

154154
if (!result) {
155-
throw new FlashpointProxyException();
155+
throw new FlashpointProxyException("Could not query the Internet Options.");
156156
}
157157
}
158158

@@ -213,12 +213,12 @@ public static void Enable(string proxyServer) {
213213
Marshal.FreeCoTaskMem(internetPerConnOptionListPointer);
214214

215215
if (!InternetCloseHandle(internetHandle)) {
216-
throw new FlashpointProxyException();
216+
throw new FlashpointProxyException("Could not close the Internet Handle.");
217217
}
218218

219219
// throw an exception if this operation failed
220220
if (!result) {
221-
throw new FlashpointProxyException();
221+
throw new FlashpointProxyException("Could not set the Internet Options.");
222222
}
223223
}
224224

@@ -263,11 +263,11 @@ public static void Disable() {
263263
}
264264

265265
if (!InternetCloseHandle(internetHandle)) {
266-
throw new FlashpointProxyException();
266+
throw new FlashpointProxyException("Could not close the Internet Handle.");
267267
}
268268

269269
if (!result) {
270-
throw new FlashpointProxyException();
270+
throw new FlashpointProxyException("Could not set the Internet Options.");
271271
}
272272
}
273273
}

0 commit comments

Comments
 (0)