add ability to specify cache dir in settings file

closes #97
This commit is contained in:
Chris
2023-09-12 16:27:07 -06:00
parent f9abbf5220
commit 0c74eb19f6
5 changed files with 21 additions and 7 deletions

View File

@ -2,6 +2,10 @@
## [Unreleased]
### New Features
- Add ability to specify cache directory in settings file since Windows users don't have an environment variable
like `XDG_CACHE_DIR` on Linux. Add `cacheDir` to your [settings file].
### Bug Fixes
- Fix launcher not shutting down when a startup process doesn't properly shutdown or takes too long to shutdown.
The timeout for taking too long can be configured via the new `shutdownTimeout` property in the [settings file].

View File

@ -207,6 +207,7 @@ double backslash (`\\`) instead of a single backslash (`\`).
"checkForLauncherUpdates": true,
"maxConcurrentDownloads": 4,
"forceUpdate": "PUBLIC_TEST_SERVER_OD",
"cacheDir": "C:\\path\\to\\dir",
"processes": [
{
"fileName": "C:\\path\\to\\app.exe",

View File

@ -222,6 +222,7 @@ let updateProduct downloader (hashProgress: ISampledProgress<int>) (cacheProgres
type AppError =
| Version of string
| ProductsDirectory of string
| CacheDirectory of string
| MachineId of string
| AuthorizedProducts of string
| Login of LoginError
@ -233,6 +234,7 @@ module AppError =
let toDisplayString = function
| Version m -> $"Unable to get version: %s{m}"
| ProductsDirectory m -> $"Unable to get products directory: %s{m}"
| CacheDirectory m -> $"Unable to get cache directory: %s{m}"
| MachineId m -> $"Couldn't get machine id: %s{m}"
| AuthorizedProducts m -> $"Couldn't get available products: %s{m}"
| Login (ActionRequired m) -> $"Unsupported login action required: %s{m}"
@ -350,6 +352,7 @@ let run settings launcherVersion cancellationToken = taskResult {
let messages = failedManifests |> List.map (fun (name, error) -> $"%s{name} - %s{error}") |> String.join separator
Log.error $"Unable to update the following products. Failed to get their manifests:%s{separator}%s{messages}"
let! cacheDir = settings.CacheDir |> FileIO.ensureDirExists |> Result.mapError CacheDirectory
let! updated =
let productsDir = Path.Combine(settings.CbLauncherDir, "Products")
@ -357,11 +360,11 @@ let run settings launcherVersion cancellationToken = taskResult {
|> List.chooseTasksSequential (fun (product, manifest) -> task {
Log.info $"Updating %s{product.Name}"
let productDir = Path.Combine(productsDir, product.Directory)
let productCacheDir = Path.Combine(Environment.cacheDir, $"%s{manifest.Title}%s{manifest.Version}")
let productCacheDir = Path.Combine(cacheDir, $"%s{manifest.Title}%s{manifest.Version}")
let pathInfo = { ProductDir = productDir
ProductCacheDir = productCacheDir
CacheHashMap = Path.Combine(productCacheDir, "hashmap.txt")
ProductHashMap = Path.Combine(Environment.cacheDir, $"hashmap.%s{Path.GetFileName(productDir)}.txt") }
ProductHashMap = Path.Combine(cacheDir, $"hashmap.%s{Path.GetFileName(productDir)}.txt") }
let barLength = 30
let downloadProgress = Console.Progress(Console.productDownloadIndicator barLength)
let totalFiles = manifest.Files.Length
@ -379,7 +382,7 @@ let run settings launcherVersion cancellationToken = taskResult {
Console.CursorVisible <- true
File.Delete(pathInfo.CacheHashMap)
FileIO.mergeDirectories productDir productCacheDir
Log.debug $"Moved downloaded files from '%s{Environment.cacheDir}' to '%s{productDir}'"
Log.debug $"Moved downloaded files from '%s{cacheDir}' to '%s{productDir}'"
Log.info $"Finished updating %s{product.Name}"
return Some product
| Error e ->

View File

@ -30,7 +30,8 @@ let defaults =
FilterOverrides = OrdinalIgnoreCaseMap.empty
AdditionalProducts = List.empty
DryRun = false
ShutdownTimeout = TimeSpan.FromSeconds(10) }
ShutdownTimeout = TimeSpan.FromSeconds(10)
CacheDir = "" }
[<RequireQualifiedAccess>]
type FrontierCredResult = Found of string * string * string option | NotFound of string | UnexpectedFormat of string | Error of string
@ -174,7 +175,8 @@ type Config =
FilterOverrides: FilterConfig list
AdditionalProducts: AuthorizedProduct list
[<DefaultValue("10")>]
ShutdownTimeout: int }
ShutdownTimeout: int
CacheDir: string option }
let parseConfig fileName =
let configRoot = ConfigurationBuilder()
.AddJsonFile(fileName, false)
@ -258,4 +260,7 @@ let getSettings args appDir fileConfig = task {
FilterOverrides = filterOverrides
WatchForCrashes = fileConfig.WatchForCrashes
AdditionalProducts = fileConfig.AdditionalProducts
ShutdownTimeout = TimeSpan.FromSeconds(fileConfig.ShutdownTimeout) }) }
ShutdownTimeout = TimeSpan.FromSeconds(fileConfig.ShutdownTimeout)
CacheDir = fileConfig.CacheDir |> Option.defaultValue Environment.cacheDir
})
}

View File

@ -126,7 +126,8 @@ type LauncherSettings =
FilterOverrides: OrdinalIgnoreCaseMap<string>
AdditionalProducts: AuthorizedProduct list
DryRun: bool
ShutdownTimeout: TimeSpan }
ShutdownTimeout: TimeSpan
CacheDir: string }
type ProductMode = Online | Offline
type VersionInfo =
{ Name: string