Skip to content

Commit 1e9c43d

Browse files
committed
fix bug for executable paths containing quotes
1 parent a96736b commit 1e9c43d

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

FlashpointSecurePlayer/EnvironmentVariables.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ private string GetValue(EnvironmentVariablesElement environmentVariablesElement)
196196
// the compatibility layers may contain more values
197197
// but we're only concerned if it contains the values we want
198198
if (compatibilityLayerValue != null) {
199-
compatibilityLayerValues = compatibilityLayerValue.Split(WHITESPACE).ToList();
199+
compatibilityLayerValues = compatibilityLayerValue.Split().ToList();
200200
}
201201

202202
if (value != null) {
203-
values = value.Split(WHITESPACE).ToList();
203+
values = value.Split().ToList();
204204
}
205205

206206
// we have to restart in this case in server mode
@@ -286,7 +286,7 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod = M
286286
// we get this right away here
287287
// as opposed to after the variable has been potentially set like during activation
288288
if (compatibilityLayerValue != null) {
289-
compatibilityLayerValues = compatibilityLayerValue.Split(WHITESPACE).ToList();
289+
compatibilityLayerValues = compatibilityLayerValue.Split().ToList();
290290
}
291291

292292
ProgressManager.CurrentGoal.Start(activeModificationsElement.EnvironmentVariables.Count);
@@ -317,7 +317,7 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod = M
317317
values = new List<string>();
318318

319319
if (value != null) {
320-
values = value.Split(WHITESPACE).ToList();
320+
values = value.Split().ToList();
321321
}
322322

323323
if (modificationsRevertMethod == MODIFICATIONS_REVERT_METHOD.DELETE_ALL) {

FlashpointSecurePlayer/FlashpointSecurePlayerGUI.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ private void AskLaunchWithOldCPUSimulator() {
267267

268268
try {
269269
processStartInfo = new ProcessStartInfo {
270-
FileName = fullPath,
270+
FileName = GetValidArgument(fullPath, true),
271271
Arguments = GetOldCPUSimulatorProcessStartInfoArguments(modificationsElement.OldCPUSimulator, Environment.CommandLine),
272272
WorkingDirectory = Environment.CurrentDirectory
273273
};
@@ -556,7 +556,7 @@ private void ActivateMode(TemplateElement templateElement, ErrorDelegate errorDe
556556
}
557557

558558
if (String.IsNullOrEmpty(softwareProcessStartInfo.FileName)) {
559-
softwareProcessStartInfo.FileName = fullPath;
559+
softwareProcessStartInfo.FileName = GetValidArgument(fullPath, true);
560560
}
561561

562562
if (String.IsNullOrEmpty(softwareProcessStartInfo.Arguments)) {

FlashpointSecurePlayer/OldCPUSimulator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ public void Activate(string templateName, ref ProcessStartInfo softwareProcessSt
160160

161161
string fullPath = Path.GetFullPath(argv[0]);
162162
workingDirectory = Path.GetDirectoryName(fullPath);
163-
GetValidArgument(ref fullPath);
164-
oldCPUSimulatorSoftware.Append(fullPath);
163+
oldCPUSimulatorSoftware.Append(GetValidArgument(fullPath, true));
165164
} catch (Exception ex) {
166165
LogExceptionToLauncher(ex);
167166
throw new InvalidOldCPUSimulatorException("The command line is invalid.");

FlashpointSecurePlayer/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
// You can specify all the values or you can default the Build and Revision Numbers
3434
// by using the '*' as shown below:
3535
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("2.1.5.0")]
37-
[assembly: AssemblyFileVersion("2.1.5.0")]
36+
[assembly: AssemblyVersion("2.1.6.0")]
37+
[assembly: AssemblyFileVersion("2.1.6.0")]
3838
[assembly: NeutralResourcesLanguage("en")]
3939

FlashpointSecurePlayer/Shared.cs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -924,8 +924,6 @@ public enum MODIFICATIONS_REVERT_METHOD {
924924
private const string CONFIGURATION_FOLDER_NAME = "FlashpointSecurePlayerConfigs";
925925
private const string CONFIGURATION_DOWNLOAD_NAME = "flashpointsecureplayerconfigs";
926926

927-
public static readonly char[] WHITESPACE = { ' ', '\t', '\n', '\v', '\"' };
928-
929927
public const string OLD_CPU_SIMULATOR_PATH = "OldCPUSimulator\\OldCPUSimulator.exe";
930928
public const string OLD_CPU_SIMULATOR_PARENT_PROCESS_FILE_NAME = "OLDCPUSIMULATOR.EXE";
931929

@@ -2530,7 +2528,7 @@ public static void HideWindow(ref ProcessStartInfo processStartInfo) {
25302528
public static void RestartApplication(bool runAsAdministrator, Form form, ref Mutex applicationMutex, ProcessStartInfo processStartInfo = null) {
25312529
if (processStartInfo == null) {
25322530
processStartInfo = new ProcessStartInfo {
2533-
FileName = Application.ExecutablePath,
2531+
FileName = GetValidArgument(Application.ExecutablePath, true),
25342532
// can't use GetCommandLineArgs() and String.Join because arguments that were in quotes will lose their quotes
25352533
// need to use Environment.CommandLine and find arguments
25362534
Arguments = GetArgumentSliceFromCommandLine(Environment.CommandLine, 1)
@@ -2972,33 +2970,36 @@ public static string[] GetCommandLineToArgv(string commandLine, out int argc) {
29722970
}
29732971

29742972
// http://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
2975-
public static void GetValidArgument(ref string argument, bool force = false) {
2976-
if (force || argument == String.Empty || argument.IndexOfAny(WHITESPACE) != -1) {
2977-
int backslashes = 0;
2978-
StringBuilder validArgument = new StringBuilder();
2973+
public static string GetValidArgument(string argument, bool force = false) {
2974+
if (!force && argument != String.Empty && argument.IndexOfAny(new char[]{ ' ', '\t', '\n', '\v', '\"' }) == -1) {
2975+
return argument;
2976+
}
29792977

2980-
for (int i = 0; i < argument.Length; i++) {
2981-
backslashes = 0;
2978+
int backslashes = 0;
2979+
StringBuilder validArgument = new StringBuilder("\"");
29822980

2983-
while (i != argument.Length && argument[i] == '\\') {
2984-
backslashes++;
2985-
i++;
2986-
}
2981+
for (int i = 0; i < argument.Length; i++) {
2982+
backslashes = 0;
29872983

2988-
if (i != argument.Length) {
2989-
if (argument[i] == '"') {
2990-
validArgument.Append('\\', backslashes + backslashes + 1);
2991-
} else {
2992-
validArgument.Append('\\', backslashes);
2993-
}
2984+
while (i != argument.Length && argument[i].ToString().Equals("\\", StringComparison.Ordinal)) {
2985+
backslashes++;
2986+
i++;
2987+
}
29942988

2995-
validArgument.Append(argument[i]);
2989+
if (i != argument.Length) {
2990+
if (argument[i].ToString().Equals("\"", StringComparison.Ordinal)) {
2991+
validArgument.Append('\\', backslashes + backslashes + 1);
2992+
} else {
2993+
validArgument.Append('\\', backslashes);
29962994
}
2997-
}
29982995

2999-
validArgument.Append('\\', backslashes + backslashes);
3000-
argument = "\"" + validArgument.ToString() + "\"";
2996+
validArgument.Append(argument[i]);
2997+
}
30012998
}
2999+
3000+
validArgument.Append('\\', backslashes + backslashes);
3001+
validArgument.Append("\"");
3002+
return validArgument.ToString();
30023003
}
30033004

30043005
public static string GetArgumentSliceFromCommandLine(string commandLine, int begin = 0, int end = -1) {

0 commit comments

Comments
 (0)