Skip to content

Commit

Permalink
show ui for choosing to install new products
Browse files Browse the repository at this point in the history
fixes #126
  • Loading branch information
rfvgyhn committed May 3, 2024
1 parent b1a7a5f commit 614cea6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 30 deletions.
23 changes: 19 additions & 4 deletions src/MinEdLauncher/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,33 @@ let run settings launcherVersion cancellationToken = taskResult {

Log.info $"Available Products:{Environment.NewLine}\t%s{Console.availableProductsDisplay products}"

let productsRequiringUpdate = Product.filterByUpdateRequired settings.Platform settings.ForceUpdate products |> List.toArray
let missingToInstall =
let missing =
products
|> Product.filterByMissing
|> Product.filterByUpdateable settings.Platform settings.ForceUpdate
|> List.toArray
if settings.AutoRun then
Product.selectProduct settings.ProductWhitelist missing |> Option.map(fun p -> [| p |]) |> Option.defaultWith(fun () -> [||])
else
missing |> Console.promptForProductsToUpdate "install"
let productsRequiringUpdate =
products
|> Product.filterByUpdateRequired
|> Product.filterByUpdateable settings.Platform settings.ForceUpdate
|> List.toArray
let productsToUpdate =
let products =
if settings.AutoUpdate then
productsRequiringUpdate
else
productsRequiringUpdate |> Console.promptForProductsToUpdate
productsRequiringUpdate |> Console.promptForProductsToUpdate "update"
|> Array.append missingToInstall
products
|> Array.filter (fun p -> p.Metadata.IsNone)
|> Array.filter (_.Metadata.IsNone)
|> Array.iter (fun p -> Log.error $"Unknown product metadata for %s{p.Name}")

products |> Array.filter (fun p -> p.Metadata.IsSome)
products |> Array.filter (_.Metadata.IsSome)

let! productManifests =
if productsToUpdate.Length > 0 then
Expand Down
6 changes: 3 additions & 3 deletions src/MinEdLauncher/Console.fs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ let promptUserPass() =
let password = readPassword() |> Cobra.encrypt |> Result.defaultValue ""
username, password

let promptForProductsToUpdate (products: ProductDetails array) =
let promptForProductsToUpdate verb (products: ProductDetails array) =
if products.Length > 0 then
printfn $"Select product(s) to update (eg: \"1\", \"1 2 3\") (default=None):"
printfn $"Select product(s) to %s{verb} (eg: \"1\", \"1 2 3\") (default=None):"
products
|> Array.indexed
|> Array.iter (fun (i, product) -> printfn $"%i{i + 1}) %s{product.Name}")
Expand All @@ -117,7 +117,7 @@ let promptForProductsToUpdate (products: ProductDetails array) =
None
else
match Int32.Parse(d) with
| n when n > 0 && n < products.Length -> Some n
| n when n > 0 && n <= products.Length -> Some n
| _ -> None)
|> Array.map (fun i -> products.[i - 1])
if selection.Length > 0 then
Expand Down
17 changes: 9 additions & 8 deletions src/MinEdLauncher/Product.fs
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,19 @@ let downloadFiles downloader destDir (files: Types.ProductManifest.File[]) : Tas
return Ok result
with e -> return e.ToString() |> Error }

let filterByUpdateRequired platform updateOverride (products: Product list) =
// Steam and Epic updates should be handled by their CDNs.
// Sometimes FDev doesn't release updates through them though (e.g. Odyssey alpha)
// so allow users to specify if they want to override that behavior
let updateable (details: ProductDetails list) =
// Steam and Epic updates should be handled by their CDNs.
// Sometimes FDev doesn't release updates through them though (e.g. Odyssey alpha)
// so allow users to specify if they want to override that behavior
let filterByUpdateable platform updateOverride (details: ProductDetails list) =
match platform with
| Steam | Epic _ -> details |> List.filter (fun p -> updateOverride |> Set.contains p.Sku)
| Frontier _ | Oculus _ | Dev -> details

products
|> List.choose (fun p -> match p with | RequiresUpdate p | Missing p -> Some p | _ -> None)
|> updateable
let filterByMissing (products: Product list) =
products |> List.choose (function | Missing p -> Some p | _ -> None)

let filterByUpdateRequired (products: Product list) =
products |> List.choose (function | RequiresUpdate p -> Some p | _ -> None)

let selectProduct (whitelist: OrdinalIgnoreCaseSet) (products: ProductDetails[]) =
if whitelist.IsEmpty then
Expand Down
34 changes: 19 additions & 15 deletions tests/Product.fs
Original file line number Diff line number Diff line change
Expand Up @@ -350,56 +350,60 @@ open MinEdLauncher.Tests.Extensions
test "only returns products that require update" {
let playable = { product with Sku = "Playable" }
let needsUpdate = { product with Sku = "NeedsUpdate" }
let products = [ Playable playable ; RequiresUpdate needsUpdate ; Missing needsUpdate ]
let missing = { product with Sku = "Missing" }
let products = [ Playable playable ; RequiresUpdate needsUpdate ; Missing missing ]

let result = filterByUpdateRequired Dev Set.empty products
let result = filterByUpdateRequired products

Expect.hasLength result 2 ""
Expect.allEqual result needsUpdate ""
}
Expect.hasLength result 1 ""
Expect.equal result[0] needsUpdate ""
} ]
testList "filterByUpdateable" [
test "epic excludes all if no override specified" {
let products = [ RequiresUpdate product; Missing product ]
let products = [ product; product ]

let result = filterByUpdateRequired (Epic EpicDetails.Empty) Set.empty products
let result = filterByUpdateable (Epic EpicDetails.Empty) Set.empty products

Expect.isEmpty result ""
}
test "epic excludes all except override" {
let override1 = { product with Sku = "1" }
let override2 = { product with Sku = "2" }
let notOverride = { product with Sku = "3" }
let products = [ RequiresUpdate override1; Missing override2; RequiresUpdate notOverride; Missing notOverride ]
let products = [ override1; override2; notOverride ]
let force = [ override1; override2 ] |> List.map _.Sku |> Set.ofList

let result = filterByUpdateRequired (Epic EpicDetails.Empty) force products
let result = filterByUpdateable (Epic EpicDetails.Empty) force products

Expect.hasLength result 2 ""
Expect.all result (fun p -> p.Sku <> notOverride.Sku) ""
}
test "steam excludes all if no override specified" {
let products = [ RequiresUpdate product; Missing product ]
let products = [ product; product ]

let result = filterByUpdateRequired Steam Set.empty products
let result = filterByUpdateable Steam Set.empty products

Expect.isEmpty result ""
}
test "steam excludes all except override" {
let override1 = { product with Sku = "1" }
let override2 = { product with Sku = "2" }
let notOverride = { product with Sku = "3" }
let products = [ RequiresUpdate override1; Missing override2; RequiresUpdate notOverride; Missing notOverride ]
let products = [ override1; override2; notOverride ]
let force = [ override1; override2 ] |> List.map _.Sku |> Set.ofList

let result = filterByUpdateRequired Steam force products
let result = filterByUpdateable Steam force products

Expect.hasLength result 2 ""
Expect.all result (fun p -> p.Sku <> notOverride.Sku) ""
}
test "frontier includes all" {
let products = [ product; product ]
let p1 = { product with Sku = "1" }
let p2 = { product with Sku = "2" }
let products = [ p1; p2 ]
let platform = Frontier FrontierDetails.Empty

let result = filterByUpdateRequired platform Set.empty (products |> List.map RequiresUpdate)
let result = filterByUpdateable platform Set.empty products

Expect.sequenceEqual result products ""
} ]
Expand Down

0 comments on commit 614cea6

Please sign in to comment.