Skip to content

Commit 3436527

Browse files
committed
fix for Process Sync on Windows 7
1 parent 9db0b23 commit 3436527

7 files changed

Lines changed: 258 additions & 44 deletions

File tree

FlashpointSecurePlayer/FlashpointSecurePlayerGUI.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ private void ActivateMode(TemplateElement templateElement, ErrorDelegate errorDe
535535
softwareProcessStartInfo.Arguments = GetArgumentSliceFromCommandLine(commandLineExpanded, 1);
536536
}
537537

538+
softwareProcessStartInfo.UseShellExecute = false;
538539
softwareProcessStartInfo.ErrorDialog = false;
539540

540541
if (modeElement.HideWindow.GetValueOrDefault()) {
@@ -545,18 +546,15 @@ private void ActivateMode(TemplateElement templateElement, ErrorDelegate errorDe
545546
if (String.IsNullOrEmpty(modeElement.WorkingDirectory)) {
546547
softwareProcessStartInfo.WorkingDirectory = Path.GetDirectoryName(fullPath);
547548
} else {
548-
try {
549-
SetWorkingDirectory(ref softwareProcessStartInfo, Environment.ExpandEnvironmentVariables(modeElement.WorkingDirectory));
550-
} catch (ArgumentNullException) {
551-
throw new InvalidModeException("The Mode failed because the Working Directory must not be null.");
552-
}
549+
softwareProcessStartInfo.WorkingDirectory = Environment.ExpandEnvironmentVariables(modeElement.WorkingDirectory);
553550
}
554551
}
555552

556-
Process softwareProcess = Process.Start(softwareProcessStartInfo);
553+
Process softwareProcess = null;
557554

558555
try {
559-
ProcessSync.Start(softwareProcess);
556+
// StartProcessCreateBreakawayFromJob required for Process Sync on Windows 7
557+
softwareProcess = StartProcessCreateBreakawayFromJob(softwareProcessStartInfo);
560558
} catch (JobObjectException ex) {
561559
LogExceptionToLauncher(ex);
562560
// popup message box and blow up
@@ -575,6 +573,7 @@ private void ActivateMode(TemplateElement templateElement, ErrorDelegate errorDe
575573
Show();
576574
Refresh();
577575

576+
/*
578577
string softwareProcessStandardError = null;
579578
string softwareProcessStandardOutput = null;
580579
@@ -585,11 +584,14 @@ private void ActivateMode(TemplateElement templateElement, ErrorDelegate errorDe
585584
if (softwareProcessStartInfo.RedirectStandardOutput) {
586585
softwareProcessStandardOutput = softwareProcess.StandardOutput.ReadToEnd();
587586
}
587+
*/
588588

589589
if (softwareIsOldCPUSimulator) {
590590
switch (softwareProcess.ExitCode) {
591591
case 0:
592592
break;
593+
// RedirectStandardError is not supported by StartProcessCreateBreakawayFromJob
594+
/*
593595
case -1:
594596
if (!String.IsNullOrEmpty(softwareProcessStandardError)) {
595597
string[] lastSoftwareProcessStandardErrors = softwareProcessStandardError.Split('\n');
@@ -604,6 +606,7 @@ private void ActivateMode(TemplateElement templateElement, ErrorDelegate errorDe
604606
}
605607
}
606608
break;
609+
*/
607610
case -2:
608611
MessageBox.Show(Properties.Resources.OCS_NoMultipleInstances);
609612
break;

FlashpointSecurePlayer/OldCPUSimulator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ public void Activate(string templateName, ref ProcessStartInfo softwareProcessSt
178178

179179
softwareProcessStartInfo.FileName = OLD_CPU_SIMULATOR_PATH;
180180
softwareProcessStartInfo.Arguments = GetOldCPUSimulatorProcessStartInfoArguments(oldCPUSimulatorElement, oldCPUSimulatorSoftware.ToString());
181-
softwareProcessStartInfo.RedirectStandardError = true;
181+
//softwareProcessStartInfo.RedirectStandardError = true;
182+
softwareProcessStartInfo.RedirectStandardError = false;
182183
softwareProcessStartInfo.RedirectStandardOutput = false;
183184
softwareProcessStartInfo.RedirectStandardInput = false;
184185

FlashpointSecurePlayer/ProcessSync.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,42 +102,44 @@ string name
102102
public static void Start(Process process = null) {
103103
// this is here to make it so if the player crashes
104104
// the process it started is killed along with it
105-
if (!Started) {
106-
if (jobHandle == IntPtr.Zero) {
107-
jobHandle = CreateJobObject(IntPtr.Zero, null);
105+
if (Started) {
106+
return;
107+
}
108108

109-
if (jobHandle == IntPtr.Zero) {
110-
throw new JobObjectException("Could not create the Job Object.");
111-
}
112-
}
109+
if (jobHandle == IntPtr.Zero) {
110+
jobHandle = CreateJobObject(IntPtr.Zero, null);
113111

114-
JOBOBJECT_BASIC_LIMIT_INFORMATION jobobjectBasicLimitInformation = new JOBOBJECT_BASIC_LIMIT_INFORMATION {
115-
LimitFlags = JOB_OBJECT_LIMITFlags.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
116-
};
112+
if (jobHandle == IntPtr.Zero) {
113+
throw new JobObjectException("Could not create the Job Object.");
114+
}
115+
}
117116

118-
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jobobjectExtendedLimitInformation = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION {
119-
BasicLimitInformation = jobobjectBasicLimitInformation
120-
};
117+
JOBOBJECT_BASIC_LIMIT_INFORMATION jobobjectBasicLimitInformation = new JOBOBJECT_BASIC_LIMIT_INFORMATION {
118+
LimitFlags = JOB_OBJECT_LIMITFlags.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
119+
};
121120

122-
int jobobjectExtendedLimitInformationSize = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
123-
IntPtr jobobjectExtendedLimitInformationPointer = Marshal.AllocHGlobal(jobobjectExtendedLimitInformationSize);
121+
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jobobjectExtendedLimitInformation = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION {
122+
BasicLimitInformation = jobobjectBasicLimitInformation
123+
};
124124

125-
Marshal.StructureToPtr(jobobjectExtendedLimitInformation, jobobjectExtendedLimitInformationPointer, false);
125+
int jobobjectExtendedLimitInformationSize = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
126+
IntPtr jobobjectExtendedLimitInformationPointer = Marshal.AllocHGlobal(jobobjectExtendedLimitInformationSize);
126127

127-
bool result = SetInformationJobObject(jobHandle, JOBOBJECTINFOCLASS.JobObjectExtendedLimitInformation, jobobjectExtendedLimitInformationPointer, (uint)jobobjectExtendedLimitInformationSize);
128+
Marshal.StructureToPtr(jobobjectExtendedLimitInformation, jobobjectExtendedLimitInformationPointer, false);
128129

129-
Marshal.FreeHGlobal(jobobjectExtendedLimitInformationPointer);
130+
bool result = SetInformationJobObject(jobHandle, JOBOBJECTINFOCLASS.JobObjectExtendedLimitInformation, jobobjectExtendedLimitInformationPointer, (uint)jobobjectExtendedLimitInformationSize);
130131

131-
if (process == null) {
132-
process = Process.GetCurrentProcess();
133-
}
132+
Marshal.FreeHGlobal(jobobjectExtendedLimitInformationPointer);
134133

135-
if (!result || !AssignProcessToJobObject(jobHandle, process.Handle)) {
136-
throw new JobObjectException("Could not set the Job Object Information or assign the Process to the Job Object.");
137-
}
134+
if (process == null) {
135+
process = Process.GetCurrentProcess();
136+
}
138137

139-
Started = true;
138+
if (!result || !AssignProcessToJobObject(jobHandle, process.Handle)) {
139+
throw new JobObjectException("Could not set the Job Object Information or assign the Process to the Job Object.");
140140
}
141+
142+
Started = true;
141143
}
142144
}
143145
}

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.2.0")]
37-
[assembly: AssemblyFileVersion("2.1.2.0")]
36+
[assembly: AssemblyVersion("2.1.3.0")]
37+
[assembly: AssemblyFileVersion("2.1.3.0")]
3838
[assembly: NeutralResourcesLanguage("en")]
3939

FlashpointSecurePlayer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Flashpoint Secure Player 2.1.2
1+
# Flashpoint Secure Player 2.1.3
22
This player attempts to solve common compatibility or portability issues posed by browser plugins on Windows for the purpose of playback in BlueMaxima's Flashpoint.
33

44
It is compatible with Windows 7, Windows 8, Windows 8.1 and Windows 10, and requires .NET Framework 4.5. If you are on Windows 8.1 or Windows 10, or if you are on Windows 7/8 and have updates enabled, you already have .NET Framework 4.5. Otherwise, you may [download .NET Framework 4.5.](http://www.microsoft.com/en-us/download/details.aspx?id=30653)

FlashpointSecurePlayer/RegistryStates.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,15 @@ public async Task StartImportAsync(string templateName, BINARY_TYPE binaryType)
756756
throw new ArgumentException("The path to \"" + TemplateName + "\" is not supported.");
757757
}
758758

759+
// fix for loading dependencies
760+
try {
761+
Directory.SetCurrentDirectory(fullPath);
762+
} catch (SecurityException) {
763+
throw new TaskRequiresElevationException("Setting the Current Directory requires elevation.");
764+
} catch {
765+
// Fail silently.
766+
}
767+
759768
// check permission to run
760769
if (!TraceEventSession.IsElevated().GetValueOrDefault()) {
761770
throw new TaskRequiresElevationException("The Trace Event Session requires elevation.");

0 commit comments

Comments
 (0)