Skip to content

Commit d1ca043

Browse files
Fixed some edge cases involving quotes and exception logic in ProcessWrapper
1 parent 3b025f6 commit d1ca043

3 files changed

Lines changed: 39 additions & 25 deletions

File tree

Changelog.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
* c108990 (HEAD -> staging) Exclude assembly PID when validating child PIDs
2-
* 81355bb (origin/staging, origin/master, origin/HEAD, master) Update assembly version
3-
* af7eced Update changelog
4-
* 9e404b1 Grammar fix in README
1+
* 9e404b1 (HEAD -> master) Grammar fix in README
52
* 138c598 Small code cleanup in WMI validator
63
* b6da235 Excluded GOG Notifications from hooked windows. (#69)
74
* 3582e6f (tag: v1.09h) Bump changelog for posterity

OriginSteamOverlayLauncher/LaunchLogic.cs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class LaunchLogic
1818
private string MonitorPath { get; set; }
1919
private string MonitorName { get; set; }
2020
private bool LauncherPathValid { get; set; }
21+
private bool PreLaunchPathValid { get; set; }
22+
private bool PostGamePathValid { get; set; }
2123
private bool GamePathValid { get; set; }
2224
private bool LauncherURIMode { get; set; }
2325
private bool ExitRequested { get; set; }
@@ -35,6 +37,8 @@ public LaunchLogic()
3537
LauncherPathValid = SettingsData.ValidatePath(SetHnd.Paths.LauncherPath);
3638
GamePathValid = SettingsData.ValidatePath(SetHnd.Paths.GamePath);
3739
LauncherURIMode = SettingsData.ValidateURI(SetHnd.Paths.LauncherURI);
40+
PreLaunchPathValid = SettingsData.ValidatePath(SetHnd.Paths.PreLaunchExecPath);
41+
PostGamePathValid = SettingsData.ValidatePath(SetHnd.Paths.PostGameExecPath);
3842
TrayUtil = new TrayIconUtil();
3943
}
4044

@@ -47,13 +51,16 @@ public async Task ProcessLauncher()
4751
ProcessWrapper.KillProcTreeByName(LauncherName);
4852
}
4953

50-
// run PreLaunchExecPath/Args before the launcher
51-
PreLauncherPL = new ProcessLauncher(
52-
SetHnd.Paths.PreLaunchExecPath,
53-
SetHnd.Paths.PreLaunchExecArgs,
54-
elevate: SetHnd.Options.ElevateExternals
55-
);
56-
await PreLauncherPL.Launch();
54+
if (PreLaunchPathValid)
55+
{
56+
// run PreLaunchExecPath/Args before the launcher
57+
PreLauncherPL = new ProcessLauncher(
58+
SetHnd.Paths.PreLaunchExecPath,
59+
SetHnd.Paths.PreLaunchExecArgs,
60+
elevate: SetHnd.Options.ElevateExternals
61+
);
62+
await PreLauncherPL.Launch();
63+
}
5764

5865
if (LauncherPathValid && !SetHnd.Options.SkipLauncher)
5966
{
@@ -79,11 +86,13 @@ public async Task ProcessLauncher()
7986
LauncherMonitor.ProcessAcquired += OnLauncherAcquired;
8087

8188
// wait for all running threads to exit
82-
while (!ExitRequested ||
89+
while (
90+
PreLauncherPL != null && PreLauncherPL.ProcWrapper.IsRunning() ||
8391
LauncherMonitor != null && LauncherMonitor.IsRunning() ||
8492
GameMonitor != null && GameMonitor.IsRunning() ||
85-
PreLauncherPL != null && PreLauncherPL.ProcWrapper.IsRunning() ||
86-
PostGamePL != null && PostGamePL.ProcWrapper.IsRunning())
93+
PostGamePL != null && PostGamePL.ProcWrapper.IsRunning() ||
94+
!ExitRequested
95+
)
8796
await Task.Delay(1000);
8897
}
8998

@@ -225,14 +234,17 @@ private async void OnGameExited(object sender, ProcessEventArgs e)
225234
if (SetHnd.Options.MinimizeLauncher && LauncherPL.ProcWrapper.IsRunning())
226235
WindowUtils.MinimizeWindow(LauncherPL.ProcWrapper.Hwnd);
227236

228-
// run PostGameExecPath/Args after the game exits
229-
PostGamePL = new ProcessLauncher(
230-
SetHnd.Paths.PostGameExecPath,
231-
SetHnd.Paths.PostGameExecArgs,
232-
elevate: SetHnd.Options.ElevateExternals,
233-
delayTime: SetHnd.Options.PostGameWaitTime
234-
);
235-
await PostGamePL.Launch();
237+
if (PostGamePathValid)
238+
{
239+
// run PostGameExecPath/Args after the game exits
240+
PostGamePL = new ProcessLauncher(
241+
SetHnd.Paths.PostGameExecPath,
242+
SetHnd.Paths.PostGameExecArgs,
243+
elevate: SetHnd.Options.ElevateExternals,
244+
delayTime: SetHnd.Options.PostGameWaitTime
245+
);
246+
await PostGamePL.Launch();
247+
}
236248

237249
if (SetHnd.Options.PostGameWaitTime > 0)
238250
ProcessUtils.Logger("OSOL", $"Game exited, moving on to clean up after {SetHnd.Options.PostGameWaitTime}s...");

OriginSteamOverlayLauncher/ProcessWrapper.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ public List<Tuple<int, int, Process>> GetChildProcesses(int PID = 0)
7272
public List<Process> GetProcessesByName(string exeName)
7373
{
7474
var output = new List<Process>();
75-
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(
76-
$"SELECT * FROM Win32_Process where Name LIKE '{exeName}.exe'"))
75+
76+
// try to make sure single quotes are escaped
77+
exeName = exeName.Replace("'", "''");
78+
string query = $"SELECT * FROM Win32_Process WHERE Name LIKE '{exeName}.exe'";
79+
80+
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
7781
using (ManagementObjectCollection processes = searcher.Get())
7882
{
7983
foreach (var process in processes)
@@ -89,6 +93,7 @@ public List<Process> GetProcessesByName(string exeName)
8993
output.Add(curProcess);
9094
}
9195
}
96+
catch (ManagementException) { return output; }
9297
catch (Win32Exception) { continue; }
9398
catch (InvalidOperationException) { continue; }
9499
}
@@ -167,7 +172,7 @@ public bool IsRunning()
167172
}
168173
catch (Exception) {
169174
// rough check until the next iteration
170-
return Proc == null || PID > 0 && !NativeProcessUtils.IsProcessAlive(PID);
175+
return Proc != null && PID > 0 && NativeProcessUtils.IsProcessAlive(PID);
171176
}
172177
}
173178

0 commit comments

Comments
 (0)