Add support for specifying game's language

Fixes #4
This commit is contained in:
Chris
2020-12-28 16:38:22 -07:00
parent 35ad22bda0
commit 728b18ad73
7 changed files with 35 additions and 13 deletions

View File

@ -1,5 +1,11 @@
# Changelog
## [Unreleased]
### New Features
- Add support for specifying Elite's language instead of just using the system default
## [0.2.0] - 2020-12-13
### New Features

View File

@ -113,10 +113,11 @@ Windows: `%LOCALAPPDATA%\min-ed-launcher\settings.json`
Linux: `$XDG_CONFIG_DIR/min-ed-launcher/settings.json` (`~/.config` if `$XDG_CONFIG_DIR` isn't set)
| Settings | Effect |
|-----------------|-------------------------------------------------------------------------------------------|
|-----------------|------------------------------------------------------------------------------------------------------------------------|
| apiUri | FDev API base URI. Should only be changed if you are doing local development |
| watchForCrashes | Determines if the game should be launched by `WatchDog64.exe` or not |
| gameLocation | Path to game's install folder. Specify this if the launcher can't figure it out by itself |
| language | Sets the game's language. Supported values are _en_ and the names of the language folders in Elite's install directory |
| restart | Restart the game after it has closed |
| processes | Additional applications to launch before launching the game |
@ -128,6 +129,7 @@ double backslash (`\\`) instead of a single backslash (`\`).
"apiUri": "https://api.zaonce.net",
"watchForCrashes": false,
"gameLocation": null,
"language": "en",
"restart": {
"enabled": false,
"shutdownTimeout": 3

View File

@ -167,7 +167,7 @@ let run settings = task {
match selectedProduct, true with
| Some product, true ->
let gameLanguage = Cobra.getGameLang settings.CbLauncherDir
let gameLanguage = Cobra.getGameLang settings.CbLauncherDir settings.PreferredLanguage
let processArgs() = Product.createArgString settings.DisplayMode gameLanguage connection.Session machineId (runningTime()) settings.WatchForCrashes settings.Platform SHA1.hashFile product
match Product.validateForRun settings.CbLauncherDir settings.WatchForCrashes product with

View File

@ -1,6 +1,7 @@
module MinEdLauncher.Cobra
open System
open System.Diagnostics
open System.Globalization
open System.IO
open System.Reflection
open System.Resources
@ -27,10 +28,18 @@ let getVersion cbLauncherDir =
Ok (cobraVersion, launcherVersion)
let getGameLang cbLauncherDir =
let asm = Assembly.LoadFrom(Path.Combine(cbLauncherDir, "LocalResources.dll"))
let getGameLang cbLauncherDir langCode =
let asm = Assembly.LoadFrom(Path.Combine(cbLauncherDir, $"LocalResources.dll"))
let resManager = ResourceManager("LocalResources.Properties.Resources", asm)
try
resManager.GetString("GameLanguage") |> Some
with
| e -> None
langCode
|> Option.bind (fun c ->
if Directory.Exists(Path.Combine(cbLauncherDir, c))
|| c.Equals("en", StringComparison.OrdinalIgnoreCase)
then c.ToLowerInvariant() |> Some
else None)
|> Option.map (fun c ->
let culture = CultureInfo.CreateSpecificCulture(c)
resManager.GetString("GameLanguage", culture))
|> Option.orElseWith (fun () -> resManager.GetString("GameLanguage") |> Some)
with e -> None

View File

@ -17,6 +17,7 @@ let defaults =
ForceLocal = false
Proton = None
CbLauncherDir = "."
PreferredLanguage = None
ApiUri = Uri("http://localhost:8080")
Restart = false, 0L
Processes = List.empty }
@ -97,6 +98,7 @@ type Config =
{ ApiUri: string
WatchForCrashes: bool
GameLocation: string option
Language: string option
Restart: RestartConfig
Processes: ProcessConfig list }
let parseConfig fileName =
@ -154,6 +156,7 @@ let getSettings args fileConfig =
parseArgs defaults fallbackDirs args
|> Result.map (fun settings -> { settings with ApiUri = apiUri
PreferredLanguage = fileConfig.Language
Processes = processes
Restart = restart
WatchForCrashes = fileConfig.WatchForCrashes })

View File

@ -34,6 +34,7 @@ type LauncherSettings =
ForceLocal: ForceLocal
Proton: Proton option
CbLauncherDir: string
PreferredLanguage: string option
ApiUri: Uri
Restart: (bool * int64)
Processes: ProcessStartInfo list }

View File

@ -1,6 +1,7 @@
{
"apiUri": "https://api.zaonce.net",
"watchForCrashes": false,
"language": null,
"restart": {
"enabled": false,
"shutdownTimeout": 3