all: (experimentally) added tracing
library use
This commit is contained in:
parent
a62aeef9cd
commit
6fc4fba4f3
10 changed files with 35 additions and 11 deletions
|
@ -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 }
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 27f8d7cd102b116570634bf297ad9b08518fcaf7
|
||||
Subproject commit bd10a7505f5709183b9858c581fe6bc210fa860d
|
|
@ -37,12 +37,14 @@ impl Version {
|
|||
}
|
||||
|
||||
/// Check is current dxvk downloaded in specified folder
|
||||
pub fn is_downloaded_in<T: Into<PathBuf>>(&self, folder: T) -> bool {
|
||||
#[tracing::instrument(level = "trace")]
|
||||
pub fn is_downloaded_in<T: Into<PathBuf> + std::fmt::Debug>(&self, folder: T) -> bool {
|
||||
folder.into().join(&self.name).exists()
|
||||
}
|
||||
|
||||
/// Install current dxvk
|
||||
pub fn install<T: Into<PathBuf>>(&self, dxvks_folder: T, wine: &Wine, params: InstallParams) -> std::io::Result<()> {
|
||||
#[tracing::instrument(level = "debug")]
|
||||
pub fn install<T: Into<PathBuf> + 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<T: Into<PathBuf>>(&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<Group> {
|
|||
}
|
||||
|
||||
/// List downloaded dxvk versions in some specific folder
|
||||
pub fn get_downloaded<T: Into<PathBuf>>(folder: T) -> std::io::Result<Vec<Version>> {
|
||||
#[tracing::instrument(level = "trace")]
|
||||
pub fn get_downloaded<T: Into<PathBuf> + std::fmt::Debug>(folder: T) -> std::io::Result<Vec<Version>> {
|
||||
let mut downloaded = Vec::new();
|
||||
|
||||
let list = get_groups()
|
||||
|
|
|
@ -46,7 +46,8 @@ impl Version {
|
|||
}
|
||||
|
||||
/// Check is current wine downloaded in specified folder
|
||||
pub fn is_downloaded_in<T: Into<PathBuf>>(&self, folder: T) -> bool {
|
||||
#[tracing::instrument(level = "trace")]
|
||||
pub fn is_downloaded_in<T: Into<PathBuf> + std::fmt::Debug>(&self, folder: T) -> bool {
|
||||
folder.into().join(&self.name).exists()
|
||||
}
|
||||
|
||||
|
@ -82,7 +83,8 @@ pub fn get_groups() -> Vec<Group> {
|
|||
}
|
||||
|
||||
/// List downloaded wine versions in some specific folder
|
||||
pub fn get_downloaded<T: Into<PathBuf>>(folder: T) -> std::io::Result<Vec<Version>> {
|
||||
#[tracing::instrument(level = "trace")]
|
||||
pub fn get_downloaded<T: Into<PathBuf> + std::fmt::Debug>(folder: T) -> std::io::Result<Vec<Version>> {
|
||||
let mut downloaded = Vec::new();
|
||||
|
||||
let list = get_groups()
|
||||
|
|
|
@ -30,6 +30,7 @@ static mut CONFIG: Option<Config> = 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<Config> {
|
||||
unsafe {
|
||||
match &CONFIG {
|
||||
|
@ -42,6 +43,7 @@ pub fn get() -> anyhow::Result<Config> {
|
|||
/// 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<Config> {
|
||||
match config_file() {
|
||||
Some(path) => {
|
||||
|
@ -80,6 +82,7 @@ pub fn get_raw() -> anyhow::Result<Config> {
|
|||
/// 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<WineVersion> {
|
||||
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<PathBuf> {
|
||||
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<Option<DxvkVersion>> {
|
||||
Ok(match wincompatlib::dxvk::Dxvk::get_version(&self.game.wine.prefix)? {
|
||||
Some(version) => {
|
||||
|
|
|
@ -10,6 +10,7 @@ pub const PATCH_FETCHING_TIMEOUT: Option<Duration> = 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<PathBuf> {
|
||||
dirs::data_dir().map(|dir| dir.join("anime-game-launcher"))
|
||||
}
|
||||
|
@ -17,6 +18,7 @@ pub fn launcher_dir() -> Option<PathBuf> {
|
|||
/// Get default config file path
|
||||
///
|
||||
/// `$HOME/.local/share/anime-game-launcher/config.json`
|
||||
#[tracing::instrument(level = "trace")]
|
||||
pub fn config_file() -> Option<PathBuf> {
|
||||
launcher_dir().map(|dir| dir.join("config.json"))
|
||||
}
|
||||
|
|
|
@ -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<T: Into<PathBuf>>(dir: T) -> anyhow::Result<Option<Self>> {
|
||||
#[tracing::instrument(level = "trace")]
|
||||
pub fn from_dir<T: Into<PathBuf> + std::fmt::Debug>(dir: T) -> anyhow::Result<Option<Self>> {
|
||||
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<T: Into<PathBuf>>(dir: T) -> anyhow::Result<Self> {
|
||||
#[tracing::instrument(level = "debug")]
|
||||
pub fn download<T: Into<PathBuf> + std::fmt::Debug>(dir: T) -> anyhow::Result<Self> {
|
||||
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);
|
||||
|
||||
|
|
|
@ -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()?;
|
||||
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -57,11 +57,12 @@ pub enum StateUpdating {
|
|||
}
|
||||
|
||||
impl LauncherState {
|
||||
#[tracing::instrument(level = "debug", skip(status))]
|
||||
pub fn get<T, F, S>(wine_prefix: T, game_path: T, voices: Vec<VoiceLocale>, patch_servers: Vec<S>, status: F) -> anyhow::Result<Self>
|
||||
where
|
||||
T: Into<PathBuf>,
|
||||
T: Into<PathBuf> + 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<T: Fn(StateUpdating)>(status: T) -> anyhow::Result<Self> {
|
||||
let config = crate::config::get()?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue