From 166c89a8d1c8707335f5c0329deefd8220c7813d Mon Sep 17 00:00:00 2001 From: hinto-janaiyo Date: Fri, 16 Dec 2022 22:38:46 -0500 Subject: [PATCH] disk: fix serializing quotes in strings --- src/disk.rs | 31 +++++++++++++++++++++++++------ src/main.rs | 4 ++-- src/sudo.rs | 2 +- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/disk.rs b/src/disk.rs index f94cc0b..3c7e26d 100644 --- a/src/disk.rs +++ b/src/disk.rs @@ -348,15 +348,24 @@ impl Node { let mut vec = Vec::with_capacity(size); for (key, values) in nodes.iter() { let ip = match values.get("ip") { - Some(ip) => ip.to_string(), + Some(ip) => match ip.as_str() { + Some(ip) => ip.to_string(), + None => { error!("Node | [None] at [ip] parse"); return Err(TomlError::Parse("[None] at [ip] parse")) }, + }, None => { error!("Node | [None] at [ip] parse"); return Err(TomlError::Parse("[None] at [ip] parse")) }, }; let rpc = match values.get("rpc") { - Some(rpc) => rpc.to_string(), + Some(rpc) => match rpc.as_str() { + Some(rpc) => rpc.to_string(), + None => { error!("Node | [None] at [rpc] parse"); return Err(TomlError::Parse("[None] at [rpc] parse")) }, + }, None => { error!("Node | [None] at [rpc] parse"); return Err(TomlError::Parse("[None] at [rpc] parse")) }, }; let zmq = match values.get("zmq") { - Some(zmq) => zmq.to_string(), + Some(zmq) => match zmq.as_str() { + Some(zmq) => zmq.to_string(), + None => { error!("Node | [None] at [zmq] parse"); return Err(TomlError::Parse("[None] at [zmq] parse")) }, + }, None => { error!("Node | [None] at [zmq] parse"); return Err(TomlError::Parse("[None] at [zmq] parse")) }, }; let node = Node { @@ -470,17 +479,27 @@ impl Pool { }; let size = pools.keys().len(); let mut vec = Vec::with_capacity(size); + // We have to do [.as_str()] -> [.to_string()] to get rid of the \"...\" that gets added on. for (key, values) in pools.iter() { let rig = match values.get("rig") { - Some(rig) => rig.to_string(), + Some(rig) => match rig.as_str() { + Some(rig) => rig.to_string(), + None => { error!("Pool | [None] at [rig] parse"); return Err(TomlError::Parse("[None] at [rig] parse")) }, + }, None => { error!("Pool | [None] at [rig] parse"); return Err(TomlError::Parse("[None] at [rig] parse")) }, }; let ip = match values.get("ip") { - Some(ip) => ip.to_string(), + Some(ip) => match ip.as_str() { + Some(ip) => ip.to_string(), + None => { error!("Pool | [None] at [ip] parse"); return Err(TomlError::Parse("[None] at [ip] parse")) }, + }, None => { error!("Pool | [None] at [ip] parse"); return Err(TomlError::Parse("[None] at [ip] parse")) }, }; let port = match values.get("port") { - Some(port) => port.to_string(), + Some(port) => match port.as_str() { + Some(port) => port.to_string(), + None => { error!("Pool | [None] at [port] parse"); return Err(TomlError::Parse("[None] at [port] parse")) }, + }, None => { error!("Pool | [None] at [port] parse"); return Err(TomlError::Parse("[None] at [port] parse")) }, }; let pool = Pool { diff --git a/src/main.rs b/src/main.rs index a99a97c..cde3df4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1308,7 +1308,7 @@ impl eframe::App for App { ui.group(|ui| { ui.set_enabled(self.diff); let width = width / 2.0; - if key.is_r() && !wants_input || ui.add_sized([width, height], Button::new("Reset")).on_hover_text("Reset changes").clicked() { + if key.is_r() && !wants_input && self.diff || ui.add_sized([width, height], Button::new("Reset")).on_hover_text("Reset changes").clicked() { let og = self.og.lock().unwrap().clone(); self.state.gupax = og.gupax; self.state.p2pool = og.p2pool; @@ -1316,7 +1316,7 @@ impl eframe::App for App { self.node_vec = self.og_node_vec.clone(); self.pool_vec = self.og_pool_vec.clone(); } - if key.is_s() && !wants_input || ui.add_sized([width, height], Button::new("Save")).on_hover_text("Save changes").clicked() { + if key.is_s() && !wants_input && self.diff || ui.add_sized([width, height], Button::new("Save")).on_hover_text("Save changes").clicked() { match State::save(&mut self.state, &self.state_path) { Ok(_) => { let mut og = self.og.lock().unwrap(); diff --git a/src/sudo.rs b/src/sudo.rs index f3f349b..19645cf 100644 --- a/src/sudo.rs +++ b/src/sudo.rs @@ -165,7 +165,7 @@ impl SudoState { }, } } - if let Err(e) = sudo.kill() { error!("Sudo | Kill error: {}", e); } + if let Err(e) = sudo.kill() { warn!("Sudo | Kill error (it probably already exited): {}", e); } if state.lock().unwrap().success { match state.lock().unwrap().signal { ProcessSignal::Restart => crate::helper::Helper::restart_xmrig(&helper, &xmrig, &path, Arc::clone(&state)),