Added class Json.
This commit is contained in:
parent
2df204f8a8
commit
b368ffacdb
10 changed files with 309 additions and 52 deletions
|
@ -5,7 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -53,6 +54,7 @@
|
|||
#endif
|
||||
|
||||
|
||||
#include "base/io/Json.h"
|
||||
#include "common/config/CommonConfig.h"
|
||||
#include "common/log/Log.h"
|
||||
#include "donate.h"
|
||||
|
@ -203,31 +205,15 @@ bool xmrig::CommonConfig::save()
|
|||
return false;
|
||||
}
|
||||
|
||||
uv_fs_t req;
|
||||
const int fd = uv_fs_open(uv_default_loop(), &req, m_fileName.data(), O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr);
|
||||
if (fd < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
rapidjson::Document doc;
|
||||
getJSON(doc);
|
||||
|
||||
FILE *fp = fdopen(fd, "w");
|
||||
if (Json::save(m_fileName, doc)) {
|
||||
LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data());
|
||||
return true;
|
||||
}
|
||||
|
||||
char buf[4096];
|
||||
rapidjson::FileWriteStream os(fp, buf, sizeof(buf));
|
||||
rapidjson::PrettyWriter<rapidjson::FileWriteStream> writer(os);
|
||||
doc.Accept(writer);
|
||||
|
||||
fflush(fp);
|
||||
|
||||
uv_fs_close(uv_default_loop(), &req, fd, nullptr);
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data());
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -28,9 +29,9 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
#include "base/tools/String.h"
|
||||
#include "common/interfaces/IConfig.h"
|
||||
#include "common/net/Pool.h"
|
||||
#include "common/utils/c_str.h"
|
||||
#include "common/xmrig.h"
|
||||
|
||||
|
||||
|
@ -103,12 +104,12 @@ protected:
|
|||
State m_state;
|
||||
std::vector<Pool> m_activePools;
|
||||
std::vector<Pool> m_pools;
|
||||
xmrig::c_str m_apiId;
|
||||
xmrig::c_str m_apiToken;
|
||||
xmrig::c_str m_apiWorkerId;
|
||||
xmrig::c_str m_fileName;
|
||||
xmrig::c_str m_logFile;
|
||||
xmrig::c_str m_userAgent;
|
||||
xmrig::String m_apiId;
|
||||
xmrig::String m_apiToken;
|
||||
xmrig::String m_apiWorkerId;
|
||||
xmrig::String m_fileName;
|
||||
xmrig::String m_logFile;
|
||||
xmrig::String m_userAgent;
|
||||
|
||||
private:
|
||||
bool parseInt(int key, int arg);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
@ -37,6 +38,7 @@
|
|||
#endif
|
||||
|
||||
|
||||
#include "base/io/Json.h"
|
||||
#include "common/config/ConfigLoader.h"
|
||||
#include "common/config/ConfigWatcher.h"
|
||||
#include "common/interfaces/IConfig.h"
|
||||
|
@ -151,7 +153,7 @@ xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator
|
|||
int key;
|
||||
|
||||
while (1) {
|
||||
key = getopt_long(argc, argv, short_options, options, NULL);
|
||||
key = getopt_long(argc, argv, short_options, options, nullptr);
|
||||
if (key < 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -207,30 +209,18 @@ void xmrig::ConfigLoader::release()
|
|||
|
||||
bool xmrig::ConfigLoader::getJSON(const char *fileName, rapidjson::Document &doc)
|
||||
{
|
||||
uv_fs_t req;
|
||||
const int fd = uv_fs_open(uv_default_loop(), &req, fileName, O_RDONLY, 0644, nullptr);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "unable to open %s: %s\n", fileName, uv_strerror(fd));
|
||||
return false;
|
||||
if (Json::get(fileName, doc)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
FILE *fp = fdopen(fd, "rb");
|
||||
char buf[8192];
|
||||
rapidjson::FileReadStream is(fp, buf, sizeof(buf));
|
||||
|
||||
doc.ParseStream(is);
|
||||
|
||||
uv_fs_close(uv_default_loop(), &req, fd, nullptr);
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
if (doc.HasParseError()) {
|
||||
printf("%s<%d>: %s\n", fileName, (int) doc.GetErrorOffset(), rapidjson::GetParseError_En(doc.GetParseError()));
|
||||
return false;
|
||||
printf("%s<offset:%zu>: \"%s\"\n", fileName, doc.GetErrorOffset(), rapidjson::GetParseError_En(doc.GetParseError()));
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "unable to open \"%s\".\n", fileName);
|
||||
}
|
||||
|
||||
return doc.IsObject();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2018 XMRig <support@xmrig.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -125,7 +127,7 @@ public:
|
|||
CudaMaxUsageKey = 1206,
|
||||
};
|
||||
|
||||
virtual ~IConfig() {}
|
||||
virtual ~IConfig() = default;
|
||||
|
||||
virtual bool finalize() = 0;
|
||||
virtual bool isWatch() const = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue