wip
This commit is contained in:
@@ -6,6 +6,7 @@ mod peer;
|
||||
use std::{
|
||||
cmp::Reverse,
|
||||
collections::{HashMap, HashSet, VecDeque},
|
||||
io::ErrorKind,
|
||||
net::{IpAddr, SocketAddr},
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
@@ -1162,6 +1163,29 @@ async fn retry_failed_chunks(
|
||||
/// Load local game database combining locally installed games
|
||||
async fn load_local_game_db(game_dir: &str) -> eyre::Result<GameDB> {
|
||||
let game_path = PathBuf::from(game_dir);
|
||||
|
||||
let metadata = match tokio::fs::metadata(&game_path).await {
|
||||
Ok(metadata) => metadata,
|
||||
Err(err) => {
|
||||
if err.kind() == ErrorKind::NotFound {
|
||||
log::warn!(
|
||||
"Local game directory {} missing; reporting empty game database",
|
||||
game_path.display()
|
||||
);
|
||||
return Ok(GameDB::empty());
|
||||
}
|
||||
return Err(err.into());
|
||||
}
|
||||
};
|
||||
|
||||
if !metadata.is_dir() {
|
||||
log::warn!(
|
||||
"Configured game directory {} is not a directory; reporting empty game database",
|
||||
game_path.display()
|
||||
);
|
||||
return Ok(GameDB::empty());
|
||||
}
|
||||
|
||||
let mut games = Vec::new();
|
||||
|
||||
// Scan game directory and create entries for installed games
|
||||
|
||||
@@ -417,12 +417,12 @@ async fn refresh_games_list(app_handle: &AppHandle) {
|
||||
|
||||
let games_folder = games_folder_lock.read().await.clone();
|
||||
|
||||
if games_folder.is_empty() {
|
||||
log::debug!("Games folder not set; skipping games list refresh");
|
||||
return;
|
||||
}
|
||||
|
||||
let path = PathBuf::from(&games_folder);
|
||||
let path = if games_folder.is_empty() {
|
||||
log::debug!("Games folder not set; emitting current game list without rescan");
|
||||
None
|
||||
} else {
|
||||
Some(PathBuf::from(&games_folder))
|
||||
};
|
||||
|
||||
let mut game_db = games_db_lock.write().await;
|
||||
|
||||
@@ -431,14 +431,18 @@ async fn refresh_games_list(app_handle: &AppHandle) {
|
||||
return;
|
||||
}
|
||||
|
||||
game_db.set_all_uninstalled();
|
||||
|
||||
if let Some(ref path) = path {
|
||||
if path.exists() {
|
||||
game_db.set_all_uninstalled();
|
||||
for game in game_db.games.values_mut() {
|
||||
update_game_installation_state(game, &path);
|
||||
update_game_installation_state(game, path);
|
||||
}
|
||||
} else {
|
||||
log::error!("game dir {} does not exist", path.display());
|
||||
log::error!(
|
||||
"game dir {} does not exist; keeping last known installation state",
|
||||
path.display()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let games_to_emit = game_db
|
||||
|
||||
Reference in New Issue
Block a user