From 0bce364f0bdcee9cffbc70451014be56600b840a Mon Sep 17 00:00:00 2001 From: adityapk00 Date: Sun, 18 Nov 2018 18:55:24 -0800 Subject: [PATCH] Add backup wallet option --- src/connection.cpp | 3 ++- src/connection.h | 1 + src/mainwindow.cpp | 23 +++++++++++++++++++++++ src/mainwindow.h | 2 ++ src/mainwindow.ui | 14 ++++++++++---- src/settings.h | 6 +++--- 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index 7768ffd..e980fc3 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -478,6 +478,7 @@ std::shared_ptr ConnectionLoader::autoDetectZcashConf() { zcashconf->host = "127.0.0.1"; zcashconf->connType = ConnectionType::DetectedConfExternalZcashD; zcashconf->usingZcashConf = true; + zcashconf->zcashDir = QFileInfo(confLocation).absoluteDir().absolutePath(); Settings::getInstance()->setUsingZcashConf(confLocation); @@ -526,7 +527,7 @@ std::shared_ptr ConnectionLoader::loadFromSettings() { if (username.isEmpty() || password.isEmpty()) return nullptr; - auto uiConfig = new ConnectionConfig{ host, port, username, password, false, ConnectionType::UISettingsZCashD }; + auto uiConfig = new ConnectionConfig{ host, port, username, password, false, "", ConnectionType::UISettingsZCashD}; return std::shared_ptr(uiConfig); } diff --git a/src/connection.h b/src/connection.h index cafd196..b072939 100644 --- a/src/connection.h +++ b/src/connection.h @@ -21,6 +21,7 @@ struct ConnectionConfig { QString rpcuser; QString rpcpassword; bool usingZcashConf; + QString zcashDir; ConnectionType connType; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fbfcb01..c0b73a6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -48,6 +48,9 @@ MainWindow::MainWindow(QWidget *parent) : // Export All Private Keys QObject::connect(ui->actionExport_All_Private_Keys, &QAction::triggered, this, &MainWindow::exportAllKeys); + // Backup wallet.dat + QObject::connect(ui->actionBackup_wallet_dat, &QAction::triggered, this, &MainWindow::backupWalletDat); + // z-Board.net QObject::connect(ui->actionz_board_net, &QAction::triggered, this, &MainWindow::postToZBoard); @@ -633,6 +636,26 @@ void MainWindow::importPrivKey() { } } +void MainWindow::backupWalletDat() { + QFile wallet(QDir(rpc->getConnection()->config->zcashDir).filePath("wallet.dat")); + if (!wallet.exists()) { + QMessageBox::critical(this, "No wallet.dat", "Couldn't find the wallet.dat on this computer." + "You need to backup it up from the machine zcashd is running on", QMessageBox::Ok); + return; + } + + QUrl backupName = QFileDialog::getSaveFileUrl(this, "Backup wallet.dat", + "zcash-wallet-backup-" + QDateTime::currentDateTime().toString("yyyyMMdd") + ".dat", + "Data file (*.dat)"); + if (backupName.isEmpty()) + return; + + if (!wallet.copy(backupName.toLocalFile())) { + QMessageBox::critical(this, "Couldn't backup", "Couldn't backup the wallet.dat file." + "You need to backup it up manually.", QMessageBox::Ok); + } +} + void MainWindow::exportAllKeys() { QDialog d(this); Ui_PrivKey pui; diff --git a/src/mainwindow.h b/src/mainwindow.h index 81914b9..237aa4d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -89,6 +89,8 @@ private: void postToZBoard(); void importPrivKey(); void exportAllKeys(); + void backupWalletDat(); + void doImport(QList* keys); void restoreSavedStates(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 8bee872..4fbcf14 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -316,8 +316,8 @@ 0 0 - 920 - 334 + 928 + 380 @@ -849,7 +849,7 @@ 0 0 968 - 22 + 19 @@ -858,6 +858,7 @@ + @@ -932,7 +933,7 @@ - Export all private keys + &Export all private keys @@ -951,6 +952,11 @@ Ctrl+B + + + &Backup wallet.dat + + diff --git a/src/settings.h b/src/settings.h index 42614d3..0745dba 100644 --- a/src/settings.h +++ b/src/settings.h @@ -16,8 +16,8 @@ struct Tx; class Settings { public: - static Settings* init(); - static Settings* getInstance(); + static Settings* init(); + static Settings* getInstance(); Config getSettings(); void saveSettings(const QString& host, const QString& port, const QString& username, const QString& password); @@ -78,7 +78,7 @@ public: static const int updateSpeed = 20 * 1000; // 20 sec static const int quickUpdateSpeed = 5 * 1000; // 5 sec - static const int priceRefreshSpeed = 60 * 60 * 1000; // 1 hr + static const int priceRefreshSpeed = 60 * 60 * 1000; // 1 hr private: // This class can only be accessed through Settings::getInstance()