mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-12-23 12:09:57 +00:00
DaemonManager: support dataDir parameter + validator
This commit is contained in:
parent
0cb6900295
commit
9037eed805
2 changed files with 57 additions and 2 deletions
|
@ -8,6 +8,10 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
#include <QStorageInfo>
|
||||||
|
#include <QVariantMap>
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static const int DAEMON_START_TIMEOUT_SECONDS = 30;
|
static const int DAEMON_START_TIMEOUT_SECONDS = 30;
|
||||||
|
@ -28,7 +32,7 @@ DaemonManager *DaemonManager::instance(const QStringList *args)
|
||||||
return m_instance;
|
return m_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DaemonManager::start(const QString &flags, bool testnet)
|
bool DaemonManager::start(const QString &flags, bool testnet, const QString &dataDir)
|
||||||
{
|
{
|
||||||
// prepare command line arguments and pass to monerod
|
// prepare command line arguments and pass to monerod
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
|
@ -54,8 +58,19 @@ bool DaemonManager::start(const QString &flags, bool testnet)
|
||||||
arguments << str;
|
arguments << str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Custom data-dir
|
||||||
|
if(!dataDir.isEmpty()) {
|
||||||
|
if(testnet)
|
||||||
|
arguments << "--testnet-data-dir";
|
||||||
|
else
|
||||||
|
arguments << "--data-dir";
|
||||||
|
arguments << dataDir;
|
||||||
|
}
|
||||||
|
|
||||||
arguments << "--check-updates" << "disabled";
|
arguments << "--check-updates" << "disabled";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
qDebug() << "starting monerod " + m_monerod;
|
qDebug() << "starting monerod " + m_monerod;
|
||||||
qDebug() << "With command line arguments " << arguments;
|
qDebug() << "With command line arguments " << arguments;
|
||||||
|
|
||||||
|
@ -236,6 +251,44 @@ void DaemonManager::exit()
|
||||||
m_app_exit = true;
|
m_app_exit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariantMap DaemonManager::validateDataDir(const QString &dataDir) const
|
||||||
|
{
|
||||||
|
QVariantMap result;
|
||||||
|
bool valid = true;
|
||||||
|
bool readOnly = false;
|
||||||
|
int storageAvailable = 0;
|
||||||
|
bool lmdbExists = true;
|
||||||
|
|
||||||
|
QStorageInfo storage(dataDir);
|
||||||
|
if (storage.isValid() && storage.isReady()) {
|
||||||
|
if (storage.isReadOnly()) {
|
||||||
|
readOnly = true;
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure there is 20GB storage available
|
||||||
|
storageAvailable = storage.bytesAvailable()/1000/1000/1000;
|
||||||
|
if (storageAvailable < 20) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!QDir(dataDir+"/lmdb").exists()) {
|
||||||
|
lmdbExists = false;
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.insert("valid", valid);
|
||||||
|
result.insert("lmdbExists", lmdbExists);
|
||||||
|
result.insert("readOnly", readOnly);
|
||||||
|
result.insert("storageAvailable", storageAvailable);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
DaemonManager::DaemonManager(QObject *parent)
|
DaemonManager::DaemonManager(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QVariantMap>
|
||||||
|
|
||||||
class DaemonManager : public QObject
|
class DaemonManager : public QObject
|
||||||
{
|
{
|
||||||
|
@ -13,7 +14,7 @@ public:
|
||||||
|
|
||||||
static DaemonManager * instance(const QStringList *args);
|
static DaemonManager * instance(const QStringList *args);
|
||||||
|
|
||||||
Q_INVOKABLE bool start(const QString &flags, bool testnet);
|
Q_INVOKABLE bool start(const QString &flags, bool testnet, const QString &dataDir = "");
|
||||||
Q_INVOKABLE bool stop(bool testnet);
|
Q_INVOKABLE bool stop(bool testnet);
|
||||||
|
|
||||||
// return true if daemon process is started
|
// return true if daemon process is started
|
||||||
|
@ -21,6 +22,7 @@ public:
|
||||||
// Send daemon command from qml and prints output in console window.
|
// Send daemon command from qml and prints output in console window.
|
||||||
Q_INVOKABLE bool sendCommand(const QString &cmd, bool testnet) const;
|
Q_INVOKABLE bool sendCommand(const QString &cmd, bool testnet) const;
|
||||||
Q_INVOKABLE void exit();
|
Q_INVOKABLE void exit();
|
||||||
|
Q_INVOKABLE QVariantMap validateDataDir(const QString &dataDir) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue