From 6ff16af175c6d39b04aa6829fa739d667619c5de Mon Sep 17 00:00:00 2001 From: Cyrix126 Date: Wed, 11 Dec 2024 23:51:46 +0100 Subject: [PATCH] fix: checking of valid path before starting, correct hover text for windows --- src/app/panels/bottom.rs | 22 ++++++++++++++-------- src/components/update.rs | 4 ++-- src/utils/constants.rs | 8 ++++++-- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/app/panels/bottom.rs b/src/app/panels/bottom.rs index 07d3bae..fc51fd2 100644 --- a/src/app/panels/bottom.rs +++ b/src/app/panels/bottom.rs @@ -565,8 +565,10 @@ impl crate::app::App { let path = match name { ProcessName::Node => { // check path of DB valid, empty valid. - if !Gupax::path_is_file(&self.state.node.path_db) { - return Err(format!("Error: {}", NODE_PATH_NOT_FILE)); + if !self.state.node.path_db.is_empty() + && !Gupax::path_is_file(&self.state.node.path_db) + { + return Err(format!("Error: {}", NODE_DB_DIR)); } &self.state.gupax.node_path } @@ -587,13 +589,17 @@ impl crate::app::App { } }; // check path of binary except for XvB - if name != ProcessName::Xvb && !crate::components::update::check_binary_path(path, name) { - let msg_error = format!( - "{name} binary at the given PATH in the Gupaxx tab doesn't look like {name}! To fix: goto the [Gupaxx Advanced] tab, select [Open] and specify where {name} is located." - ); - return Err(msg_error); + if name != ProcessName::Xvb { + if path.is_empty() { + return Err(name.msg_binary_path_empty().to_string()); + } + if !Gupax::path_is_file(path) { + return Err(name.msg_binary_path_not_file().to_string()); + } + if !crate::components::update::check_binary_path(path, name) { + return Err(name.msg_binary_path_invalid().to_string()); + } } - Ok(()) } } diff --git a/src/components/update.rs b/src/components/update.rs index f7fa2fb..f05f051 100644 --- a/src/components/update.rs +++ b/src/components/update.rs @@ -144,14 +144,14 @@ pub fn check_binary_path(path: &str, process: ProcessName) -> bool { Ok(p) => p, Err(_) => return false, }; - let path = match path.file_name() { + let filename = match path.file_name() { Some(p) => p, None => { error!("Couldn't get {process} file name"); return false; } }; - path == process.binary_name() + filename == process.binary_name() } //---------------------------------------------------------------------------------------------------- Update struct/impl diff --git a/src/utils/constants.rs b/src/utils/constants.rs index 9558312..c75749e 100644 --- a/src/utils/constants.rs +++ b/src/utils/constants.rs @@ -430,9 +430,13 @@ pub const LIST_CLEAR: &str = "Clear all current values"; pub const NODE_ARGUMENTS: &str = r#"WARNING: Make sure to set [--zmq-pub ] so that P2Pool can connect to it !"#; pub const NODE_INPUT: &str = "Send a command to Node"; pub const NODE_PRUNNING: &str = "Reduce the database size to a third. Does not have any security/privacy impact.If you have enough storage, a full node is preferable to make the network even more decentralized."; +#[cfg(not(windows))] pub const NODE_DB_PATH_EMPTY: &str = "If the PATH of the DB is empty, the default ~/.bitmonero will be used."; -pub const NODE_DB_DIR: &str = "The PATH needs to be a correct path to a directory"; +#[cfg(windows)] +pub const NODE_DB_PATH_EMPTY: &str = + r#"If the PATH of the DB is empty, the default C:\ProgramData\bitmonero will be used."#; +pub const NODE_DB_DIR: &str = "The DB path needs to be a correct path to a directory if not empty"; pub const NODE_SIMPLE: &str = r#"Use simple Node settings: - Default Node settings"#; pub const NODE_ADVANCED: &str = r#"Use advanced Node settings: @@ -445,7 +449,7 @@ pub const NODE_ADVANCED: &str = r#"Use advanced Node settings: - Log level setting - Disable DNS checkpoint - DNS blocking"#; -pub const GUPAX_PATH_NODE: &str = "The location of the DB for the Node: Both absolute and relative paths are accepted; A red [X] will appear if there is no directory found at the given path"; +pub const GUPAX_PATH_NODE: &str = "The location of the Node binary: Both absolute and relative paths are accepted; A red [X] will appear if there is no directory found at the given path"; pub const NODE_PATH_OK: &str = "PATH for DB is valid."; pub const NODE_PATH_NOT_FILE: &str = "Node binary not found at the given PATH in the Gupaxx tab! To fix: goto the [Gupaxx Advanced] tab, select [Open] and specify where NODE is located."; pub const NODE_PATH_NOT_VALID: &str = "Node binary at the given PATH in the Gupaxx tab doesn't look like Node! To fix: goto the [Gupaxx Advanced] tab, select [Open] and specify where Node is located.";