public void TestLaunchTool() { Mount mount = new Mount() { AppId = 440000, IsRequired = true }; Assume.That(mount.MountPath, Is.Not.Null.Or.Empty); Process process = null; Assert.That(() => { process = ToolsUtil.LaunchTool(mount.BinDirectory, "hammer"); Assert.That(process.HasExited, Is.False); }, Throws.Nothing); process.Kill(true); Assert.That(process.HasExited, Is.True); }
private void LaunchGame() { string binDir = _currentProfile.Mod.Mount.BinDirectory; string executableName = _currentProfile.Mod.ExecutableName; string gameRootPath = _currentProfile.Mod.Mount.MountPath; if (OperatingSystem.IsWindows()) { executableName += ".exe"; } else if (OperatingSystem.IsLinux()) { executableName += ".sh"; } string binPath = Path.Combine(binDir, executableName); // See if the binary is in bin folder if (!File.Exists(binPath)) { // Not in a chaos game. Try to find it in game root. binPath = Path.Combine(gameRootPath, executableName); if (!File.Exists(binPath)) { var dialog = new NotificationDialog($"Unable to find game binary '{binPath}'"); dialog.ShowDialog(this); return; } } var args = $"{_currentProfile.Mod.LaunchArguments} -game {_currentProfile.Mod.Mount.PrimarySearchPath}"; if (!string.IsNullOrWhiteSpace(_currentProfile.AdditionalMount.MountPath)) { args += $" -mountmod \"{Path.Combine(_currentProfile.AdditionalMount.MountPath, _currentProfile.AdditionalMount.PrimarySearchPath)}\""; } if (ToolsModeCheckBox.IsChecked != null && ToolsModeCheckBox.IsChecked.Value && !args.Contains("-tools")) { args += " -tools"; } if (LegacyUiCheckBox.IsChecked != null && LegacyUiCheckBox.IsChecked.Value && !args.Contains("-legacyui")) { args += " -legacyui"; } if (GraphicsApiCheckBox.IsChecked != null && GraphicsApiCheckBox.IsChecked.Value && !args.Contains("-shaderapi")) { args += " -shaderapi shaderapidx11"; } if (ConsoleCheckBox.IsChecked != null && ConsoleCheckBox.IsChecked.Value && !args.Contains("-console")) { args += " -console"; } if (DeveloperCheckBox.IsChecked != null && DeveloperCheckBox.IsChecked.Value && !args.Contains("-dev")) { args += " -dev"; } try { ToolsUtil.LaunchTool(binDir, executableName, args, false, gameRootPath); } catch (ToolsLaunchException e) { var dialog = new NotificationDialog(e.Message); dialog.ShowDialog(this); } Close(); }