UI image selection (#97)

This commit is contained in:
Philip Kristoffersen
2022-04-23 20:33:16 +02:00
committed by GitHub
parent 91782b74eb
commit e77f2b5f31
49 changed files with 1368 additions and 801 deletions
+4 -15
View File
@@ -1,25 +1,14 @@
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
#[derive(Debug, Clone)]
pub struct AmazonGame{
pub title : String,
pub id : String
pub struct AmazonGame {
pub title: String,
pub id: String,
}
impl From<AmazonGame> for ShortcutOwned {
fn from(game: AmazonGame) -> Self {
let launch = format!("amazon-games://play/{}", game.id);
Shortcut::new(
"0",
game.title.as_str(),
launch.as_str(),
"",
"",
"",
"",
)
.to_owned()
Shortcut::new("0", game.title.as_str(), launch.as_str(), "", "", "", "").to_owned()
}
}
+31 -22
View File
@@ -1,23 +1,25 @@
use std::{error::Error, path::{PathBuf, Path}};
use std::{
error::Error,
path::{Path, PathBuf},
};
use sqlite::State;
use crate::platform::Platform;
use super::{AmazonSettings, AmazonGame};
use super::{AmazonGame, AmazonSettings};
pub struct AmazonPlatform{
pub settings:AmazonSettings
pub struct AmazonPlatform {
pub settings: AmazonSettings,
}
impl Platform<AmazonGame, Box<dyn Error>> for AmazonPlatform{
impl Platform<AmazonGame, Box<dyn Error>> for AmazonPlatform {
#[cfg(windows)]
fn enabled(&self) -> bool {
fn enabled(&self) -> bool {
self.settings.enabled
}
#[cfg(target_family="unix")]
#[cfg(target_family = "unix")]
fn enabled(&self) -> bool {
false
}
@@ -27,14 +29,16 @@ impl Platform<AmazonGame, Box<dyn Error>> for AmazonPlatform{
}
fn get_shortcuts(&self) -> Result<Vec<AmazonGame>, Box<dyn Error>> {
let sqllite_path = get_sqlite_path().expect("This should enver get called if settings are invalid");
let sqllite_path =
get_sqlite_path().expect("This should enver get called if settings are invalid");
let mut result = vec![];
let connection = sqlite::open(sqllite_path)?;
let mut statement = connection.prepare("SELECT Id, ProductTitle FROM DbSet WHERE Installed = 1")?;
let mut statement =
connection.prepare("SELECT Id, ProductTitle FROM DbSet WHERE Installed = 1")?;
while let State::Row = statement.next().unwrap() {
let id = statement.read::<String>(0);
let title = statement.read::<String>(1);
if let (Ok(id),Ok(title)) = (id,title){
if let (Ok(id), Ok(title)) = (id, title) {
result.push(AmazonGame { title, id });
}
}
@@ -43,15 +47,16 @@ impl Platform<AmazonGame, Box<dyn Error>> for AmazonPlatform{
fn settings_valid(&self) -> crate::platform::SettingsValidity {
let path = get_sqlite_path();
if path.is_some(){
if path.is_some() {
crate::platform::SettingsValidity::Valid
}else{
crate::platform::SettingsValidity::Invalid { reason: format!("Could not find Amazon Games installation")}
} else {
crate::platform::SettingsValidity::Invalid {
reason: "Could not find Amazon Games installation".to_string(),
}
}
}
#[cfg(target_family ="unix")]
#[cfg(target_family = "unix")]
fn create_symlinks(&self) -> bool {
false
}
@@ -61,17 +66,21 @@ impl Platform<AmazonGame, Box<dyn Error>> for AmazonPlatform{
}
}
fn get_sqlite_path() -> Option<PathBuf> {
match std::env::var("LOCALAPPDATA") {
Ok(localdata) => {
let path = Path::new(&localdata).join("Amazon Games").join("Data").join("Games").join("Sql").join("GameInstallInfo.sqlite");
Ok(localdata) => {
let path = Path::new(&localdata)
.join("Amazon Games")
.join("Data")
.join("Games")
.join("Sql")
.join("GameInstallInfo.sqlite");
if path.exists() {
Some(path)
}else{
} else {
None
}
}
Err(_e) => None,
}
}
}
+3 -3
View File
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct AmazonSettings{
pub enabled:bool
}
pub struct AmazonSettings {
pub enabled: bool,
}
+1 -1
View File
@@ -5,4 +5,4 @@ pub mod amazon_game;
pub use amazon_game::*;
pub mod amazon_settings;
pub use amazon_settings::*;
pub use amazon_settings::*;