Skip to content

Commit

Permalink
UI image selection (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipK authored Apr 23, 2022
1 parent 91782b7 commit e77f2b5
Show file tree
Hide file tree
Showing 49 changed files with 1,369 additions and 802 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target
auth_key.txt
cache.json
config.toml
config.toml
.thumbnails
Binary file added biglogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::io;
#[cfg(windows)] use winres::WindowsResource;
#[cfg(windows)]
use winres::WindowsResource;

fn main() -> io::Result<()> {
#[cfg(windows)] {
#[cfg(windows)]
{
WindowsResource::new()
.set_icon("resources/logo.ico")
.compile()?;
}
Ok(())
}
}
19 changes: 4 additions & 15 deletions src/amazon/amazon_game.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
53 changes: 31 additions & 22 deletions src/amazon/amazon_platform.rs
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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 });
}
}
Expand All @@ -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
}
Expand All @@ -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,
}
}
}
6 changes: 3 additions & 3 deletions src/amazon/amazon_settings.rs
Original file line number Diff line number Diff line change
@@ -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,
}
2 changes: 1 addition & 1 deletion src/amazon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ pub mod amazon_game;
pub use amazon_game::*;

pub mod amazon_settings;
pub use amazon_settings::*;
pub use amazon_settings::*;
4 changes: 3 additions & 1 deletion src/egs/epic_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ pub struct EpicPlatform {

impl EpicPlatform {
pub fn new(settings: &EpicGamesLauncherSettings) -> Self {
EpicPlatform { settings: settings.clone() }
EpicPlatform {
settings: settings.clone(),
}
}
}

Expand Down
29 changes: 20 additions & 9 deletions src/egs/get_manifests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,24 @@ pub(crate) fn get_egs_manifests(
.filter_map(|dir| dir.ok())
.filter_map(get_manifest_item)
.filter(is_game_installed)
.filter(is_game_launchable);
let mut manifests : Vec<ManifestItem> = manifests.collect();
manifests.sort_by_key(|m| format!("{}-{}-{}",m.install_location,m.launch_executable,m.is_managed));
manifests.dedup_by_key(|m| format!("{}-{}-{}",m.install_location,m.launch_executable,m.is_managed));
for mut manifest in &mut manifests{
if settings.safe_launch.contains(&manifest.display_name) || settings.safe_launch.contains(&manifest.get_key()){
.filter(is_game_launchable);
let mut manifests: Vec<ManifestItem> = manifests.collect();
manifests.sort_by_key(|m| {
format!(
"{}-{}-{}",
m.install_location, m.launch_executable, m.is_managed
)
});
manifests.dedup_by_key(|m| {
format!(
"{}-{}-{}",
m.install_location, m.launch_executable, m.is_managed
)
});
for mut manifest in &mut manifests {
if settings.safe_launch.contains(&manifest.display_name)
|| settings.safe_launch.contains(&manifest.get_key())
{
manifest.safe_launch = true;
}
}
Expand All @@ -58,7 +70,6 @@ pub(crate) fn get_egs_manifests(
}
}


fn get_manifest_dir_path(
settings: &EpicGamesLauncherSettings,
) -> Result<String, EpicGamesManifestsError> {
Expand Down Expand Up @@ -113,7 +124,7 @@ fn location_from_registry() -> Option<PathBuf> {
if let Ok(path_string) = path_string {
let path = Path::new(&path_string).join("Manifests");
if path.exists() {
return Some(path.to_path_buf());
return Some(path);
}
}
}
Expand All @@ -132,7 +143,7 @@ fn guess_default_location() -> PathBuf {
.join("EpicGamesLauncher")
.join("Data")
.join("Manifests");
path.to_path_buf()
path
}

fn is_game_installed(manifest: &ManifestItem) -> bool {
Expand Down
8 changes: 4 additions & 4 deletions src/egs/manifest_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ impl ManifestItem {
)
}

pub fn get_key(&self) -> String{
pub fn get_key(&self) -> String {
format!(
"{}-{}-{}",
self.catalog_namespace, self.catalog_item_id, self.app_name
)
}

fn needs_launcher(&self) -> bool {
if self.safe_launch{
if self.safe_launch {
return true;
}
match (&self.is_managed, &self.expected_dlc) {
Expand Down Expand Up @@ -157,7 +157,7 @@ mod tests {
let mut manifest: ManifestItem = serde_json::from_str(json).unwrap();
manifest.is_managed = false;
manifest.expected_dlc = None;
let shortcut: ShortcutOwned = manifest.clone().into();
let shortcut: ShortcutOwned = manifest.into();

#[cfg(target_os = "windows")]
assert_eq!(shortcut.exe, "C:\\Games\\MarvelGOTG\\retail/gotg.exe");
Expand All @@ -172,7 +172,7 @@ mod tests {
let json = include_str!("example_item.json");
let mut manifest: ManifestItem = serde_json::from_str(json).unwrap();
manifest.is_managed = false;
let shortcut: ShortcutOwned = manifest.clone().into();
let shortcut: ShortcutOwned = manifest.into();

let expected ="com.epicgames.launcher://apps/2a09fb19b47f46dfb11ebd382f132a8f%3A88f4bb0bb06e4962a2042d5e20fb6ace%3A63a665088eb1480298f1e57943b225d8?action=launch&silent=true";
let actual = shortcut.exe;
Expand Down
2 changes: 1 addition & 1 deletion src/egs/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pub struct EpicGamesLauncherSettings {
#[cfg(target_family = "unix")]
pub create_symlinks: bool,

pub safe_launch : Vec<String>
pub safe_launch: Vec<String>,
}
9 changes: 4 additions & 5 deletions src/gog/gog_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub(crate) struct PlayTask {
#[serde(alias = "workingDir")]
pub working_dir: Option<String>,
pub arguments: Option<String>,

}

#[derive(Clone)]
Expand All @@ -48,13 +47,13 @@ impl From<GogShortcut> for ShortcutOwned {
exe.to_str().unwrap_or("").to_string()
};
let mut exe_string = exe.to_string_lossy().to_string();
if exe_string.contains(" ") && !exe_string.starts_with("\""){
exe_string = format!("\"{}\"",exe_string);
if exe_string.contains(' ') && !exe_string.starts_with('\"') {
exe_string = format!("\"{}\"", exe_string);
}

let mut working_dir_string = gogs.working_dir;
if working_dir_string.contains(" ") && !working_dir_string.starts_with("\""){
working_dir_string = format!("\"{}\"",working_dir_string);
if working_dir_string.contains(' ') && !working_dir_string.starts_with('\"') {
working_dir_string = format!("\"{}\"", working_dir_string);
}

let shortcut = Shortcut::new(
Expand Down
Loading

0 comments on commit e77f2b5

Please sign in to comment.