From 8903dedaf556d0032b4f72e76b78fc0b58b44e0d Mon Sep 17 00:00:00 2001 From: edouard Date: Tue, 8 Nov 2022 18:11:05 +0100 Subject: [PATCH] fix installer: check if setup exists before install --- gui/src/installer/mod.rs | 2 +- gui/src/installer/step/mod.rs | 19 ++++++++++--------- gui/src/installer/view.rs | 16 ++++++++++------ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/gui/src/installer/mod.rs b/gui/src/installer/mod.rs index 60d52124..4b425bcc 100644 --- a/gui/src/installer/mod.rs +++ b/gui/src/installer/mod.rs @@ -50,7 +50,7 @@ impl Installer { should_exit: false, current: 0, steps: vec![ - Welcome::new(network).into(), + Welcome::new(network, destination_path.clone()).into(), DefineDescriptor::new().into(), RegisterDescriptor::default().into(), DefineBitcoind::new().into(), diff --git a/gui/src/installer/step/mod.rs b/gui/src/installer/step/mod.rs index f8add589..38ab8c2a 100644 --- a/gui/src/installer/step/mod.rs +++ b/gui/src/installer/step/mod.rs @@ -63,11 +63,18 @@ impl Context { pub struct Welcome { network: bitcoin::Network, + data_dir: PathBuf, } impl Welcome { - pub fn new(network: bitcoin::Network) -> Self { - Self { network } + pub fn new(network: bitcoin::Network, data_dir: PathBuf) -> Self { + Self { network, data_dir } + } + + fn valid(&self) -> bool { + let mut network_datadir = self.data_dir.clone(); + network_datadir.push(self.network.to_string()); + !network_datadir.exists() } } @@ -83,13 +90,7 @@ impl Step for Welcome { true } fn view(&self) -> Element { - view::welcome(&self.network) - } -} - -impl Default for Welcome { - fn default() -> Self { - Self::new(bitcoin::Network::Bitcoin) + view::welcome(&self.network, self.valid()) } } diff --git a/gui/src/installer/view.rs b/gui/src/installer/view.rs index 93047802..6940dbea 100644 --- a/gui/src/installer/view.rs +++ b/gui/src/installer/view.rs @@ -27,17 +27,21 @@ const NETWORKS: [bitcoin::Network; 4] = [ bitcoin::Network::Regtest, ]; -pub fn welcome(network: &bitcoin::Network) -> Element { +pub fn welcome(network: &bitcoin::Network, valid: bool) -> Element { container(container( column() .push(container( pick_list(&NETWORKS[..], Some(*network), message::Message::Network).padding(10), )) - .push( - button::primary(None, "Install") - .on_press(Message::Next) - .width(Length::Units(200)), - ) + .push(if valid { + container( + button::primary(None, "Start the install") + .on_press(Message::Next) + .width(Length::Units(200)), + ) + } else { + card::warning("A data directory already exists for this network") + }) .width(Length::Fill) .height(Length::Fill) .padding(100)