mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-12-22 19:49:34 +00:00
wizard: Ensure temporary wallet files are deleted
This commit is contained in:
parent
d8f9e7360f
commit
ba8decca3f
5 changed files with 27 additions and 16 deletions
12
oshelper.cpp
12
oshelper.cpp
|
@ -1,6 +1,8 @@
|
||||||
#include "oshelper.h"
|
#include "oshelper.h"
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
OSHelper::OSHelper(QObject *parent) : QObject(parent)
|
OSHelper::OSHelper(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
@ -18,6 +20,16 @@ QString OSHelper::temporaryFilename() const
|
||||||
return tempFileName;
|
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
|
QString OSHelper::temporaryPath() const
|
||||||
{
|
{
|
||||||
return QDir::tempPath();
|
return QDir::tempPath();
|
||||||
|
|
|
@ -13,6 +13,7 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE QString temporaryFilename() const;
|
Q_INVOKABLE QString temporaryFilename() const;
|
||||||
Q_INVOKABLE QString temporaryPath() const;
|
Q_INVOKABLE QString temporaryPath() const;
|
||||||
|
Q_INVOKABLE bool removeTemporaryWallet(const QString &walletName) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
|
@ -82,16 +82,16 @@ Item {
|
||||||
console.log("deleting wallet")
|
console.log("deleting wallet")
|
||||||
}
|
}
|
||||||
|
|
||||||
var wallet_filename = oshelper.temporaryFilename();
|
var tmp_wallet_filename = oshelper.temporaryFilename();
|
||||||
//var wallet = walletManager.createWallet(wallet_filename, "", settingsObject.language)
|
console.log("Creating temporary wallet", tmp_wallet_filename)
|
||||||
var testnet = appWindow.persistentSettings.testnet;
|
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)
|
testnet)
|
||||||
uiItem.wordsTextItem.memoText = wallet.seed
|
uiItem.wordsTextItem.memoText = wallet.seed
|
||||||
// saving wallet in "global" settings object
|
// saving wallet in "global" settings object
|
||||||
// TODO: wallet should have a property pointing to the file where it stored or loaded from
|
// TODO: wallet should have a property pointing to the file where it stored or loaded from
|
||||||
settingsObject.wallet = wallet
|
settingsObject.wallet = wallet
|
||||||
settingsObject.wallet_filename = wallet_filename
|
settingsObject.tmp_wallet_filename = tmp_wallet_filename
|
||||||
}
|
}
|
||||||
|
|
||||||
WizardManageWalletUI {
|
WizardManageWalletUI {
|
||||||
|
|
|
@ -174,18 +174,14 @@ Rectangle {
|
||||||
|
|
||||||
//! actually writes the wallet
|
//! actually writes the wallet
|
||||||
function applySettings() {
|
function applySettings() {
|
||||||
console.log("Here we apply the settings");
|
// Save wallet files in user specified location
|
||||||
// here we need to actually move wallet to the new location
|
|
||||||
console.log(settings.wallet_full_path);
|
|
||||||
|
|
||||||
var new_wallet_filename = createWalletPath(settings.wallet_path,settings.account_name)
|
var new_wallet_filename = createWalletPath(settings.wallet_path,settings.account_name)
|
||||||
|
|
||||||
console.log("saving in wizard: "+ new_wallet_filename)
|
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
|
// protecting wallet with password
|
||||||
settings.wallet.setPassword(settings.wallet_password);
|
settings.wallet.setPassword(settings.wallet_password);
|
||||||
|
@ -209,7 +205,6 @@ Rectangle {
|
||||||
appWindow.persistentSettings.restore_height = (isNaN(settings.restore_height))? 0 : settings.restore_height
|
appWindow.persistentSettings.restore_height = (isNaN(settings.restore_height))? 0 : settings.restore_height
|
||||||
appWindow.persistentSettings.is_recovering = (settings.is_recovering === undefined)? false : settings.is_recovering
|
appWindow.persistentSettings.is_recovering = (settings.is_recovering === undefined)? false : settings.is_recovering
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// reading settings from persistent storage
|
// reading settings from persistent storage
|
||||||
|
|
|
@ -73,11 +73,14 @@ Item {
|
||||||
function recoveryWallet(settingsObject) {
|
function recoveryWallet(settingsObject) {
|
||||||
var testnet = appWindow.persistentSettings.testnet;
|
var testnet = appWindow.persistentSettings.testnet;
|
||||||
var restoreHeight = settingsObject.restore_height;
|
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;
|
var success = wallet.status === Wallet.Status_Ok;
|
||||||
if (success) {
|
if (success) {
|
||||||
settingsObject['wallet'] = wallet;
|
settingsObject['wallet'] = wallet;
|
||||||
settingsObject['is_recovering'] = true;
|
settingsObject['is_recovering'] = true;
|
||||||
|
settingsObject['tmp_wallet_filename'] = tmp_wallet_filename
|
||||||
} else {
|
} else {
|
||||||
walletManager.closeWallet();
|
walletManager.closeWallet();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue