mirror of
https://github.com/lifegpc/game-auto-sync.git
synced 2026-06-06 13:58:57 +08:00
Bug fix
This commit is contained in:
14
src/cfg.rs
14
src/cfg.rs
@@ -42,6 +42,16 @@ impl Config {
|
||||
self.obj.get(&k)
|
||||
}
|
||||
|
||||
pub fn get_bool<S: AsRef<str> + ?Sized>(&self, s: &S) -> Option<&bool> {
|
||||
match self.get(s) {
|
||||
Some(y) => match y {
|
||||
Yaml::Boolean(i) => Some(i),
|
||||
_ => None,
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_str<S: AsRef<str> + ?Sized>(&self, s: &S) -> Option<&str> {
|
||||
match self.get(s) {
|
||||
Some(y) => match y {
|
||||
@@ -98,4 +108,8 @@ impl Config {
|
||||
pub fn restore_command(&self) -> Option<Vec<String>> {
|
||||
self.get_str_vec("restore_command")
|
||||
}
|
||||
|
||||
pub fn pause_at_exit(&self) -> bool {
|
||||
self.get_bool("pause_at_exit").map(|s| s.to_owned()).unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
||||
18
src/main.rs
18
src/main.rs
@@ -52,7 +52,7 @@ impl Main {
|
||||
} else {
|
||||
let e = Self::call(cml)?;
|
||||
let ok = match &e {
|
||||
ExitStatus::Exited(c) => *c != 0,
|
||||
ExitStatus::Exited(c) => *c == 0,
|
||||
_ => false,
|
||||
};
|
||||
if !ok {
|
||||
@@ -87,7 +87,7 @@ impl Main {
|
||||
} else {
|
||||
let e = Self::call(cml)?;
|
||||
let ok = match &e {
|
||||
ExitStatus::Exited(c) => *c != 0,
|
||||
ExitStatus::Exited(c) => *c == 0,
|
||||
_ => false,
|
||||
};
|
||||
if !ok {
|
||||
@@ -115,7 +115,7 @@ impl Main {
|
||||
} else {
|
||||
let e = Self::call(cml)?;
|
||||
let ok = match &e {
|
||||
ExitStatus::Exited(c) => *c != 0,
|
||||
ExitStatus::Exited(c) => *c == 0,
|
||||
_ => false,
|
||||
};
|
||||
if !ok {
|
||||
@@ -130,7 +130,6 @@ impl Main {
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
println!("Hello, world!");
|
||||
let argv: Vec<String> = std::env::args().collect();
|
||||
let mut opts = Options::new();
|
||||
opts.optflag("h", "help", "Print help message.");
|
||||
@@ -164,12 +163,15 @@ fn main() -> ExitCode {
|
||||
return ExitCode::from(1);
|
||||
}
|
||||
let m = Main::new(cfg, result.opt_present("d"));
|
||||
match m.run() {
|
||||
Ok(_) => {}
|
||||
let e = match m.run() {
|
||||
Ok(_) => 0,
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return ExitCode::from(1);
|
||||
1
|
||||
}
|
||||
};
|
||||
if m._cfg.pause_at_exit() {
|
||||
utils::enter_continue();
|
||||
}
|
||||
return ExitCode::from(0);
|
||||
return ExitCode::from(e);
|
||||
}
|
||||
|
||||
10
src/utils.rs
10
src/utils.rs
@@ -1,4 +1,5 @@
|
||||
use std::env;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
@@ -36,3 +37,12 @@ pub fn ask_continue() -> bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enter_continue() {
|
||||
print!("Press enter to continue.");
|
||||
std::io::stdout().flush().unwrap();
|
||||
let mut f = [0u8; 1];
|
||||
match std::io::stdin().read_exact(&mut f) {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user