From: tobtoht Date: Wed, 22 Jun 2022 19:06:32 +0000 (+0200) Subject: Portable mode: set ringdb path X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=1ae80093293a831dea56c056f34f0548e642da26;p=gamesguru%2Ffeather.git Portable mode: set ringdb path --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a3673ca..735bfe9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ if(DEBUG) set(CMAKE_VERBOSE_MAKEFILE ON) endif() -set(MONERO_HEAD "2ab81abe7bea16f0f6da55da3b212f9ffbca8dcd") +set(MONERO_HEAD "4982ac420c101be2afb387138c4ee57b1a5c2f9b") set(BUILD_GUI_DEPS ON) option(ARCH "Target architecture" "native") set(BUILD_64 ON) diff --git a/monero b/monero index 2ab81abe..4982ac42 160000 --- a/monero +++ b/monero @@ -1 +1 @@ -Subproject commit 2ab81abe7bea16f0f6da55da3b212f9ffbca8dcd +Subproject commit 4982ac420c101be2afb387138c4ee57b1a5c2f9b diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 569f13f6..d4f2fec8 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -159,7 +159,7 @@ void Settings::setupNodeTab() { void Settings::setupPathsTab() { ui->lineEdit_defaultWalletDir->setText(config()->get(Config::walletDirectory).toString()); ui->lineEdit_configDir->setText(Config::defaultConfigDir().path()); - ui->lineEdit_applicationDir->setText(QCoreApplication::applicationDirPath()); + ui->lineEdit_applicationDir->setText(Utils::applicationPath()); connect(ui->btn_browseDefaultWalletDir, &QPushButton::clicked, [this]{ QString walletDirOld = config()->get(Config::walletDirectory).toString(); diff --git a/src/WindowManager.cpp b/src/WindowManager.cpp index 414eb84d..64978a38 100644 --- a/src/WindowManager.cpp +++ b/src/WindowManager.cpp @@ -156,7 +156,7 @@ void WindowManager::tryOpenWallet(const QString &path, const QString &password) } m_openingWallet = true; - m_walletManager->openWalletAsync(path, password, constants::networkType, 1); + m_walletManager->openWalletAsync(path, password, constants::networkType, constants::kdfRounds, Utils::ringDatabasePath()); } void WindowManager::onWalletOpened(Wallet *wallet) { diff --git a/src/cli.cpp b/src/cli.cpp index 79c4cd4c..0ca825c0 100644 --- a/src/cli.cpp +++ b/src/cli.cpp @@ -9,6 +9,7 @@ #include "model/AddressBookModel.h" #include "model/TransactionHistoryModel.h" #include "utils/brute.h" +#include "utils/Utils.h" #include "constants.h" CLI::CLI(Mode mode, QCommandLineParser *cmdargs, QObject *parent) @@ -34,7 +35,7 @@ CLI::CLI(Mode mode, QCommandLineParser *cmdargs, QObject *parent) QString password = cmdargs->value("password"); - m_walletManager->openWalletAsync(walletFile, password, constants::networkType); + m_walletManager->openWalletAsync(walletFile, password, constants::networkType, constants::kdfRounds, Utils::ringDatabasePath()); } else if (mode == Mode::BruteforcePassword) { diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 109f8c96..3273e689 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -74,7 +74,7 @@ Wallet *WalletManager::createWallet(const QString &path, const QString &password return new Wallet(w); } -Wallet *WalletManager::openWallet(const QString &path, const QString &password, NetworkType::Type nettype, quint64 kdfRounds) +Wallet *WalletManager::openWallet(const QString &path, const QString &password, NetworkType::Type nettype, quint64 kdfRounds, const QString &ringDatabasePath) { QMutexLocker locker(&m_mutex); WalletPassphraseListenerImpl tmpListener(this); @@ -88,7 +88,7 @@ Wallet *WalletManager::openWallet(const QString &path, const QString &password, qDebug() << QString("%1: opening wallet at %2, nettype = %3 ").arg(__PRETTY_FUNCTION__).arg(qPrintable(path)).arg(nettype); - Monero::Wallet * w = m_pimpl->openWallet(path.toStdString(), password.toStdString(), static_cast(nettype), kdfRounds, &tmpListener); + Monero::Wallet * w = m_pimpl->openWallet(path.toStdString(), password.toStdString(), static_cast(nettype), kdfRounds, ringDatabasePath.toStdString(), &tmpListener); w->setListener(nullptr); qDebug() << QString("%1: opened wallet: %2, status: %3").arg(__PRETTY_FUNCTION__).arg(w->address(0, 0).c_str()).arg(w->status()); @@ -102,10 +102,10 @@ Wallet *WalletManager::openWallet(const QString &path, const QString &password, return wallet; } -void WalletManager::openWalletAsync(const QString &path, const QString &password, NetworkType::Type nettype, quint64 kdfRounds) +void WalletManager::openWalletAsync(const QString &path, const QString &password, NetworkType::Type nettype, quint64 kdfRounds, const QString &ringDatabasePath) { - m_scheduler.run([this, path, password, nettype, kdfRounds] { - emit walletOpened(openWallet(path, password, nettype, kdfRounds)); + m_scheduler.run([this, path, password, nettype, kdfRounds, ringDatabasePath] { + emit walletOpened(openWallet(path, password, nettype, kdfRounds, ringDatabasePath)); }); } diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 626ccfce..6390b49b 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -35,13 +35,13 @@ public: * \param nettype - type of network the wallet is running on * \return wallet object pointer */ - Wallet * openWallet(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1); + Wallet * openWallet(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1, const QString &ringDatabasePath = ""); /*! * \brief openWalletAsync - asynchronous version of "openWallet". Returns immediately. "walletOpened" signal * emitted when wallet opened; */ - void openWalletAsync(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1); + void openWalletAsync(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1, const QString &ringDatabasePath = ""); Wallet * recoveryWallet(const QString &path, const QString &password, const QString &seed, const QString &seed_offset, NetworkType::Type nettype = NetworkType::MAINNET, quint64 restoreHeight = 0, quint64 kdfRounds = 1); diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index 997fb4af..f241f0b6 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -102,6 +102,14 @@ bool dirExists(const QString &path) { return pathDir.exists(); } +QString portablePath() { + return Utils::applicationPath() + "/feather_data"; +} + +bool isPortableMode() { + return Utils::portableFileExists(Utils::applicationPath()); +} + bool portableFileExists(const QString &dir) { QStringList portableFiles = {".portable", ".portable.txt", "portable.txt"}; @@ -111,9 +119,8 @@ bool portableFileExists(const QString &dir) { } QString defaultWalletDir() { - QString portablePath = QCoreApplication::applicationDirPath(); - if (Utils::portableFileExists(portablePath)) { - return portablePath + "/feather_data/wallets"; + if (Utils::isPortableMode()) { + return Utils::portablePath() + "/wallets"; } if (TailsOS::detect()) { @@ -145,13 +152,35 @@ QString defaultWalletDir() { return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/wallets"; } +QString ringDatabasePath() { + if (Utils::isPortableMode()) { + QString suffix = ""; + if (constants::networkType != NetworkType::Type::MAINNET) { + suffix = "-" + Utils::QtEnumToString(constants::networkType); + } + return Utils::portablePath() + "/ringdb" + suffix; + } + return ""; // Use libwallet default +} + QString applicationPath() { - QString applicationPath = qgetenv("APPIMAGE"); - if (!applicationPath.isEmpty()) { - applicationPath = QFileInfo(applicationPath).absoluteDir().path(); - } else { - applicationPath = QCoreApplication::applicationDirPath(); + QString applicationPath = QCoreApplication::applicationDirPath(); + QDir appDir(applicationPath); + +#ifdef Q_OS_MACOS + // applicationDirPath will be inside the app bundle + + if (applicationPath.endsWith("Contents/MacOS")) { + appDir.cd("../../.."); } + return appDir.absolutePath(); +#endif + + QString appimagePath = qgetenv("APPIMAGE"); + if (!appimagePath.isEmpty()) { + return QFileInfo(appimagePath).absoluteDir().path(); + } + return applicationPath; } diff --git a/src/utils/Utils.h b/src/utils/Utils.h index ecdf8063..badd6180 100644 --- a/src/utils/Utils.h +++ b/src/utils/Utils.h @@ -21,8 +21,12 @@ namespace Utils bool pixmapWrite(const QString &path, const QPixmap &pixmap); QStringList fileFind(const QRegularExpression &pattern, const QString &baseDir, int level, int depth, int maxPerDir); - bool dirExists(const QString &path); + QString portablePath(); + bool isPortableMode(); bool portableFileExists(const QString &dir); + QString ringDatabasePath(); + + bool dirExists(const QString &path); QString defaultWalletDir(); QString applicationPath(); diff --git a/src/utils/config.cpp b/src/utils/config.cpp index dfdda028..426f96bf 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -168,9 +168,8 @@ Config::Config(QObject* parent) } QDir Config::defaultConfigDir() { - QString portablePath = QCoreApplication::applicationDirPath(); - if (Utils::portableFileExists(portablePath)) { - return portablePath + "/feather_data"; + if (Utils::isPortableMode()) { + return Utils::portablePath(); } if (TailsOS::detect()) { @@ -204,10 +203,6 @@ QDir Config::defaultConfigDir() { #endif } -QDir Config::defaultPortableConfigDir() { - return QDir(QCoreApplication::applicationDirPath() + "/feather_data"); -} - Config::~Config() { } diff --git a/src/utils/config.h b/src/utils/config.h index f0131ae9..cc3ca7ff 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -123,7 +123,6 @@ public: void resetToDefaults(); static QDir defaultConfigDir(); - static QDir defaultPortableConfigDir(); static Config* instance();