mirror of
https://github.com/PixlOne/logiops.git
synced 2025-09-14 13:56:50 +08:00
Do not throw error if config file does not exist
This commit is contained in:
parent
c5a9c1d0a4
commit
44e319d770
@ -19,6 +19,7 @@
|
|||||||
#include <Configuration.h>
|
#include <Configuration.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <filesystem>
|
||||||
#include <ipc_defs.h>
|
#include <ipc_defs.h>
|
||||||
|
|
||||||
using namespace logid;
|
using namespace logid;
|
||||||
@ -27,19 +28,23 @@ using namespace logid::config;
|
|||||||
|
|
||||||
Configuration::Configuration(std::string config_file) :
|
Configuration::Configuration(std::string config_file) :
|
||||||
_config_file(std::move(config_file)) {
|
_config_file(std::move(config_file)) {
|
||||||
try {
|
if (std::filesystem::exists(_config_file)) {
|
||||||
_config.readFile(_config_file);
|
try {
|
||||||
} catch (const FileIOException& e) {
|
_config.readFile(_config_file);
|
||||||
logPrintf(ERROR, "I/O Error while reading %s: %s", _config_file.c_str(),
|
} catch (const FileIOException& e) {
|
||||||
|
logPrintf(ERROR, "I/O Error while reading %s: %s", _config_file.c_str(),
|
||||||
e.what());
|
e.what());
|
||||||
throw;
|
throw;
|
||||||
} catch (const ParseException& e) {
|
} catch (const ParseException& e) {
|
||||||
logPrintf(ERROR, "Parse error in %s, line %d: %s", e.getFile(),
|
logPrintf(ERROR, "Parse error in %s, line %d: %s", e.getFile(),
|
||||||
e.getLine(), e.getError());
|
e.getLine(), e.getError());
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::operator=(get<Config>(_config.getRoot()));
|
Config::operator=(get<Config>(_config.getRoot()));
|
||||||
|
} else {
|
||||||
|
logPrintf(INFO, "Config file does not exist, using empty config.");
|
||||||
|
}
|
||||||
|
|
||||||
if (!devices.has_value())
|
if (!devices.has_value())
|
||||||
devices.emplace();
|
devices.emplace();
|
||||||
@ -68,4 +73,4 @@ Configuration::IPC::IPC(Configuration* config) :
|
|||||||
ipcgull::interface(SERVICE_ROOT_NAME ".Config", {
|
ipcgull::interface(SERVICE_ROOT_NAME ".Config", {
|
||||||
{"Save", {config, &Configuration::save}}
|
{"Save", {config, &Configuration::save}}
|
||||||
}, {}, {}) {
|
}, {}, {}) {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user