Miscellaneous changes #266

Merged
lucas merged 49 commits from feat/misc into master 2025-07-02 16:25:44 +02:00
20 changed files with 39 additions and 40 deletions
Showing only changes of commit d61ffdfef2 - Show all commits

View file

@ -469,7 +469,7 @@ async fn patch_boot_bundle(state: Arc<ActionState>, deployment_info: &str) -> Re
} }
.instrument(tracing::trace_span!("read boot bundle")) .instrument(tracing::trace_span!("read boot bundle"))
.await .await
.wrap_err_with(|| format!("Failed to read bundle '{}'", BOOT_BUNDLE_NAME))?; .wrap_err_with(|| format!("Failed to read bundle '{BOOT_BUNDLE_NAME}'"))?;
{ {
tracing::trace!("Adding mod package file to boot bundle"); tracing::trace!("Adding mod package file to boot bundle");

View file

@ -208,7 +208,7 @@ pub(crate) async fn reset_mod_deployment(state: ActionState) -> Result<()> {
for p in paths { for p in paths {
let path = bundle_dir.join(p); let path = bundle_dir.join(p);
let backup = bundle_dir.join(format!("{}.bak", p)); let backup = bundle_dir.join(format!("{p}.bak"));
let res = async { let res = async {
tracing::debug!( tracing::debug!(

View file

@ -363,7 +363,7 @@ fn extract_legacy_mod<R: Read + Seek>(
for i in 0..file_count { for i in 0..file_count {
let mut f = archive let mut f = archive
.by_index(i) .by_index(i)
.wrap_err_with(|| format!("Failed to get file at index {}", i))?; .wrap_err_with(|| format!("Failed to get file at index {i}"))?;
let Some(name) = f.enclosed_name().map(|p| p.to_path_buf()) else { let Some(name) = f.enclosed_name().map(|p| p.to_path_buf()) else {
let err = eyre::eyre!("File name in archive is not a safe path value.").suggestion( let err = eyre::eyre!("File name in archive is not a safe path value.").suggestion(
@ -426,7 +426,7 @@ pub(crate) async fn import_from_file(state: ActionState, info: FileInfo) -> Resu
let mod_info = api let mod_info = api
.mods_id(id) .mods_id(id)
.await .await
.wrap_err_with(|| format!("Failed to query mod {} from Nexus", id))?; .wrap_err_with(|| format!("Failed to query mod {id} from Nexus"))?;
let version = match api.file_version(id, timestamp).await { let version = match api.file_version(id, timestamp).await {
Ok(version) => version, Ok(version) => version,
@ -461,13 +461,13 @@ pub(crate) async fn import_from_file(state: ActionState, info: FileInfo) -> Resu
pub(crate) async fn import_from_nxm(state: ActionState, uri: String) -> Result<ModInfo> { pub(crate) async fn import_from_nxm(state: ActionState, uri: String) -> Result<ModInfo> {
let url = uri let url = uri
.parse() .parse()
.wrap_err_with(|| format!("Invalid Uri '{}'", uri))?; .wrap_err_with(|| format!("Invalid Uri '{uri}'"))?;
let api = NexusApi::new(state.nexus_api_key.to_string())?; let api = NexusApi::new(state.nexus_api_key.to_string())?;
let (mod_info, file_info, data) = api let (mod_info, file_info, data) = api
.handle_nxm(url) .handle_nxm(url)
.await .await
.wrap_err_with(|| format!("Failed to download mod from NXM uri '{}'", uri))?; .wrap_err_with(|| format!("Failed to download mod from NXM uri '{uri}'"))?;
let nexus = NexusInfo::from(mod_info); let nexus = NexusInfo::from(mod_info);
import_mod(state, Some((nexus, file_info.version)), data).await import_mod(state, Some((nexus, file_info.version)), data).await
@ -524,7 +524,7 @@ pub(crate) async fn import_mod(
let data = api let data = api
.picture(url) .picture(url)
.await .await
.wrap_err_with(|| format!("Failed to download Nexus image from '{}'", url))?; .wrap_err_with(|| format!("Failed to download Nexus image from '{url}'"))?;
let img = image_data_to_buffer(&data)?; let img = image_data_to_buffer(&data)?;

View file

@ -47,7 +47,7 @@ fn notify_nxm_download(
.to_ns_name::<GenericNamespaced>() .to_ns_name::<GenericNamespaced>()
.expect("Invalid socket name"), .expect("Invalid socket name"),
) )
.wrap_err_with(|| format!("Failed to connect to '{}'", IPC_ADDRESS)) .wrap_err_with(|| format!("Failed to connect to '{IPC_ADDRESS}'"))
.suggestion("Make sure the main window is open.")?; .suggestion("Make sure the main window is open.")?;
tracing::debug!("Connected to main process at '{}'", IPC_ADDRESS); tracing::debug!("Connected to main process at '{}'", IPC_ADDRESS);
@ -159,7 +159,7 @@ fn main() -> Result<()> {
loop { loop {
let res = server.accept().wrap_err_with(|| { let res = server.accept().wrap_err_with(|| {
format!("IPC server failed to listen on '{}'", IPC_ADDRESS) format!("IPC server failed to listen on '{IPC_ADDRESS}'")
}); });
match res { match res {

View file

@ -108,20 +108,19 @@ impl std::fmt::Debug for AsyncAction {
match self { match self {
AsyncAction::DeployMods(_) => write!(f, "AsyncAction::DeployMods(_state)"), AsyncAction::DeployMods(_) => write!(f, "AsyncAction::DeployMods(_state)"),
AsyncAction::ResetDeployment(_) => write!(f, "AsyncAction::ResetDeployment(_state)"), AsyncAction::ResetDeployment(_) => write!(f, "AsyncAction::ResetDeployment(_state)"),
AsyncAction::AddMod(_, info) => write!(f, "AsyncAction::AddMod(_state, {:?})", info), AsyncAction::AddMod(_, info) => write!(f, "AsyncAction::AddMod(_state, {info:?})"),
AsyncAction::DeleteMod(_, info) => { AsyncAction::DeleteMod(_, info) => {
write!(f, "AsyncAction::DeleteMod(_state, {:?})", info) write!(f, "AsyncAction::DeleteMod(_state, {info:?})")
} }
AsyncAction::SaveSettings(_) => write!(f, "AsyncAction::SaveSettings(_state)"), AsyncAction::SaveSettings(_) => write!(f, "AsyncAction::SaveSettings(_state)"),
AsyncAction::CheckUpdates(_) => write!(f, "AsyncAction::CheckUpdates(_state)"), AsyncAction::CheckUpdates(_) => write!(f, "AsyncAction::CheckUpdates(_state)"),
AsyncAction::LoadInitial((path, is_default)) => write!( AsyncAction::LoadInitial((path, is_default)) => write!(
f, f,
"AsyncAction::LoadInitial(({:?}, {:?}))", "AsyncAction::LoadInitial(({path:?}, {is_default:?}))"
path, is_default
), ),
AsyncAction::Log(_) => write!(f, "AsyncAction::Log(_)"), AsyncAction::Log(_) => write!(f, "AsyncAction::Log(_)"),
AsyncAction::NxmDownload(_, uri) => { AsyncAction::NxmDownload(_, uri) => {
write!(f, "AsyncAction::NxmDownload(_state, {})", uri) write!(f, "AsyncAction::NxmDownload(_state, {uri})")
} }
} }
} }
@ -448,7 +447,7 @@ impl AppDelegate<State> for Delegate {
if let Err(err) = open::that_detached(Arc::as_ref(url)) { if let Err(err) = open::that_detached(Arc::as_ref(url)) {
tracing::error!( tracing::error!(
"{:?}", "{:?}",
Report::new(err).wrap_err(format!("Failed to open url '{}'", url)) Report::new(err).wrap_err(format!("Failed to open url '{url}'"))
); );
} }

View file

@ -76,7 +76,7 @@ impl ColorExt for Color {
fn darken(&self, fac: f32) -> Self { fn darken(&self, fac: f32) -> Self {
let (r, g, b, a) = self.as_rgba(); let (r, g, b, a) = self.as_rgba();
let rgb = Rgb::from(r as f32, g as f32, b as f32); let rgb = Rgb::from(r as f32, g as f32, b as f32);
let rgb = rgb.lighten(-1. * fac); let rgb = rgb.lighten(-fac);
Self::rgba( Self::rgba(
rgb.get_red() as f64, rgb.get_red() as f64,
rgb.get_green() as f64, rgb.get_green() as f64,

View file

@ -5,6 +5,7 @@ use druid::{
use crate::state::{State, ACTION_SET_DIRTY, ACTION_START_SAVE_SETTINGS}; use crate::state::{State, ACTION_SET_DIRTY, ACTION_START_SAVE_SETTINGS};
#[allow(dead_code)]
pub struct DisabledButtonController; pub struct DisabledButtonController;
impl<T: Data> Controller<T, Button<T>> for DisabledButtonController { impl<T: Data> Controller<T, Button<T>> for DisabledButtonController {

View file

@ -34,9 +34,9 @@ pub fn error<T: Data>(err: Report, _parent: WindowHandle) -> WindowDesc<T> {
// The second to last one, the context to the root cause // The second to last one, the context to the root cause
let context = err.chain().nth(count - 2).unwrap(); let context = err.chain().nth(count - 2).unwrap();
(format!("{first}!"), format!("{}: {}", context, root)) (format!("{first}!"), format!("{context}: {root}"))
} else { } else {
("An error occurred!".to_string(), format!("{}: {}", first, root)) ("An error occurred!".to_string(), format!("{first}: {root}"))
} }
} }
}; };

View file

@ -348,7 +348,7 @@ fn build_mod_details_info() -> impl Widget<State> {
let nexus_link = Maybe::or_empty(|| { let nexus_link = Maybe::or_empty(|| {
let link = Label::raw().lens(NexusInfo::id.map( let link = Label::raw().lens(NexusInfo::id.map(
|id| { |id| {
let url = format!("https://nexusmods.com/warhammer40kdarktide/mods/{}", id); let url = format!("https://nexusmods.com/warhammer40kdarktide/mods/{id}");
let mut builder = RichTextBuilder::new(); let mut builder = RichTextBuilder::new();
builder builder
.push("Open on Nexusmods") .push("Open on Nexusmods")

View file

@ -94,10 +94,10 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> {
match bundle_name { match bundle_name {
IdString64::String(name) => { IdString64::String(name) => {
println!("{:016x} {}", bundle_hash, name); println!("{bundle_hash:016x} {name}");
} }
IdString64::Hash(hash) => { IdString64::Hash(hash) => {
println!("{:016x}", hash); println!("{hash:016x}");
} }
} }
@ -110,7 +110,7 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> {
println!("\t{:016x}.{:<12} {}", file.name, extension, name); println!("\t{:016x}.{:<12} {}", file.name, extension, name);
} }
IdString64::Hash(hash) => { IdString64::Hash(hash) => {
println!("\t{:016x}.{}", hash, extension); println!("\t{hash:016x}.{extension}");
} }
} }
} }
@ -127,10 +127,10 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> {
match bundle_name { match bundle_name {
IdString64::String(name) => { IdString64::String(name) => {
println!("{:016x} {}", bundle_hash, name); println!("{bundle_hash:016x} {name}");
} }
IdString64::Hash(hash) => { IdString64::Hash(hash) => {
println!("{:016x}", hash); println!("{hash:016x}");
} }
} }
} }
@ -158,7 +158,7 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> {
for bundle in bundles { for bundle in bundles {
found = true; found = true;
println!("{:016x}", bundle); println!("{bundle:016x}");
} }
if !found { if !found {

View file

@ -473,7 +473,7 @@ where
} }
} }
Err(err) => { Err(err) => {
let err = err.wrap_err(format!("Failed to decompile file {}", name)); let err = err.wrap_err(format!("Failed to decompile file {name}"));
tracing::error!("{:?}", err); tracing::error!("{:?}", err);
} }
}; };

View file

@ -147,7 +147,7 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> {
let patch_number = matches let patch_number = matches
.get_one::<u16>("patch") .get_one::<u16>("patch")
.map(|num| format!("{:03}", num)); .map(|num| format!("{num:03}"));
let output_path = matches let output_path = matches
.get_one::<PathBuf>("output") .get_one::<PathBuf>("output")
@ -156,7 +156,7 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> {
let mut output_path = bundle_path.clone(); let mut output_path = bundle_path.clone();
if let Some(patch_number) = patch_number.as_ref() { if let Some(patch_number) = patch_number.as_ref() {
output_path.set_extension(format!("patch_{:03}", patch_number)); output_path.set_extension(format!("patch_{patch_number:03}"));
} }
output_path output_path
@ -196,7 +196,7 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> {
span.record("output_path", output_path.display().to_string()); span.record("output_path", output_path.display().to_string());
span.record("raw", sub_matches.get_flag("raw")); span.record("raw", sub_matches.get_flag("raw"));
span.record("target_name", target_name.display().to_string()); span.record("target_name", target_name.display().to_string());
span.record("file_type", format!("{:?}", file_type)); span.record("file_type", format!("{file_type:?}"));
} }
} }

View file

@ -38,7 +38,7 @@ enum OutputFormat {
fn format_byte_size(size: usize) -> String { fn format_byte_size(size: usize) -> String {
if size < 1024 { if size < 1024 {
format!("{} Bytes", size) format!("{size} Bytes")
} else if size < 1024 * 1024 { } else if size < 1024 * 1024 {
format!("{} kB", size / 1024) format!("{} kB", size / 1024)
} else if size < 1024 * 1024 * 1024 { } else if size < 1024 * 1024 * 1024 {

View file

@ -164,7 +164,7 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
.iter() .iter()
.map(|(path_tmpl, content_tmpl)| { .map(|(path_tmpl, content_tmpl)| {
env.render_str(path_tmpl, &render_ctx) env.render_str(path_tmpl, &render_ctx)
.wrap_err_with(|| format!("Failed to render template: {}", path_tmpl)) .wrap_err_with(|| format!("Failed to render template: {path_tmpl}"))
.and_then(|path| { .and_then(|path| {
env.render_named_str(&path, content_tmpl, &render_ctx) env.render_named_str(&path, content_tmpl, &render_ctx)
.wrap_err_with(|| format!("Failed to render template '{}'", &path)) .wrap_err_with(|| format!("Failed to render template '{}'", &path))

View file

@ -1,6 +1,5 @@
#![feature(io_error_more)] #![feature(io_error_more)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(result_flattening)]
#![feature(test)] #![feature(test)]
#![windows_subsystem = "console"] #![windows_subsystem = "console"]

View file

@ -19,7 +19,7 @@ pub const TIME_FORMAT: &[FormatItem] = format_description!("[hour]:[minute]:[sec
pub fn format_fields(w: &mut Writer<'_>, field: &Field, val: &dyn std::fmt::Debug) -> Result { pub fn format_fields(w: &mut Writer<'_>, field: &Field, val: &dyn std::fmt::Debug) -> Result {
if field.name() == "message" { if field.name() == "message" {
write!(w, "{:?}", val) write!(w, "{val:?}")
} else { } else {
Ok(()) Ok(())
} }
@ -70,7 +70,7 @@ where
writer, writer,
"[{}] [{:>5}] ", "[{}] [{:>5}] ",
time, time,
color.bold().paint(format!("{}", level)) color.bold().paint(format!("{level}"))
)?; )?;
ctx.field_format().format_fields(writer.by_ref(), event)?; ctx.field_format().format_fields(writer.by_ref(), event)?;

View file

@ -99,7 +99,7 @@ impl Api {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub async fn mods_id(&self, id: u64) -> Result<Mod> { pub async fn mods_id(&self, id: u64) -> Result<Mod> {
let url = BASE_URL_GAME.join(&format!("mods/{}.json", id))?; let url = BASE_URL_GAME.join(&format!("mods/{id}.json"))?;
let req = self.client.get(url); let req = self.client.get(url);
self.send(req).await self.send(req).await
} }

View file

@ -11,7 +11,7 @@ fn main() {
} else { } else {
"oo2core_win64" "oo2core_win64"
}; };
println!("cargo:rustc-link-lib=static={}", lib_name); println!("cargo:rustc-link-lib=static={lib_name}");
} else { } else {
println!("cargo:rustc-link-lib=static=oo2corelinux64"); println!("cargo:rustc-link-lib=static=oo2corelinux64");
println!("cargo:rustc-link-lib=stdc++"); println!("cargo:rustc-link-lib=stdc++");

View file

@ -247,7 +247,7 @@ pub mod sync {
fn read_string_len(mut r: impl Read, len: usize) -> Result<String> { fn read_string_len(mut r: impl Read, len: usize) -> Result<String> {
let mut buf = vec![0; len]; let mut buf = vec![0; len];
r.read_exact(&mut buf) r.read_exact(&mut buf)
.wrap_err_with(|| format!("Failed to read {} bytes", len))?; .wrap_err_with(|| format!("Failed to read {len} bytes"))?;
let res = match CStr::from_bytes_until_nul(&buf) { let res = match CStr::from_bytes_until_nul(&buf) {
Ok(s) => { Ok(s) => {
@ -259,6 +259,6 @@ pub mod sync {
res.wrap_err("Invalid binary for UTF8 string") res.wrap_err("Invalid binary for UTF8 string")
.with_section(|| format!("{}", String::from_utf8_lossy(&buf)).header("ASCI:")) .with_section(|| format!("{}", String::from_utf8_lossy(&buf)).header("ASCI:"))
.with_section(|| format!("{:x?}", buf).header("Bytes:")) .with_section(|| format!("{buf:x?}").header("Bytes:"))
} }
} }

View file

@ -50,7 +50,7 @@ impl fmt::LowerHex for Murmur64 {
impl fmt::Display for Murmur64 { impl fmt::Display for Murmur64 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:016X}", self) write!(f, "{self:016X}")
} }
} }
@ -158,7 +158,7 @@ impl fmt::LowerHex for Murmur32 {
impl fmt::Display for Murmur32 { impl fmt::Display for Murmur32 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:08X}", self) write!(f, "{self:08X}")
} }
} }