Allow opening multiple windows

This commit is contained in:
tobtoht
2021-05-18 18:08:40 +02:00
parent cc01924858
commit f43949a346
110 changed files with 1839 additions and 1903 deletions
+66 -66
View File
@@ -9,48 +9,59 @@
#include "model/AddressBookModel.h"
#include "model/TransactionHistoryModel.h"
#include "utils/brute.h"
#include "constants.h"
CLI::CLI(AppContext *ctx, QObject *parent) :
QObject(parent),
ctx(ctx) {
connect(this->ctx, &AppContext::walletOpened, this, &CLI::onWalletOpened);
connect(this->ctx, &AppContext::walletOpenedError, this, &CLI::onWalletOpenedError);
connect(this->ctx, &AppContext::walletOpenPasswordNeeded, this, &CLI::onWalletOpenPasswordRequired);
}
CLI::CLI(Mode mode, QCommandLineParser *cmdargs, QObject *parent)
: QObject(parent)
, m_mode(mode)
, m_cmdargs(cmdargs)
{
m_walletManager = WalletManager::instance();
connect(m_walletManager, &WalletManager::walletOpened, this, &CLI::onWalletOpened);
void CLI::run() {
if (mode == CLIMode::ExportContacts || mode == CLIMode::ExportTxHistory)
if (m_mode == Mode::ExportContacts || m_mode == Mode::ExportTxHistory)
{
if(!ctx->cmdargs->isSet("wallet-file"))
return this->finishedError("--wallet-file argument missing");
if(!ctx->cmdargs->isSet("password"))
return this->finishedError("--password argument missing");
ctx->onOpenWallet(ctx->cmdargs->value("wallet-file"), ctx->cmdargs->value("password"));
if (!cmdargs->isSet("wallet-file")) {
this->finished("--wallet-file argument missing");
return;
}
if (!cmdargs->isSet("password")) {
this->finished("--password argument missing");
return;
}
QString walletFile = cmdargs->value("wallet-file");
QString password = cmdargs->value("password");
m_walletManager->openWalletAsync(walletFile, password, constants::networkType);
}
else if (mode == CLIMode::BruteforcePassword)
else if (mode == Mode::BruteforcePassword)
{
QString keys_file = ctx->cmdargs->value("bruteforce-password");
QString keys_file = m_cmdargs->value("bruteforce-password");
if (!keys_file.endsWith(".keys")) {
return this->finishedError("Wallet file does not end with .keys");
this->finished("Wallet file does not end with .keys");
return;
}
QStringList words;
if (ctx->cmdargs->isSet("bruteforce-dict")) {
QString data = Utils::barrayToString(Utils::fileOpen(ctx->cmdargs->value("bruteforce-dict")));
if (m_cmdargs->isSet("bruteforce-dict")) {
QString data = Utils::barrayToString(Utils::fileOpen(m_cmdargs->value("bruteforce-dict")));
words = data.split("\n");
}
if (!ctx->cmdargs->isSet("bruteforce-chars")) {
return this->finishedError("--bruteforce-chars argument missing");
if (!m_cmdargs->isSet("bruteforce-chars")) {
this->finished("--bruteforce-chars argument missing");
return;
}
QString chars = ctx->cmdargs->value("bruteforce-chars");
QString chars = m_cmdargs->value("bruteforce-chars");
brute b(chars.toStdString());
if (words.isEmpty()) {
qDebug() << "No dictionairy specified, bruteforcing all chars";
while (true) {
QString pass = QString::fromStdString(b.next());
if (ctx->walletManager->verifyWalletPassword(keys_file, pass, false)) {
if (m_walletManager->verifyWalletPassword(keys_file, pass, false)) {
this->finished(QString("Found password: %1").arg(pass));
break;
}
@@ -60,7 +71,7 @@ void CLI::run() {
else {
bruteword bb(chars.toStdString());
bool foundPass = false;
for (auto word: words) {
for (const auto& word: words) {
if (word.isEmpty()) {
continue;
}
@@ -71,7 +82,7 @@ void CLI::run() {
if (pass == "") {
break;
}
if (ctx->walletManager->verifyWalletPassword(keys_file, pass, false)) {
if (m_walletManager->verifyWalletPassword(keys_file, pass, false)) {
this->finished(QString("Found password: %1").arg(pass));
foundPass = true;
break;
@@ -88,50 +99,39 @@ void CLI::run() {
}
}
}
}
void CLI::onWalletOpened() {
if(mode == CLIMode::ExportContacts){
auto *model = ctx->currentWallet->addressBookModel();
auto fn = ctx->cmdargs->value("export-contacts");
if(model->writeCSV(fn))
this->finished(QString("Address book exported to %1").arg(fn));
else
this->finishedError("Address book export failure");
} else if(mode == ExportTxHistory) {
ctx->currentWallet->history()->refresh(ctx->currentWallet->currentSubaddressAccount());
auto *model = ctx->currentWallet->history();
auto fn = ctx->cmdargs->value("export-txhistory");
if(model->writeCSV(fn))
this->finished(QString("Transaction history exported to %1").arg(fn));
else
this->finishedError("Transaction history export failure");
else {
this->finished("Invalid mode");
}
}
void CLI::onWalletOpenedError(const QString &err) {
if(mode == CLIMode::ExportContacts ||
mode == CLIMode::ExportTxHistory)
return this->finishedError(err);
void CLI::onWalletOpened(Wallet *w) {
QScopedPointer<Wallet> wallet{w};
if (wallet->status() != Wallet::Status_Ok) {
this->finished(wallet->errorString());
return;
}
if (m_mode == Mode::ExportContacts) {
auto *model = wallet->addressBookModel();
QString fileName = m_cmdargs->value("export-contacts");
if (model->writeCSV(fileName))
this->finished(QString("Contacts exported to %1").arg(fileName));
else
this->finished("Failed to export contacts");
}
else if (m_mode == Mode::ExportTxHistory) {
wallet->history()->refresh(wallet->currentSubaddressAccount());
auto *model = wallet->history();
QString fileName = m_cmdargs->value("export-txhistory");
if (model->writeCSV(fileName))
this->finished(QString("Transaction history exported to %1").arg(fileName));
else
this->finished("Failed to export transaction history");
}
}
void CLI::onWalletOpenPasswordRequired(bool invalidPassword, const QString &path) {
if(mode == CLIMode::ExportContacts ||
mode == CLIMode::ExportTxHistory)
return this->finishedError("invalid password");
}
void CLI::finished(const QString &msg){
qInfo() << msg;
emit closeApplication();
}
void CLI::finishedError(const QString &err) {
qCritical() << err;
emit closeApplication();
}
CLI::~CLI() {
ctx->disconnect();
delete ctx;
void CLI::finished(const QString &message) {
qInfo() << message;
QApplication::quit();
}