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 -5
View File
@@ -24,7 +24,6 @@ pub(crate) struct PlayTask {
#[serde(alias = "workingDir")]
pub working_dir: Option<String>,
pub arguments: Option<String>,
}
#[derive(Clone)]
@@ -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(
+21 -18
View File
@@ -12,12 +12,13 @@ pub struct GogPlatform {
pub settings: GogSettings,
}
pub fn get_shortcuts_from_config(wine_c_drive : Option<String>, config_path: PathBuf) -> Result<Vec<GogShortcut>, GogErrors> {
pub fn get_shortcuts_from_config(
_wine_c_drive: Option<String>,
config_path: PathBuf,
) -> Result<Vec<GogShortcut>, GogErrors> {
let install_locations = get_install_locations(config_path)?;
#[cfg(target_family = "unix")]
let install_locations = if let Some(wine_c_drive) = &wine_c_drive {
let install_locations = if let Some(wine_c_drive) = &_wine_c_drive {
fix_paths(wine_c_drive, install_locations)
} else {
install_locations
@@ -44,14 +45,13 @@ pub fn get_shortcuts_from_config(wine_c_drive : Option<String>, config_path: Pat
pub fn get_shortcuts_from_game_folders(game_folders: Vec<PathBuf>) -> Vec<GogShortcut> {
let games = get_games_from_game_folders(game_folders);
let shortcuts = get_shortcuts_from_games(games);
shortcuts
get_shortcuts_from_games(games)
}
fn get_shortcuts_from_games(games: Vec<(GogGame, PathBuf)>) -> Vec<GogShortcut> {
let mut shortcuts = vec![];
for (game, game_folder) in games {
if let Some(folder_path) = game_folder.to_str() {
if let Some(tasks) = &game.play_tasks {
if let Some(primary_task) = tasks.iter().find(|t| {
@@ -68,19 +68,23 @@ fn get_shortcuts_from_games(games: Vec<(GogGame, PathBuf)>) -> Vec<GogShortcut>
Some(working_dir) => game_folder
.join(working_dir)
.to_str()
.unwrap_or_else(|| folder_path.as_str())
.unwrap_or(folder_path.as_str())
.to_string(),
None => folder_path.to_string(),
};
#[cfg(target_family = "unix")]
let working_dir = working_dir.replace("\\", "/");
let working_dir = working_dir.replace('\\', "/");
let full_path_string = full_path.to_string();
#[cfg(target_family = "unix")]
let full_path_string = full_path_string.replace("\\", "/");
let arguments = primary_task.arguments.as_ref().unwrap_or(&"".to_string()).clone();
let full_path_string = full_path_string.replace('\\', "/");
let arguments = primary_task
.arguments
.as_ref()
.unwrap_or(&"".to_string())
.clone();
let shortcut = GogShortcut {
name: game.name,
game_folder: folder_path,
@@ -133,7 +137,6 @@ fn get_games_from_game_folders(game_folders: Vec<PathBuf>) -> Vec<(GogGame, Path
games
}
impl Platform<GogShortcut, GogErrors> for GogPlatform {
fn enabled(&self) -> bool {
self.settings.enabled
@@ -162,7 +165,7 @@ impl Platform<GogShortcut, GogErrors> for GogPlatform {
if !config_path.exists() {
return Err(GogErrors::ConfigFileNotFound { path: config_path });
}
get_shortcuts_from_config(self.settings.wine_c_drive.clone(),config_path)
get_shortcuts_from_config(self.settings.wine_c_drive.clone(), config_path)
}
fn settings_valid(&self) -> crate::platform::SettingsValidity {
@@ -177,10 +180,10 @@ impl Platform<GogShortcut, GogErrors> for GogPlatform {
}
fn needs_proton(&self, _input: &GogShortcut) -> bool {
#[cfg(target_family = "unix")]
return true;
#[cfg(target_os = "windows")]
return false;
#[cfg(target_family = "unix")]
return true;
#[cfg(target_os = "windows")]
return false;
}
}
@@ -191,7 +194,7 @@ fn fix_paths(wine_c_drive: &str, paths: Vec<String>) -> Vec<String> {
.flat_map(|path| {
if let Some(stripped) = path.strip_prefix("C:\\") {
let path_buf = Path::new(wine_c_drive).join(stripped);
path_buf.to_str().map(|s| s.to_string().replace("\\", "/"))
path_buf.to_str().map(|s| s.to_string().replace('\\', "/"))
} else {
None
}
+1 -1
View File
@@ -3,6 +3,6 @@ mod gog_game;
mod gog_platform;
mod gog_settings;
pub use gog_game::GogShortcut;
pub use gog_platform::*;
pub use gog_settings::*;
pub use gog_game::GogShortcut;