Added function to load cutterrc from all standard paths along with home (#2109)

* added function to load cutterrc from all standard paths along with home
This commit is contained in:
NIRMAL MANOJ C 2020-03-26 18:37:33 +05:30 committed by GitHub
parent 3f4edfb3a0
commit b06a6d0da8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 10 deletions

View File

@ -3,6 +3,9 @@
#include <QRegularExpression>
#include <QDir>
#include <QCoreApplication>
#include <QVector>
#include <QStringList>
#include <QStandardPaths>
#include <cassert>
#include <memory>
@ -226,20 +229,32 @@ RCoreLocked CutterCore::core()
return RCoreLocked(this);
}
QVector<QDir> CutterCore::getCutterRCDirectories() const
{
QVector<QDir> result;
result.push_back(QDir::home());
QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppConfigLocation);
for (auto &location : locations) {
result.push_back(QDir(location));
}
return result;
}
void CutterCore::loadCutterRC()
{
CORE_LOCK();
auto home = QDir::home();
if (!home.exists()) {
return;
const auto result = getCutterRCDirectories();
for(auto &dir : result){
if(!dir.exists())continue;
auto cutterRCFileInfo = QFileInfo(dir, ".cutterrc");
auto path = cutterRCFileInfo.absoluteFilePath();
if (!cutterRCFileInfo.isFile()) {
continue;
}
qInfo() << "Loading initialization file from" << path;
r_core_cmd_file(core, path.toUtf8().constData());
}
auto cutterRCFileInfo = QFileInfo(home, ".cutterrc");
if (!cutterRCFileInfo.isFile()) {
return;
}
auto path = cutterRCFileInfo.absoluteFilePath();
qInfo() << "Loading" << path;
r_core_cmd_file(core, path.toUtf8().constData());
}

View File

@ -14,6 +14,7 @@
#include <QJsonDocument>
#include <QErrorMessage>
#include <QMutex>
#include <QDir>
class AsyncTaskManager;
class BasicInstructionHighlighter;
@ -706,6 +707,8 @@ private:
QSharedPointer<R2Task> debugTask;
R2TaskDialog *debugTaskDialog;
QVector<QDir> getCutterRCDirectories() const;
};
class RCoreLocked