Darktide Mod Manager #39
6 changed files with 147 additions and 49 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -722,6 +722,10 @@ name = "dtmt-shared"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
|
"time",
|
||||||
|
"tracing",
|
||||||
|
"tracing-error",
|
||||||
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1564,6 +1568,15 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num_threads"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "objc"
|
name = "objc"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
|
@ -2277,8 +2290,12 @@ version = "0.3.19"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "53250a3b3fed8ff8fd988587d8925d26a83ac3845d9e03b220b37f34c2b8d6c2"
|
checksum = "53250a3b3fed8ff8fd988587d8925d26a83ac3845d9e03b220b37f34c2b8d6c2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"libc",
|
||||||
|
"num_threads",
|
||||||
"serde",
|
"serde",
|
||||||
"time-core",
|
"time-core",
|
||||||
|
"time-macros",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2287,6 +2304,15 @@ version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
|
checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-macros"
|
||||||
|
version = "0.2.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a460aeb8de6dcb0f381e1ee05f1cd56fcf5a5f6eb8187ff3d8f0b11078d38b7c"
|
||||||
|
dependencies = [
|
||||||
|
"time-core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tinystr"
|
name = "tinystr"
|
||||||
version = "0.7.1"
|
version = "0.7.1"
|
||||||
|
|
|
@ -26,9 +26,6 @@ use state::ACTION_FINISH_DELETE_SELECTED_MOD;
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
use tokio::sync::mpsc::UnboundedReceiver;
|
use tokio::sync::mpsc::UnboundedReceiver;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tracing_error::ErrorLayer;
|
|
||||||
use tracing_subscriber::prelude::*;
|
|
||||||
use tracing_subscriber::EnvFilter;
|
|
||||||
|
|
||||||
use crate::engine::deploy_mods;
|
use crate::engine::deploy_mods;
|
||||||
use crate::state::{AsyncAction, Delegate, State, ACTION_FINISH_DEPLOY};
|
use crate::state::{AsyncAction, Delegate, State, ACTION_FINISH_DEPLOY};
|
||||||
|
@ -175,32 +172,7 @@ fn main() -> Result<()> {
|
||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
{
|
dtmt_shared::create_tracing_subscriber();
|
||||||
let filter_layer =
|
|
||||||
EnvFilter::try_from_default_env().or_else(|_| EnvFilter::try_new("info"))?;
|
|
||||||
|
|
||||||
if cfg!(debug_assertions) {
|
|
||||||
let fmt_layer = tracing_subscriber::fmt::layer().pretty();
|
|
||||||
|
|
||||||
tracing_subscriber::registry()
|
|
||||||
.with(filter_layer)
|
|
||||||
.with(fmt_layer)
|
|
||||||
.with(ErrorLayer::new(
|
|
||||||
tracing_subscriber::fmt::format::Pretty::default(),
|
|
||||||
))
|
|
||||||
.init();
|
|
||||||
} else {
|
|
||||||
let fmt_layer = tracing_subscriber::fmt::layer().compact();
|
|
||||||
|
|
||||||
tracing_subscriber::registry()
|
|
||||||
.with(filter_layer)
|
|
||||||
.with(fmt_layer)
|
|
||||||
.with(ErrorLayer::new(
|
|
||||||
tracing_subscriber::fmt::format::Pretty::default(),
|
|
||||||
))
|
|
||||||
.init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
oodle_sys::init(matches.get_one::<String>("oodle"));
|
oodle_sys::init(matches.get_one::<String>("oodle"));
|
||||||
|
|
|
@ -13,9 +13,6 @@ use serde::{Deserialize, Serialize};
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
use tokio::io::BufReader;
|
use tokio::io::BufReader;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tracing_error::ErrorLayer;
|
|
||||||
use tracing_subscriber::prelude::*;
|
|
||||||
use tracing_subscriber::EnvFilter;
|
|
||||||
|
|
||||||
mod cmd {
|
mod cmd {
|
||||||
pub mod build;
|
pub mod build;
|
||||||
|
@ -62,19 +59,7 @@ async fn main() -> Result<()> {
|
||||||
// .subcommand(cmd::watch::command_definition())
|
// .subcommand(cmd::watch::command_definition())
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
{
|
dtmt_shared::create_tracing_subscriber();
|
||||||
let fmt_layer = tracing_subscriber::fmt::layer().pretty();
|
|
||||||
let filter_layer =
|
|
||||||
EnvFilter::try_from_default_env().or_else(|_| EnvFilter::try_new("info"))?;
|
|
||||||
|
|
||||||
tracing_subscriber::registry()
|
|
||||||
.with(filter_layer)
|
|
||||||
.with(fmt_layer)
|
|
||||||
.with(ErrorLayer::new(
|
|
||||||
tracing_subscriber::fmt::format::Pretty::default(),
|
|
||||||
))
|
|
||||||
.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Move this into a `Context::init` method?
|
// TODO: Move this into a `Context::init` method?
|
||||||
let ctx = sdk::Context::new();
|
let ctx = sdk::Context::new();
|
||||||
|
|
|
@ -7,3 +7,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "1.0.152"
|
serde = "1.0.152"
|
||||||
|
time = { version = "0.3.19", features = ["formatting", "local-offset", "macros"] }
|
||||||
|
tracing = "0.1.37"
|
||||||
|
tracing-error = "0.2.0"
|
||||||
|
tracing-subscriber = "0.3.16"
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
mod log;
|
||||||
|
|
||||||
|
pub use log::*;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, serde::Deserialize)]
|
#[derive(Clone, Debug, Default, serde::Deserialize)]
|
||||||
pub struct ModConfigResources {
|
pub struct ModConfigResources {
|
||||||
pub init: String,
|
pub init: String,
|
||||||
|
|
|
@ -1,6 +1,113 @@
|
||||||
use tracing_subscriber::fmt::format::Writer;
|
// Rust Analyzer cannot properly determine that `cfg!(debug_assertions)` alone does not make code
|
||||||
|
// unused. These sections should be small enough that no truly dead code slips in.
|
||||||
|
|
||||||
fn format_time(w: &mut Writer) -> std::fmt::Result {
|
#[allow(dead_code)]
|
||||||
let time = now_local();
|
mod prod {
|
||||||
write!(w, "");
|
use std::fmt::Result;
|
||||||
|
|
||||||
|
use time::format_description::FormatItem;
|
||||||
|
use time::macros::format_description;
|
||||||
|
use time::OffsetDateTime;
|
||||||
|
use tracing::field::Field;
|
||||||
|
use tracing::{Event, Metadata, Subscriber};
|
||||||
|
use tracing_error::ErrorLayer;
|
||||||
|
use tracing_subscriber::filter::FilterFn;
|
||||||
|
use tracing_subscriber::fmt::format::{debug_fn, Writer};
|
||||||
|
use tracing_subscriber::fmt::{FmtContext, FormatEvent, FormatFields};
|
||||||
|
use tracing_subscriber::prelude::*;
|
||||||
|
use tracing_subscriber::registry::LookupSpan;
|
||||||
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
|
const TIME_FORMAT: &[FormatItem] = format_description!("[hour]:[minute]:[second]");
|
||||||
|
|
||||||
|
fn format_field(w: &mut Writer<'_>, field: &Field, val: &dyn std::fmt::Debug) -> Result {
|
||||||
|
if field.name() == "message" {
|
||||||
|
write!(w, "{:?}", val)
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn filter(metadata: &Metadata<'_>) -> bool {
|
||||||
|
metadata
|
||||||
|
.fields()
|
||||||
|
.iter()
|
||||||
|
.any(|field| field.name() == "message")
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Formatter;
|
||||||
|
|
||||||
|
impl<S, N> FormatEvent<S, N> for Formatter
|
||||||
|
where
|
||||||
|
S: Subscriber + for<'a> LookupSpan<'a>,
|
||||||
|
N: for<'a> FormatFields<'a> + 'static,
|
||||||
|
{
|
||||||
|
fn format_event(
|
||||||
|
&self,
|
||||||
|
ctx: &FmtContext<'_, S, N>,
|
||||||
|
mut writer: Writer<'_>,
|
||||||
|
event: &Event<'_>,
|
||||||
|
) -> Result {
|
||||||
|
let meta = event.metadata();
|
||||||
|
|
||||||
|
let time = OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc());
|
||||||
|
let time = time.format(TIME_FORMAT).map_err(|_| std::fmt::Error)?;
|
||||||
|
|
||||||
|
write!(writer, "[{}] [{:>5}] ", time, meta.level())?;
|
||||||
|
|
||||||
|
ctx.field_format().format_fields(writer.by_ref(), event)?;
|
||||||
|
|
||||||
|
writeln!(writer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a subscriber that
|
||||||
|
/// - only prints events that contain a message
|
||||||
|
/// - does not print fields
|
||||||
|
/// - does not print spans/targets
|
||||||
|
/// - only prints time, not date
|
||||||
|
pub fn create_tracing_subscriber() {
|
||||||
|
let filter_layer = EnvFilter::try_from_default_env()
|
||||||
|
.unwrap_or_else(|_| EnvFilter::try_new("info").unwrap());
|
||||||
|
|
||||||
|
let fmt_layer = tracing_subscriber::fmt::layer()
|
||||||
|
.event_format(Formatter)
|
||||||
|
.fmt_fields(debug_fn(format_field));
|
||||||
|
|
||||||
|
tracing_subscriber::registry()
|
||||||
|
.with(FilterFn::new(filter))
|
||||||
|
.with(filter_layer)
|
||||||
|
.with(fmt_layer)
|
||||||
|
.with(ErrorLayer::new(
|
||||||
|
tracing_subscriber::fmt::format::Pretty::default(),
|
||||||
|
))
|
||||||
|
.init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
mod dev {
|
||||||
|
use tracing_error::ErrorLayer;
|
||||||
|
use tracing_subscriber::prelude::*;
|
||||||
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
|
pub fn create_tracing_subscriber() {
|
||||||
|
let filter_layer = EnvFilter::try_from_default_env()
|
||||||
|
.unwrap_or_else(|_| EnvFilter::try_new("info").unwrap());
|
||||||
|
let fmt_layer = tracing_subscriber::fmt::layer().pretty();
|
||||||
|
|
||||||
|
tracing_subscriber::registry()
|
||||||
|
.with(filter_layer)
|
||||||
|
.with(fmt_layer)
|
||||||
|
.with(ErrorLayer::new(
|
||||||
|
tracing_subscriber::fmt::format::Pretty::default(),
|
||||||
|
))
|
||||||
|
.init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
pub use dev::create_tracing_subscriber;
|
||||||
|
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
pub use prod::create_tracing_subscriber;
|
||||||
|
|
Loading…
Add table
Reference in a new issue