From 76da7787dbf19fc2662dc2bcea2400cb66cd999d Mon Sep 17 00:00:00 2001 From: D33r-Gee Date: Tue, 2 Jul 2024 11:49:39 -0700 Subject: [PATCH] android: custom datadir retrieve filepath --- src/qml/androidcustomdatadir.cpp | 48 ++++++++++++++++++++++++++++++++ src/qml/androidcustomdatadir.h | 32 +++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/qml/androidcustomdatadir.cpp create mode 100644 src/qml/androidcustomdatadir.h diff --git a/src/qml/androidcustomdatadir.cpp b/src/qml/androidcustomdatadir.cpp new file mode 100644 index 0000000000..eba691fc93 --- /dev/null +++ b/src/qml/androidcustomdatadir.cpp @@ -0,0 +1,48 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +AndroidCustomDataDir::AndroidCustomDataDir(QObject * parent) + : QObject(parent) +{ + m_default_data_dir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); +} + +void AndroidCustomDataDir::setDataDir(const QString & new_data_dir) +{ + if (m_data_dir == new_data_dir) { + return; + } + + m_data_dir = new_data_dir; + gArgs.SoftSetArg("-datadir", fs::PathToString(GUIUtil::QStringToPath(m_data_dir))); + gArgs.ClearPathCache(); + Q_EMIT dataDirChanged(); +} + +QString AndroidCustomDataDir::readCustomDataDir() +{ + QFile file(m_default_data_dir + "/filepath.txt"); + QString storedPath; + + if (file.open(QIODevice::ReadOnly)) { + QTextStream in(&file); + storedPath = in.readAll().trimmed(); + file.close(); + // Process the retrieved path + qDebug() << "Retrieved path: " << storedPath; + } + return storedPath; +} diff --git a/src/qml/androidcustomdatadir.h b/src/qml/androidcustomdatadir.h new file mode 100644 index 0000000000..24578f33b8 --- /dev/null +++ b/src/qml/androidcustomdatadir.h @@ -0,0 +1,32 @@ +// Copyright (c) 2024 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_QML_ANDROIDCUSTOMDATADIR_H +#define BITCOIN_QML_ANDROIDCUSTOMDATADIR_H + +#include +#include +#include + +class AndroidCustomDataDir : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString dataDir READ dataDir WRITE setDataDir NOTIFY dataDirChanged) + +public: + explicit AndroidCustomDataDir(QObject * parent = nullptr); + + QString dataDir() const { return m_data_dir; } + void setDataDir(const QString & new_data_dir); + QString readCustomDataDir(); + +Q_SIGNALS: + void dataDirChanged(); + +private: + QString m_data_dir; + QString m_default_data_dir; +}; + +#endif // BITCOIN_QML_ANDROIDCUSTOMDATADIR_H