diff --git a/src/games/genshin/game.rs b/src/games/genshin/game.rs index 6f3dbff..91e6205 100644 --- a/src/games/genshin/game.rs +++ b/src/games/genshin/game.rs @@ -314,8 +314,6 @@ pub fn run() -> anyhow::Result<()> { // Log process output while it's running while child.try_wait()?.is_none() { - std::thread::sleep(std::time::Duration::from_secs(3)); - // Check if we've written less than a limit amount of data if written < *consts::GAME_LOG_FILE_LIMIT { // Redirect stdout to the game.log file @@ -331,11 +329,16 @@ pub fn run() -> anyhow::Result<()> { game_output.write_all(b"\n")?; written += line.len() + 14; + + // buf can contain more data than the limit + if written > *consts::GAME_LOG_FILE_LIMIT { + break; + } } } } - // Redirect stdout to the game.log file + // Redirect stderr to the game.log file if let Some(stderr) = &mut child.stderr { let mut buf = Vec::new(); @@ -348,19 +351,35 @@ pub fn run() -> anyhow::Result<()> { game_output.write_all(b"\n")?; written += line.len() + 14; + + // buf can contain more data than the limit + if written > *consts::GAME_LOG_FILE_LIMIT { + break; + } } } } + + // Drop stdio bufs if the limit was reached + if written >= *consts::GAME_LOG_FILE_LIMIT { + drop(child.stdout.take()); + drop(child.stderr.take()); + } } #[cfg(feature = "discord-rpc")] if let Some(rpc) = &rpc { rpc.update(RpcUpdates::Update)?; } + + std::thread::sleep(std::time::Duration::from_secs(3)); } + // Flush and close the game log file game_output.flush()?; + drop(game_output); + // Workaround for fast process closing (is it still a thing?) loop { std::thread::sleep(std::time::Duration::from_secs(3)); diff --git a/src/games/honkai/game.rs b/src/games/honkai/game.rs index 0b39405..cf129b2 100644 --- a/src/games/honkai/game.rs +++ b/src/games/honkai/game.rs @@ -267,8 +267,6 @@ pub fn run() -> anyhow::Result<()> { // Log process output while it's running while child.try_wait()?.is_none() { - std::thread::sleep(std::time::Duration::from_secs(3)); - // Check if we've written less than a limit amount of data if written < *consts::GAME_LOG_FILE_LIMIT { // Redirect stdout to the game.log file @@ -284,11 +282,16 @@ pub fn run() -> anyhow::Result<()> { game_output.write_all(b"\n")?; written += line.len() + 14; + + // buf can contain more data than the limit + if written > *consts::GAME_LOG_FILE_LIMIT { + break; + } } } } - // Redirect stdout to the game.log file + // Redirect stderr to the game.log file if let Some(stderr) = &mut child.stderr { let mut buf = Vec::new(); @@ -301,17 +304,35 @@ pub fn run() -> anyhow::Result<()> { game_output.write_all(b"\n")?; written += line.len() + 14; + + // buf can contain more data than the limit + if written > *consts::GAME_LOG_FILE_LIMIT { + break; + } } } } + + // Drop stdio bufs if the limit was reached + if written >= *consts::GAME_LOG_FILE_LIMIT { + drop(child.stdout.take()); + drop(child.stderr.take()); + } } #[cfg(feature = "discord-rpc")] if let Some(rpc) = &rpc { rpc.update(RpcUpdates::Update)?; } + + std::thread::sleep(std::time::Duration::from_secs(3)); } + // Flush and close the game log file + game_output.flush()?; + + drop(game_output); + // Workaround for fast process closing (is it still a thing?) loop { std::thread::sleep(std::time::Duration::from_secs(3)); diff --git a/src/games/pgr/game.rs b/src/games/pgr/game.rs index 8d844e8..8b7d3b1 100644 --- a/src/games/pgr/game.rs +++ b/src/games/pgr/game.rs @@ -257,8 +257,6 @@ pub fn run() -> anyhow::Result<()> { // Log process output while it's running while child.try_wait()?.is_none() { - std::thread::sleep(std::time::Duration::from_secs(3)); - // Check if we've written less than a limit amount of data if written < *consts::GAME_LOG_FILE_LIMIT { // Redirect stdout to the game.log file @@ -274,11 +272,16 @@ pub fn run() -> anyhow::Result<()> { game_output.write_all(b"\n")?; written += line.len() + 14; + + // buf can contain more data than the limit + if written > *consts::GAME_LOG_FILE_LIMIT { + break; + } } } } - // Redirect stdout to the game.log file + // Redirect stderr to the game.log file if let Some(stderr) = &mut child.stderr { let mut buf = Vec::new(); @@ -291,17 +294,35 @@ pub fn run() -> anyhow::Result<()> { game_output.write_all(b"\n")?; written += line.len() + 14; + + // buf can contain more data than the limit + if written > *consts::GAME_LOG_FILE_LIMIT { + break; + } } } } + + // Drop stdio bufs if the limit was reached + if written >= *consts::GAME_LOG_FILE_LIMIT { + drop(child.stdout.take()); + drop(child.stderr.take()); + } } #[cfg(feature = "discord-rpc")] if let Some(rpc) = &rpc { rpc.update(RpcUpdates::Update)?; } + + std::thread::sleep(std::time::Duration::from_secs(3)); } + // Flush and close the game log file + game_output.flush()?; + + drop(game_output); + // Workaround for fast process closing (is it still a thing?) loop { std::thread::sleep(std::time::Duration::from_secs(3)); diff --git a/src/games/star_rail/game.rs b/src/games/star_rail/game.rs index 14c518e..d28314a 100644 --- a/src/games/star_rail/game.rs +++ b/src/games/star_rail/game.rs @@ -268,8 +268,6 @@ pub fn run() -> anyhow::Result<()> { // Log process output while it's running while child.try_wait()?.is_none() { - std::thread::sleep(std::time::Duration::from_secs(3)); - // Check if we've written less than a limit amount of data if written < *consts::GAME_LOG_FILE_LIMIT { // Redirect stdout to the game.log file @@ -285,11 +283,16 @@ pub fn run() -> anyhow::Result<()> { game_output.write_all(b"\n")?; written += line.len() + 14; + + // buf can contain more data than the limit + if written > *consts::GAME_LOG_FILE_LIMIT { + break; + } } } } - // Redirect stdout to the game.log file + // Redirect stderr to the game.log file if let Some(stderr) = &mut child.stderr { let mut buf = Vec::new(); @@ -302,17 +305,35 @@ pub fn run() -> anyhow::Result<()> { game_output.write_all(b"\n")?; written += line.len() + 14; + + // buf can contain more data than the limit + if written > *consts::GAME_LOG_FILE_LIMIT { + break; + } } } } + + // Drop stdio bufs if the limit was reached + if written >= *consts::GAME_LOG_FILE_LIMIT { + drop(child.stdout.take()); + drop(child.stderr.take()); + } } #[cfg(feature = "discord-rpc")] if let Some(rpc) = &rpc { rpc.update(RpcUpdates::Update)?; } + + std::thread::sleep(std::time::Duration::from_secs(3)); } + // Flush and close the game log file + game_output.flush()?; + + drop(game_output); + // Workaround for fast process closing (is it still a thing?) loop { std::thread::sleep(std::time::Duration::from_secs(3)); diff --git a/src/games/wuwa/game.rs b/src/games/wuwa/game.rs index 33955df..420281d 100644 --- a/src/games/wuwa/game.rs +++ b/src/games/wuwa/game.rs @@ -248,8 +248,6 @@ pub fn run() -> anyhow::Result<()> { // Log process output while it's running while child.try_wait()?.is_none() { - std::thread::sleep(std::time::Duration::from_secs(3)); - // Check if we've written less than a limit amount of data if written < *consts::GAME_LOG_FILE_LIMIT { // Redirect stdout to the game.log file @@ -265,11 +263,16 @@ pub fn run() -> anyhow::Result<()> { game_output.write_all(b"\n")?; written += line.len() + 14; + + // buf can contain more data than the limit + if written > *consts::GAME_LOG_FILE_LIMIT { + break; + } } } } - // Redirect stdout to the game.log file + // Redirect stderr to the game.log file if let Some(stderr) = &mut child.stderr { let mut buf = Vec::new(); @@ -282,17 +285,35 @@ pub fn run() -> anyhow::Result<()> { game_output.write_all(b"\n")?; written += line.len() + 14; + + // buf can contain more data than the limit + if written > *consts::GAME_LOG_FILE_LIMIT { + break; + } } } } + + // Drop stdio bufs if the limit was reached + if written >= *consts::GAME_LOG_FILE_LIMIT { + drop(child.stdout.take()); + drop(child.stderr.take()); + } } #[cfg(feature = "discord-rpc")] if let Some(rpc) = &rpc { rpc.update(RpcUpdates::Update)?; } + + std::thread::sleep(std::time::Duration::from_secs(3)); } + // Flush and close the game log file + game_output.flush()?; + + drop(game_output); + // Workaround for fast process closing (is it still a thing?) loop { std::thread::sleep(std::time::Duration::from_secs(3)); diff --git a/src/games/zzz/game.rs b/src/games/zzz/game.rs index 8e6ccdf..56b5be5 100644 --- a/src/games/zzz/game.rs +++ b/src/games/zzz/game.rs @@ -266,8 +266,6 @@ pub fn run() -> anyhow::Result<()> { // Log process output while it's running while child.try_wait()?.is_none() { - std::thread::sleep(std::time::Duration::from_secs(3)); - // Check if we've written less than a limit amount of data if written < *consts::GAME_LOG_FILE_LIMIT { // Redirect stdout to the game.log file @@ -283,11 +281,16 @@ pub fn run() -> anyhow::Result<()> { game_output.write_all(b"\n")?; written += line.len() + 14; + + // buf can contain more data than the limit + if written > *consts::GAME_LOG_FILE_LIMIT { + break; + } } } } - // Redirect stdout to the game.log file + // Redirect stderr to the game.log file if let Some(stderr) = &mut child.stderr { let mut buf = Vec::new(); @@ -300,17 +303,35 @@ pub fn run() -> anyhow::Result<()> { game_output.write_all(b"\n")?; written += line.len() + 14; + + // buf can contain more data than the limit + if written > *consts::GAME_LOG_FILE_LIMIT { + break; + } } } } + + // Drop stdio bufs if the limit was reached + if written >= *consts::GAME_LOG_FILE_LIMIT { + drop(child.stdout.take()); + drop(child.stderr.take()); + } } #[cfg(feature = "discord-rpc")] if let Some(rpc) = &rpc { rpc.update(RpcUpdates::Update)?; } + + std::thread::sleep(std::time::Duration::from_secs(3)); } + // Flush and close the game log file + game_output.flush()?; + + drop(game_output); + // Workaround for fast process closing (is it still a thing?) loop { std::thread::sleep(std::time::Duration::from_secs(3));