Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FInd installed Epic and GOG games #100

Merged
merged 10 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
439 changes: 425 additions & 14 deletions backend/Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ glob = { git = "https://github.com/rust-lang/glob", version = "0.3.1" }
# Also I made my own fork to remove some annoying prints.
steamlocate = { git = "https://github.com/Raicuparta/steamlocate-rs", branch = "dev-v2.0" }

# Made my own fork to fix builds on windows and add my own stuff.
game-scanner = { git = "https://github.com/Raicuparta/game-scanner", branch = "main"}

specta = "1.0.5"
tauri-specta = { version = "1.0.2", features = ["typescript"] }
serde = { version = "1.0", features = ["derive"] }
Expand Down
130 changes: 130 additions & 0 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,135 @@ async fn frontend_ready() -> Result {
Ok(())
}

#[tauri::command]
#[specta::specta]
async fn get_other_games() -> Result<HashMap<String, Vec<String>>> {
let games = HashMap::from([
(
"Epic".to_string(),
game_scanner::epicgames::games()
.unwrap_or_default()
.iter()
.map(|game| {
format!(
"{}: {}. {} ({})",
game.id,
game.name,
if game.state.installed {
"installed"
} else {
"owned"
},
game.path.clone().unwrap_or_default().to_string_lossy()
)
})
.collect(),
),
(
"GOG".to_string(),
game_scanner::gog::games()
.unwrap_or_default()
.iter()
.map(|game| {
format!(
"{}: {}. {} ({})",
game.id,
game.name,
if game.state.installed {
"installed"
} else {
"owned"
},
game.path.clone().unwrap_or_default().to_string_lossy()
)
})
.collect(),
),
(
"Origin".to_string(),
game_scanner::origin::games()
.unwrap_or_default()
.iter()
.map(|game| {
format!(
"{}: {}. {} ({})",
game.id,
game.name,
if game.state.installed {
"installed"
} else {
"owned"
},
game.path.clone().unwrap_or_default().to_string_lossy()
)
})
.collect(),
),
(
"Ubisoft".to_string(),
game_scanner::ubisoft::games()
.unwrap_or_default()
.iter()
.map(|game| {
format!(
"{}: {}. {} ({})",
game.id,
game.name,
if game.state.installed {
"installed"
} else {
"owned"
},
game.path.clone().unwrap_or_default().to_string_lossy()
)
})
.collect(),
),
(
"Amazon".to_string(),
game_scanner::amazon::games()
.unwrap_or_default()
.iter()
.map(|game| {
format!(
"{}: {}. {} ({})",
game.id,
game.name,
if game.state.installed {
"installed"
} else {
"owned"
},
game.path.clone().unwrap_or_default().to_string_lossy()
)
})
.collect(),
),
(
"Steam".to_string(),
game_scanner::steam::games()
.unwrap_or_default()
.iter()
.map(|game| {
format!(
"{}: {}. {} ({})",
game.id,
game.name,
if game.state.installed {
"installed"
} else {
"owned"
},
game.path.clone().unwrap_or_default().to_string_lossy()
)
})
.collect(),
),
]);

Ok(games)
}

#[tauri::command]
#[specta::specta]
async fn dummy_command() -> Result<(InstalledGame, AppEvent)> {
Expand Down Expand Up @@ -555,6 +684,7 @@ fn main() {
get_remote_mods,
open_mod_loader_folder,
refresh_game,
get_other_games,
]
);

Expand Down
49 changes: 49 additions & 0 deletions backend/src/providers/epic_provider.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use async_trait::async_trait;

use super::provider::ProviderId;
use crate::{
installed_game::InstalledGame,
owned_game::OwnedGame,
provider::{
ProviderActions,
ProviderStatic,
},
Result,
};

pub struct EpicProvider {}

impl ProviderStatic for EpicProvider {
const ID: &'static ProviderId = &ProviderId::Epic;

fn new() -> Result<Self>
where
Self: Sized,
{
Ok(Self {})
}
}

#[async_trait]
impl ProviderActions for EpicProvider {
fn get_installed_games(&self) -> Result<Vec<InstalledGame>> {
Ok(game_scanner::epicgames::games()
.unwrap_or_default()
.iter()
.filter_map(|game| {
InstalledGame::new(
game.path.as_ref()?,
&game.name,
Self::ID.to_owned(),
None,
None,
None,
)
})
.collect())
}

async fn get_owned_games(&self) -> Result<Vec<OwnedGame>> {
Ok(Vec::default())
}
}
69 changes: 69 additions & 0 deletions backend/src/providers/gog_provider.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use async_trait::async_trait;

use super::provider::ProviderId;
use crate::{
installed_game::InstalledGame,
owned_game::OwnedGame,
provider::{
ProviderActions,
ProviderStatic,
},
Result,
};

pub struct GogProvider {}

impl ProviderStatic for GogProvider {
const ID: &'static ProviderId = &ProviderId::Gog;

fn new() -> Result<Self>
where
Self: Sized,
{
Ok(Self {})
}
}

#[async_trait]
impl ProviderActions for GogProvider {
fn get_installed_games(&self) -> Result<Vec<InstalledGame>> {
Ok(game_scanner::gog::games()
.unwrap_or_default()
.iter()
.filter_map(|game| {
InstalledGame::new(
game.path.as_ref()?,
&game.name,
Self::ID.to_owned(),
None,
None,
None,
)
})
.collect())
}

async fn get_owned_games(&self) -> Result<Vec<OwnedGame>> {
Ok(Vec::default())

// TODO figure out if this is worth implementing.
// Ok(game_scanner::gog::games()
// .unwrap_or_default()
// .iter()
// .map(|game| OwnedGame {
// // TODO should add a constructor to OwnedGame to avoid ID collisions and stuff.
// id: game.id.clone(),
// provider_id: *Self::ID,
// name: game.name.clone(),
// installed: false, // TODO
// os_list: HashSet::default(),
// // Make engine optional?
// engine: GameEngineBrand::Unity,
// release_date: 0,
// thumbnail_url: String::default(),
// game_mode: GameMode::Flat,
// uevr_score: None,
// })
// .collect())
}
}
2 changes: 2 additions & 0 deletions backend/src/providers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod epic_provider;
pub mod gog_provider;
pub mod manual_provider;
pub mod provider;
pub mod steam_provider;
15 changes: 14 additions & 1 deletion backend/src/providers/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use std::collections::HashMap;
use async_trait::async_trait;
use enum_dispatch::enum_dispatch;

use super::{
epic_provider::EpicProvider,
gog_provider::GogProvider,
};
use crate::{
installed_game::InstalledGame,
owned_game::OwnedGame,
Expand All @@ -15,12 +19,19 @@ use crate::{
Result,
};

serializable_enum!(ProviderId { Steam, Manual });
serializable_enum!(ProviderId {
Steam,
Manual,
Epic,
Gog,
});

#[enum_dispatch]
pub enum Provider {
SteamProvider,
ManualProvider,
EpicProvider,
GogProvider,
}

#[async_trait]
Expand Down Expand Up @@ -70,6 +81,8 @@ where
let mut map = Map::new();

add_entry::<SteamProvider, F>(&mut map, &error_handler);
add_entry::<EpicProvider, F>(&mut map, &error_handler);
add_entry::<GogProvider, F>(&mut map, &error_handler);
add_entry::<ManualProvider, F>(&mut map, &error_handler);

map
Expand Down
36 changes: 20 additions & 16 deletions frontend/api/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,30 @@ export function refreshGame(gameId: string) {
return invoke()<null>("refresh_game", { gameId })
}

export type OwnedGame = { id: string; providerId: ProviderId; name: string; installed: boolean; osList: OperatingSystem[]; engine: GameEngineBrand; releaseDate: number; thumbnailUrl: string; gameMode: GameMode; uevrScore: UevrScore | null }
export type LocalMod = { data: LocalModData; common: CommonModData }
export type ModLoaderData = { id: string; path: string; kind: ModKind }
export type GameExecutable = { path: string; engine: GameEngine | null; architecture: Architecture | null; operatingSystem: OperatingSystem | null; scriptingBackend: UnityScriptingBackend | null }
export type ModDownload = { id: string; url: string; root: string | null }
export function getOtherGames() {
return invoke()<{ [key: string]: string[] }>("get_other_games")
}

export type GameEngineVersion = { major: number; minor: number; patch: number; suffix: string | null; display: string }
export type GameEngineBrand = "Unity" | "Unreal" | "Godot"
export type GameMode = "VR" | "Flat"
export type InstalledGame = { id: string; name: string; providerId: ProviderId; discriminator: string | null; steamLaunch: SteamLaunchOption | null; executable: GameExecutable; thumbnailUrl: string | null; installedModVersions: { [key: string]: string | null }; gameMode: GameMode }
export type RemoteModData = { title: string; author: string; sourceCode: string; description: string; latestVersion: ModDownload | null }
export type GameEngine = { brand: GameEngineBrand; version: GameEngineVersion | null }
export type SteamLaunchOption = { launchId: string; appId: number; description: string | null; executable: string | null; arguments: string | null; appType: string | null; osList: string | null; betaKey: string | null; osArch: string | null }
export type UnityScriptingBackend = "Il2Cpp" | "Mono"
export type Architecture = "X64" | "X86"
export type GameEngineVersion = { major: number; minor: number; patch: number; suffix: string | null; display: string }
export type OwnedGame = { id: string; providerId: ProviderId; name: string; installed: boolean; osList: OperatingSystem[]; engine: GameEngineBrand; releaseDate: number; thumbnailUrl: string; gameMode: GameMode; uevrScore: UevrScore | null }
export type AppEvent = "SyncInstalledGames" | "SyncOwnedGames" | "SyncModLoaders" | "SyncLocalMods" | "SyncRemoteMods" | "ExecutedSteamCommand" | "GameAdded" | "GameRemoved" | "Error"
export type OperatingSystem = "Linux" | "Windows"
export type RemoteModData = { title: string; author: string; sourceCode: string; description: string; latestVersion: ModDownload | null }
export type SteamLaunchOption = { launchId: string; appId: number; description: string | null; executable: string | null; arguments: string | null; appType: string | null; osList: string | null; betaKey: string | null; osArch: string | null }
export type GameExecutable = { path: string; engine: GameEngine | null; architecture: Architecture | null; operatingSystem: OperatingSystem | null; scriptingBackend: UnityScriptingBackend | null }
export type Manifest = { version: string }
export type UevrScore = "A" | "B" | "C" | "D" | "E"
export type ProviderId = "Steam" | "Manual"
export type InstalledGame = { id: string; name: string; providerId: ProviderId; discriminator: string | null; steamLaunch: SteamLaunchOption | null; executable: GameExecutable; thumbnailUrl: string | null; installedModVersions: { [key: string]: string | null }; gameMode: GameMode }
export type LocalMod = { data: LocalModData; common: CommonModData }
export type RemoteMod = { common: CommonModData; data: RemoteModData }
export type ModDownload = { id: string; url: string; root: string | null }
export type ModKind = "Installable" | "Runnable"
export type UnityScriptingBackend = "Il2Cpp" | "Mono"
export type GameEngine = { brand: GameEngineBrand; version: GameEngineVersion | null }
export type CommonModData = { id: string; engine: GameEngineBrand | null; unityBackend: UnityScriptingBackend | null; loaderId: string }
export type GameEngineBrand = "Unity" | "Unreal" | "Godot"
export type LocalModData = { path: string; manifest: Manifest | null }
export type ModKind = "Installable" | "Runnable"
export type RemoteMod = { common: CommonModData; data: RemoteModData }
export type UevrScore = "A" | "B" | "C" | "D" | "E"
export type ProviderId = "Steam" | "Manual" | "Epic" | "Gog"
export type ModLoaderData = { id: string; path: string; kind: ModKind }
2 changes: 2 additions & 0 deletions frontend/components/badges/color-coded-badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export const OperatingSystemBadge = CreateColorCodedBadge<OperatingSystem>(
export const ProviderBadge = CreateColorCodedBadge<ProviderId>("Unknown", {
Manual: "gray",
Steam: "blue",
Epic: "red",
Gog: "violet",
});

export const UevrScoreBadge = CreateColorCodedBadge<UevrScore>("-", {
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/debug-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Props<TData> = {

export function DebugData<TData>(props: Props<TData>) {
const debugText = useMemo(
() => JSON.stringify(props.data, null, 2),
() => JSON.stringify(props.data, null, 2) ?? "",
[props.data],
);

Expand Down
Loading
Loading