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
|
||||
|
||||
@@ -29,6 +29,7 @@ interface Game {
|
||||
description: string;
|
||||
size: number;
|
||||
thumbnail: Uint8Array | number[];
|
||||
downloaded: boolean;
|
||||
installed: boolean;
|
||||
install_status: InstallStatus;
|
||||
eti_game_version?: string;
|
||||
@@ -49,7 +50,7 @@ const App = () => {
|
||||
switch (filter) {
|
||||
case 'available':
|
||||
// Show union of installed games and games with peers
|
||||
return games.filter(game => game.installed || game.peer_count > 0);
|
||||
return games.filter(game => game.installed || game.downloaded || game.peer_count > 0);
|
||||
case 'installed':
|
||||
return games.filter(game => game.installed);
|
||||
case 'all':
|
||||
@@ -381,6 +382,36 @@ const App = () => {
|
||||
return false;
|
||||
};
|
||||
|
||||
const getInProgressLabel = (game: Game): string | undefined => {
|
||||
switch (game.install_status) {
|
||||
case InstallStatus.CheckingPeers:
|
||||
return 'Checking peers...';
|
||||
case InstallStatus.Downloading:
|
||||
return 'Downloading...';
|
||||
case InstallStatus.Unpacking:
|
||||
return 'Unpacking...';
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const getActionLabel = (game: Game): string => {
|
||||
const inProgress = getInProgressLabel(game);
|
||||
if (inProgress) {
|
||||
return inProgress;
|
||||
}
|
||||
|
||||
if (!game.installed) {
|
||||
return game.downloaded ? 'Install' : 'Download';
|
||||
}
|
||||
|
||||
if (needsUpdate(game)) {
|
||||
return 'Update';
|
||||
}
|
||||
|
||||
return 'Play';
|
||||
};
|
||||
|
||||
const dialogGameDir = async () => {
|
||||
const file = await open({
|
||||
multiple: false,
|
||||
@@ -484,21 +515,11 @@ const App = () => {
|
||||
runGame(item.id);
|
||||
}
|
||||
}}>
|
||||
{!item.installed
|
||||
? item.install_status === InstallStatus.CheckingPeers ? 'Checking peers...'
|
||||
: item.install_status === InstallStatus.Downloading ? 'Downloading...'
|
||||
: item.install_status === InstallStatus.Unpacking ? 'Unpacking...'
|
||||
: 'Install'
|
||||
: needsUpdate(item)
|
||||
? item.install_status === InstallStatus.CheckingPeers ? 'Checking peers...'
|
||||
: item.install_status === InstallStatus.Downloading ? 'Downloading...'
|
||||
: item.install_status === InstallStatus.Unpacking ? 'Unpacking...'
|
||||
: 'Update'
|
||||
: 'Play'}
|
||||
{getActionLabel(item)}
|
||||
</div>
|
||||
<div className={`item-info${item.status_level ? ` ${item.status_level}` : ''}`}>
|
||||
<div className="status-left">
|
||||
{item.status_message && item.peer_count === 0 && !item.installed ? item.status_message : ''}
|
||||
{item.status_message && item.peer_count === 0 && !item.installed && !item.downloaded ? item.status_message : ''}
|
||||
</div>
|
||||
<div className="status-right">
|
||||
{item.peer_count > 0 && (
|
||||
|
||||
Reference in New Issue
Block a user