mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 18:55:38 +08:00
refs #621, allow to load setup from resource dir file
* CValueObjects can be loaded from JSON file * get bootstrap file location
This commit is contained in:
@@ -144,6 +144,9 @@ namespace BlackCore
|
|||||||
//! Build bootstrap file URL
|
//! Build bootstrap file URL
|
||||||
static QString buildBootstrapFileUrl(const QString &candidate);
|
static QString buildBootstrapFileUrl(const QString &candidate);
|
||||||
|
|
||||||
|
//! Object initialized by JSON file
|
||||||
|
static CGlobalSetup fromJsonFile(const QString &fileNameAndPath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BLACK_ENABLE_TUPLE_CONVERSION(BlackCore::Data::CGlobalSetup)
|
BLACK_ENABLE_TUPLE_CONVERSION(BlackCore::Data::CGlobalSetup)
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "blackmisc/blackmiscexport.h"
|
#include "blackmisc/blackmiscexport.h"
|
||||||
#include "blackmisc/tuple.h"
|
#include "blackmisc/tuple.h"
|
||||||
#include "blackmisc/inheritancetraits.h"
|
#include "blackmisc/inheritancetraits.h"
|
||||||
|
#include "blackmisc/fileutils.h"
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
@@ -164,6 +165,28 @@ namespace BlackMisc
|
|||||||
//! Merges an incremental json object into an existing one
|
//! Merges an incremental json object into an existing one
|
||||||
BLACKMISC_EXPORT QJsonObject applyIncrementalObject(const QJsonObject &previousObject, const QJsonObject &incrementalObject);
|
BLACKMISC_EXPORT QJsonObject applyIncrementalObject(const QJsonObject &previousObject, const QJsonObject &incrementalObject);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Load JSON file and init by that
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
bool loadFromJsonFile(T &object, const QString &fileNameAndPath)
|
||||||
|
{
|
||||||
|
const QString jsonString(CFileUtils::readFileToString(fileNameAndPath));
|
||||||
|
if (jsonString.isEmpty()) { return false; }
|
||||||
|
object.convertFromJson(jsonString);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Save to JSON file
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
bool saveToJsonFile(const T &object, const QString &fileNameAndPath)
|
||||||
|
{
|
||||||
|
const QString jsonString(object.toJsonString());
|
||||||
|
if (jsonString.isEmpty()) { return false; }
|
||||||
|
return CFileUtils::writeStringToFile(jsonString, fileNameAndPath);
|
||||||
|
}
|
||||||
} // Json
|
} // Json
|
||||||
|
|
||||||
namespace Mixin
|
namespace Mixin
|
||||||
@@ -266,8 +289,8 @@ namespace BlackMisc
|
|||||||
* the derived class uses this macro to disambiguate the inherited members.
|
* the derived class uses this macro to disambiguate the inherited members.
|
||||||
*/
|
*/
|
||||||
# define BLACKMISC_DECLARE_USING_MIXIN_JSON(DERIVED) \
|
# define BLACKMISC_DECLARE_USING_MIXIN_JSON(DERIVED) \
|
||||||
using ::BlackMisc::Mixin::JsonByTuple<DERIVED>::toJson; \
|
using ::BlackMisc::Mixin::JsonByTuple<DERIVED>::toJson; \
|
||||||
using ::BlackMisc::Mixin::JsonByTuple<DERIVED>::convertFromJson;
|
using ::BlackMisc::Mixin::JsonByTuple<DERIVED>::convertFromJson;
|
||||||
|
|
||||||
} // Mixin
|
} // Mixin
|
||||||
} // BlackMisc
|
} // BlackMisc
|
||||||
|
|||||||
@@ -305,6 +305,21 @@ namespace BlackMisc
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString getBootstrapResourceFileImpl()
|
||||||
|
{
|
||||||
|
const QString d(CProject::getSwiftResourceDir());
|
||||||
|
if (d.isEmpty()) { return ""; }
|
||||||
|
const QFile file(CFileUtils::appendFilePaths(d, "shared/boostrap/boostrap.json"));
|
||||||
|
Q_ASSERT_X(file.exists(), Q_FUNC_INFO, "missing dir");
|
||||||
|
return QFileInfo(file).absoluteFilePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &CProject::getBootstrapResourceFile()
|
||||||
|
{
|
||||||
|
static const QString s(getBootstrapResourceFileImpl());
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
QString getSwiftStaticDbFilesDirImpl()
|
QString getSwiftStaticDbFilesDirImpl()
|
||||||
{
|
{
|
||||||
const QString d(CProject::getSwiftResourceDir());
|
const QString d(CProject::getSwiftResourceDir());
|
||||||
|
|||||||
@@ -96,6 +96,9 @@ namespace BlackMisc
|
|||||||
//! Where resource files (static DB files, ...) etc are located
|
//! Where resource files (static DB files, ...) etc are located
|
||||||
static const QString &getSwiftResourceDir();
|
static const QString &getSwiftResourceDir();
|
||||||
|
|
||||||
|
//! Bootstrap resource directory
|
||||||
|
static const QString &getBootstrapResourceFile();
|
||||||
|
|
||||||
//! Where static DB files are located
|
//! Where static DB files are located
|
||||||
static const QString &getSwiftStaticDbFilesDir();
|
static const QString &getSwiftStaticDbFilesDir();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user