async Task<Process> LaunchUpdaterProcess(LaunchGameInfoBase spec, ProcessStartInfo startInfo) { LogGameInfo(spec); LogStartupInfo(startInfo); if (spec.WaitForExit) { // TODO: Problem; WaitForExit actually doesnt stop after the child process is exited, but also all i'ts child processes>?! if (spec.LaunchAsAdministrator) await LaunchAsAdmin(startInfo).ConfigureAwait(false); else { var lResult = await LaunchNormally(startInfo).ConfigureAwait(false); try { var p = Process.GetProcessById(lResult.ProcessId); var path = Tools.ProcessManager.Management.GetProcessPath(lResult.ProcessId); if ((path != null) && path.Equals(spec.ExpectedExecutable)) return p; } catch (ArgumentException) {} } } else using (var p = _processManager.Start(startInfo)) {} var procName = spec.ExpectedExecutable.FileNameWithoutExtension; return await FindGameProcess(procName).ConfigureAwait(false); }
void LogGameInfo(LaunchGameInfoBase spec) { // TODO: Par file logging... needs RV specific support.. this.Logger() .Info("Launching the game: {0} from {1}, with: {2}. AsAdmin: {3}. Expecting: {4}", spec.LaunchExecutable, spec.WorkingDirectory, spec.StartupParameters.CombineParameters(), spec.LaunchAsAdministrator, spec.ExpectedExecutable); }
Task<Process> PerformUpdaterAction(LaunchGameInfoBase spec, IEnumerable<string> args) { var startInfo = BuildProcessStartInfo(spec, args); return LaunchUpdaterProcess(spec, startInfo); }
static ProcessStartInfo BuildProcessStartInfo(LaunchGameInfoBase spec, IEnumerable<string> args) => new ProcessStartInfoBuilder(Common.Paths.ServiceExePath, args.CombineParameters()) { //AsAdministrator = spec.LaunchAsAdministrator, WorkingDirectory = Common.Paths.ServiceExePath.ParentDirectoryPath }.Build();
protected SULaunchGameArgumentsBuilder(LaunchGameInfoBase spec) { Contract.Requires<ArgumentNullException>(spec != null); Contract.Requires<ArgumentNullException>(spec.LaunchExecutable != null); Contract.Requires<ArgumentNullException>(spec.WorkingDirectory != null); Contract.Requires<ArgumentNullException>(spec.StartupParameters != null); Spec = spec; }