Skip to content

Commit

Permalink
wizard: Ensure temporary wallet files are deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaqueeee committed Jan 3, 2017
1 parent d8f9e73 commit ba8decc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
12 changes: 12 additions & 0 deletions oshelper.cpp
@@ -1,6 +1,8 @@
#include "oshelper.h"
#include <QTemporaryFile>
#include <QDir>
#include <QDebug>
#include <QString>

OSHelper::OSHelper(QObject *parent) : QObject(parent)
{
Expand All @@ -18,6 +20,16 @@ QString OSHelper::temporaryFilename() const
return tempFileName;
}

bool OSHelper::removeTemporaryWallet(const QString &fileName) const
{
// Temporary files should be deleted automatically by default, in case they wouldn't, we delete them manually as well
bool cache_deleted = QFile::remove(fileName);
bool address_deleted = QFile::remove(fileName + ".address.txt");
bool keys_deleted = QFile::remove(fileName +".keys");

return cache_deleted && address_deleted && keys_deleted;
}

QString OSHelper::temporaryPath() const
{
return QDir::tempPath();
Expand Down
1 change: 1 addition & 0 deletions oshelper.h
Expand Up @@ -13,6 +13,7 @@ class OSHelper : public QObject

Q_INVOKABLE QString temporaryFilename() const;
Q_INVOKABLE QString temporaryPath() const;
Q_INVOKABLE bool removeTemporaryWallet(const QString &walletName) const;

signals:

Expand Down
8 changes: 4 additions & 4 deletions wizard/WizardCreateWallet.qml
Expand Up @@ -82,16 +82,16 @@ Item {
console.log("deleting wallet")
}

var wallet_filename = oshelper.temporaryFilename();
//var wallet = walletManager.createWallet(wallet_filename, "", settingsObject.language)
var tmp_wallet_filename = oshelper.temporaryFilename();
console.log("Creating temporary wallet", tmp_wallet_filename)
var testnet = appWindow.persistentSettings.testnet;
var wallet = walletManager.createWallet(wallet_filename, "", settingsObject.wallet_language,
var wallet = walletManager.createWallet(tmp_wallet_filename, "", settingsObject.wallet_language,
testnet)
uiItem.wordsTextItem.memoText = wallet.seed
// saving wallet in "global" settings object
// TODO: wallet should have a property pointing to the file where it stored or loaded from
settingsObject.wallet = wallet
settingsObject.wallet_filename = wallet_filename
settingsObject.tmp_wallet_filename = tmp_wallet_filename
}

WizardManageWalletUI {
Expand Down
17 changes: 6 additions & 11 deletions wizard/WizardMain.qml
Expand Up @@ -174,18 +174,14 @@ Rectangle {

//! actually writes the wallet
function applySettings() {
console.log("Here we apply the settings");
// here we need to actually move wallet to the new location
console.log(settings.wallet_full_path);

// Save wallet files in user specified location
var new_wallet_filename = createWalletPath(settings.wallet_path,settings.account_name)

console.log("saving in wizard: "+ new_wallet_filename)
// moving wallet files to the new destination, if user changed it
if (new_wallet_filename !== settings.wallet_filename) {
// using previously saved wallet;
settings.wallet.store(new_wallet_filename);
}
settings.wallet.store(new_wallet_filename);

// make sure temporary wallet files are deleted
console.log("Removing temporary wallet: "+ settings.tmp_wallet_filename)
oshelper.removeTemporaryWallet(settings.tmp_wallet_filename)

// protecting wallet with password
settings.wallet.setPassword(settings.wallet_password);
Expand All @@ -209,7 +205,6 @@ Rectangle {
appWindow.persistentSettings.restore_height = (isNaN(settings.restore_height))? 0 : settings.restore_height
appWindow.persistentSettings.is_recovering = (settings.is_recovering === undefined)? false : settings.is_recovering


}

// reading settings from persistent storage
Expand Down
5 changes: 4 additions & 1 deletion wizard/WizardRecoveryWallet.qml
Expand Up @@ -73,11 +73,14 @@ Item {
function recoveryWallet(settingsObject) {
var testnet = appWindow.persistentSettings.testnet;
var restoreHeight = settingsObject.restore_height;
var wallet = walletManager.recoveryWallet(oshelper.temporaryFilename(), settingsObject.words, testnet, restoreHeight);
var tmp_wallet_filename = oshelper.temporaryFilename()
console.log("Creating temporary wallet", tmp_wallet_filename)
var wallet = walletManager.recoveryWallet(tmp_wallet_filename, settingsObject.words, testnet, restoreHeight);
var success = wallet.status === Wallet.Status_Ok;
if (success) {
settingsObject['wallet'] = wallet;
settingsObject['is_recovering'] = true;
settingsObject['tmp_wallet_filename'] = tmp_wallet_filename
} else {
walletManager.closeWallet();
}
Expand Down

0 comments on commit ba8decc

Please sign in to comment.