fix installer: check if setup exists before install
This commit is contained in:
parent
9fa4b95847
commit
8903dedaf5
@ -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(),
|
||||
|
||||
@ -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<Message> {
|
||||
view::welcome(&self.network)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Welcome {
|
||||
fn default() -> Self {
|
||||
Self::new(bitcoin::Network::Bitcoin)
|
||||
view::welcome(&self.network, self.valid())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -27,17 +27,21 @@ const NETWORKS: [bitcoin::Network; 4] = [
|
||||
bitcoin::Network::Regtest,
|
||||
];
|
||||
|
||||
pub fn welcome(network: &bitcoin::Network) -> Element<Message> {
|
||||
pub fn welcome(network: &bitcoin::Network, valid: bool) -> Element<Message> {
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user