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