mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-15 17:21:19 +10:00
Compare commits
6 Commits
160-generi
...
0f48f3fb44
| Author | SHA1 | Date | |
|---|---|---|---|
| 0f48f3fb44 | |||
| 974666efe2 | |||
| 9e1bf9852f | |||
| 5d22b883d5 | |||
| 62a2561539 | |||
| 59f040bc8b |
8290
Cargo.lock
generated
Normal file
8290
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"client",
|
||||||
|
"database",
|
||||||
|
"src-tauri",
|
||||||
|
"process",
|
||||||
|
"remote",
|
||||||
|
"utils",
|
||||||
|
"cloud_saves",
|
||||||
|
"download_manager",
|
||||||
|
"games",
|
||||||
|
]
|
||||||
|
|
||||||
|
resolver = "3"
|
||||||
@ -6,7 +6,6 @@ edition = "2024"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
bitcode = "0.6.7"
|
bitcode = "0.6.7"
|
||||||
database = { version = "0.1.0", path = "../database" }
|
database = { version = "0.1.0", path = "../database" }
|
||||||
drop-consts = { version = "0.1.0", path = "../drop-consts" }
|
|
||||||
log = "0.4.28"
|
log = "0.4.28"
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
tauri = "2.8.5"
|
tauri = "2.8.5"
|
||||||
@ -5,7 +5,6 @@ use std::{
|
|||||||
sync::LazyLock,
|
sync::LazyLock,
|
||||||
};
|
};
|
||||||
|
|
||||||
use drop_consts::{UMU_BASE_LAUNCHER_EXECUTABLE, UMU_INSTALL_DIRS};
|
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
pub static COMPAT_INFO: LazyLock<Option<CompatInfo>> = LazyLock::new(create_new_compat_info);
|
pub static COMPAT_INFO: LazyLock<Option<CompatInfo>> = LazyLock::new(create_new_compat_info);
|
||||||
@ -31,6 +30,9 @@ fn create_new_compat_info() -> Option<CompatInfo> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const UMU_BASE_LAUNCHER_EXECUTABLE: &str = "umu-run";
|
||||||
|
const UMU_INSTALL_DIRS: [&str; 4] = ["/app/share", "/use/local/share", "/usr/share", "/opt"];
|
||||||
|
|
||||||
fn get_umu_executable() -> Option<PathBuf> {
|
fn get_umu_executable() -> Option<PathBuf> {
|
||||||
if check_executable_exists(UMU_BASE_LAUNCHER_EXECUTABLE) {
|
if check_executable_exists(UMU_BASE_LAUNCHER_EXECUTABLE) {
|
||||||
return Some(PathBuf::from(UMU_BASE_LAUNCHER_EXECUTABLE));
|
return Some(PathBuf::from(UMU_BASE_LAUNCHER_EXECUTABLE));
|
||||||
@ -1,4 +1,3 @@
|
|||||||
pub mod app_state;
|
|
||||||
pub mod app_status;
|
pub mod app_status;
|
||||||
pub mod autostart;
|
pub mod autostart;
|
||||||
pub mod compat;
|
pub mod compat;
|
||||||
@ -6,7 +6,6 @@ edition = "2024"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
database = { version = "0.1.0", path = "../database" }
|
database = { version = "0.1.0", path = "../database" }
|
||||||
dirs = "6.0.0"
|
dirs = "6.0.0"
|
||||||
drop-consts = { version = "0.1.0", path = "../drop-consts" }
|
|
||||||
log = "0.4.28"
|
log = "0.4.28"
|
||||||
regex = "1.11.3"
|
regex = "1.11.3"
|
||||||
rustix = "1.1.2"
|
rustix = "1.1.2"
|
||||||
@ -2,7 +2,7 @@ use std::{collections::HashMap, path::PathBuf, str::FromStr};
|
|||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
use database::platform::Platform;
|
use database::platform::Platform;
|
||||||
use database::{db::DATA_ROOT_DIR, GameVersion};
|
use database::{GameVersion, db::DATA_ROOT_DIR};
|
||||||
use log::warn;
|
use log::warn;
|
||||||
|
|
||||||
use crate::error::BackupError;
|
use crate::error::BackupError;
|
||||||
@ -27,7 +27,7 @@ impl BackupManager<'_> {
|
|||||||
current_platform: Platform::Windows,
|
current_platform: Platform::Windows,
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
current_platform: Platform::macOS,
|
current_platform: Platform::MacOs,
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
current_platform: Platform::Linux,
|
current_platform: Platform::Linux,
|
||||||
@ -43,7 +43,7 @@ impl BackupManager<'_> {
|
|||||||
&LinuxBackupManager {} as &(dyn BackupHandler + Sync + Send),
|
&LinuxBackupManager {} as &(dyn BackupHandler + Sync + Send),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
(Platform::macOS, Platform::macOS),
|
(Platform::MacOs, Platform::MacOs),
|
||||||
&MacBackupManager {} as &(dyn BackupHandler + Sync + Send),
|
&MacBackupManager {} as &(dyn BackupHandler + Sync + Send),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
0
cloud_saves/src/strict_path.rs
Normal file
0
cloud_saves/src/strict_path.rs
Normal file
@ -4,10 +4,8 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitcode = "0.6.7"
|
|
||||||
chrono = "0.4.42"
|
chrono = "0.4.42"
|
||||||
dirs = "6.0.0"
|
dirs = "6.0.0"
|
||||||
drop-consts = { version = "0.1.0", path = "../drop-consts" }
|
|
||||||
log = "0.4.28"
|
log = "0.4.28"
|
||||||
native_model = { version = "0.6.4", features = ["rmp_serde_1_3"], git = "https://github.com/Drop-OSS/native_model.git"}
|
native_model = { version = "0.6.4", features = ["rmp_serde_1_3"], git = "https://github.com/Drop-OSS/native_model.git"}
|
||||||
rustbreak = "2.0.0"
|
rustbreak = "2.0.0"
|
||||||
@ -3,18 +3,24 @@ use std::{
|
|||||||
sync::{Arc, LazyLock},
|
sync::{Arc, LazyLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
use drop_consts::DATA_ROOT_PREFIX;
|
|
||||||
use rustbreak::{DeSerError, DeSerializer};
|
use rustbreak::{DeSerError, DeSerializer};
|
||||||
use serde::{Serialize, de::DeserializeOwned};
|
use serde::{Serialize, de::DeserializeOwned};
|
||||||
|
|
||||||
use crate::{interface::DatabaseImpls, models::DatabaseInterface};
|
use crate::interface::{DatabaseImpls, DatabaseInterface};
|
||||||
|
|
||||||
pub static DB: LazyLock<DatabaseInterface> = LazyLock::new(DatabaseInterface::set_up_database);
|
pub static DB: LazyLock<DatabaseInterface> = LazyLock::new(DatabaseInterface::set_up_database);
|
||||||
|
|
||||||
pub static DATA_ROOT_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
|
#[cfg(not(debug_assertions))]
|
||||||
|
static DATA_ROOT_PREFIX: &str = "drop";
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
static DATA_ROOT_PREFIX: &str = "drop-debug";
|
||||||
|
|
||||||
|
pub static DATA_ROOT_DIR: LazyLock<Arc<PathBuf>> = LazyLock::new(|| {
|
||||||
|
Arc::new(
|
||||||
dirs::data_dir()
|
dirs::data_dir()
|
||||||
.expect("Failed to get data dir")
|
.expect("Failed to get data dir")
|
||||||
.join(DATA_ROOT_PREFIX)
|
.join(DATA_ROOT_PREFIX),
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Custom JSON serializer to support everything we need
|
// Custom JSON serializer to support everything we need
|
||||||
@ -9,14 +9,20 @@ use std::{
|
|||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use rustbreak::{PathDatabase, RustbreakError};
|
use rustbreak::{PathDatabase, RustbreakError};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::{DropDatabaseSerializer, DATA_ROOT_DIR, DB},
|
db::{DATA_ROOT_DIR, DB, DropDatabaseSerializer},
|
||||||
models::{Database, DatabaseInterface},
|
models::data::Database,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub type DatabaseInterface =
|
||||||
|
rustbreak::Database<Database, rustbreak::backend::PathBackend, DropDatabaseSerializer>;
|
||||||
|
|
||||||
pub trait DatabaseImpls {
|
pub trait DatabaseImpls {
|
||||||
fn set_up_database() -> DatabaseInterface;
|
fn set_up_database() -> DatabaseInterface;
|
||||||
|
fn database_is_set_up(&self) -> bool;
|
||||||
|
fn fetch_base_url(&self) -> Url;
|
||||||
}
|
}
|
||||||
impl DatabaseImpls for DatabaseInterface {
|
impl DatabaseImpls for DatabaseInterface {
|
||||||
fn set_up_database() -> DatabaseInterface {
|
fn set_up_database() -> DatabaseInterface {
|
||||||
@ -82,6 +88,16 @@ impl DatabaseImpls for DatabaseInterface {
|
|||||||
PathDatabase::create_at_path(db_path, default).expect("Database could not be created")
|
PathDatabase::create_at_path(db_path, default).expect("Database could not be created")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn database_is_set_up(&self) -> bool {
|
||||||
|
!borrow_db_checked().base_url.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fetch_base_url(&self) -> Url {
|
||||||
|
let handle = borrow_db_checked();
|
||||||
|
Url::parse(&handle.base_url)
|
||||||
|
.unwrap_or_else(|_| panic!("Failed to parse base url {}", handle.base_url))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make the error relelvant rather than just assume that it's a Deserialize error
|
// TODO: Make the error relelvant rather than just assume that it's a Deserialize error
|
||||||
@ -8,7 +8,7 @@ pub mod platform;
|
|||||||
|
|
||||||
pub use db::DB;
|
pub use db::DB;
|
||||||
pub use interface::{borrow_db_checked, borrow_db_mut_checked};
|
pub use interface::{borrow_db_checked, borrow_db_mut_checked};
|
||||||
pub use models::{
|
pub use models::data::{
|
||||||
ApplicationTransientStatus, Database, DatabaseApplications, DatabaseAuth, DownloadType,
|
ApplicationTransientStatus, Database, DatabaseApplications, DatabaseAuth, DownloadType,
|
||||||
DownloadableMetadata, GameDownloadStatus, GameVersion, Settings,
|
DownloadableMetadata, GameDownloadStatus, GameVersion, Settings,
|
||||||
};
|
};
|
||||||
373
database/src/models.rs
Normal file
373
database/src/models.rs
Normal file
@ -0,0 +1,373 @@
|
|||||||
|
pub mod data {
|
||||||
|
use std::{hash::Hash, path::PathBuf};
|
||||||
|
|
||||||
|
use native_model::native_model;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
// NOTE: Within each version, you should NEVER use these types.
|
||||||
|
// Declare it using the actual version that it is from, i.e. v1::Settings rather than just Settings from here
|
||||||
|
|
||||||
|
pub type GameVersion = v1::GameVersion;
|
||||||
|
pub type Database = v3::Database;
|
||||||
|
pub type Settings = v1::Settings;
|
||||||
|
pub type DatabaseAuth = v1::DatabaseAuth;
|
||||||
|
|
||||||
|
pub type GameDownloadStatus = v2::GameDownloadStatus;
|
||||||
|
pub type ApplicationTransientStatus = v1::ApplicationTransientStatus;
|
||||||
|
/**
|
||||||
|
* Need to be universally accessible by the ID, and the version is just a couple sprinkles on top
|
||||||
|
*/
|
||||||
|
pub type DownloadableMetadata = v1::DownloadableMetadata;
|
||||||
|
pub type DownloadType = v1::DownloadType;
|
||||||
|
pub type DatabaseApplications = v2::DatabaseApplications;
|
||||||
|
// pub type DatabaseCompatInfo = v2::DatabaseCompatInfo;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
impl PartialEq for DownloadableMetadata {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.id == other.id && self.download_type == other.download_type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Hash for DownloadableMetadata {
|
||||||
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||||
|
self.id.hash(state);
|
||||||
|
self.download_type.hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod v1 {
|
||||||
|
use serde_with::serde_as;
|
||||||
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
|
|
||||||
|
use crate::platform::Platform;
|
||||||
|
|
||||||
|
use super::{Deserialize, Serialize, native_model};
|
||||||
|
|
||||||
|
fn default_template() -> String {
|
||||||
|
"{}".to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[native_model(id = 2, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
||||||
|
pub struct GameVersion {
|
||||||
|
pub game_id: String,
|
||||||
|
pub version_name: String,
|
||||||
|
|
||||||
|
pub platform: Platform,
|
||||||
|
|
||||||
|
pub launch_command: String,
|
||||||
|
pub launch_args: Vec<String>,
|
||||||
|
#[serde(default = "default_template")]
|
||||||
|
pub launch_command_template: String,
|
||||||
|
|
||||||
|
pub setup_command: String,
|
||||||
|
pub setup_args: Vec<String>,
|
||||||
|
#[serde(default = "default_template")]
|
||||||
|
pub setup_command_template: String,
|
||||||
|
|
||||||
|
pub only_setup: bool,
|
||||||
|
|
||||||
|
pub version_index: usize,
|
||||||
|
pub delta: bool,
|
||||||
|
|
||||||
|
pub umu_id_override: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[serde_as]
|
||||||
|
#[derive(Serialize, Clone, Deserialize, Default)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[native_model(id = 3, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
||||||
|
pub struct DatabaseApplications {
|
||||||
|
pub install_dirs: Vec<PathBuf>,
|
||||||
|
// Guaranteed to exist if the game also exists in the app state map
|
||||||
|
pub game_statuses: HashMap<String, GameDownloadStatus>,
|
||||||
|
pub game_versions: HashMap<String, HashMap<String, GameVersion>>,
|
||||||
|
pub installed_game_version: HashMap<String, DownloadableMetadata>,
|
||||||
|
|
||||||
|
#[serde(skip)]
|
||||||
|
pub transient_statuses: HashMap<DownloadableMetadata, ApplicationTransientStatus>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[native_model(id = 4, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
||||||
|
pub struct Settings {
|
||||||
|
pub autostart: bool,
|
||||||
|
pub max_download_threads: usize,
|
||||||
|
pub force_offline: bool, // ... other settings ...
|
||||||
|
}
|
||||||
|
impl Default for Settings {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
autostart: false,
|
||||||
|
max_download_threads: 4,
|
||||||
|
force_offline: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings are version names for a particular game
|
||||||
|
#[derive(Serialize, Clone, Deserialize)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
#[native_model(id = 5, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
||||||
|
pub enum GameDownloadStatus {
|
||||||
|
Remote {},
|
||||||
|
SetupRequired {
|
||||||
|
version_name: String,
|
||||||
|
install_dir: String,
|
||||||
|
},
|
||||||
|
Installed {
|
||||||
|
version_name: String,
|
||||||
|
install_dir: String,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stuff that shouldn't be synced to disk
|
||||||
|
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||||
|
pub enum ApplicationTransientStatus {
|
||||||
|
Queued { version_name: String },
|
||||||
|
Downloading { version_name: String },
|
||||||
|
Uninstalling {},
|
||||||
|
Updating { version_name: String },
|
||||||
|
Validating { version_name: String },
|
||||||
|
Running {},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, Clone, Deserialize)]
|
||||||
|
#[native_model(id = 6, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
||||||
|
pub struct DatabaseAuth {
|
||||||
|
pub private: String,
|
||||||
|
pub cert: String,
|
||||||
|
pub client_id: String,
|
||||||
|
pub web_token: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_model(id = 8, version = 1)]
|
||||||
|
#[derive(
|
||||||
|
Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Clone, Copy,
|
||||||
|
)]
|
||||||
|
pub enum DownloadType {
|
||||||
|
Game,
|
||||||
|
Tool,
|
||||||
|
Dlc,
|
||||||
|
Mod,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_model(id = 7, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
||||||
|
#[derive(Debug, Eq, PartialOrd, Ord, Serialize, Deserialize, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct DownloadableMetadata {
|
||||||
|
pub id: String,
|
||||||
|
pub version: Option<String>,
|
||||||
|
pub download_type: DownloadType,
|
||||||
|
}
|
||||||
|
impl DownloadableMetadata {
|
||||||
|
pub fn new(id: String, version: Option<String>, download_type: DownloadType) -> Self {
|
||||||
|
Self {
|
||||||
|
id,
|
||||||
|
version,
|
||||||
|
download_type,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_model(id = 1, version = 1)]
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||||
|
pub struct Database {
|
||||||
|
#[serde(default)]
|
||||||
|
pub settings: Settings,
|
||||||
|
pub auth: Option<DatabaseAuth>,
|
||||||
|
pub base_url: String,
|
||||||
|
pub applications: DatabaseApplications,
|
||||||
|
pub prev_database: Option<PathBuf>,
|
||||||
|
pub cache_dir: PathBuf,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod v2 {
|
||||||
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
|
|
||||||
|
use serde_with::serde_as;
|
||||||
|
|
||||||
|
use super::{Deserialize, Serialize, native_model, v1};
|
||||||
|
|
||||||
|
#[native_model(id = 1, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from = v1::Database)]
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||||
|
pub struct Database {
|
||||||
|
#[serde(default)]
|
||||||
|
pub settings: v1::Settings,
|
||||||
|
pub auth: Option<v1::DatabaseAuth>,
|
||||||
|
pub base_url: String,
|
||||||
|
pub applications: v1::DatabaseApplications,
|
||||||
|
#[serde(skip)]
|
||||||
|
pub prev_database: Option<PathBuf>,
|
||||||
|
pub cache_dir: PathBuf,
|
||||||
|
pub compat_info: Option<DatabaseCompatInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_model(id = 9, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||||
|
|
||||||
|
pub struct DatabaseCompatInfo {
|
||||||
|
pub umu_installed: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<v1::Database> for Database {
|
||||||
|
fn from(value: v1::Database) -> Self {
|
||||||
|
Self {
|
||||||
|
settings: value.settings,
|
||||||
|
auth: value.auth,
|
||||||
|
base_url: value.base_url,
|
||||||
|
applications: value.applications,
|
||||||
|
prev_database: value.prev_database,
|
||||||
|
cache_dir: value.cache_dir,
|
||||||
|
compat_info: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Strings are version names for a particular game
|
||||||
|
#[derive(Serialize, Clone, Deserialize, Debug)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
#[native_model(id = 5, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from = v1::GameDownloadStatus)]
|
||||||
|
pub enum GameDownloadStatus {
|
||||||
|
Remote {},
|
||||||
|
SetupRequired {
|
||||||
|
version_name: String,
|
||||||
|
install_dir: String,
|
||||||
|
},
|
||||||
|
Installed {
|
||||||
|
version_name: String,
|
||||||
|
install_dir: String,
|
||||||
|
},
|
||||||
|
PartiallyInstalled {
|
||||||
|
version_name: String,
|
||||||
|
install_dir: String,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
impl From<v1::GameDownloadStatus> for GameDownloadStatus {
|
||||||
|
fn from(value: v1::GameDownloadStatus) -> Self {
|
||||||
|
match value {
|
||||||
|
v1::GameDownloadStatus::Remote {} => Self::Remote {},
|
||||||
|
v1::GameDownloadStatus::SetupRequired {
|
||||||
|
version_name,
|
||||||
|
install_dir,
|
||||||
|
} => Self::SetupRequired {
|
||||||
|
version_name,
|
||||||
|
install_dir,
|
||||||
|
},
|
||||||
|
v1::GameDownloadStatus::Installed {
|
||||||
|
version_name,
|
||||||
|
install_dir,
|
||||||
|
} => Self::Installed {
|
||||||
|
version_name,
|
||||||
|
install_dir,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[serde_as]
|
||||||
|
#[derive(Serialize, Clone, Deserialize, Default)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[native_model(id = 3, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from=v1::DatabaseApplications)]
|
||||||
|
pub struct DatabaseApplications {
|
||||||
|
pub install_dirs: Vec<PathBuf>,
|
||||||
|
// Guaranteed to exist if the game also exists in the app state map
|
||||||
|
pub game_statuses: HashMap<String, GameDownloadStatus>,
|
||||||
|
|
||||||
|
pub game_versions: HashMap<String, HashMap<String, v1::GameVersion>>,
|
||||||
|
pub installed_game_version: HashMap<String, v1::DownloadableMetadata>,
|
||||||
|
|
||||||
|
#[serde(skip)]
|
||||||
|
pub transient_statuses:
|
||||||
|
HashMap<v1::DownloadableMetadata, v1::ApplicationTransientStatus>,
|
||||||
|
}
|
||||||
|
impl From<v1::DatabaseApplications> for DatabaseApplications {
|
||||||
|
fn from(value: v1::DatabaseApplications) -> Self {
|
||||||
|
Self {
|
||||||
|
game_statuses: value
|
||||||
|
.game_statuses
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| (x.0, x.1.into()))
|
||||||
|
.collect::<HashMap<String, GameDownloadStatus>>(),
|
||||||
|
install_dirs: value.install_dirs,
|
||||||
|
game_versions: value.game_versions,
|
||||||
|
installed_game_version: value.installed_game_version,
|
||||||
|
transient_statuses: value.transient_statuses,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mod v3 {
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use super::{Deserialize, Serialize, native_model, v1, v2};
|
||||||
|
#[native_model(id = 1, version = 3, with = native_model::rmp_serde_1_3::RmpSerde, from = v2::Database)]
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||||
|
pub struct Database {
|
||||||
|
#[serde(default)]
|
||||||
|
pub settings: v1::Settings,
|
||||||
|
pub auth: Option<v1::DatabaseAuth>,
|
||||||
|
pub base_url: String,
|
||||||
|
pub applications: v2::DatabaseApplications,
|
||||||
|
#[serde(skip)]
|
||||||
|
pub prev_database: Option<PathBuf>,
|
||||||
|
pub cache_dir: PathBuf,
|
||||||
|
pub compat_info: Option<v2::DatabaseCompatInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<v2::Database> for Database {
|
||||||
|
fn from(value: v2::Database) -> Self {
|
||||||
|
Self {
|
||||||
|
settings: value.settings,
|
||||||
|
auth: value.auth,
|
||||||
|
base_url: value.base_url,
|
||||||
|
applications: value.applications.into(),
|
||||||
|
prev_database: value.prev_database,
|
||||||
|
cache_dir: value.cache_dir,
|
||||||
|
compat_info: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub fn new<T: Into<PathBuf>>(
|
||||||
|
games_base_dir: T,
|
||||||
|
prev_database: Option<PathBuf>,
|
||||||
|
cache_dir: PathBuf,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
applications: DatabaseApplications {
|
||||||
|
install_dirs: vec![games_base_dir.into()],
|
||||||
|
game_statuses: HashMap::new(),
|
||||||
|
game_versions: HashMap::new(),
|
||||||
|
installed_game_version: HashMap::new(),
|
||||||
|
transient_statuses: HashMap::new(),
|
||||||
|
},
|
||||||
|
prev_database,
|
||||||
|
base_url: String::new(),
|
||||||
|
auth: None,
|
||||||
|
settings: Settings::default(),
|
||||||
|
cache_dir,
|
||||||
|
compat_info: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl DatabaseAuth {
|
||||||
|
pub fn new(
|
||||||
|
private: String,
|
||||||
|
cert: String,
|
||||||
|
client_id: String,
|
||||||
|
web_token: Option<String>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
private,
|
||||||
|
cert,
|
||||||
|
client_id,
|
||||||
|
web_token,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,20 +4,20 @@ use serde::{Deserialize, Serialize};
|
|||||||
pub enum Platform {
|
pub enum Platform {
|
||||||
Windows,
|
Windows,
|
||||||
Linux,
|
Linux,
|
||||||
macOS,
|
MacOs,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Platform {
|
impl Platform {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub const HOST: Platform = Self::Windows;
|
pub const HOST: Platform = Self::Windows;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub const HOST: Platform = Self::macOS;
|
pub const HOST: Platform = Self::MacOs;
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub const HOST: Platform = Self::Linux;
|
pub const HOST: Platform = Self::Linux;
|
||||||
|
|
||||||
pub fn is_case_sensitive(&self) -> bool {
|
pub fn is_case_sensitive(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Windows | Self::macOS => false,
|
Self::Windows | Self::MacOs => false,
|
||||||
Self::Linux => true,
|
Self::Linux => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ impl From<&str> for Platform {
|
|||||||
match value.to_lowercase().trim() {
|
match value.to_lowercase().trim() {
|
||||||
"windows" => Self::Windows,
|
"windows" => Self::Windows,
|
||||||
"linux" => Self::Linux,
|
"linux" => Self::Linux,
|
||||||
"mac" | "macos" => Self::macOS,
|
"mac" | "macos" => Self::MacOs,
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ impl From<whoami::Platform> for Platform {
|
|||||||
match value {
|
match value {
|
||||||
whoami::Platform::Windows => Platform::Windows,
|
whoami::Platform::Windows => Platform::Windows,
|
||||||
whoami::Platform::Linux => Platform::Linux,
|
whoami::Platform::Linux => Platform::Linux,
|
||||||
whoami::Platform::MacOS => Platform::macOS,
|
whoami::Platform::MacOS => Platform::MacOs,
|
||||||
platform => unimplemented!("Playform {} is not supported", platform),
|
platform => unimplemented!("Playform {} is not supported", platform),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -22,8 +22,5 @@ sysinfo = "0.37.2"
|
|||||||
tauri = "2.8.5"
|
tauri = "2.8.5"
|
||||||
throttle_my_fn = "0.2.6"
|
throttle_my_fn = "0.2.6"
|
||||||
utils = { version = "0.1.0", path = "../utils" }
|
utils = { version = "0.1.0", path = "../utils" }
|
||||||
native_model = { version = "0.6.4", features = [
|
native_model = { version = "0.6.4", features = ["rmp_serde_1_3"], git = "https://github.com/Drop-OSS/native_model.git"}
|
||||||
"rmp_serde_1_3",
|
|
||||||
], git = "https://github.com/Drop-OSS/native_model.git" }
|
|
||||||
serde_json = "1.0.145"
|
serde_json = "1.0.145"
|
||||||
drop-consts = { version = "0.1.0", path = "../drop-consts" }
|
|
||||||
@ -1,7 +1,8 @@
|
|||||||
use bitcode::{Decode, Encode};
|
use bitcode::{Decode, Encode};
|
||||||
use database::models::Game;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::library::Game;
|
||||||
|
|
||||||
pub type Collections = Vec<Collection>;
|
pub type Collections = Vec<Collection>;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, Encode, Decode)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Default, Encode, Decode)]
|
||||||
@ -14,7 +15,7 @@ pub struct Collection {
|
|||||||
entries: Vec<CollectionObject>,
|
entries: Vec<CollectionObject>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Encode, Decode)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Default, Encode, Decode)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct CollectionObject {
|
pub struct CollectionObject {
|
||||||
collection_id: String,
|
collection_id: String,
|
||||||
@ -9,7 +9,6 @@ use download_manager::util::download_thread_control_flag::{
|
|||||||
DownloadThreadControl, DownloadThreadControlFlag,
|
DownloadThreadControl, DownloadThreadControlFlag,
|
||||||
};
|
};
|
||||||
use download_manager::util::progress_object::{ProgressHandle, ProgressObject};
|
use download_manager::util::progress_object::{ProgressHandle, ProgressObject};
|
||||||
use drop_consts::{MAX_FILES_PER_BUCKET, RETRY_COUNT, TARGET_BUCKET_SIZE};
|
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use rayon::ThreadPoolBuilder;
|
use rayon::ThreadPoolBuilder;
|
||||||
use remote::auth::generate_authorization_header;
|
use remote::auth::generate_authorization_header;
|
||||||
@ -40,6 +39,11 @@ use crate::state::GameStatusManager;
|
|||||||
use super::download_logic::download_game_bucket;
|
use super::download_logic::download_game_bucket;
|
||||||
use super::drop_data::DropData;
|
use super::drop_data::DropData;
|
||||||
|
|
||||||
|
static RETRY_COUNT: usize = 3;
|
||||||
|
|
||||||
|
const TARGET_BUCKET_SIZE: usize = 63 * 1000 * 1000;
|
||||||
|
const MAX_FILES_PER_BUCKET: usize = (1024 / 4) - 1;
|
||||||
|
|
||||||
pub struct GameDownloadAgent {
|
pub struct GameDownloadAgent {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub version: String,
|
pub version: String,
|
||||||
@ -5,13 +5,14 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use drop_consts::DROP_DATA_PATH;
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use native_model::{Decode, Encode};
|
use native_model::{Decode, Encode};
|
||||||
use utils::lock;
|
use utils::lock;
|
||||||
|
|
||||||
pub type DropData = v1::DropData;
|
pub type DropData = v1::DropData;
|
||||||
|
|
||||||
|
pub static DROP_DATA_PATH: &str = ".dropdata";
|
||||||
|
|
||||||
pub mod v1 {
|
pub mod v1 {
|
||||||
use std::{collections::HashMap, path::PathBuf, sync::Mutex};
|
use std::{collections::HashMap, path::PathBuf, sync::Mutex};
|
||||||
|
|
||||||
@ -1,5 +1,7 @@
|
|||||||
|
use bitcode::{Decode, Encode};
|
||||||
use database::{
|
use database::{
|
||||||
borrow_db_checked, borrow_db_mut_checked, models::Game, ApplicationTransientStatus, Database, DownloadableMetadata, GameDownloadStatus, GameVersion
|
ApplicationTransientStatus, Database, DownloadableMetadata, GameDownloadStatus, GameVersion,
|
||||||
|
borrow_db_checked, borrow_db_mut_checked,
|
||||||
};
|
};
|
||||||
use log::{debug, error, warn};
|
use log::{debug, error, warn};
|
||||||
use remote::{
|
use remote::{
|
||||||
@ -31,6 +33,26 @@ impl FetchGameStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug, Default, Encode, Decode)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct Game {
|
||||||
|
id: String,
|
||||||
|
m_name: String,
|
||||||
|
m_short_description: String,
|
||||||
|
m_description: String,
|
||||||
|
// mDevelopers
|
||||||
|
// mPublishers
|
||||||
|
m_icon_object_id: String,
|
||||||
|
m_banner_object_id: String,
|
||||||
|
m_cover_object_id: String,
|
||||||
|
m_image_library_object_ids: Vec<String>,
|
||||||
|
m_image_carousel_object_ids: Vec<String>,
|
||||||
|
}
|
||||||
|
impl Game {
|
||||||
|
pub fn id(&self) -> &String {
|
||||||
|
&self.id
|
||||||
|
}
|
||||||
|
}
|
||||||
#[derive(serde::Serialize, Clone)]
|
#[derive(serde::Serialize, Clone)]
|
||||||
pub struct GameUpdateEvent {
|
pub struct GameUpdateEvent {
|
||||||
pub game_id: String,
|
pub game_id: String,
|
||||||
@ -1,11 +1,10 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use database::{DownloadType, DownloadableMetadata, borrow_db_mut_checked};
|
use database::{DownloadType, DownloadableMetadata, borrow_db_mut_checked};
|
||||||
use drop_consts::DROP_DATA_PATH;
|
|
||||||
use log::warn;
|
use log::warn;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
downloads::drop_data::DropData,
|
downloads::drop_data::{DROP_DATA_PATH, DropData},
|
||||||
library::set_partially_installed_db,
|
library::set_partially_installed_db,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
use database::{
|
use database::models::data::{
|
||||||
ApplicationTransientStatus, Database, DownloadType, DownloadableMetadata, GameDownloadStatus,
|
ApplicationTransientStatus, Database, DownloadType, DownloadableMetadata, GameDownloadStatus,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ platformInfo.value = currentPlatform;
|
|||||||
async function openDataDir() {
|
async function openDataDir() {
|
||||||
if (!dataDir.value) return;
|
if (!dataDir.value) return;
|
||||||
try {
|
try {
|
||||||
await invoke("open_fs", { path: dataDir.value });
|
await open(dataDir.value);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to open data dir:", error);
|
console.error("Failed to open data dir:", error);
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ async function openLogFile() {
|
|||||||
if (!dataDir.value) return;
|
if (!dataDir.value) return;
|
||||||
try {
|
try {
|
||||||
const logPath = `${dataDir.value}/drop.log`;
|
const logPath = `${dataDir.value}/drop.log`;
|
||||||
await invoke("open_fs", { path: logPath });
|
await open(logPath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to open log file:", error);
|
console.error("Failed to open log file:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,8 +9,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tauri-apps/api": "^2.7.0",
|
"@tauri-apps/api": "^2.7.0",
|
||||||
"@tauri-apps/plugin-deep-link": "^2.4.1",
|
"@tauri-apps/plugin-deep-link": "^2.4.1",
|
||||||
"@tauri-apps/plugin-dialog": "^2.4.0",
|
"@tauri-apps/plugin-dialog": "^2.3.2",
|
||||||
"@tauri-apps/plugin-opener": "^2.5.0",
|
"@tauri-apps/plugin-opener": "^2.4.0",
|
||||||
"@tauri-apps/plugin-os": "^2.3.0",
|
"@tauri-apps/plugin-os": "^2.3.0",
|
||||||
"@tauri-apps/plugin-shell": "^2.3.0",
|
"@tauri-apps/plugin-shell": "^2.3.0",
|
||||||
"pino": "^9.7.0",
|
"pino": "^9.7.0",
|
||||||
|
|||||||
@ -54,7 +54,7 @@ impl ProcessManager<'_> {
|
|||||||
current_platform: Platform::Windows,
|
current_platform: Platform::Windows,
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
current_platform: Platform::macOS,
|
current_platform: Platform::MacOs,
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
current_platform: Platform::Linux,
|
current_platform: Platform::Linux,
|
||||||
@ -72,7 +72,7 @@ impl ProcessManager<'_> {
|
|||||||
&NativeGameLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
|
&NativeGameLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
(Platform::macOS, Platform::macOS),
|
(Platform::MacOs, Platform::MacOs),
|
||||||
&NativeGameLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
|
&NativeGameLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@ -60,17 +60,22 @@ impl From<HandshakeResponse> for DatabaseAuth {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_authorization_header(auth: DatabaseAuth) -> String {
|
pub fn generate_authorization_header() -> String {
|
||||||
|
let certs = {
|
||||||
|
let db = borrow_db_checked();
|
||||||
|
db.auth.clone().expect("Authorisation not initialised")
|
||||||
|
};
|
||||||
|
|
||||||
let nonce = Utc::now().timestamp_millis().to_string();
|
let nonce = Utc::now().timestamp_millis().to_string();
|
||||||
|
|
||||||
let signature =
|
let signature =
|
||||||
sign_nonce(auth.private, nonce.clone()).expect("Failed to generate authorisation header");
|
sign_nonce(certs.private, nonce.clone()).expect("Failed to generate authorisation header");
|
||||||
|
|
||||||
format!("Nonce {} {} {}", auth.client_id, nonce, signature)
|
format!("Nonce {} {} {}", certs.client_id, nonce, signature)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_user(auth: DatabaseAuth, base_url: Url) -> Result<User, RemoteAccessError> {
|
pub async fn fetch_user() -> Result<User, RemoteAccessError> {
|
||||||
let response = make_authenticated_get(generate_url(&["/api/v1/client/user"], &[], base_url)?, auth).await?;
|
let response = make_authenticated_get(generate_url(&["/api/v1/client/user"], &[])?).await?;
|
||||||
if response.status() != 200 {
|
if response.status() != 200 {
|
||||||
let err: DropServerError = response.json().await?;
|
let err: DropServerError = response.json().await?;
|
||||||
warn!("{err:?}");
|
warn!("{err:?}");
|
||||||
@ -88,7 +93,12 @@ pub async fn fetch_user(auth: DatabaseAuth, base_url: Url) -> Result<User, Remot
|
|||||||
.map_err(std::convert::Into::into)
|
.map_err(std::convert::Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn auth_initiate_logic(mode: String, base_url: Url) -> Result<String, RemoteAccessError> {
|
pub fn auth_initiate_logic(mode: String) -> Result<String, RemoteAccessError> {
|
||||||
|
let base_url = {
|
||||||
|
let db_lock = borrow_db_checked();
|
||||||
|
Url::parse(&db_lock.base_url.clone())?
|
||||||
|
};
|
||||||
|
|
||||||
let hostname = gethostname();
|
let hostname = gethostname();
|
||||||
|
|
||||||
let endpoint = base_url.join("/api/v1/client/auth/initiate")?;
|
let endpoint = base_url.join("/api/v1/client/auth/initiate")?;
|
||||||
@ -117,8 +127,14 @@ pub fn auth_initiate_logic(mode: String, base_url: Url) -> Result<String, Remote
|
|||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn setup(auth: DatabaseAuth, base_url: Url) -> (AppStatus, Option<User>) {
|
pub async fn setup() -> (AppStatus, Option<User>) {
|
||||||
let user_result = match fetch_user(auth, base_url).await {
|
let auth = {
|
||||||
|
let data = borrow_db_checked();
|
||||||
|
data.auth.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
if auth.is_some() {
|
||||||
|
let user_result = match fetch_user().await {
|
||||||
Ok(data) => data,
|
Ok(data) => data,
|
||||||
Err(RemoteAccessError::FetchError(_)) => {
|
Err(RemoteAccessError::FetchError(_)) => {
|
||||||
let user = get_cached_object::<User>("user").ok();
|
let user = get_cached_object::<User>("user").ok();
|
||||||
@ -130,4 +146,7 @@ pub async fn setup(auth: DatabaseAuth, base_url: Url) -> (AppStatus, Option<User
|
|||||||
warn!("Could not cache user object with error {e}");
|
warn!("Could not cache user object with error {e}");
|
||||||
}
|
}
|
||||||
return (AppStatus::SignedIn, Some(user_result));
|
return (AppStatus::SignedIn, Some(user_result));
|
||||||
|
}
|
||||||
|
|
||||||
|
(AppStatus::SignedOut, None)
|
||||||
}
|
}
|
||||||
@ -17,7 +17,7 @@ macro_rules! offline {
|
|||||||
|
|
||||||
async move {
|
async move {
|
||||||
if ::database::borrow_db_checked().settings.force_offline
|
if ::database::borrow_db_checked().settings.force_offline
|
||||||
|| *$var.lock().status() == ::client::app_status::AppStatus::Offline {
|
|| $var.lock().status == ::client::app_status::AppStatus::Offline {
|
||||||
$func2( $( $arg ), *).await
|
$func2( $( $arg ), *).await
|
||||||
} else {
|
} else {
|
||||||
$func1( $( $arg ), *).await
|
$func1( $( $arg ), *).await
|
||||||
@ -1,8 +1,7 @@
|
|||||||
use database::{DB, DatabaseAuth, interface::DatabaseImpls};
|
use database::{DB, interface::DatabaseImpls};
|
||||||
use http::{Response, header::CONTENT_TYPE, response::Builder as ResponseBuilder};
|
use http::{Response, header::CONTENT_TYPE, response::Builder as ResponseBuilder};
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
use tauri::UriSchemeResponder;
|
use tauri::UriSchemeResponder;
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
use crate::{error::CacheError, utils::DROP_CLIENT_ASYNC};
|
use crate::{error::CacheError, utils::DROP_CLIENT_ASYNC};
|
||||||
|
|
||||||
@ -11,8 +10,8 @@ use super::{
|
|||||||
cache::{ObjectCache, cache_object, get_cached_object},
|
cache::{ObjectCache, cache_object, get_cached_object},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn fetch_object_wrapper(request: http::Request<Vec<u8>>, responder: UriSchemeResponder, auth: DatabaseAuth, base_url: Url) {
|
pub async fn fetch_object_wrapper(request: http::Request<Vec<u8>>, responder: UriSchemeResponder) {
|
||||||
match fetch_object(request, auth, base_url).await {
|
match fetch_object(request).await {
|
||||||
Ok(r) => responder.respond(r),
|
Ok(r) => responder.respond(r),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("Cache error: {e}");
|
warn!("Cache error: {e}");
|
||||||
@ -28,8 +27,6 @@ pub async fn fetch_object_wrapper(request: http::Request<Vec<u8>>, responder: Ur
|
|||||||
|
|
||||||
pub async fn fetch_object(
|
pub async fn fetch_object(
|
||||||
request: http::Request<Vec<u8>>,
|
request: http::Request<Vec<u8>>,
|
||||||
auth: DatabaseAuth,
|
|
||||||
base_url: Url
|
|
||||||
) -> Result<Response<Vec<u8>>, CacheError> {
|
) -> Result<Response<Vec<u8>>, CacheError> {
|
||||||
// Drop leading /
|
// Drop leading /
|
||||||
let object_id = &request.uri().path()[1..];
|
let object_id = &request.uri().path()[1..];
|
||||||
@ -41,9 +38,9 @@ pub async fn fetch_object(
|
|||||||
return cache_result.try_into();
|
return cache_result.try_into();
|
||||||
}
|
}
|
||||||
|
|
||||||
let header = generate_authorization_header(auth);
|
let header = generate_authorization_header();
|
||||||
let client = DROP_CLIENT_ASYNC.clone();
|
let client = DROP_CLIENT_ASYNC.clone();
|
||||||
let url = format!("{}api/v1/client/object/{object_id}", base_url);
|
let url = format!("{}api/v1/client/object/{object_id}", DB.fetch_base_url());
|
||||||
let response = client.get(url).header("Authorization", header).send().await;
|
let response = client.get(url).header("Authorization", header).send().await;
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
@ -1,4 +1,4 @@
|
|||||||
use database::{DB, DatabaseAuth, interface::DatabaseImpls};
|
use database::{DB, interface::DatabaseImpls};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -8,9 +8,8 @@ use crate::{
|
|||||||
pub fn generate_url<T: AsRef<str>>(
|
pub fn generate_url<T: AsRef<str>>(
|
||||||
path_components: &[T],
|
path_components: &[T],
|
||||||
query: &[(T, T)],
|
query: &[(T, T)],
|
||||||
base_url: Url
|
|
||||||
) -> Result<Url, RemoteAccessError> {
|
) -> Result<Url, RemoteAccessError> {
|
||||||
let mut base_url = base_url.clone();
|
let mut base_url = DB.fetch_base_url();
|
||||||
for endpoint in path_components {
|
for endpoint in path_components {
|
||||||
base_url = base_url.join(endpoint.as_ref())?;
|
base_url = base_url.join(endpoint.as_ref())?;
|
||||||
}
|
}
|
||||||
@ -23,10 +22,10 @@ pub fn generate_url<T: AsRef<str>>(
|
|||||||
Ok(base_url)
|
Ok(base_url)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn make_authenticated_get(url: Url, auth: DatabaseAuth) -> Result<reqwest::Response, reqwest::Error> {
|
pub async fn make_authenticated_get(url: Url) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
DROP_CLIENT_ASYNC
|
DROP_CLIENT_ASYNC
|
||||||
.get(url)
|
.get(url)
|
||||||
.header("Authorization", generate_authorization_header(auth))
|
.header("Authorization", generate_authorization_header())
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
@ -1,10 +1,9 @@
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use database::{DatabaseAuth, borrow_db_checked};
|
use database::borrow_db_checked;
|
||||||
use http::{Request, Response, StatusCode, Uri, uri::PathAndQuery};
|
use http::{Request, Response, StatusCode, Uri, uri::PathAndQuery};
|
||||||
use log::warn;
|
use log::{error, warn};
|
||||||
use tauri::UriSchemeResponder;
|
use tauri::UriSchemeResponder;
|
||||||
use url::Url;
|
|
||||||
use utils::webbrowser_open::webbrowser_open;
|
use utils::webbrowser_open::webbrowser_open;
|
||||||
|
|
||||||
use crate::utils::DROP_CLIENT_SYNC;
|
use crate::utils::DROP_CLIENT_SYNC;
|
||||||
@ -28,8 +27,8 @@ pub async fn handle_server_proto_offline(
|
|||||||
.expect("Failed to build error response for proto offline"))
|
.expect("Failed to build error response for proto offline"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_server_proto_wrapper(request: Request<Vec<u8>>, responder: UriSchemeResponder, auth: DatabaseAuth, base_url: Url) {
|
pub async fn handle_server_proto_wrapper(request: Request<Vec<u8>>, responder: UriSchemeResponder) {
|
||||||
match handle_server_proto(request, auth, base_url).await {
|
match handle_server_proto(request).await {
|
||||||
Ok(r) => responder.respond(r),
|
Ok(r) => responder.respond(r),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("Cache error: {e}");
|
warn!("Cache error: {e}");
|
||||||
@ -43,16 +42,23 @@ pub async fn handle_server_proto_wrapper(request: Request<Vec<u8>>, responder: U
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_server_proto(
|
async fn handle_server_proto(request: Request<Vec<u8>>) -> Result<Response<Vec<u8>>, StatusCode> {
|
||||||
request: Request<Vec<u8>>,
|
let db_handle = borrow_db_checked();
|
||||||
auth: DatabaseAuth,
|
let auth = match db_handle.auth.as_ref() {
|
||||||
base_url: Url,
|
Some(auth) => auth,
|
||||||
) -> Result<Response<Vec<u8>>, StatusCode> {
|
None => {
|
||||||
|
error!("Could not find auth in database");
|
||||||
|
return Err(StatusCode::UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
};
|
||||||
let web_token = match &auth.web_token {
|
let web_token = match &auth.web_token {
|
||||||
Some(token) => token,
|
Some(token) => token,
|
||||||
None => return Err(StatusCode::UNAUTHORIZED),
|
None => return Err(StatusCode::UNAUTHORIZED),
|
||||||
};
|
};
|
||||||
let remote_uri = base_url.as_str().parse::<Uri>().expect("Failed to parse base url");
|
let remote_uri = db_handle
|
||||||
|
.base_url
|
||||||
|
.parse::<Uri>()
|
||||||
|
.expect("Failed to parse base url");
|
||||||
|
|
||||||
let path = request.uri().path();
|
let path = request.uri().path();
|
||||||
|
|
||||||
2292
src-tauri/Cargo.lock
generated
2292
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -65,9 +65,7 @@ whoami = "1.6.0"
|
|||||||
filetime = "0.2.25"
|
filetime = "0.2.25"
|
||||||
walkdir = "2.5.0"
|
walkdir = "2.5.0"
|
||||||
known-folders = "1.2.0"
|
known-folders = "1.2.0"
|
||||||
native_model = { version = "0.6.4", features = [
|
native_model = { version = "0.6.4", features = ["rmp_serde_1_3"], git = "https://github.com/Drop-OSS/native_model.git"}
|
||||||
"rmp_serde_1_3",
|
|
||||||
], git = "https://github.com/Drop-OSS/native_model.git" }
|
|
||||||
tauri-plugin-opener = "2.4.0"
|
tauri-plugin-opener = "2.4.0"
|
||||||
bitcode = "0.6.6"
|
bitcode = "0.6.6"
|
||||||
reqwest-websocket = "0.5.0"
|
reqwest-websocket = "0.5.0"
|
||||||
@ -82,13 +80,13 @@ bytes = "1.10.1"
|
|||||||
|
|
||||||
|
|
||||||
# Workspaces
|
# Workspaces
|
||||||
client = { version = "0.1.0", path = "./client" }
|
client = { version = "0.1.0", path = "../client" }
|
||||||
database = { path = "./database" }
|
database = { path = "../database" }
|
||||||
process = { path = "./process" }
|
process = { path = "../process" }
|
||||||
remote = { version = "0.1.0", path = "./remote" }
|
remote = { version = "0.1.0", path = "../remote" }
|
||||||
utils = { path = "./utils" }
|
utils = { path = "../utils" }
|
||||||
games = { version = "0.1.0", path = "./games" }
|
games = { version = "0.1.0", path = "../games" }
|
||||||
download_manager = { version = "0.1.0", path = "./download_manager" }
|
download_manager = { version = "0.1.0", path = "../download_manager" }
|
||||||
|
|
||||||
[dependencies.dynfmt]
|
[dependencies.dynfmt]
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
@ -139,20 +137,3 @@ features = ["derive", "rc"]
|
|||||||
lto = true
|
lto = true
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
panic = 'abort'
|
panic = 'abort'
|
||||||
|
|
||||||
|
|
||||||
[workspace]
|
|
||||||
members = [
|
|
||||||
"client",
|
|
||||||
"database",
|
|
||||||
"process",
|
|
||||||
"remote",
|
|
||||||
"utils",
|
|
||||||
"cloud_saves",
|
|
||||||
"download_manager",
|
|
||||||
"games",
|
|
||||||
"library",
|
|
||||||
"drop-consts",
|
|
||||||
]
|
|
||||||
|
|
||||||
resolver = "3"
|
|
||||||
|
|||||||
@ -1,42 +0,0 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use database::models::Game;
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
use crate::{app_status::AppStatus, user::User};
|
|
||||||
|
|
||||||
#[derive(Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct AppState {
|
|
||||||
status: AppStatus,
|
|
||||||
user: Option<User>,
|
|
||||||
games: HashMap<String, Game>,
|
|
||||||
}
|
|
||||||
impl AppState {
|
|
||||||
pub fn new(status: AppStatus, user: Option<User>, games: HashMap<String, Game>) -> Self {
|
|
||||||
Self {
|
|
||||||
status,
|
|
||||||
user,
|
|
||||||
games,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn status(&self) -> &AppStatus {
|
|
||||||
&self.status
|
|
||||||
}
|
|
||||||
pub fn status_mut(&mut self) -> &mut AppStatus {
|
|
||||||
&mut self.status
|
|
||||||
}
|
|
||||||
pub fn games(&self) -> &HashMap<String, Game> {
|
|
||||||
&self.games
|
|
||||||
}
|
|
||||||
pub fn games_mut(&mut self) -> &mut HashMap<String, Game> {
|
|
||||||
&mut self.games
|
|
||||||
}
|
|
||||||
pub fn user(&self) -> &Option<User> {
|
|
||||||
&self.user
|
|
||||||
}
|
|
||||||
pub fn user_mut(&mut self) -> &mut Option<User> {
|
|
||||||
&mut self.user
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,110 +0,0 @@
|
|||||||
mod v1;
|
|
||||||
mod v2;
|
|
||||||
mod v3;
|
|
||||||
mod v4;
|
|
||||||
|
|
||||||
use std::{hash::Hash, path::PathBuf};
|
|
||||||
|
|
||||||
use native_model::native_model;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use crate::db::DropDatabaseSerializer;
|
|
||||||
|
|
||||||
|
|
||||||
// NOTE: Within each version, you should NEVER use these types.
|
|
||||||
// Declare it using the actual version that it is from, i.e. v1::Settings rather than just Settings from here
|
|
||||||
|
|
||||||
pub type GameVersion = v1::GameVersion;
|
|
||||||
pub type Database = v4::Database;
|
|
||||||
pub type Settings = v1::Settings;
|
|
||||||
pub type DatabaseAuth = v1::DatabaseAuth;
|
|
||||||
|
|
||||||
pub type GameDownloadStatus = v2::GameDownloadStatus;
|
|
||||||
pub type ApplicationTransientStatus = v1::ApplicationTransientStatus;
|
|
||||||
/**
|
|
||||||
* Need to be universally accessible by the ID, and the version is just a couple sprinkles on top
|
|
||||||
*/
|
|
||||||
pub type DownloadableMetadata = v1::DownloadableMetadata;
|
|
||||||
pub type DownloadType = v1::DownloadType;
|
|
||||||
pub type DatabaseApplications = v2::DatabaseApplications;
|
|
||||||
// pub type DatabaseCompatInfo = v2::DatabaseCompatInfo;
|
|
||||||
|
|
||||||
pub type Game = v1::Game;
|
|
||||||
|
|
||||||
impl Game {
|
|
||||||
pub fn id(&self) -> &String {
|
|
||||||
&self.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type DatabaseInterface =
|
|
||||||
rustbreak::Database<Database, rustbreak::backend::PathBackend, DropDatabaseSerializer>;
|
|
||||||
|
|
||||||
pub type LibraryMetadata = v1::LibraryMetadata;
|
|
||||||
pub type LibraryProviderMetadata = v1::LibraryProviderMetadata;
|
|
||||||
pub type ProviderType = v1::ProviderType;
|
|
||||||
|
|
||||||
pub type Collection = v1::Collection;
|
|
||||||
pub type CollectionObject = v1::CollectionObject;
|
|
||||||
|
|
||||||
impl PartialEq for DownloadableMetadata {
|
|
||||||
fn eq(&self, other: &Self) -> bool {
|
|
||||||
self.id == other.id && self.download_type == other.download_type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Hash for DownloadableMetadata {
|
|
||||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
|
||||||
self.id.hash(state);
|
|
||||||
self.download_type.hash(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl LibraryProviderMetadata {
|
|
||||||
pub fn provider(&self) -> &ProviderType {
|
|
||||||
&self.provider
|
|
||||||
}
|
|
||||||
pub fn id(&self) -> usize {
|
|
||||||
self.id
|
|
||||||
}
|
|
||||||
pub fn name(&self) -> &String {
|
|
||||||
&self.name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Database {
|
|
||||||
pub fn new<T: Into<PathBuf>>(
|
|
||||||
games_base_dir: T,
|
|
||||||
prev_database: Option<PathBuf>,
|
|
||||||
cache_dir: PathBuf,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
prev_database,
|
|
||||||
settings: Settings::default(),
|
|
||||||
cache_dir,
|
|
||||||
compat_info: None,
|
|
||||||
library: v1::LibraryMetadata { providers: vec![] },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl DatabaseAuth {
|
|
||||||
pub fn new(
|
|
||||||
private: String,
|
|
||||||
cert: String,
|
|
||||||
client_id: String,
|
|
||||||
web_token: Option<String>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
private,
|
|
||||||
cert,
|
|
||||||
client_id,
|
|
||||||
web_token,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LibraryMetadata {
|
|
||||||
pub fn providers(&self) -> &Vec<LibraryProviderMetadata> {
|
|
||||||
&self.providers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,201 +0,0 @@
|
|||||||
use bitcode::{Decode, Encode};
|
|
||||||
use serde_with::serde_as;
|
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
|
||||||
|
|
||||||
use crate::{models::v1, platform::Platform};
|
|
||||||
|
|
||||||
use super::{Deserialize, Serialize, native_model};
|
|
||||||
|
|
||||||
fn default_template() -> String {
|
|
||||||
"{}".to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
#[native_model(id = 2, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
pub struct GameVersion {
|
|
||||||
pub game_id: String,
|
|
||||||
pub version_name: String,
|
|
||||||
|
|
||||||
pub platform: Platform,
|
|
||||||
|
|
||||||
pub launch_command: String,
|
|
||||||
pub launch_args: Vec<String>,
|
|
||||||
#[serde(default = "default_template")]
|
|
||||||
pub launch_command_template: String,
|
|
||||||
|
|
||||||
pub setup_command: String,
|
|
||||||
pub setup_args: Vec<String>,
|
|
||||||
#[serde(default = "default_template")]
|
|
||||||
pub setup_command_template: String,
|
|
||||||
|
|
||||||
pub only_setup: bool,
|
|
||||||
|
|
||||||
pub version_index: usize,
|
|
||||||
pub delta: bool,
|
|
||||||
|
|
||||||
pub umu_id_override: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[serde_as]
|
|
||||||
#[derive(Serialize, Clone, Deserialize, Default)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
#[native_model(id = 3, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
pub struct DatabaseApplications {
|
|
||||||
pub install_dirs: Vec<PathBuf>,
|
|
||||||
// Guaranteed to exist if the game also exists in the app state map
|
|
||||||
pub game_statuses: HashMap<String, v1::GameDownloadStatus>,
|
|
||||||
pub game_versions: HashMap<String, HashMap<String, v1::GameVersion>>,
|
|
||||||
pub installed_game_version: HashMap<String, v1::DownloadableMetadata>,
|
|
||||||
|
|
||||||
#[serde(skip)]
|
|
||||||
pub transient_statuses: HashMap<v1::DownloadableMetadata, v1::ApplicationTransientStatus>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
#[native_model(id = 4, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
pub struct Settings {
|
|
||||||
pub autostart: bool,
|
|
||||||
pub max_download_threads: usize,
|
|
||||||
pub force_offline: bool, // ... other settings ...
|
|
||||||
}
|
|
||||||
impl Default for Settings {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
autostart: false,
|
|
||||||
max_download_threads: 4,
|
|
||||||
force_offline: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strings are version names for a particular game
|
|
||||||
#[derive(Serialize, Clone, Deserialize, Debug)]
|
|
||||||
#[serde(tag = "type")]
|
|
||||||
#[native_model(id = 5, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
pub enum GameDownloadStatus {
|
|
||||||
Remote {},
|
|
||||||
SetupRequired {
|
|
||||||
version_name: String,
|
|
||||||
install_dir: String,
|
|
||||||
},
|
|
||||||
Installed {
|
|
||||||
version_name: String,
|
|
||||||
install_dir: String,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stuff that shouldn't be synced to disk
|
|
||||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
|
||||||
pub enum ApplicationTransientStatus {
|
|
||||||
Queued { version_name: String },
|
|
||||||
Downloading { version_name: String },
|
|
||||||
Uninstalling {},
|
|
||||||
Updating { version_name: String },
|
|
||||||
Validating { version_name: String },
|
|
||||||
Running {},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, Encode, Decode)]
|
|
||||||
#[native_model(id = 6, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
pub struct DatabaseAuth {
|
|
||||||
pub private: String,
|
|
||||||
pub cert: String,
|
|
||||||
pub client_id: String,
|
|
||||||
pub web_token: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[native_model(id = 8, version = 1)]
|
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Clone, Copy)]
|
|
||||||
pub enum DownloadType {
|
|
||||||
Game,
|
|
||||||
Tool,
|
|
||||||
Dlc,
|
|
||||||
Mod,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[native_model(id = 7, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
#[derive(Debug, Eq, PartialOrd, Ord, Serialize, Deserialize, Clone)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct DownloadableMetadata {
|
|
||||||
pub id: String,
|
|
||||||
pub version: Option<String>,
|
|
||||||
pub download_type: v1::DownloadType,
|
|
||||||
}
|
|
||||||
impl DownloadableMetadata {
|
|
||||||
pub fn new(id: String, version: Option<String>, download_type: v1::DownloadType) -> Self {
|
|
||||||
Self {
|
|
||||||
id,
|
|
||||||
version,
|
|
||||||
download_type,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[native_model(id = 1, version = 1)]
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
|
||||||
pub struct Database {
|
|
||||||
#[serde(default)]
|
|
||||||
pub settings: Settings,
|
|
||||||
pub auth: Option<v1::DatabaseAuth>,
|
|
||||||
pub base_url: String,
|
|
||||||
pub applications: v1::DatabaseApplications,
|
|
||||||
pub prev_database: Option<PathBuf>,
|
|
||||||
pub cache_dir: PathBuf,
|
|
||||||
}
|
|
||||||
#[native_model(id = 15, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Encode, Decode, Default)]
|
|
||||||
pub struct LibraryMetadata {
|
|
||||||
pub(crate) providers: Vec<v1::LibraryProviderMetadata>
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[native_model(id = 11, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Encode, Decode)]
|
|
||||||
pub struct LibraryProviderMetadata {
|
|
||||||
pub(crate) id: usize,
|
|
||||||
pub(crate) name: String,
|
|
||||||
pub(crate) provider: v1::ProviderType
|
|
||||||
}
|
|
||||||
#[native_model(id = 10, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Encode, Decode)]
|
|
||||||
pub enum ProviderType {
|
|
||||||
Drop(v1::DatabaseAuth),
|
|
||||||
}
|
|
||||||
#[native_model(id = 12, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Encode, Decode)]
|
|
||||||
pub struct Game {
|
|
||||||
pub library_id: LibraryProviderMetadata,
|
|
||||||
pub(crate) id: String,
|
|
||||||
m_name: String,
|
|
||||||
m_short_description: String,
|
|
||||||
m_description: String,
|
|
||||||
// mDevelopers
|
|
||||||
// mPublishers
|
|
||||||
m_icon_object_id: String,
|
|
||||||
m_banner_object_id: String,
|
|
||||||
m_cover_object_id: String,
|
|
||||||
m_image_library_object_ids: Vec<String>,
|
|
||||||
m_image_carousel_object_ids: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[native_model(id = 13, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct Collection {
|
|
||||||
id: String,
|
|
||||||
name: String,
|
|
||||||
is_default: bool,
|
|
||||||
user_id: String,
|
|
||||||
entries: Vec<CollectionObject>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[native_model(id = 14, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct CollectionObject {
|
|
||||||
collection_id: String,
|
|
||||||
game_id: String,
|
|
||||||
game: Game,
|
|
||||||
}
|
|
||||||
@ -1,111 +0,0 @@
|
|||||||
use std::{collections::HashMap, path::PathBuf};
|
|
||||||
|
|
||||||
use serde_with::serde_as;
|
|
||||||
|
|
||||||
use super::{Deserialize, Serialize, native_model, v1};
|
|
||||||
|
|
||||||
#[native_model(id = 1, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from = v1::Database)]
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
|
||||||
pub struct Database {
|
|
||||||
#[serde(default)]
|
|
||||||
pub settings: v1::Settings,
|
|
||||||
pub auth: Option<v1::DatabaseAuth>,
|
|
||||||
pub base_url: String,
|
|
||||||
pub applications: v1::DatabaseApplications,
|
|
||||||
#[serde(skip)]
|
|
||||||
pub prev_database: Option<PathBuf>,
|
|
||||||
pub cache_dir: PathBuf,
|
|
||||||
pub compat_info: Option<DatabaseCompatInfo>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[native_model(id = 9, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
|
||||||
|
|
||||||
pub struct DatabaseCompatInfo {
|
|
||||||
pub umu_installed: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v1::Database> for Database {
|
|
||||||
fn from(value: v1::Database) -> Self {
|
|
||||||
Self {
|
|
||||||
settings: value.settings,
|
|
||||||
auth: value.auth,
|
|
||||||
base_url: value.base_url,
|
|
||||||
applications: value.applications,
|
|
||||||
prev_database: value.prev_database,
|
|
||||||
cache_dir: value.cache_dir,
|
|
||||||
compat_info: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Strings are version names for a particular game
|
|
||||||
#[derive(Serialize, Clone, Deserialize, Debug)]
|
|
||||||
#[serde(tag = "type")]
|
|
||||||
#[native_model(id = 5, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from = v1::GameDownloadStatus)]
|
|
||||||
pub enum GameDownloadStatus {
|
|
||||||
Remote {},
|
|
||||||
SetupRequired {
|
|
||||||
version_name: String,
|
|
||||||
install_dir: String,
|
|
||||||
},
|
|
||||||
Installed {
|
|
||||||
version_name: String,
|
|
||||||
install_dir: String,
|
|
||||||
},
|
|
||||||
PartiallyInstalled {
|
|
||||||
version_name: String,
|
|
||||||
install_dir: String,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
impl From<v1::GameDownloadStatus> for GameDownloadStatus {
|
|
||||||
fn from(value: v1::GameDownloadStatus) -> Self {
|
|
||||||
match value {
|
|
||||||
v1::GameDownloadStatus::Remote {} => Self::Remote {},
|
|
||||||
v1::GameDownloadStatus::SetupRequired {
|
|
||||||
version_name,
|
|
||||||
install_dir,
|
|
||||||
} => Self::SetupRequired {
|
|
||||||
version_name,
|
|
||||||
install_dir,
|
|
||||||
},
|
|
||||||
v1::GameDownloadStatus::Installed {
|
|
||||||
version_name,
|
|
||||||
install_dir,
|
|
||||||
} => Self::Installed {
|
|
||||||
version_name,
|
|
||||||
install_dir,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[serde_as]
|
|
||||||
#[derive(Serialize, Clone, Deserialize, Default)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
#[native_model(id = 3, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from=v1::DatabaseApplications)]
|
|
||||||
pub struct DatabaseApplications {
|
|
||||||
pub install_dirs: Vec<PathBuf>,
|
|
||||||
// Guaranteed to exist if the game also exists in the app state map
|
|
||||||
pub game_statuses: HashMap<String, GameDownloadStatus>,
|
|
||||||
|
|
||||||
pub game_versions: HashMap<String, HashMap<String, v1::GameVersion>>,
|
|
||||||
pub installed_game_version: HashMap<String, v1::DownloadableMetadata>,
|
|
||||||
|
|
||||||
#[serde(skip)]
|
|
||||||
pub transient_statuses:
|
|
||||||
HashMap<v1::DownloadableMetadata, v1::ApplicationTransientStatus>,
|
|
||||||
}
|
|
||||||
impl From<v1::DatabaseApplications> for DatabaseApplications {
|
|
||||||
fn from(value: v1::DatabaseApplications) -> Self {
|
|
||||||
Self {
|
|
||||||
game_statuses: value
|
|
||||||
.game_statuses
|
|
||||||
.into_iter()
|
|
||||||
.map(|x| (x.0, x.1.into()))
|
|
||||||
.collect::<HashMap<String, GameDownloadStatus>>(),
|
|
||||||
install_dirs: value.install_dirs,
|
|
||||||
game_versions: value.game_versions,
|
|
||||||
installed_game_version: value.installed_game_version,
|
|
||||||
transient_statuses: value.transient_statuses,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
use std::{collections::HashMap, path::PathBuf};
|
|
||||||
|
|
||||||
use serde_with::serde_as;
|
|
||||||
|
|
||||||
use super::{Deserialize, Serialize, native_model, v1, v2};
|
|
||||||
#[native_model(id = 1, version = 3, with = native_model::rmp_serde_1_3::RmpSerde, from = v2::Database)]
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
|
||||||
pub struct Database {
|
|
||||||
#[serde(default)]
|
|
||||||
pub settings: v1::Settings,
|
|
||||||
pub auth: Option<v1::DatabaseAuth>,
|
|
||||||
pub base_url: String,
|
|
||||||
pub applications: v2::DatabaseApplications,
|
|
||||||
#[serde(skip)]
|
|
||||||
pub prev_database: Option<PathBuf>,
|
|
||||||
pub cache_dir: PathBuf,
|
|
||||||
pub compat_info: Option<v2::DatabaseCompatInfo>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v2::Database> for Database {
|
|
||||||
fn from(value: v2::Database) -> Self {
|
|
||||||
Self {
|
|
||||||
settings: value.settings,
|
|
||||||
auth: value.auth,
|
|
||||||
base_url: value.base_url,
|
|
||||||
applications: value.applications.into(),
|
|
||||||
prev_database: value.prev_database,
|
|
||||||
cache_dir: value.cache_dir,
|
|
||||||
compat_info: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use native_model::native_model;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::models::{
|
|
||||||
v1::{self, LibraryMetadata},
|
|
||||||
v2, v3,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[native_model(id = 1, version = 4, with = native_model::rmp_serde_1_3::RmpSerde, from = v3::Database)]
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
|
||||||
pub struct Database {
|
|
||||||
#[serde(default)]
|
|
||||||
pub settings: v1::Settings,
|
|
||||||
#[serde(skip)]
|
|
||||||
pub prev_database: Option<PathBuf>,
|
|
||||||
pub cache_dir: PathBuf,
|
|
||||||
pub compat_info: Option<v2::DatabaseCompatInfo>,
|
|
||||||
pub library: v1::LibraryMetadata,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v3::Database> for Database {
|
|
||||||
fn from(value: v3::Database) -> Self {
|
|
||||||
Self {
|
|
||||||
settings: value.settings,
|
|
||||||
prev_database: value.prev_database,
|
|
||||||
cache_dir: value.cache_dir,
|
|
||||||
compat_info: value.compat_info,
|
|
||||||
library: v1::LibraryMetadata {
|
|
||||||
providers: if let Some(auth) = value.auth {
|
|
||||||
vec![v1::LibraryProviderMetadata {
|
|
||||||
id: 0,
|
|
||||||
name: String::from("Default"),
|
|
||||||
provider: v1::ProviderType::Drop(auth),
|
|
||||||
}]
|
|
||||||
} else {
|
|
||||||
vec![]
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "drop-consts"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
dirs = "6.0.0"
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
use std::{path::PathBuf, sync::LazyLock};
|
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
pub const DATA_ROOT_PREFIX: &str = "drop";
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
pub const DATA_ROOT_PREFIX: &str = "drop-debug";
|
|
||||||
|
|
||||||
pub const DROP_DATA_PATH: &str = ".dropdata";
|
|
||||||
|
|
||||||
pub const RETRY_COUNT: usize = 3;
|
|
||||||
|
|
||||||
pub const TARGET_BUCKET_SIZE: usize = 63 * 1000 * 1000;
|
|
||||||
pub const MAX_FILES_PER_BUCKET: usize = (1024 / 4) - 1;
|
|
||||||
|
|
||||||
pub const UMU_BASE_LAUNCHER_EXECUTABLE: &str = "umu-run";
|
|
||||||
pub const UMU_INSTALL_DIRS: [&str; 4] = ["/app/share", "/use/local/share", "/usr/share", "/opt"];
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "library"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
async-trait = "0.1.89"
|
|
||||||
client = { version = "0.1.0", path = "../client" }
|
|
||||||
database = { version = "0.1.0", path = "../database" }
|
|
||||||
futures = "0.3.31"
|
|
||||||
itertools = "0.14.0"
|
|
||||||
log = "0.4.28"
|
|
||||||
remote = { version = "0.1.0", path = "../remote" }
|
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
|
||||||
serde_with = "3.15.0"
|
|
||||||
tauri = "2.8.5"
|
|
||||||
url = "2.5.7"
|
|
||||||
@ -1,134 +0,0 @@
|
|||||||
use std::sync::nonpoison::Mutex;
|
|
||||||
|
|
||||||
use async_trait::async_trait;
|
|
||||||
use client::app_state::AppState;
|
|
||||||
use database::{
|
|
||||||
DatabaseAuth, GameDownloadStatus, borrow_db_mut_checked,
|
|
||||||
models::{Collection, Game, LibraryProviderMetadata},
|
|
||||||
};
|
|
||||||
use log::warn;
|
|
||||||
use remote::{
|
|
||||||
auth::generate_authorization_header,
|
|
||||||
cache::{cache_object, get_cached_object, get_cached_object_db},
|
|
||||||
error::{DropServerError, RemoteAccessError},
|
|
||||||
requests::generate_url,
|
|
||||||
utils::DROP_CLIENT_ASYNC,
|
|
||||||
};
|
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
use crate::{error::LibraryError, provider::LibraryProvider};
|
|
||||||
|
|
||||||
pub struct DropLibraryProvider {
|
|
||||||
metadata: LibraryProviderMetadata,
|
|
||||||
auth: DatabaseAuth,
|
|
||||||
base_url: Url,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DropLibraryProvider {
|
|
||||||
pub fn new(metadata: LibraryProviderMetadata, auth: DatabaseAuth, base_url: Url) -> Self {
|
|
||||||
Self {
|
|
||||||
metadata,
|
|
||||||
auth,
|
|
||||||
base_url,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[async_trait]
|
|
||||||
impl LibraryProvider for DropLibraryProvider {
|
|
||||||
async fn get_library(
|
|
||||||
&self,
|
|
||||||
state: &tauri::State<'_, Mutex<AppState>>,
|
|
||||||
) -> Result<Vec<Game>, LibraryError> {
|
|
||||||
// let do_hard_refresh = hard_fresh.unwrap_or(false);
|
|
||||||
if
|
|
||||||
/* !do_hard_refresh &&*/
|
|
||||||
let Ok(library) = get_cached_object("library") {
|
|
||||||
return Ok(library);
|
|
||||||
}
|
|
||||||
|
|
||||||
let client = DROP_CLIENT_ASYNC.clone();
|
|
||||||
let response = generate_url(&["/api/v1/client/user/library"], &[], self.base_url)?;
|
|
||||||
let response = client
|
|
||||||
.get(response)
|
|
||||||
.header("Authorization", generate_authorization_header(self.auth))
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.map_err(|e| LibraryError::FetchError(RemoteAccessError::FetchError(e.into())))?;
|
|
||||||
|
|
||||||
if response.status() != 200 {
|
|
||||||
let err = response.json().await.unwrap_or(DropServerError {
|
|
||||||
status_code: 500,
|
|
||||||
status_message: "Invalid response from server.".to_owned(),
|
|
||||||
});
|
|
||||||
warn!("{err:?}");
|
|
||||||
return Err(LibraryError::FetchError(
|
|
||||||
RemoteAccessError::InvalidResponse(err),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut games: Vec<Game> = response
|
|
||||||
.json()
|
|
||||||
.await
|
|
||||||
.map_err(|e| RemoteAccessError::FetchError(e.into()))?;
|
|
||||||
|
|
||||||
let mut handle = state.lock();
|
|
||||||
|
|
||||||
let mut db_handle = borrow_db_mut_checked();
|
|
||||||
|
|
||||||
for game in &games {
|
|
||||||
handle.games_mut().insert(game.id().clone(), game.clone());
|
|
||||||
if !db_handle.applications.game_statuses.contains_key(game.id()) {
|
|
||||||
db_handle
|
|
||||||
.applications
|
|
||||||
.game_statuses
|
|
||||||
.insert(game.id().clone(), GameDownloadStatus::Remote {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add games that are installed but no longer in library
|
|
||||||
for meta in db_handle.applications.installed_game_version.values() {
|
|
||||||
if games.iter().any(|e| *e.id() == meta.id) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// We should always have a cache of the object
|
|
||||||
// Pass db_handle because otherwise we get a gridlock
|
|
||||||
let game = match get_cached_object_db::<Game>(&meta.id.clone(), &db_handle) {
|
|
||||||
Ok(game) => game,
|
|
||||||
Err(err) => {
|
|
||||||
warn!(
|
|
||||||
"{} is installed, but encountered error fetching its error: {}.",
|
|
||||||
meta.id, err
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
games.push(game);
|
|
||||||
}
|
|
||||||
|
|
||||||
drop(handle);
|
|
||||||
drop(db_handle);
|
|
||||||
cache_object("library", &games)?;
|
|
||||||
|
|
||||||
Ok(games)
|
|
||||||
}
|
|
||||||
async fn get_collections(&self) -> Result<Vec<Collection>, LibraryError> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn install(&mut self, game_id: String) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn uninstall(&mut self, game_id: String) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn metadata(&self) -> LibraryProviderMetadata {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fetch_library_logic(state: &Mutex<AppState>) -> Result<Vec<Game>, RemoteAccessError> {}
|
|
||||||
async fn fetch_library_logic_offline() -> Result<Vec<Game>, RemoteAccessError> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
pub mod drop;
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
use std::fmt::Display;
|
|
||||||
|
|
||||||
use database::models::LibraryProviderMetadata;
|
|
||||||
use remote::error::RemoteAccessError;
|
|
||||||
use serde_with::SerializeDisplay;
|
|
||||||
|
|
||||||
#[derive(Debug, SerializeDisplay)]
|
|
||||||
pub enum LibraryError {
|
|
||||||
ProviderConnection(ProviderError),
|
|
||||||
FetchError(RemoteAccessError)
|
|
||||||
}
|
|
||||||
#[derive(Debug, SerializeDisplay)]
|
|
||||||
pub struct ProviderError {
|
|
||||||
provider: LibraryProviderMetadata
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for LibraryError {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Display for ProviderError {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl From<RemoteAccessError> for LibraryError {
|
|
||||||
fn from(value: RemoteAccessError) -> Self {
|
|
||||||
LibraryError::FetchError(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,69 +0,0 @@
|
|||||||
#![feature(nonpoison_mutex)]
|
|
||||||
#![feature(sync_nonpoison)]
|
|
||||||
|
|
||||||
use std::sync::{LazyLock, nonpoison::Mutex};
|
|
||||||
|
|
||||||
use client::app_state::AppState;
|
|
||||||
use database::{borrow_db_checked, models::{Game, LibraryProviderMetadata, ProviderType}};
|
|
||||||
use futures::{StreamExt, future::join_all};
|
|
||||||
use itertools::Itertools;
|
|
||||||
|
|
||||||
use crate::{drop::drop::DropLibraryProvider, error::LibraryError, provider::LibraryProvider};
|
|
||||||
|
|
||||||
pub mod drop;
|
|
||||||
pub mod error;
|
|
||||||
pub mod provider;
|
|
||||||
|
|
||||||
pub static LIBRARY: LazyLock<Library> = LazyLock::new(Library::init);
|
|
||||||
|
|
||||||
pub struct Library {
|
|
||||||
providers: Vec<Box<dyn LibraryProvider>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Library {
|
|
||||||
pub fn init() -> Self {
|
|
||||||
let metadata = borrow_db_checked();
|
|
||||||
let library = &metadata.library;
|
|
||||||
let providers = library.providers().iter().map(|provider| {
|
|
||||||
Library::construct(provider)
|
|
||||||
}).collect();
|
|
||||||
Self {
|
|
||||||
providers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn construct(provider: &LibraryProviderMetadata) -> Box<dyn LibraryProvider> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
pub async fn get_library(
|
|
||||||
&self,
|
|
||||||
state: &tauri::State<'_, Mutex<AppState>>,
|
|
||||||
) -> (Vec<Game>, Vec<LibraryError>) {
|
|
||||||
let res = join_all(
|
|
||||||
self.providers
|
|
||||||
.iter()
|
|
||||||
.map(|provider| provider.get_library(state)),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.into_iter()
|
|
||||||
.fold(
|
|
||||||
(Vec::new(), Vec::new()),
|
|
||||||
|(mut acc_ok, mut acc_err), res| {
|
|
||||||
match res {
|
|
||||||
Ok(games) => acc_ok.extend(games),
|
|
||||||
Err(e) => acc_err.push(e),
|
|
||||||
};
|
|
||||||
(acc_ok, acc_err)
|
|
||||||
},
|
|
||||||
);
|
|
||||||
res
|
|
||||||
}
|
|
||||||
pub fn add(&mut self, provider: LibraryProviderMetadata) {
|
|
||||||
let new_provider = Box::new(match provider.provider() {
|
|
||||||
ProviderType::Drop(_) => DropLibraryProvider::new(provider),
|
|
||||||
});
|
|
||||||
self.providers.push(new_provider);
|
|
||||||
}
|
|
||||||
pub fn remove(&mut self, id: usize) {
|
|
||||||
self.providers.retain(|v| v.metadata().id() != id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
use std::sync::nonpoison::Mutex;
|
|
||||||
|
|
||||||
use async_trait::async_trait;
|
|
||||||
use client::app_state::AppState;
|
|
||||||
use database::models::{Collection, Game, LibraryProviderMetadata};
|
|
||||||
|
|
||||||
use crate::error::LibraryError;
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
pub trait LibraryProvider: Sync + Send {
|
|
||||||
async fn get_library(&self, state: &tauri::State<'_, Mutex<AppState>>) -> Result<Vec<Game>, LibraryError>;
|
|
||||||
async fn get_collections(&self) -> Result<Vec<Collection>, LibraryError>;
|
|
||||||
fn install(&mut self, game_id: String);
|
|
||||||
fn uninstall(&mut self, game_id: String);
|
|
||||||
fn metadata(&self) -> LibraryProviderMetadata;
|
|
||||||
}
|
|
||||||
@ -1,12 +1,12 @@
|
|||||||
use std::sync::nonpoison::Mutex;
|
use std::sync::nonpoison::Mutex;
|
||||||
|
|
||||||
use client::app_state::AppState;
|
|
||||||
use database::{borrow_db_checked, borrow_db_mut_checked};
|
use database::{borrow_db_checked, borrow_db_mut_checked};
|
||||||
use download_manager::DOWNLOAD_MANAGER;
|
use download_manager::DOWNLOAD_MANAGER;
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
use tauri::AppHandle;
|
use tauri::AppHandle;
|
||||||
use tauri_plugin_autostart::ManagerExt;
|
use tauri_plugin_autostart::ManagerExt;
|
||||||
use tauri_plugin_opener::OpenerExt;
|
|
||||||
|
use crate::AppState;
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn fetch_state(state: tauri::State<'_, Mutex<AppState>>) -> Result<String, String> {
|
pub fn fetch_state(state: tauri::State<'_, Mutex<AppState>>) -> Result<String, String> {
|
||||||
@ -72,10 +72,3 @@ pub fn get_autostart_enabled(app: AppHandle) -> Result<bool, tauri_plugin_autost
|
|||||||
|
|
||||||
Ok(db_state)
|
Ok(db_state)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
pub fn open_fs(path: String, app_handle: AppHandle) -> Result<(), tauri_plugin_opener::Error> {
|
|
||||||
app_handle
|
|
||||||
.opener()
|
|
||||||
.open_path(path, None::<&str>)
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
use std::sync::nonpoison::Mutex;
|
use std::sync::nonpoison::Mutex;
|
||||||
|
|
||||||
use database::{GameDownloadStatus, GameVersion, borrow_db_checked, borrow_db_mut_checked, models::Game};
|
use database::{GameDownloadStatus, GameVersion, borrow_db_checked, borrow_db_mut_checked};
|
||||||
use games::{
|
use games::{
|
||||||
downloads::error::LibraryError,
|
downloads::error::LibraryError,
|
||||||
library::{FetchGameStruct, FrontendGameOptions, get_current_meta, uninstall_game_logic},
|
library::{FetchGameStruct, FrontendGameOptions, Game, get_current_meta, uninstall_game_logic},
|
||||||
state::{GameStatusManager, GameStatusWithTransient},
|
state::{GameStatusManager, GameStatusWithTransient},
|
||||||
};
|
};
|
||||||
use log::warn;
|
use log::warn;
|
||||||
@ -18,7 +18,7 @@ use remote::{
|
|||||||
};
|
};
|
||||||
use tauri::AppHandle;
|
use tauri::AppHandle;
|
||||||
|
|
||||||
use client::app_state::AppState;
|
use crate::AppState;
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn fetch_library(
|
pub async fn fetch_library(
|
||||||
@ -38,13 +38,75 @@ pub async fn fetch_library(
|
|||||||
pub async fn fetch_library_logic(
|
pub async fn fetch_library_logic(
|
||||||
state: tauri::State<'_, Mutex<AppState>>,
|
state: tauri::State<'_, Mutex<AppState>>,
|
||||||
hard_fresh: Option<bool>,
|
hard_fresh: Option<bool>,
|
||||||
) -> (Vec<Game>, Vec<LibraryError>) {
|
) -> Result<Vec<Game>, RemoteAccessError> {
|
||||||
|
let do_hard_refresh = hard_fresh.unwrap_or(false);
|
||||||
|
if !do_hard_refresh && let Ok(library) = get_cached_object("library") {
|
||||||
|
return Ok(library);
|
||||||
|
}
|
||||||
|
|
||||||
|
let client = DROP_CLIENT_ASYNC.clone();
|
||||||
|
let response = generate_url(&["/api/v1/client/user/library"], &[])?;
|
||||||
|
let response = client
|
||||||
|
.get(response)
|
||||||
|
.header("Authorization", generate_authorization_header())
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if response.status() != 200 {
|
||||||
|
let err = response.json().await.unwrap_or(DropServerError {
|
||||||
|
status_code: 500,
|
||||||
|
status_message: "Invalid response from server.".to_owned(),
|
||||||
|
});
|
||||||
|
warn!("{err:?}");
|
||||||
|
return Err(RemoteAccessError::InvalidResponse(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut games: Vec<Game> = response.json().await?;
|
||||||
|
|
||||||
|
let mut handle = state.lock();
|
||||||
|
|
||||||
|
let mut db_handle = borrow_db_mut_checked();
|
||||||
|
|
||||||
|
for game in &games {
|
||||||
|
handle.games.insert(game.id().clone(), game.clone());
|
||||||
|
if !db_handle.applications.game_statuses.contains_key(game.id()) {
|
||||||
|
db_handle
|
||||||
|
.applications
|
||||||
|
.game_statuses
|
||||||
|
.insert(game.id().clone(), GameDownloadStatus::Remote {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add games that are installed but no longer in library
|
||||||
|
for meta in db_handle.applications.installed_game_version.values() {
|
||||||
|
if games.iter().any(|e| *e.id() == meta.id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// We should always have a cache of the object
|
||||||
|
// Pass db_handle because otherwise we get a gridlock
|
||||||
|
let game = match get_cached_object_db::<Game>(&meta.id.clone(), &db_handle) {
|
||||||
|
Ok(game) => game,
|
||||||
|
Err(err) => {
|
||||||
|
warn!(
|
||||||
|
"{} is installed, but encountered error fetching its error: {}.",
|
||||||
|
meta.id, err
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
games.push(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
drop(handle);
|
||||||
|
drop(db_handle);
|
||||||
|
cache_object("library", &games)?;
|
||||||
|
|
||||||
|
Ok(games)
|
||||||
}
|
}
|
||||||
pub async fn fetch_library_logic_offline(
|
pub async fn fetch_library_logic_offline(
|
||||||
_state: tauri::State<'_, Mutex<AppState>>,
|
_state: tauri::State<'_, Mutex<AppState>>,
|
||||||
_hard_refresh: Option<bool>,
|
_hard_refresh: Option<bool>,
|
||||||
) -> (Vec<Game>, Vec<LibraryError>) {
|
) -> Result<Vec<Game>, RemoteAccessError> {
|
||||||
let mut games: Vec<Game> = get_cached_object("library")?;
|
let mut games: Vec<Game> = get_cached_object("library")?;
|
||||||
|
|
||||||
let db_handle = borrow_db_checked();
|
let db_handle = borrow_db_checked();
|
||||||
@ -82,7 +144,7 @@ pub async fn fetch_game_logic(
|
|||||||
.cloned(),
|
.cloned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let game = state_handle.games().get(&id);
|
let game = state_handle.games.get(&id);
|
||||||
if let Some(game) = game {
|
if let Some(game) = game {
|
||||||
let status = GameStatusManager::fetch_state(&id, &db_lock);
|
let status = GameStatusManager::fetch_state(&id, &db_lock);
|
||||||
|
|
||||||
@ -121,7 +183,7 @@ pub async fn fetch_game_logic(
|
|||||||
let game: Game = response.json().await?;
|
let game: Game = response.json().await?;
|
||||||
|
|
||||||
let mut state_handle = state.lock();
|
let mut state_handle = state.lock();
|
||||||
state_handle.games_mut().insert(id.clone(), game.clone());
|
state_handle.games.insert(id.clone(), game.clone());
|
||||||
|
|
||||||
let mut db_handle = borrow_db_mut_checked();
|
let mut db_handle = borrow_db_mut_checked();
|
||||||
|
|
||||||
|
|||||||
@ -12,11 +12,9 @@ use std::{
|
|||||||
sync::nonpoison::Mutex, time::SystemTime,
|
sync::nonpoison::Mutex, time::SystemTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
use ::client::{
|
use ::client::{app_status::AppStatus, autostart::sync_autostart_on_startup, user::User};
|
||||||
app_state::AppState, app_status::AppStatus, autostart::sync_autostart_on_startup,
|
|
||||||
};
|
|
||||||
use ::download_manager::DownloadManagerWrapper;
|
use ::download_manager::DownloadManagerWrapper;
|
||||||
use ::games::scan::scan_install_dirs;
|
use ::games::{library::Game, scan::scan_install_dirs};
|
||||||
use ::process::ProcessManagerWrapper;
|
use ::process::ProcessManagerWrapper;
|
||||||
use ::remote::{
|
use ::remote::{
|
||||||
auth::{self, HandshakeRequestBody, HandshakeResponse, generate_authorization_header},
|
auth::{self, HandshakeRequestBody, HandshakeResponse, generate_authorization_header},
|
||||||
@ -38,6 +36,7 @@ use log4rs::{
|
|||||||
config::{Appender, Root},
|
config::{Appender, Root},
|
||||||
encode::pattern::PatternEncoder,
|
encode::pattern::PatternEncoder,
|
||||||
};
|
};
|
||||||
|
use serde::Serialize;
|
||||||
use tauri::{
|
use tauri::{
|
||||||
AppHandle, Manager, RunEvent, WindowEvent,
|
AppHandle, Manager, RunEvent, WindowEvent,
|
||||||
menu::{Menu, MenuItem, PredefinedMenuItem},
|
menu::{Menu, MenuItem, PredefinedMenuItem},
|
||||||
@ -68,6 +67,14 @@ use process::*;
|
|||||||
use remote::*;
|
use remote::*;
|
||||||
use settings::*;
|
use settings::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct AppState {
|
||||||
|
status: AppStatus,
|
||||||
|
user: Option<User>,
|
||||||
|
games: HashMap<String, Game>,
|
||||||
|
}
|
||||||
|
|
||||||
async fn setup(handle: AppHandle) -> AppState {
|
async fn setup(handle: AppHandle) -> AppState {
|
||||||
let logfile = FileAppender::builder()
|
let logfile = FileAppender::builder()
|
||||||
.encoder(Box::new(PatternEncoder::new(
|
.encoder(Box::new(PatternEncoder::new(
|
||||||
@ -110,7 +117,11 @@ async fn setup(handle: AppHandle) -> AppState {
|
|||||||
scan_install_dirs();
|
scan_install_dirs();
|
||||||
|
|
||||||
if !is_set_up {
|
if !is_set_up {
|
||||||
return AppState::new(AppStatus::NotConfigured, None, games);
|
return AppState {
|
||||||
|
status: AppStatus::NotConfigured,
|
||||||
|
user: None,
|
||||||
|
games,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("database is set up");
|
debug!("database is set up");
|
||||||
@ -168,7 +179,11 @@ async fn setup(handle: AppHandle) -> AppState {
|
|||||||
warn!("failed to sync autostart state: {e}");
|
warn!("failed to sync autostart state: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
AppState::new(app_status, user, games)
|
AppState {
|
||||||
|
status: app_status,
|
||||||
|
user,
|
||||||
|
games,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn custom_panic_handler(e: &PanicHookInfo) -> Option<()> {
|
pub fn custom_panic_handler(e: &PanicHookInfo) -> Option<()> {
|
||||||
@ -214,7 +229,6 @@ pub fn run() {
|
|||||||
fetch_state,
|
fetch_state,
|
||||||
quit,
|
quit,
|
||||||
fetch_system_data,
|
fetch_system_data,
|
||||||
open_fs,
|
|
||||||
// User utils
|
// User utils
|
||||||
update_settings,
|
update_settings,
|
||||||
fetch_settings,
|
fetch_settings,
|
||||||
@ -458,12 +472,14 @@ pub async fn recieve_handshake(app: AppHandle, path: String) {
|
|||||||
|
|
||||||
let mut state_lock = app_state.lock();
|
let mut state_lock = app_state.lock();
|
||||||
|
|
||||||
*state_lock.status_mut() = app_status;
|
state_lock.status = app_status;
|
||||||
*state_lock.user_mut() = user;
|
state_lock.user = user;
|
||||||
|
|
||||||
let _ = clear_cached_object("collections");
|
let _ = clear_cached_object("collections");
|
||||||
let _ = clear_cached_object("library");
|
let _ = clear_cached_object("library");
|
||||||
|
|
||||||
|
drop(state_lock);
|
||||||
|
|
||||||
app_emit!(&app, "auth/finished", ());
|
app_emit!(&app, "auth/finished", ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,17 @@
|
|||||||
|
use std::sync::nonpoison::Mutex;
|
||||||
|
|
||||||
use process::{PROCESS_MANAGER, error::ProcessError};
|
use process::{PROCESS_MANAGER, error::ProcessError};
|
||||||
use tauri::AppHandle;
|
use tauri::AppHandle;
|
||||||
use tauri_plugin_opener::OpenerExt;
|
use tauri_plugin_opener::OpenerExt;
|
||||||
|
|
||||||
|
use crate::AppState;
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn launch_game(
|
pub fn launch_game(
|
||||||
id: String,
|
id: String,
|
||||||
|
state: tauri::State<'_, Mutex<AppState>>,
|
||||||
) -> Result<(), ProcessError> {
|
) -> Result<(), ProcessError> {
|
||||||
|
let state_lock = state.lock();
|
||||||
let mut process_manager_lock = PROCESS_MANAGER.lock();
|
let mut process_manager_lock = PROCESS_MANAGER.lock();
|
||||||
//let meta = DownloadableMetadata {
|
//let meta = DownloadableMetadata {
|
||||||
// id,
|
// id,
|
||||||
@ -18,6 +24,9 @@ pub fn launch_game(
|
|||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop(process_manager_lock);
|
||||||
|
drop(state_lock);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use std::{sync::nonpoison::Mutex, time::Duration};
|
use std::{sync::nonpoison::Mutex, time::Duration};
|
||||||
|
|
||||||
use client::{app_state::AppState, app_status::AppStatus};
|
use client::app_status::AppStatus;
|
||||||
use database::{borrow_db_checked, borrow_db_mut_checked};
|
use database::{borrow_db_checked, borrow_db_mut_checked};
|
||||||
use futures_lite::StreamExt;
|
use futures_lite::StreamExt;
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
@ -18,7 +18,7 @@ use tauri::{AppHandle, Manager};
|
|||||||
use url::Url;
|
use url::Url;
|
||||||
use utils::{app_emit, webbrowser_open::webbrowser_open};
|
use utils::{app_emit, webbrowser_open::webbrowser_open};
|
||||||
|
|
||||||
use crate::{recieve_handshake};
|
use crate::{AppState, recieve_handshake};
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn use_remote(
|
pub async fn use_remote(
|
||||||
@ -45,7 +45,7 @@ pub async fn use_remote(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut app_state = state.lock();
|
let mut app_state = state.lock();
|
||||||
*app_state.status_mut() = AppStatus::SignedOut;
|
app_state.status = AppStatus::SignedOut;
|
||||||
drop(app_state);
|
drop(app_state);
|
||||||
|
|
||||||
let mut db_state = borrow_db_mut_checked();
|
let mut db_state = borrow_db_mut_checked();
|
||||||
@ -100,8 +100,8 @@ pub fn sign_out(app: AppHandle) {
|
|||||||
{
|
{
|
||||||
let state = app.state::<Mutex<AppState>>();
|
let state = app.state::<Mutex<AppState>>();
|
||||||
let mut app_state_handle = state.lock();
|
let mut app_state_handle = state.lock();
|
||||||
*app_state_handle.status_mut() = AppStatus::SignedOut;
|
app_state_handle.status = AppStatus::SignedOut;
|
||||||
*app_state_handle.user_mut() = None;
|
app_state_handle.user = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit event for frontend
|
// Emit event for frontend
|
||||||
@ -112,9 +112,10 @@ pub fn sign_out(app: AppHandle) {
|
|||||||
pub async fn retry_connect(state: tauri::State<'_, Mutex<AppState>>) -> Result<(), ()> {
|
pub async fn retry_connect(state: tauri::State<'_, Mutex<AppState>>) -> Result<(), ()> {
|
||||||
let (app_status, user) = setup().await;
|
let (app_status, user) = setup().await;
|
||||||
|
|
||||||
let mut state_lock = state.lock();
|
let mut guard = state.lock();
|
||||||
*state_lock.status_mut() = app_status;
|
guard.status = app_status;
|
||||||
*state_lock.user_mut() = user;
|
guard.user = user;
|
||||||
|
drop(guard);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user