diff --git a/.idea/chuniio-tasoller.iml b/.idea/chuniio-tasoller.iml index a86057d..87c8e7d 100644 --- a/.idea/chuniio-tasoller.iml +++ b/.idea/chuniio-tasoller.iml @@ -6,6 +6,7 @@ + diff --git a/Cargo.toml b/Cargo.toml index 0e203cd..561a75e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,19 @@ [workspace] -members = ["chuniio-tasoller-amdaemon", "chuniio-tasoller-chusan", "chuniio-tasoller-common", "vendor/shared_memory"] +members = [ + "chuniio-tasoller-amdaemon", + "chuniio-tasoller-chuni", + "chuniio-tasoller-chusan", + "chuniio-tasoller-common" +] +exclude = ["vendor"] resolver = "2" +[workspace.dependencies] +anyhow = "1.0.75" +log = "0.4.20" +rusb = "0.9.3" +winapi = "0.3.9" + [profile.release] strip = true # Automatically strip symbols from the binary. opt-level = "z" # Optimize for size. diff --git a/chuniio-tasoller-amdaemon/Cargo.toml b/chuniio-tasoller-amdaemon/Cargo.toml index 041625b..9ec2484 100644 --- a/chuniio-tasoller-amdaemon/Cargo.toml +++ b/chuniio-tasoller-amdaemon/Cargo.toml @@ -8,9 +8,9 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -anyhow = "1.0.75" +anyhow = { workspace = true } chuniio-tasoller-common = { path = "../chuniio-tasoller-common" } lazy_static = "1.4.0" -log = "0.4.20" -rusb = "0.9.3" -winapi = { version = "0.3.9", features = ["ntdef", "winbase", "winerror", "minwindef", "winuser"] } +log = { workspace = true } +rusb = { workspace = true } +winapi = { workspace = true, features = ["ntdef", "winbase", "winerror", "minwindef", "winuser"] } diff --git a/chuniio-tasoller-amdaemon/src/lib.rs b/chuniio-tasoller-amdaemon/src/lib.rs index 96b54ab..84dd1bf 100644 --- a/chuniio-tasoller-amdaemon/src/lib.rs +++ b/chuniio-tasoller-amdaemon/src/lib.rs @@ -1,17 +1,21 @@ mod configuration; -use crate::configuration::Configuration; -use chuniio_tasoller_common::create_input_shared_memory; -use chuniio_tasoller_common::log::init_logger; +use std::{ + ffi::{c_int, c_void, CString}, + sync::atomic::{AtomicBool, AtomicU16, Ordering}, +}; + +use chuniio_tasoller_common::{create_input_shared_memory, log::init_logger}; use lazy_static::lazy_static; -use std::ffi::{c_int, c_void, CString}; -use std::sync::atomic::{AtomicBool, AtomicU16, Ordering}; -use winapi::shared::minwindef::{BOOL, DWORD, HINSTANCE, LPVOID, TRUE}; -use winapi::shared::ntdef::HRESULT; -use winapi::shared::winerror::S_OK; -use winapi::um::winbase::GetPrivateProfileIntA; -use winapi::um::winnt::DLL_PROCESS_ATTACH; -use winapi::um::winuser::GetAsyncKeyState; +use winapi::{ + shared::{ + minwindef::{BOOL, DWORD, HINSTANCE, LPVOID, TRUE}, + winerror::{HRESULT, S_OK}, + }, + um::{winbase::GetPrivateProfileIntA, winnt::DLL_PROCESS_ATTACH, winuser::GetAsyncKeyState}, +}; + +use crate::configuration::Configuration; static COIN_COUNT: AtomicU16 = AtomicU16::new(0); static COIN_PRESSED: AtomicBool = AtomicBool::new(false); diff --git a/chuniio-tasoller-chusan/Cargo.toml b/chuniio-tasoller-chusan/Cargo.toml index d6cf8de..1dab6c3 100644 --- a/chuniio-tasoller-chusan/Cargo.toml +++ b/chuniio-tasoller-chusan/Cargo.toml @@ -8,8 +8,8 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -anyhow = "1.0.75" +anyhow = { workspace = true } chuniio-tasoller-common = { path = "../chuniio-tasoller-common" } -log = "0.4.20" -rusb = "0.9.3" -winapi = { version = "0.3.9", features = ["ntdef", "winerror", "minwindef"] } \ No newline at end of file +log = { workspace = true } +rusb = { workspace = true } +winapi = { workspace = true, features = ["ntdef", "winerror", "minwindef", "winnt"] } \ No newline at end of file diff --git a/chuniio-tasoller-chusan/src/lib.rs b/chuniio-tasoller-chusan/src/lib.rs index c4c485a..902379b 100644 --- a/chuniio-tasoller-chusan/src/lib.rs +++ b/chuniio-tasoller-chusan/src/lib.rs @@ -1,25 +1,26 @@ -use std::ffi::c_void; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::OnceLock; -use std::thread; -use std::thread::JoinHandle; -use std::time::Duration; +use std::{ + ffi::c_void, + sync::{ + atomic::{AtomicBool, Ordering}, + OnceLock, + }, + thread::{self, JoinHandle}, + time::Duration, +}; use anyhow::{anyhow, Result}; +use chuniio_tasoller_common::{create_input_shared_memory, log::init_logger}; +use log::{error, info, warn}; use rusb::{DeviceHandle, GlobalContext}; use winapi::{ shared::{ minwindef::{BOOL, DWORD, HINSTANCE, LPVOID, TRUE}, ntdef::HRESULT, - winerror::S_OK, + winerror::{E_FAIL, S_OK}, }, um::winnt::DLL_PROCESS_ATTACH, }; -use chuniio_tasoller_common::{create_input_shared_memory, log::init_logger}; -use log::{error, info, warn}; -use winapi::shared::winerror::E_FAIL; - type SliderCallbackFn = unsafe extern "C" fn(data: *const u8); static TASOLLER: OnceLock> = OnceLock::new(); diff --git a/chuniio-tasoller-common/Cargo.toml b/chuniio-tasoller-common/Cargo.toml index 3c8bb84..38e3939 100644 --- a/chuniio-tasoller-common/Cargo.toml +++ b/chuniio-tasoller-common/Cargo.toml @@ -6,9 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -anyhow = "1.0.75" +anyhow = { workspace = true } env_logger = { version = "0.10.1", default-features = false } -log = "0.4.20" -rusb = "0.9.3" +log = { workspace = true } shared_memory = { path = "../vendor/shared_memory" } -winapi = { version = "0.3.9", features = ["debugapi"] } +winapi = { workspace = true, features = ["debugapi"] } diff --git a/chuniio-tasoller-common/src/log.rs b/chuniio-tasoller-common/src/log.rs index 9e8ad33..134ae11 100644 --- a/chuniio-tasoller-common/src/log.rs +++ b/chuniio-tasoller-common/src/log.rs @@ -1,42 +1,42 @@ -use std::ffi::CString; -use std::io::Write; -use winapi::um::debugapi::OutputDebugStringA; - -#[derive(Debug)] -pub struct Logger {} - -impl Write for Logger { - fn write(&mut self, buf: &[u8]) -> std::io::Result { - if let Ok(c_str) = CString::new(buf) { - unsafe { OutputDebugStringA(c_str.as_ptr()) } - } - - std::io::stdout().write(buf) - } - - fn flush(&mut self) -> std::io::Result<()> { - std::io::stdout().flush() - } -} - -pub fn init_logger() { - env_logger::builder() - .filter_level(::log::LevelFilter::Error) - .filter_module( - "chuniio-tasoller", - if cfg!(debug_assertions) { - ::log::LevelFilter::Debug - } else { - ::log::LevelFilter::Info - }, - ) - .parse_default_env() - .target(env_logger::Target::Pipe(Box::new(Logger {}))) - .format(|f, record| { - let target = record.target(); - let level = record.level(); - - writeln!(f, "{} {} -> {}", level, target, record.args()) - }) - .init(); -} +use std::{ffi::CString, io::Write}; + +use winapi::um::debugapi::OutputDebugStringA; + +#[derive(Debug)] +pub struct Logger {} + +impl Write for Logger { + fn write(&mut self, buf: &[u8]) -> std::io::Result { + if let Ok(c_str) = CString::new(buf) { + unsafe { OutputDebugStringA(c_str.as_ptr()) } + } + + std::io::stdout().write(buf) + } + + fn flush(&mut self) -> std::io::Result<()> { + std::io::stdout().flush() + } +} + +pub fn init_logger() { + env_logger::builder() + .filter_level(::log::LevelFilter::Error) + .filter_module( + "chuniio-tasoller", + if cfg!(debug_assertions) { + ::log::LevelFilter::Debug + } else { + ::log::LevelFilter::Info + }, + ) + .parse_default_env() + .target(env_logger::Target::Pipe(Box::new(Logger {}))) + .format(|f, record| { + let target = record.target(); + let level = record.level(); + + writeln!(f, "{} {} -> {}", level, target, record.args()) + }) + .init(); +} diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..0c3b472 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +imports_granularity = "Crate" +reorder_imports = true +group_imports = "StdExternalCrate"