swift
Loading...
Searching...
No Matches
setupreader.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
4#include "core/setupreader.h"
5
6#include <QByteArray>
7#include <QFile>
8#include <QPointer>
9#include <QScopedPointer>
10#include <QScopedPointerDeleteLater>
11#include <QStringBuilder>
12#include <QTimer>
13#include <QUrl>
14#include <QtGlobal>
15
16#include "config/buildconfig.h"
17#include "core/application.h"
18#include "misc/directoryutils.h"
19#include "misc/fileutils.h"
20#include "misc/logcategories.h"
21#include "misc/logmessage.h"
24#include "misc/network/url.h"
25#include "misc/statusmessage.h"
27#include "misc/verify.h"
28
29using namespace swift::config;
30using namespace swift::misc;
31using namespace swift::misc::db;
32using namespace swift::misc::network;
33using namespace swift::core;
34using namespace swift::core::data;
35
36namespace swift::core
37{
39
41 {
43 msgs = this->readLocalBootstrapFile();
44 m_setupAvailable = msgs.isSuccess();
45 return msgs;
46 }
47
48 CStatusMessageList CSetupReader::readLocalBootstrapFile()
49 {
51 // TODO Check if file exists or is broken
52
53 if (fileName.isEmpty())
54 {
55 return CStatusMessage(this).error(u"No file name for local bootstrap file");
56 }
57 if (!sApp || sApp->isShuttingDown())
58 {
59 return CStatusMessage(this).error(u"No sApp, shutting down?");
60 }
61 const QFile file(fileName);
62 if (!file.exists())
63 {
64 return CStatusMessage(this).error(u"File '%1' not existing") << fileName;
65 }
66
67 const QString content(CFileUtils::readFileToString(fileName));
68 if (content.isEmpty())
69 {
70 return CStatusMessage(this).error(u"File '%1' empty") << fileName;
71 }
72
73 try
74 {
75 m_setup.convertFromJson(content);
76 return CStatusMessage(this).info(u"Setup loaded from local file '%1'") << fileName;
77 }
78 catch (const CJsonException &ex)
79 {
81 QStringLiteral("Parsing local setup file '%1'").arg(fileName));
82 }
83 }
84
86 {
87 static const QStringList cats({ "swift.setupreader", CLogCategories::webservice(), CLogCategories::startup() });
88 return cats;
89 }
90
91 CGlobalSetup CSetupReader::getSetup() const { return m_setup; }
92} // namespace swift::core
data::CGlobalSetup getSetup() const
Current setup (reader URLs, DB location, crash server).
CSetupReader(QObject *parent)
Constructor.
static const QStringList & getLogCategories()
Categories.
swift::misc::CStatusMessageList loadSetup()
Load the setup. If the setup is already loaded, the setup is reloaded.
Global settings for readers, debug flags, etc.
Definition globalsetup.h:31
static QString readFileToString(const QString &fileNameAndPath)
Read file into string.
Definition fileutils.cpp:83
static const QString & startup()
Startup of application.
static const QString & webservice()
Webservice.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Streamable status message, e.g.
static CStatusMessage fromJsonException(const CJsonException &ex, const CLogCategoryList &categories, const QString &prefix)
Object from JSON exception message.
Status messages, e.g. from Core -> GUI.
bool isSuccess() const
All messages are marked as success.
static const QString & bootstrapResourceFilePath()
Bootstrap resource file path.
Core data traits (aka cached values) and classes.
Backend services of the swift project, like dealing with the network or the simulators.
Definition actionbind.cpp:7
Free functions in swift::misc.
QObject(QObject *parent)
QObject * parent() const const
bool isEmpty() const const