Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass argsmanager reference to intro instead of relying on global #75

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <node/ui_interface.h>
#include <noui.h>
#include <uint256.h>
#include <util/check.h>
#include <util/system.h>
#include <util/threadnames.h>
#include <util/translation.h>
Expand Down Expand Up @@ -469,6 +470,7 @@ int GuiMain(int argc, char* argv[])
/// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these
// Command-line options take precedence:
SetupServerArgs(node_context);
ArgsManager& args = *Assert(node_context.args);
SetupUIArgs(gArgs);
std::string error;
if (!gArgs.ParseParameters(argc, argv, error)) {
Expand Down Expand Up @@ -508,7 +510,7 @@ int GuiMain(int argc, char* argv[])
bool did_show_intro = false;
bool prune = false; // Intro dialog prune check box
// Gracefully exit if the user cancels
if (!Intro::showIfNeeded(did_show_intro, prune)) return EXIT_SUCCESS;
if (!Intro::showIfNeeded(args, did_show_intro, prune)) return EXIT_SUCCESS;

/// 6. Determine availability of data directory and parse bitcoin.conf
/// - Do not call GetDataDir(true) before this step finishes
Expand Down
41 changes: 22 additions & 19 deletions src/qt/intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,22 @@ void FreespaceChecker::check()

namespace {
//! Return pruning size that will be used if automatic pruning is enabled.
int GetPruneTargetGB()
int GetPruneTargetGB(const ArgsManager& args)
{
int64_t prune_target_mib = gArgs.GetArg("-prune", 0);
int64_t prune_target_mib = args.GetArg("-prune", 0);
// >1 means automatic pruning is enabled by config, 1 means manual pruning, 0 means no pruning.
return prune_target_mib > 1 ? PruneMiBtoGB(prune_target_mib) : DEFAULT_PRUNE_TARGET_GB;
}
} // namespace

Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_size_gb) :
QDialog(parent),
ui(new Ui::Intro),
thread(nullptr),
signalled(false),
m_blockchain_size_gb(blockchain_size_gb),
m_chain_state_size_gb(chain_state_size_gb),
m_prune_target_gb{GetPruneTargetGB()}
Intro::Intro(const ArgsManager& args, QWidget* parent, int64_t blockchain_size_gb, int64_t chain_state_size_gb)
: QDialog(parent),
ui(new Ui::Intro),
thread(nullptr),
signalled(false),
m_blockchain_size_gb(blockchain_size_gb),
m_chain_state_size_gb(chain_state_size_gb),
m_prune_target_gb{GetPruneTargetGB(args)}
{
ui->setupUi(this);
ui->welcomeLabel->setText(ui->welcomeLabel->text().arg(PACKAGE_NAME));
Expand All @@ -139,7 +139,7 @@ Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_si
);
ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(PACKAGE_NAME));

if (gArgs.GetArg("-prune", 0) > 1) { // -prune=1 means enabled, above that it's a size in MiB
if (args.GetArg("-prune", 0) > 1) { // -prune=1 means enabled, above that it's a size in MiB
ui->prune->setChecked(true);
ui->prune->setEnabled(false);
}
Expand Down Expand Up @@ -182,31 +182,34 @@ void Intro::setDataDirectory(const QString &dataDir)
}
}

bool Intro::showIfNeeded(bool& did_show_intro, bool& prune)
bool Intro::showIfNeeded(ArgsManager& args, bool& did_show_intro, bool& prune)
{
did_show_intro = false;

QSettings settings;
/* If data directory provided on command line, no need to look at settings
or show a picking dialog */
if(!gArgs.GetArg("-datadir", "").empty())
if (!args.GetArg("-datadir", "").empty()) {
return true;
}
/* 1) Default data directory for operating system */
QString dataDir = GUIUtil::getDefaultDataDirectory();
/* 2) Allow QSettings to override default dir */
dataDir = settings.value("strDataDir", dataDir).toString();

if(!fs::exists(GUIUtil::qstringToBoostPath(dataDir)) || gArgs.GetBoolArg("-choosedatadir", DEFAULT_CHOOSE_DATADIR) || settings.value("fReset", false).toBool() || gArgs.GetBoolArg("-resetguisettings", false))
{
if (!fs::exists(GUIUtil::qstringToBoostPath(dataDir)) ||
args.GetBoolArg("-choosedatadir", DEFAULT_CHOOSE_DATADIR) ||
settings.value("fReset", false).toBool() ||
args.GetBoolArg("-resetguisettings", false)) {
/* Use selectParams here to guarantee Params() can be used by node interface */
try {
SelectParams(gArgs.GetChainName());
SelectParams(args.GetChainName());
} catch (const std::exception&) {
return false;
}

/* If current default data directory does not exist, let the user choose one */
Intro intro(0, Params().AssumedBlockchainSize(), Params().AssumedChainStateSize());
Intro intro(args, nullptr, Params().AssumedBlockchainSize(), Params().AssumedChainStateSize());
intro.setDataDirectory(dataDir);
intro.setWindowIcon(QIcon(":icons/bitcoin"));
did_show_intro = true;
Expand Down Expand Up @@ -242,8 +245,8 @@ bool Intro::showIfNeeded(bool& did_show_intro, bool& prune)
* override -datadir in the bitcoin.conf file in the default data directory
* (to be consistent with bitcoind behavior)
*/
if(dataDir != GUIUtil::getDefaultDataDirectory()) {
gArgs.SoftSetArg("-datadir", GUIUtil::qstringToBoostPath(dataDir).string()); // use OS locale for path setting
if (dataDir != GUIUtil::getDefaultDataDirectory()) {
args.SoftSetArg("-datadir", GUIUtil::qstringToBoostPath(dataDir).string()); // use OS locale for path setting
}
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/qt/intro.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

static const bool DEFAULT_CHOOSE_DATADIR = false;

class ArgsManager;
class FreespaceChecker;

namespace interfaces {
Expand All @@ -30,8 +31,7 @@ class Intro : public QDialog
Q_OBJECT

public:
explicit Intro(QWidget *parent = nullptr,
int64_t blockchain_size_gb = 0, int64_t chain_state_size_gb = 0);
explicit Intro(const ArgsManager& args, QWidget* parent = nullptr, int64_t blockchain_size_gb = 0, int64_t chain_state_size_gb = 0);
~Intro();

QString getDataDirectory();
Expand All @@ -47,7 +47,7 @@ class Intro : public QDialog
* @note do NOT call global GetDataDir() before calling this function, this
* will cause the wrong path to be cached.
*/
static bool showIfNeeded(bool& did_show_intro, bool& prune);
static bool showIfNeeded(ArgsManager& args, bool& did_show_intro, bool& prune);
maflcko marked this conversation as resolved.
Show resolved Hide resolved

Q_SIGNALS:
void requestCheck();
Expand Down