diff --git a/Cargo.toml b/Cargo.toml index d7bf1c9..b026c0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ anime-game-core = { path = "anime-game-core", features = ["genshin", "all", "sta anyhow = "1.0" dirs = "4.0.0" +tracing = "0.1" serde = { version = "1.0", features = ["derive"], optional = true } serde_json = { version = "1.0", optional = true } diff --git a/anime-game-core b/anime-game-core index 27f8d7c..bd10a75 160000 --- a/anime-game-core +++ b/anime-game-core @@ -1 +1 @@ -Subproject commit 27f8d7cd102b116570634bf297ad9b08518fcaf7 +Subproject commit bd10a7505f5709183b9858c581fe6bc210fa860d diff --git a/src/components/dxvk.rs b/src/components/dxvk.rs index 792b815..40e60ca 100644 --- a/src/components/dxvk.rs +++ b/src/components/dxvk.rs @@ -37,12 +37,14 @@ impl Version { } /// Check is current dxvk downloaded in specified folder - pub fn is_downloaded_in>(&self, folder: T) -> bool { + #[tracing::instrument(level = "trace")] + pub fn is_downloaded_in + std::fmt::Debug>(&self, folder: T) -> bool { folder.into().join(&self.name).exists() } /// Install current dxvk - pub fn install>(&self, dxvks_folder: T, wine: &Wine, params: InstallParams) -> std::io::Result<()> { + #[tracing::instrument(level = "debug")] + pub fn install + std::fmt::Debug>(&self, dxvks_folder: T, wine: &Wine, params: InstallParams) -> std::io::Result<()> { Dxvk::install( wine, dxvks_folder.into().join(&self.name), @@ -51,7 +53,8 @@ impl Version { } /// Uninstall current dxvk - pub fn uninstall>(&self, wine: &Wine, params: InstallParams) -> std::io::Result<()> { + #[tracing::instrument(level = "debug")] + pub fn uninstall(&self, wine: &Wine, params: InstallParams) -> std::io::Result<()> { Dxvk::uninstall( wine, params @@ -65,7 +68,8 @@ pub fn get_groups() -> Vec { } /// List downloaded dxvk versions in some specific folder -pub fn get_downloaded>(folder: T) -> std::io::Result> { +#[tracing::instrument(level = "trace")] +pub fn get_downloaded + std::fmt::Debug>(folder: T) -> std::io::Result> { let mut downloaded = Vec::new(); let list = get_groups() diff --git a/src/components/wine.rs b/src/components/wine.rs index 75302f2..c0d9ac6 100644 --- a/src/components/wine.rs +++ b/src/components/wine.rs @@ -46,7 +46,8 @@ impl Version { } /// Check is current wine downloaded in specified folder - pub fn is_downloaded_in>(&self, folder: T) -> bool { + #[tracing::instrument(level = "trace")] + pub fn is_downloaded_in + std::fmt::Debug>(&self, folder: T) -> bool { folder.into().join(&self.name).exists() } @@ -82,7 +83,8 @@ pub fn get_groups() -> Vec { } /// List downloaded wine versions in some specific folder -pub fn get_downloaded>(folder: T) -> std::io::Result> { +#[tracing::instrument(level = "trace")] +pub fn get_downloaded + std::fmt::Debug>(folder: T) -> std::io::Result> { let mut downloaded = Vec::new(); let list = get_groups() diff --git a/src/config/mod.rs b/src/config/mod.rs index 5390c48..91a970d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -30,6 +30,7 @@ static mut CONFIG: Option = None; /// This method will load config from file once and store it into the memory. /// If you know that the config file was updated - you should run `get_raw` method /// that always loads config directly from the file. This will also update in-memory config +#[tracing::instrument(level = "trace")] pub fn get() -> anyhow::Result { unsafe { match &CONFIG { @@ -42,6 +43,7 @@ pub fn get() -> anyhow::Result { /// Get config data /// /// This method will always load data directly from the file and update in-memory config +#[tracing::instrument(level = "debug")] pub fn get_raw() -> anyhow::Result { match config_file() { Some(path) => { @@ -80,6 +82,7 @@ pub fn get_raw() -> anyhow::Result { /// Update in-memory config data /// /// Use `update_raw` if you want to update config file itself +#[tracing::instrument(level = "trace")] pub fn update(config: Config) { unsafe { CONFIG = Some(config); @@ -89,6 +92,7 @@ pub fn update(config: Config) { /// Update config file /// /// This method will also update in-memory config data +#[tracing::instrument(level = "debug")] pub fn update_raw(config: Config) -> anyhow::Result<()> { update(config.clone()); @@ -110,6 +114,7 @@ pub fn update_raw(config: Config) -> anyhow::Result<()> { } /// Update config file from the in-memory saved config +#[tracing::instrument(level = "debug")] pub fn flush() -> anyhow::Result<()> { unsafe { match &CONFIG { @@ -157,6 +162,7 @@ use crate::components::dxvk::{self, Version as DxvkVersion}; #[cfg(feature = "components")] impl Config { + #[tracing::instrument(level = "debug")] pub fn try_get_selected_wine_info(&self) -> Option { match &self.game.wine.selected { Some(selected) => { @@ -174,6 +180,7 @@ impl Config { /// Returns `Some("wine64")` if: /// 1) `game.wine.selected = None` /// 2) wine64 installed and available in system + #[tracing::instrument(level = "debug")] pub fn try_get_wine_executable(&self) -> Option { match self.try_get_selected_wine_info() { Some(selected) => Some(self.game.wine.builds.join(selected.name).join(selected.files.wine64)), @@ -193,6 +200,7 @@ impl Config { /// 1) `Ok(Some(..))` if version was found /// 2) `Ok(None)` if version wasn't found, so too old or dxvk is not applied /// 3) `Err(..)` if failed to get applied dxvk version, likely because wrong prefix path specified + #[tracing::instrument(level = "debug")] pub fn try_get_selected_dxvk_info(&self) -> std::io::Result> { Ok(match wincompatlib::dxvk::Dxvk::get_version(&self.game.wine.prefix)? { Some(version) => { diff --git a/src/consts.rs b/src/consts.rs index 08d416e..fef01bf 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -10,6 +10,7 @@ pub const PATCH_FETCHING_TIMEOUT: Option = Some(Duration::from_secs(5) /// Get default launcher dir path /// /// `$HOME/.local/share/anime-game-launcher` +#[tracing::instrument(level = "trace")] pub fn launcher_dir() -> Option { dirs::data_dir().map(|dir| dir.join("anime-game-launcher")) } @@ -17,6 +18,7 @@ pub fn launcher_dir() -> Option { /// Get default config file path /// /// `$HOME/.local/share/anime-game-launcher/config.json` +#[tracing::instrument(level = "trace")] pub fn config_file() -> Option { launcher_dir().map(|dir| dir.join("config.json")) } diff --git a/src/fps_unlocker/mod.rs b/src/fps_unlocker/mod.rs index c738ced..d57ecee 100644 --- a/src/fps_unlocker/mod.rs +++ b/src/fps_unlocker/mod.rs @@ -23,7 +23,8 @@ impl FpsUnlocker { /// - `Err(..)` if failed to read `unlocker.exe` file /// - `Ok(None)` if version is not latest /// - `Ok(..)` if version is latest - pub fn from_dir>(dir: T) -> anyhow::Result> { + #[tracing::instrument(level = "trace")] + pub fn from_dir + std::fmt::Debug>(dir: T) -> anyhow::Result> { let dir = dir.into(); let hash = format!("{:x}", md5::compute(std::fs::read(dir.join("unlocker.exe"))?)); @@ -36,7 +37,8 @@ impl FpsUnlocker { } /// Download FPS unlocker to specified directory - pub fn download>(dir: T) -> anyhow::Result { + #[tracing::instrument(level = "debug")] + pub fn download + std::fmt::Debug>(dir: T) -> anyhow::Result { let mut downloader = Downloader::new(LATEST_INFO.1)?; let dir = dir.into(); @@ -71,6 +73,7 @@ impl FpsUnlocker { } /// Generate and save FPS unlocker config file to the game's directory + #[tracing::instrument(level = "debug")] pub fn update_config(&self, config: FpsUnlockerConfig) -> anyhow::Result<()> { let config = config_schema::ConfigSchema::from_config(config); diff --git a/src/game/mod.rs b/src/game/mod.rs index e8494a5..ffa7b6e 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -11,6 +11,7 @@ use super::fps_unlocker::FpsUnlocker; /// Try to run the game /// /// If `debug = true`, then the game will be run in the new terminal window +#[tracing::instrument(level = "info")] pub fn run() -> anyhow::Result<()> { let config = config::get()?; diff --git a/src/lib.rs b/src/lib.rs index bb3cf4c..a87d9f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,7 @@ pub mod fps_unlocker; /// assert!(anime_launcher_sdk::is_available("bash")); /// ``` #[allow(unused_must_use)] +#[tracing::instrument(level = "trace")] pub fn is_available(binary: &str) -> bool { match Command::new(binary).stdout(Stdio::null()).stderr(Stdio::null()).spawn() { Ok(mut child) => { diff --git a/src/states/mod.rs b/src/states/mod.rs index f8f3481..ef65d73 100644 --- a/src/states/mod.rs +++ b/src/states/mod.rs @@ -57,11 +57,12 @@ pub enum StateUpdating { } impl LauncherState { + #[tracing::instrument(level = "debug", skip(status))] pub fn get(wine_prefix: T, game_path: T, voices: Vec, patch_servers: Vec, status: F) -> anyhow::Result where - T: Into, + T: Into + std::fmt::Debug, F: Fn(StateUpdating), - S: ToString + S: ToString + std::fmt::Debug { let wine_prefix = wine_prefix.into(); let game_path = game_path.into(); @@ -136,6 +137,7 @@ impl LauncherState { } #[cfg(feature = "config")] + #[tracing::instrument(level = "debug", skip(status))] pub fn get_from_config(status: T) -> anyhow::Result { let config = crate::config::get()?;