From c81b920f00657fbb9368f0a90fac7b921c681e64 Mon Sep 17 00:00:00 2001 From: Zihaoxu2008 Date: Sat, 25 Jan 2025 21:55:20 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E7=8E=B0=E5=9C=A8config.json?= =?UTF-8?q?=E4=BC=9A=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f8f0259385f73a22293dc96a97b02b3f0d1446f9. --- .gitignore | 4 +--- src/default/config.json => config.json | 0 src/configuration.rs | 20 ++------------------ test.txt | 5 +++++ 4 files changed, 8 insertions(+), 21 deletions(-) rename src/default/config.json => config.json (100%) create mode 100644 test.txt diff --git a/.gitignore b/.gitignore index cfb26c2..2923626 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ /target /.idea -/我是崩服小能手 -config.json -*.txt \ No newline at end of file +/我是崩服小能手 \ No newline at end of file diff --git a/src/default/config.json b/config.json similarity index 100% rename from src/default/config.json rename to config.json diff --git a/src/configuration.rs b/src/configuration.rs index 7f3f576..f2dc23a 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -1,8 +1,6 @@ -use std::fs; use std::fs::File; use serde::{Deserialize, Serialize}; -use std::io::{BufReader, Write}; -use tokio::io::AsyncWriteExt; +use std::io::BufReader; #[derive(Debug, Deserialize, Serialize)] pub struct Configuration { @@ -20,7 +18,6 @@ pub struct Configuration { pub use_thread_pool: bool } -const DEFAULT_CONFIG: &str = include_str!("default/config.json"); impl Configuration { pub fn new(filename: &str) -> Self { let file = File::open(filename); @@ -43,20 +40,7 @@ impl Configuration { } } Err(error) => { - eprintln!("[MAIN/CONF] can't read configuration: {}", error); - println!("[MAIN/CONF] creating new config.json"); - - match File::create("config.json") { - Ok(mut file) => { - if let Err(e) = file.write_all(DEFAULT_CONFIG.as_bytes()) { - eprintln!("[MAIN/CONF] can't write config.json: {}", e); - } - }, - Err(e) => { - eprintln!("[MAIN/CONF] can't create config.json: {}", e); - } - } - + eprintln!("[MAIN/CONF] Unable to read config file, will use default values: {}", error); Self::default() } } diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..9e7b180 --- /dev/null +++ b/test.txt @@ -0,0 +1,5 @@ +我奶猪好燃 +猪好燃的猪 +猪好燃的好 +猪好燃的燃 +没错,我叫猪好燃 \ No newline at end of file