wip
This commit is contained in:
@@ -1111,7 +1111,16 @@ async fn load_local_game_db(game_dir: &str) -> eyre::Result<GameDB> {
|
||||
if path.is_dir()
|
||||
&& let Some(game_id) = path.file_name().and_then(|n| n.to_str())
|
||||
{
|
||||
// Check if this game has a version.ini file
|
||||
let eti_path = path.join(format!("{game_id}.eti"));
|
||||
let downloaded = tokio::fs::metadata(&eti_path).await.is_ok();
|
||||
if !downloaded {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !local_dir_has_content(&path).await {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Ok(version) = lanspread_db::db::read_version_from_ini(&path) {
|
||||
let size = calculate_directory_size(&path).await?;
|
||||
let game = Game {
|
||||
@@ -1125,6 +1134,7 @@ async fn load_local_game_db(game_dir: &str) -> eyre::Result<GameDB> {
|
||||
genre: String::new(),
|
||||
size,
|
||||
thumbnail: None,
|
||||
downloaded,
|
||||
installed: true,
|
||||
eti_game_version: version.clone(),
|
||||
local_version: version,
|
||||
@@ -1138,6 +1148,30 @@ async fn load_local_game_db(game_dir: &str) -> eyre::Result<GameDB> {
|
||||
Ok(GameDB::from(games))
|
||||
}
|
||||
|
||||
async fn local_dir_has_content(path: &Path) -> bool {
|
||||
let local_dir = path.join("local");
|
||||
if tokio::fs::metadata(&local_dir).await.is_err() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut entries = match tokio::fs::read_dir(&local_dir).await {
|
||||
Ok(entries) => entries,
|
||||
Err(e) => {
|
||||
log::warn!("Failed to read local dir {}: {e}", local_dir.display());
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
match entries.next_entry().await {
|
||||
Ok(Some(_)) => true,
|
||||
Ok(None) => false,
|
||||
Err(e) => {
|
||||
log::warn!("Failed to iterate local dir {}: {e}", local_dir.display());
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn calculate_directory_size(dir: &Path) -> eyre::Result<u64> {
|
||||
let mut total_size = 0u64;
|
||||
let mut entries = tokio::fs::read_dir(dir).await?;
|
||||
|
||||
Reference in New Issue
Block a user