diff --git a/interface/resources/qml/hifi/commerce/wallet/Wallet.qml b/interface/resources/qml/hifi/commerce/wallet/Wallet.qml index 8cac728dec..63ed5294be 100644 --- a/interface/resources/qml/hifi/commerce/wallet/Wallet.qml +++ b/interface/resources/qml/hifi/commerce/wallet/Wallet.qml @@ -47,7 +47,7 @@ Rectangle { } } else if (walletStatus === 1) { if (root.activeView !== "walletSetup") { - walletSetup(); + walletResetSetup(); } } else if (walletStatus === 2) { if (root.activeView != "preexisting") { @@ -177,12 +177,13 @@ Rectangle { proceedFunction: function (isReset) { console.log(isReset ? "Reset wallet." : "Trying again with new wallet."); if (isReset) { - walletSetup(); + walletResetSetup(); } else { root.activeView = "initialize"; Commerce.getWalletStatus(); } } + copyFunction: Commerce.copyKeyFileFrom; z: 997; visible: (root.activeView === "preexisting") || (root.activeView === "conflicting"); activeView: root.activeView; @@ -789,7 +790,7 @@ Rectangle { }); } - function walletSetup() { + function walletResetSetup() { root.activeView = "walletSetup"; Commerce.resetLocalWalletOnly(); var timestamp = new Date(); diff --git a/interface/resources/qml/hifi/commerce/wallet/WalletChoice.qml b/interface/resources/qml/hifi/commerce/wallet/WalletChoice.qml index 6e191d54e3..47c438f72b 100644 --- a/interface/resources/qml/hifi/commerce/wallet/WalletChoice.qml +++ b/interface/resources/qml/hifi/commerce/wallet/WalletChoice.qml @@ -24,6 +24,7 @@ Item { id: root; property string activeView: "conflict"; property var proceedFunction: nil; + property var copyFunction: nil; Image { anchors.fill: parent; @@ -272,8 +273,11 @@ Item { console.log('WalletChoice.qml ignoring', e); } if (filename) { - console.log("FIXME copy file to the right place"); - proceed(false); + if (copyFunction && copyFunction(filename)) { + proceed(false); + } else { + console.log("WalletChoice.qml copyFunction", copyFunction, "failed."); + } } // Else we're still at WalletChoice } function walletChooser() { diff --git a/interface/src/commerce/QmlCommerce.cpp b/interface/src/commerce/QmlCommerce.cpp index c9caa393ce..d57b94e4dd 100644 --- a/interface/src/commerce/QmlCommerce.cpp +++ b/interface/src/commerce/QmlCommerce.cpp @@ -52,6 +52,11 @@ void QmlCommerce::getKeyFilePathIfExists() { emit keyFilePathIfExistsResult(wallet->getKeyFilePath()); } +bool QmlCommerce::copyKeyFileFrom(const QString& pathname) { + auto wallet = DependencyManager::get(); + return wallet->copyKeyFileFrom(pathname); +} + void QmlCommerce::getWalletAuthenticatedStatus() { auto wallet = DependencyManager::get(); emit walletAuthenticatedStatusResult(wallet->walletIsAuthenticatedWithPassphrase()); diff --git a/interface/src/commerce/QmlCommerce.h b/interface/src/commerce/QmlCommerce.h index b261ee6de6..bf982f5955 100644 --- a/interface/src/commerce/QmlCommerce.h +++ b/interface/src/commerce/QmlCommerce.h @@ -55,6 +55,7 @@ protected: Q_INVOKABLE void getKeyFilePathIfExists(); Q_INVOKABLE void getSecurityImage(); Q_INVOKABLE void getWalletAuthenticatedStatus(); + Q_INVOKABLE bool copyKeyFileFrom(const QString& pathname); Q_INVOKABLE void chooseSecurityImage(const QString& imageFile); Q_INVOKABLE void setPassphrase(const QString& passphrase); diff --git a/interface/src/commerce/Wallet.cpp b/interface/src/commerce/Wallet.cpp index ad3d8725a1..0e566bc019 100644 --- a/interface/src/commerce/Wallet.cpp +++ b/interface/src/commerce/Wallet.cpp @@ -59,6 +59,16 @@ QString keyFilePath() { auto accountManager = DependencyManager::get(); return PathUtils::getAppDataFilePath(QString("%1.%2").arg(accountManager->getAccountInfo().getUsername(), KEY_FILE)); } +bool Wallet::copyKeyFileFrom(const QString& pathname) { + QString existing = getKeyFilePath(); + if (!existing.isEmpty()) { + if (!QFile::rename(existing, existing + ".backup" + QDateTime::currentDateTime().toString(Qt::ISODate))) { + qCCritical(commerce) << "Unable to backup" << existing; + return false; + } + } + return QFile::copy(pathname, keyFilePath()); +} // use the cached _passphrase if it exists, otherwise we need to prompt int passwordCallback(char* password, int maxPasswordSize, int rwFlag, void* u) { diff --git a/interface/src/commerce/Wallet.h b/interface/src/commerce/Wallet.h index fd7aba4adc..9abc1d871b 100644 --- a/interface/src/commerce/Wallet.h +++ b/interface/src/commerce/Wallet.h @@ -35,6 +35,7 @@ public: void chooseSecurityImage(const QString& imageFile); bool getSecurityImage(); QString getKeyFilePath(); + bool copyKeyFileFrom(const QString& pathname); void setSalt(const QByteArray& salt) { _salt = salt; } QByteArray getSalt() { return _salt; }