wip
This commit is contained in:
@@ -233,10 +233,6 @@ async fn run_game_windows(
|
||||
id: String,
|
||||
state: tauri::State<'_, LanSpreadState>,
|
||||
) -> tauri::Result<()> {
|
||||
use std::fs::File;
|
||||
|
||||
const FIRST_START_DONE_FILE: &str = ".softlan_first_start_done";
|
||||
|
||||
let games_folder_lock = state.inner().games_folder.clone();
|
||||
let games_folder = {
|
||||
let guard = games_folder_lock.read().await;
|
||||
@@ -254,8 +250,8 @@ async fn run_game_windows(
|
||||
let game_setup_bin = game_path.join("game_setup.cmd");
|
||||
let game_start_bin = game_path.join("game_start.cmd");
|
||||
|
||||
let first_start_done_file = game_path.join(FIRST_START_DONE_FILE);
|
||||
if !first_start_done_file.exists() && game_setup_bin.exists() {
|
||||
let local_ready = local_install_is_ready(&game_path);
|
||||
if !local_ready && game_setup_bin.exists() {
|
||||
let result = run_as_admin(
|
||||
"cmd.exe",
|
||||
&format!(
|
||||
@@ -270,10 +266,6 @@ async fn run_game_windows(
|
||||
log::error!("failed to run game_setup.cmd");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Err(e) = File::create(&first_start_done_file) {
|
||||
log::error!("failed to create {first_start_done_file:?}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
if game_start_bin.exists() {
|
||||
@@ -311,31 +303,71 @@ async fn run_game(id: String, state: tauri::State<'_, LanSpreadState>) -> tauri:
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_game_install_state_from_path(game_db: &mut GameDB, path: &Path, installed: bool) {
|
||||
if let Some(file_name) = path.file_name()
|
||||
&& let Some(file_name) = file_name.to_str()
|
||||
&& let Some(game) = game_db.get_mut_game_by_id(file_name)
|
||||
{
|
||||
if installed {
|
||||
log::debug!("Set {game} to installed");
|
||||
} else {
|
||||
log::debug!("Set {game} to uninstalled");
|
||||
}
|
||||
game.installed = installed;
|
||||
fn eti_package_exists(game_path: &Path, game_id: &str) -> bool {
|
||||
game_path.is_dir() && game_path.join(format!("{game_id}.eti")).is_file()
|
||||
}
|
||||
|
||||
// Read local version.ini if installed
|
||||
if installed {
|
||||
if let Ok(version) = lanspread_db::db::read_version_from_ini(path) {
|
||||
fn local_install_is_ready(game_path: &Path) -> bool {
|
||||
let local_dir = game_path.join("local");
|
||||
if !local_dir.is_dir() {
|
||||
return false;
|
||||
}
|
||||
|
||||
match std::fs::read_dir(&local_dir) {
|
||||
Ok(mut entries) => match entries.next() {
|
||||
Some(Ok(_)) => true,
|
||||
Some(Err(e)) => {
|
||||
log::warn!(
|
||||
"Failed to inspect entry in local dir {}: {e}",
|
||||
local_dir.display()
|
||||
);
|
||||
false
|
||||
}
|
||||
None => false,
|
||||
},
|
||||
Err(e) => {
|
||||
log::warn!(
|
||||
"Failed to enumerate local dir for game {}: {e}",
|
||||
game_path.display()
|
||||
);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_game_installation_state(game: &mut Game, games_root: &Path) {
|
||||
let game_path = games_root.join(&game.id);
|
||||
if !game_path.is_dir() {
|
||||
return;
|
||||
}
|
||||
|
||||
let downloaded = eti_package_exists(&game_path, &game.id);
|
||||
game.downloaded = downloaded;
|
||||
|
||||
let installed = downloaded && local_install_is_ready(&game_path);
|
||||
game.installed = installed;
|
||||
|
||||
if installed {
|
||||
log::debug!("Set {game} to installed");
|
||||
match lanspread_db::db::read_version_from_ini(&game_path) {
|
||||
Ok(version) => {
|
||||
game.local_version = version;
|
||||
if let Some(ref version) = game.local_version {
|
||||
log::debug!("Read local version for game {}: {}", game.id, version);
|
||||
}
|
||||
} else {
|
||||
log::warn!("Failed to read local version.ini for game: {}", game.id);
|
||||
}
|
||||
} else {
|
||||
// Clear local version when uninstalled
|
||||
game.local_version = None;
|
||||
Err(e) => {
|
||||
log::warn!("Failed to read local version.ini for game {}: {e}", game.id);
|
||||
game.local_version = None;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
game.local_version = None;
|
||||
if downloaded {
|
||||
log::debug!(
|
||||
"Game {} is downloaded but awaiting local install contents",
|
||||
game.id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,41 +387,6 @@ async fn refresh_games_list(app_handle: &AppHandle) {
|
||||
|
||||
let path = PathBuf::from(&games_folder);
|
||||
|
||||
let mut installed_paths: Vec<PathBuf> = Vec::new();
|
||||
if path.exists() {
|
||||
match std::fs::read_dir(&path) {
|
||||
Ok(entries) => {
|
||||
for entry_result in entries {
|
||||
match entry_result {
|
||||
Ok(entry) => match entry.file_type() {
|
||||
Ok(file_type) if file_type.is_dir() => {
|
||||
let dir_path = entry.path();
|
||||
if dir_path.join("version.ini").exists() {
|
||||
installed_paths.push(dir_path);
|
||||
}
|
||||
}
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
log::warn!(
|
||||
"Failed to read file type for entry {}: {e}",
|
||||
entry.path().display()
|
||||
);
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
log::warn!("Failed to read directory entry in {}: {e}", path.display());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to read game dir {}: {e}", path.display());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log::error!("game dir {} does not exist", path.display());
|
||||
}
|
||||
|
||||
let mut game_db = games_db_lock.write().await;
|
||||
|
||||
if game_db.games.is_empty() {
|
||||
@@ -399,8 +396,12 @@ async fn refresh_games_list(app_handle: &AppHandle) {
|
||||
|
||||
game_db.set_all_uninstalled();
|
||||
|
||||
for dir_path in &installed_paths {
|
||||
set_game_install_state_from_path(&mut game_db, dir_path, true);
|
||||
if path.exists() {
|
||||
for game in game_db.games.values_mut() {
|
||||
update_game_installation_state(game, &path);
|
||||
}
|
||||
} else {
|
||||
log::error!("game dir {} does not exist", path.display());
|
||||
}
|
||||
|
||||
let games_to_emit = game_db
|
||||
|
||||
Reference in New Issue
Block a user