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"
|
anyhow = "1.0"
|
||||||
dirs = "4.0.0"
|
dirs = "4.0.0"
|
||||||
|
tracing = "0.1"
|
||||||
|
|
||||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||||
serde_json = { version = "1.0", 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
|
/// 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()
|
folder.into().join(&self.name).exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Install current dxvk
|
/// 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(
|
Dxvk::install(
|
||||||
wine,
|
wine,
|
||||||
dxvks_folder.into().join(&self.name),
|
dxvks_folder.into().join(&self.name),
|
||||||
|
@ -51,7 +53,8 @@ impl Version {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uninstall current dxvk
|
/// 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(
|
Dxvk::uninstall(
|
||||||
wine,
|
wine,
|
||||||
params
|
params
|
||||||
|
@ -65,7 +68,8 @@ pub fn get_groups() -> Vec<Group> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List downloaded dxvk versions in some specific folder
|
/// 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 mut downloaded = Vec::new();
|
||||||
|
|
||||||
let list = get_groups()
|
let list = get_groups()
|
||||||
|
|
|
@ -46,7 +46,8 @@ impl Version {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check is current wine downloaded in specified folder
|
/// 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()
|
folder.into().join(&self.name).exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +83,8 @@ pub fn get_groups() -> Vec<Group> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List downloaded wine versions in some specific folder
|
/// 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 mut downloaded = Vec::new();
|
||||||
|
|
||||||
let list = get_groups()
|
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.
|
/// 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
|
/// 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
|
/// 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> {
|
pub fn get() -> anyhow::Result<Config> {
|
||||||
unsafe {
|
unsafe {
|
||||||
match &CONFIG {
|
match &CONFIG {
|
||||||
|
@ -42,6 +43,7 @@ pub fn get() -> anyhow::Result<Config> {
|
||||||
/// Get config data
|
/// Get config data
|
||||||
///
|
///
|
||||||
/// This method will always load data directly from the file and update in-memory config
|
/// 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> {
|
pub fn get_raw() -> anyhow::Result<Config> {
|
||||||
match config_file() {
|
match config_file() {
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
|
@ -80,6 +82,7 @@ pub fn get_raw() -> anyhow::Result<Config> {
|
||||||
/// Update in-memory config data
|
/// Update in-memory config data
|
||||||
///
|
///
|
||||||
/// Use `update_raw` if you want to update config file itself
|
/// Use `update_raw` if you want to update config file itself
|
||||||
|
#[tracing::instrument(level = "trace")]
|
||||||
pub fn update(config: Config) {
|
pub fn update(config: Config) {
|
||||||
unsafe {
|
unsafe {
|
||||||
CONFIG = Some(config);
|
CONFIG = Some(config);
|
||||||
|
@ -89,6 +92,7 @@ pub fn update(config: Config) {
|
||||||
/// Update config file
|
/// Update config file
|
||||||
///
|
///
|
||||||
/// This method will also update in-memory config data
|
/// This method will also update in-memory config data
|
||||||
|
#[tracing::instrument(level = "debug")]
|
||||||
pub fn update_raw(config: Config) -> anyhow::Result<()> {
|
pub fn update_raw(config: Config) -> anyhow::Result<()> {
|
||||||
update(config.clone());
|
update(config.clone());
|
||||||
|
|
||||||
|
@ -110,6 +114,7 @@ pub fn update_raw(config: Config) -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update config file from the in-memory saved config
|
/// Update config file from the in-memory saved config
|
||||||
|
#[tracing::instrument(level = "debug")]
|
||||||
pub fn flush() -> anyhow::Result<()> {
|
pub fn flush() -> anyhow::Result<()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
match &CONFIG {
|
match &CONFIG {
|
||||||
|
@ -157,6 +162,7 @@ use crate::components::dxvk::{self, Version as DxvkVersion};
|
||||||
|
|
||||||
#[cfg(feature = "components")]
|
#[cfg(feature = "components")]
|
||||||
impl Config {
|
impl Config {
|
||||||
|
#[tracing::instrument(level = "debug")]
|
||||||
pub fn try_get_selected_wine_info(&self) -> Option<WineVersion> {
|
pub fn try_get_selected_wine_info(&self) -> Option<WineVersion> {
|
||||||
match &self.game.wine.selected {
|
match &self.game.wine.selected {
|
||||||
Some(selected) => {
|
Some(selected) => {
|
||||||
|
@ -174,6 +180,7 @@ impl Config {
|
||||||
/// Returns `Some("wine64")` if:
|
/// Returns `Some("wine64")` if:
|
||||||
/// 1) `game.wine.selected = None`
|
/// 1) `game.wine.selected = None`
|
||||||
/// 2) wine64 installed and available in system
|
/// 2) wine64 installed and available in system
|
||||||
|
#[tracing::instrument(level = "debug")]
|
||||||
pub fn try_get_wine_executable(&self) -> Option<PathBuf> {
|
pub fn try_get_wine_executable(&self) -> Option<PathBuf> {
|
||||||
match self.try_get_selected_wine_info() {
|
match self.try_get_selected_wine_info() {
|
||||||
Some(selected) => Some(self.game.wine.builds.join(selected.name).join(selected.files.wine64)),
|
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
|
/// 1) `Ok(Some(..))` if version was found
|
||||||
/// 2) `Ok(None)` if version wasn't found, so too old or dxvk is not applied
|
/// 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
|
/// 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>> {
|
pub fn try_get_selected_dxvk_info(&self) -> std::io::Result<Option<DxvkVersion>> {
|
||||||
Ok(match wincompatlib::dxvk::Dxvk::get_version(&self.game.wine.prefix)? {
|
Ok(match wincompatlib::dxvk::Dxvk::get_version(&self.game.wine.prefix)? {
|
||||||
Some(version) => {
|
Some(version) => {
|
||||||
|
|
|
@ -10,6 +10,7 @@ pub const PATCH_FETCHING_TIMEOUT: Option<Duration> = Some(Duration::from_secs(5)
|
||||||
/// Get default launcher dir path
|
/// Get default launcher dir path
|
||||||
///
|
///
|
||||||
/// `$HOME/.local/share/anime-game-launcher`
|
/// `$HOME/.local/share/anime-game-launcher`
|
||||||
|
#[tracing::instrument(level = "trace")]
|
||||||
pub fn launcher_dir() -> Option<PathBuf> {
|
pub fn launcher_dir() -> Option<PathBuf> {
|
||||||
dirs::data_dir().map(|dir| dir.join("anime-game-launcher"))
|
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
|
/// Get default config file path
|
||||||
///
|
///
|
||||||
/// `$HOME/.local/share/anime-game-launcher/config.json`
|
/// `$HOME/.local/share/anime-game-launcher/config.json`
|
||||||
|
#[tracing::instrument(level = "trace")]
|
||||||
pub fn config_file() -> Option<PathBuf> {
|
pub fn config_file() -> Option<PathBuf> {
|
||||||
launcher_dir().map(|dir| dir.join("config.json"))
|
launcher_dir().map(|dir| dir.join("config.json"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,8 @@ impl FpsUnlocker {
|
||||||
/// - `Err(..)` if failed to read `unlocker.exe` file
|
/// - `Err(..)` if failed to read `unlocker.exe` file
|
||||||
/// - `Ok(None)` if version is not latest
|
/// - `Ok(None)` if version is not latest
|
||||||
/// - `Ok(..)` if version is 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 dir = dir.into();
|
||||||
|
|
||||||
let hash = format!("{:x}", md5::compute(std::fs::read(dir.join("unlocker.exe"))?));
|
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
|
/// 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 mut downloader = Downloader::new(LATEST_INFO.1)?;
|
||||||
|
|
||||||
let dir = dir.into();
|
let dir = dir.into();
|
||||||
|
@ -71,6 +73,7 @@ impl FpsUnlocker {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate and save FPS unlocker config file to the game's directory
|
/// 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<()> {
|
pub fn update_config(&self, config: FpsUnlockerConfig) -> anyhow::Result<()> {
|
||||||
let config = config_schema::ConfigSchema::from_config(config);
|
let config = config_schema::ConfigSchema::from_config(config);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ use super::fps_unlocker::FpsUnlocker;
|
||||||
/// Try to run the game
|
/// Try to run the game
|
||||||
///
|
///
|
||||||
/// If `debug = true`, then the game will be run in the new terminal window
|
/// If `debug = true`, then the game will be run in the new terminal window
|
||||||
|
#[tracing::instrument(level = "info")]
|
||||||
pub fn run() -> anyhow::Result<()> {
|
pub fn run() -> anyhow::Result<()> {
|
||||||
let config = config::get()?;
|
let config = config::get()?;
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ pub mod fps_unlocker;
|
||||||
/// assert!(anime_launcher_sdk::is_available("bash"));
|
/// assert!(anime_launcher_sdk::is_available("bash"));
|
||||||
/// ```
|
/// ```
|
||||||
#[allow(unused_must_use)]
|
#[allow(unused_must_use)]
|
||||||
|
#[tracing::instrument(level = "trace")]
|
||||||
pub fn is_available(binary: &str) -> bool {
|
pub fn is_available(binary: &str) -> bool {
|
||||||
match Command::new(binary).stdout(Stdio::null()).stderr(Stdio::null()).spawn() {
|
match Command::new(binary).stdout(Stdio::null()).stderr(Stdio::null()).spawn() {
|
||||||
Ok(mut child) => {
|
Ok(mut child) => {
|
||||||
|
|
|
@ -57,11 +57,12 @@ pub enum StateUpdating {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LauncherState {
|
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>
|
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
|
where
|
||||||
T: Into<PathBuf>,
|
T: Into<PathBuf> + std::fmt::Debug,
|
||||||
F: Fn(StateUpdating),
|
F: Fn(StateUpdating),
|
||||||
S: ToString
|
S: ToString + std::fmt::Debug
|
||||||
{
|
{
|
||||||
let wine_prefix = wine_prefix.into();
|
let wine_prefix = wine_prefix.into();
|
||||||
let game_path = game_path.into();
|
let game_path = game_path.into();
|
||||||
|
@ -136,6 +137,7 @@ impl LauncherState {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "config")]
|
#[cfg(feature = "config")]
|
||||||
|
#[tracing::instrument(level = "debug", skip(status))]
|
||||||
pub fn get_from_config<T: Fn(StateUpdating)>(status: T) -> anyhow::Result<Self> {
|
pub fn get_from_config<T: Fn(StateUpdating)>(status: T) -> anyhow::Result<Self> {
|
||||||
let config = crate::config::get()?;
|
let config = crate::config::get()?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue