add a dry run mode

This commit is contained in:
Chris
2022-10-12 21:01:31 -06:00
parent 93b10c3d12
commit 0dbe9fe94c
8 changed files with 37 additions and 14 deletions

View File

@ -1,5 +1,10 @@
# Changelog
## [Unreleased]
### Enhancements
- Add ability to run the launcher without launching any processes via the `/dryrun` flag
## [0.7.2] - 2022-10-10
### Enhancements

View File

@ -163,6 +163,7 @@ The following arguments are in addition to the above:
| /edh4 | Select Elite Dangerous Horizons 4.0 as the startup product |
| /frontier profile-name | Use this argument to login with a Frontier Store account. Keep the profile name to letters, numbers, dashes and underscores only |
| /restart delay | Restart the game after it has closed with _delay_ being the number of seconds given to cancel the restart (i.e `/restart 3`) |
| /dryrun | Prints output without launching any processes |
Note that the restart feature doesn't work with Epic accounts. After Elite launches, it invalidates
the launcher's auth token and doesn't communicate the new token which then prevents the ability to

View File

@ -73,11 +73,11 @@ let printInfo (platform: Platform) productsDir cobraVersion =
CobraBay Version: %s{cobraVersion}
Products Dir: %s{productsDir}"""
let rec launchProduct proton processArgs restart productName product =
let rec launchProduct dryRun proton processArgs restart productName product =
let args = processArgs()
Log.info $"Launching %s{productName}"
match Product.run proton args product with
match Product.run dryRun proton args product with
| Product.RunResult.Ok p ->
let timeout = restart |> Option.defaultValue 3000L
let cancelRestart() =
@ -106,7 +106,10 @@ let rec launchProduct proton processArgs restart productName product =
Log.info $"Shutdown %s{productName}"
if restart.IsSome && not (cancelRestart()) then
launchProduct proton processArgs restart productName product
launchProduct dryRun proton processArgs restart productName product
| Product.DryRun p ->
Console.WriteLine("\tDry run")
Console.WriteLine($"\t{p.FileName} {p.Arguments}")
| Product.RunResult.AlreadyRunning -> Log.info $"%s{productName} is already running"
| Product.RunResult.Error e -> Log.error $"Couldn't start selected product: %s{e.ToString()}"
@ -495,10 +498,15 @@ let run settings launcherVersion cancellationToken = taskResult {
let gameLanguage = Cobra.getGameLang settings.CbLauncherDir settings.PreferredLanguage
let processArgs() = Product.createArgString settings.DisplayMode gameLanguage connection.Session machineId (getRunningTime()) settings.WatchForCrashes settings.Platform SHA1.hashFile selectedProduct
let processes = Process.launchProcesses settings.Processes
settings.Processes |> List.iter (fun p -> Log.info $"Starting process %s{p.FileName}")
let processes =
if settings.DryRun then
[]
else
Process.launchProcesses settings.Processes
if not cancellationToken.IsCancellationRequested then
launchProduct settings.CompatTool processArgs settings.Restart selectedProduct.Name p
launchProduct settings.DryRun settings.CompatTool processArgs settings.Restart selectedProduct.Name p
Process.stopProcesses processes
return 0
}

View File

@ -6,7 +6,6 @@ let launchProcesses (processes:ProcessStartInfo list) =
processes
|> List.choose (fun p ->
try
Log.info $"Starting process %s{p.FileName}"
Process.Start(p) |> Some
with
| e ->

View File

@ -270,8 +270,8 @@ let createProcessInfo proton args product =
startInfo.RedirectStandardError <- true
startInfo
type RunResult = Ok of Process | AlreadyRunning | Error of exn
let run proton args (product:RunnableProduct) =
type RunResult = Ok of Process | AlreadyRunning | DryRun of ProcessStartInfo | Error of exn
let run dryRun proton args (product:RunnableProduct) =
if isRunning product then
AlreadyRunning
else
@ -279,7 +279,10 @@ let run proton args (product:RunnableProduct) =
Log.debug $"Process: %s{startInfo.FileName} %s{startInfo.Arguments}"
try
Process.Start(startInfo) |> Ok
with
| e -> Error e
if dryRun then
DryRun startInfo
else
try
Process.Start(startInfo) |> Ok
with
| e -> Error e

View File

@ -25,7 +25,8 @@ let defaults =
ForceUpdate = Set.empty
Processes = List.empty
FilterOverrides = OrdinalIgnoreCaseMap.empty
AdditionalProducts = List.empty }
AdditionalProducts = List.empty
DryRun = false }
[<RequireQualifiedAccess>]
type FrontierCredResult = Found of string * string * string option | NotFound of string | UnexpectedFormat of string | Error of string
@ -140,6 +141,7 @@ let parseArgs defaults (findCbLaunchDir: Platform -> Result<string,string>) (arg
| "/autorun", _ -> { s with AutoRun = true }
| "/autoquit", _ -> { s with AutoQuit = true }
| "/forcelocal", _ -> { s with ForceLocal = true }
| "/dryrun", _ -> { s with DryRun = true }
| arg, _ when arg.StartsWith('/')
&& arg.Length > 1 -> { s with ProductWhitelist = s.ProductWhitelist.Add (arg.TrimStart('/')) }
| _ -> s) defaults

View File

@ -95,7 +95,8 @@ type LauncherSettings =
ForceUpdate: string Set
Processes: ProcessStartInfo list
FilterOverrides: OrdinalIgnoreCaseMap<string>
AdditionalProducts: AuthorizedProduct list }
AdditionalProducts: AuthorizedProduct list
DryRun: bool }
type ProductMode = Online | Offline
type VersionInfo =
{ Name: string

View File

@ -79,6 +79,10 @@ let tests =
let! settings = parse [| "/novr" |]
Expect.equal settings.DisplayMode Pancake ""
}
testTask "Matches /dryrun" {
let! settings = parse [| "/dryrun" |]
Expect.isTrue settings.DryRun ""
}
testTask "Matches /autorun" {
let! settings = parse [| "/autorun" |]
Expect.equal settings.AutoRun true ""