mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
fix(epic): say which launcher installs a third-party-managed game (#2344)
* fix(epic): handle third-party managed titles * Clear a cached third-party launcher when catalog details report none
This commit is contained in:
1 parent
448d296a2b
commit
fbb705cf6f
39 files changed
+113
-3
No files matched your search
@@ -51,6 +51,20 @@ fn attribute_of(entry: &Value, name: &str) -> Option<String> {
|
||||
.map(str::to_string)
|
||||
}
|
||||
|
||||
fn third_party_managed_app(entry: &Value) -> Option<String> {
|
||||
let value = attribute_of(entry, "ThirdPartyManagedApp")?;
|
||||
let value = value.trim();
|
||||
if value.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let launcher = match value.to_ascii_lowercase().as_str() {
|
||||
"origin" | "ea app" | "the ea app" => "EA app",
|
||||
"ubisoft connect" | "uplay" => "Ubisoft Connect",
|
||||
_ => value,
|
||||
};
|
||||
Some(launcher.to_string())
|
||||
}
|
||||
|
||||
pub fn details_of(entry: &Value) -> Value {
|
||||
let publisher = attribute_of(entry, "publisherName")
|
||||
.map(|p| p.trim().to_string())
|
||||
@@ -73,6 +87,7 @@ pub fn details_of(entry: &Value) -> Value {
|
||||
"wide": image(entry, &["DieselGameBox", "Thumbnail"]),
|
||||
"logo": image(entry, &["DieselGameBoxLogo"]),
|
||||
"canRunOffline": offline,
|
||||
"thirdPartyManagedApp": third_party_managed_app(entry).unwrap_or_default(),
|
||||
"dlc": main_game.is_some_and(|m| !m.is_null()),
|
||||
"mainGameId": main_game.map(|m| net::str_of(m, "id")).unwrap_or(""),
|
||||
})
|
||||
@@ -118,6 +133,7 @@ mod tests {
|
||||
assert_eq!(d["logo"], "logo");
|
||||
assert_eq!(d["publisher"], "Pub");
|
||||
assert_eq!(d["canRunOffline"], false);
|
||||
assert_eq!(d["thirdPartyManagedApp"], "");
|
||||
assert_eq!(d["releaseDate"], "2020-01-01T00:00:00.000Z");
|
||||
assert_eq!(d["dlc"], false);
|
||||
let dlc = details_of(&json!({"mainGameItem": {"id": "base"}, "seller": {"name": "S"}, "viewableDate": "v"}));
|
||||
@@ -129,4 +145,14 @@ mod tests {
|
||||
assert_eq!(dlc["logo"], "");
|
||||
assert_eq!(pick_entry(&json!({"x": {"title": "Only"}}), "y").unwrap()["title"], "Only");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_third_party_managed_launchers() {
|
||||
let ea = details_of(&json!({"customAttributes": {"ThirdPartyManagedApp": {"value": "Origin"}}}));
|
||||
let ubisoft = details_of(&json!({"customAttributes": {"ThirdPartyManagedApp": {"value": "Ubisoft Connect"}}}));
|
||||
let none = details_of(&json!({}));
|
||||
assert_eq!(ea["thirdPartyManagedApp"], "EA app");
|
||||
assert_eq!(ubisoft["thirdPartyManagedApp"], "Ubisoft Connect");
|
||||
assert_eq!(none["thirdPartyManagedApp"], "");
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,9 @@ pub struct Request {
|
||||
|
||||
impl Request {
|
||||
pub fn from_json(v: &Value) -> Result<Request, String> {
|
||||
if let Some(launcher) = v.get("thirdPartyManagedApp").and_then(Value::as_str).map(str::trim).filter(|s| !s.is_empty()) {
|
||||
return Err(format!("third-party-managed:{launcher}"));
|
||||
}
|
||||
let info = v.get("info").and_then(BuildInfo::from_json).ok_or("The manifest could not be fetched")?;
|
||||
let game_dir = net::str_of(v, "gameDir");
|
||||
if game_dir.is_empty() || !game_dir.starts_with('/') {
|
||||
|
||||
@@ -12,6 +12,15 @@ use crate::epic::chunk::testing::encode;
|
||||
use crate::epic::manifest::testing::{build, chunk, TestFile, TestManifest};
|
||||
use crate::epic::manifest::{guid_text, PartRef};
|
||||
|
||||
#[test]
|
||||
fn rejects_third_party_managed_install_before_manifest_parsing() {
|
||||
let request = serde_json::json!({"thirdPartyManagedApp": "EA app"});
|
||||
match Request::from_json(&request) {
|
||||
Err(error) => assert_eq!(error, "third-party-managed:EA app"),
|
||||
Ok(_) => panic!("third-party-managed install was accepted"),
|
||||
}
|
||||
}
|
||||
|
||||
fn serve(files: HashMap<String, Vec<u8>>, hits: Arc<AtomicUsize>) -> String {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let addr = listener.local_addr().unwrap();
|
||||
|
||||
Reference in new issue
Block a user