mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-07-08 01:31:53 +08:00
Add a warning counter
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -257,6 +257,10 @@ pub fn import_script(
|
|||||||
Ok(types::ScriptResult::Ok)
|
Ok(types::ScriptResult::Ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
static ref COUNTER: utils::counter::Counter = utils::counter::Counter::new();
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let arg = args::parse_args();
|
let arg = args::parse_args();
|
||||||
if arg.backtrace {
|
if arg.backtrace {
|
||||||
@@ -265,7 +269,6 @@ fn main() {
|
|||||||
let cfg = types::ExtraConfig {
|
let cfg = types::ExtraConfig {
|
||||||
circus_mes_type: arg.circus_mes_type.clone(),
|
circus_mes_type: arg.circus_mes_type.clone(),
|
||||||
};
|
};
|
||||||
let counter = utils::counter::Counter::new();
|
|
||||||
match &arg.command {
|
match &arg.command {
|
||||||
args::Command::Export { input, output } => {
|
args::Command::Export { input, output } => {
|
||||||
let (scripts, is_dir) = utils::files::collect_files(input, arg.recursive).unwrap();
|
let (scripts, is_dir) = utils::files::collect_files(input, arg.recursive).unwrap();
|
||||||
@@ -289,10 +292,10 @@ fn main() {
|
|||||||
let re = export_script(&script, &arg, &cfg, output, is_dir);
|
let re = export_script(&script, &arg, &cfg, output, is_dir);
|
||||||
match re {
|
match re {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
counter.inc(s);
|
COUNTER.inc(s);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
counter.inc_error();
|
COUNTER.inc_error();
|
||||||
eprintln!("Error exporting {}: {}", script, e);
|
eprintln!("Error exporting {}: {}", script, e);
|
||||||
if arg.backtrace {
|
if arg.backtrace {
|
||||||
eprintln!("Backtrace: {}", e.backtrace());
|
eprintln!("Backtrace: {}", e.backtrace());
|
||||||
@@ -326,10 +329,10 @@ fn main() {
|
|||||||
let re = import_script(&script, &arg, &cfg, args, is_dir, name_csv.as_ref());
|
let re = import_script(&script, &arg, &cfg, args, is_dir, name_csv.as_ref());
|
||||||
match re {
|
match re {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
counter.inc(s);
|
COUNTER.inc(s);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
counter.inc_error();
|
COUNTER.inc_error();
|
||||||
eprintln!("Error exporting {}: {}", script, e);
|
eprintln!("Error exporting {}: {}", script, e);
|
||||||
if arg.backtrace {
|
if arg.backtrace {
|
||||||
eprintln!("Backtrace: {}", e.backtrace());
|
eprintln!("Backtrace: {}", e.backtrace());
|
||||||
@@ -339,5 +342,5 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
eprintln!("{}", counter);
|
eprintln!("{}", std::ops::Deref::deref(&COUNTER));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,6 +248,7 @@ impl Script for CircusMesScript {
|
|||||||
println!(
|
println!(
|
||||||
"Warning: Some replacements cannot used in current encoding. Ruby text may be broken."
|
"Warning: Some replacements cannot used in current encoding. Ruby text may be broken."
|
||||||
);
|
);
|
||||||
|
crate::COUNTER.inc_warning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut buffer = Vec::with_capacity(self.data.len());
|
let mut buffer = Vec::with_capacity(self.data.len());
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ pub struct Counter {
|
|||||||
ok: AtomicUsize,
|
ok: AtomicUsize,
|
||||||
ignored: AtomicUsize,
|
ignored: AtomicUsize,
|
||||||
error: AtomicUsize,
|
error: AtomicUsize,
|
||||||
|
warning: AtomicUsize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Counter {
|
impl Counter {
|
||||||
@@ -14,6 +15,7 @@ impl Counter {
|
|||||||
ok: AtomicUsize::new(0),
|
ok: AtomicUsize::new(0),
|
||||||
ignored: AtomicUsize::new(0),
|
ignored: AtomicUsize::new(0),
|
||||||
error: AtomicUsize::new(0),
|
error: AtomicUsize::new(0),
|
||||||
|
warning: AtomicUsize::new(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,6 +23,10 @@ impl Counter {
|
|||||||
self.error.fetch_add(1, SeqCst);
|
self.error.fetch_add(1, SeqCst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn inc_warning(&self) {
|
||||||
|
self.warning.fetch_add(1, SeqCst);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn inc(&self, result: ScriptResult) {
|
pub fn inc(&self, result: ScriptResult) {
|
||||||
match result {
|
match result {
|
||||||
ScriptResult::Ok => self.ok.fetch_add(1, SeqCst),
|
ScriptResult::Ok => self.ok.fetch_add(1, SeqCst),
|
||||||
@@ -33,10 +39,11 @@ impl std::fmt::Display for Counter {
|
|||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"OK: {}, Ignored: {}, Error: {}",
|
"OK: {}, Ignored: {}, Error: {}, Warning: {}",
|
||||||
self.ok.load(SeqCst),
|
self.ok.load(SeqCst),
|
||||||
self.ignored.load(SeqCst),
|
self.ignored.load(SeqCst),
|
||||||
self.error.load(SeqCst)
|
self.error.load(SeqCst),
|
||||||
|
self.warning.load(SeqCst),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ pub fn encode_string(
|
|||||||
"Warning: Some characters could not be encoded in Shift-JIS: {}",
|
"Warning: Some characters could not be encoded in Shift-JIS: {}",
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
|
crate::COUNTER.inc_warning();
|
||||||
}
|
}
|
||||||
Ok(result.0.to_vec())
|
Ok(result.0.to_vec())
|
||||||
}
|
}
|
||||||
@@ -60,6 +61,7 @@ pub fn encode_string(
|
|||||||
"Warning: Some characters could not be encoded in GB2312: {}",
|
"Warning: Some characters could not be encoded in GB2312: {}",
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
|
crate::COUNTER.inc_warning();
|
||||||
}
|
}
|
||||||
Ok(result.0.to_vec())
|
Ok(result.0.to_vec())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ pub fn encode_string(cp: u32, data: &str, check: bool) -> Result<Vec<u8>, WinErr
|
|||||||
"Warning: Some characters could not be encoded in code page {}: {}",
|
"Warning: Some characters could not be encoded in code page {}: {}",
|
||||||
cp, data
|
cp, data
|
||||||
);
|
);
|
||||||
|
crate::COUNTER.inc_warning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if result == 0 {
|
if result == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user