#1708 Added "title" option.

This commit is contained in:
XMRig 2020-06-06 00:24:58 +07:00
parent 33bfecd49b
commit ea72052f50
No known key found for this signature in database
GPG key ID: 446A53638BE94409
15 changed files with 152 additions and 10 deletions

View file

@ -7,7 +7,7 @@
[![GitHub stars](https://img.shields.io/github/stars/xmrig/xmrig.svg)](https://github.com/xmrig/xmrig/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/xmrig/xmrig.svg)](https://github.com/xmrig/xmrig/network)
XMRig High performance, open source, cross platform RandomX, CryptoNight, AstroBWT and Argon2 CPU/GPU miner, with official support for Windows.
XMRig High performance, open source, cross platform RandomX, KawPow, CryptoNight, AstroBWT and Argon2 CPU/GPU miner, with official support for Windows.
## Mining backends
- **CPU** (x64/x86/ARM)
@ -118,6 +118,8 @@ Misc:
-h, --help display this help and exit
--dry-run test configuration and exit
--export-topology export hwloc topology to a XML file and exit
--title set custom console window title
--no-title disable setting console window title
```
## Donations

View file

@ -19,6 +19,7 @@ set(HEADERS_BASE
src/base/kernel/Base.h
src/base/kernel/config/BaseConfig.h
src/base/kernel/config/BaseTransform.h
src/base/kernel/config/Title.h
src/base/kernel/Entry.h
src/base/kernel/interfaces/IBaseListener.h
src/base/kernel/interfaces/IClient.h
@ -87,6 +88,7 @@ set(SOURCES_BASE
src/base/kernel/Base.cpp
src/base/kernel/config/BaseConfig.cpp
src/base/kernel/config/BaseTransform.cpp
src/base/kernel/config/Title.cpp
src/base/kernel/Entry.cpp
src/base/kernel/Platform.cpp
src/base/kernel/Process.cpp

View file

@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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,12 +28,13 @@
#include "base/io/log/backends/ConsoleLog.h"
#include "base/tools/Handle.h"
#include "base/io/log/Log.h"
#include "base/kernel/config/Title.h"
#include "base/tools/Handle.h"
#include "version.h"
xmrig::ConsoleLog::ConsoleLog()
xmrig::ConsoleLog::ConsoleLog(const Title &title)
{
if (!isSupported()) {
Log::setColors(false);
@ -61,7 +62,9 @@ xmrig::ConsoleLog::ConsoleLog()
}
}
SetConsoleTitleA(APP_NAME " " APP_VERSION);
if (title.isEnabled()) {
SetConsoleTitleA(title.value());
}
# endif
}

View file

@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@ -38,12 +38,15 @@ using uv_tty_t = struct uv_tty_s;
namespace xmrig {
class Title;
class ConsoleLog : public ILogBackend
{
public:
XMRIG_DISABLE_COPY_MOVE(ConsoleLog)
ConsoleLog();
ConsoleLog(const Title &title);
~ConsoleLog() override;
protected:

View file

@ -184,7 +184,7 @@ int xmrig::Base::init()
Log::setBackground(true);
}
else {
Log::add(new ConsoleLog());
Log::add(new ConsoleLog(config()->title()));
}
if (config()->logFile()) {

View file

@ -63,6 +63,7 @@ const char *BaseConfig::kHttp = "http";
const char *BaseConfig::kLogFile = "log-file";
const char *BaseConfig::kPrintTime = "print-time";
const char *BaseConfig::kSyslog = "syslog";
const char *BaseConfig::kTitle = "title";
const char *BaseConfig::kUserAgent = "user-agent";
const char *BaseConfig::kVerbose = "verbose";
const char *BaseConfig::kWatch = "watch";
@ -92,6 +93,7 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
m_logFile = reader.getString(kLogFile);
m_userAgent = reader.getString(kUserAgent);
m_printTime = std::min(reader.getUint(kPrintTime, m_printTime), 3600U);
m_title = reader.getValue(kTitle);
# ifdef XMRIG_FEATURE_TLS
m_tls = reader.getValue(kTls);

View file

@ -26,6 +26,7 @@
#define XMRIG_BASECONFIG_H
#include "base/kernel/config/Title.h"
#include "base/kernel/interfaces/IConfig.h"
#include "base/net/http/Http.h"
#include "base/net/stratum/Pools.h"
@ -56,6 +57,7 @@ public:
static const char *kLogFile;
static const char *kPrintTime;
static const char *kSyslog;
static const char *kTitle;
static const char *kUserAgent;
static const char *kVerbose;
static const char *kWatch;
@ -76,6 +78,7 @@ public:
inline const Pools &pools() const { return m_pools; }
inline const String &apiId() const { return m_apiId; }
inline const String &apiWorkerId() const { return m_apiWorkerId; }
inline const Title &title() const { return m_title; }
inline uint32_t printTime() const { return m_printTime; }
# ifdef XMRIG_FEATURE_TLS
@ -105,6 +108,7 @@ protected:
String m_fileName;
String m_logFile;
String m_userAgent;
Title m_title;
uint32_t m_printTime = 60;
# ifdef XMRIG_FEATURE_TLS

View file

@ -204,6 +204,9 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
case IConfig::UserAgentKey: /* --user-agent */
return set(doc, BaseConfig::kUserAgent, arg);
case IConfig::TitleKey: /* --title */
return set(doc, BaseConfig::kTitle, arg);
# ifdef XMRIG_FEATURE_TLS
case IConfig::TlsCertKey: /* --tls-cert */
return set(doc, BaseConfig::kTls, TlsConfig::kCert, arg);
@ -248,6 +251,7 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
case IConfig::ColorKey: /* --no-color */
case IConfig::HttpRestrictedKey: /* --http-no-restricted */
case IConfig::NoTitleKey: /* --no-title */
return transformBoolean(doc, key, false);
default:
@ -298,6 +302,9 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
case IConfig::VerboseKey: /* --verbose */
return set(doc, BaseConfig::kVerbose, enable);
case IConfig::NoTitleKey: /* --no-title */
return set(doc, BaseConfig::kTitle, enable);
default:
break;
}

View file

@ -0,0 +1,58 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/kernel/config/Title.h"
#include "3rdparty/rapidjson/document.h"
#include "base/io/Env.h"
#include "version.h"
xmrig::Title::Title(const rapidjson::Value &value)
{
if (value.IsBool()) {
m_enabled = value.GetBool();
}
else if (value.IsString()) {
m_value = value.GetString();
}
}
rapidjson::Value xmrig::Title::toJSON() const
{
if (isEnabled() && !m_value.isNull()) {
return m_value.toJSON();
}
return rapidjson::Value(m_enabled);
}
xmrig::String xmrig::Title::value() const
{
if (!isEnabled()) {
return {};
}
if (m_value.isNull()) {
return APP_NAME " " APP_VERSION;
}
return Env::expand(m_value);
}

View file

@ -0,0 +1,50 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_TITLE_H
#define XMRIG_TITLE_H
#include "3rdparty/rapidjson/fwd.h"
#include "base/tools/String.h"
namespace xmrig {
class Title
{
public:
Title() = default;
Title(const rapidjson::Value &value);
inline bool isEnabled() const { return m_enabled; }
rapidjson::Value toJSON() const;
String value() const;
private:
bool m_enabled = true;
String m_value;
};
} // namespace xmrig
#endif /* XMRIG_TITLE_H */

View file

@ -74,6 +74,8 @@ public:
DaemonPollKey = 1019,
SelfSelectKey = 1028,
DataDirKey = 1035,
TitleKey = 1037,
NoTitleKey = 1038,
// xmrig common
CPUPriorityKey = 1021,

View file

@ -13,6 +13,7 @@
"autosave": true,
"background": false,
"colors": true,
"title": true,
"randomx": {
"init": -1,
"mode": "auto",

View file

@ -217,6 +217,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
doc.AddMember(StringRef(kAutosave), isAutoSave(), allocator);
doc.AddMember(StringRef(kBackground), isBackground(), allocator);
doc.AddMember(StringRef(kColors), Log::isColors(), allocator);
doc.AddMember(StringRef(kTitle), title().toJSON(), allocator);
# ifdef XMRIG_ALGO_RANDOMX
doc.AddMember(StringRef(kRandomX), rx().toJSON(doc), allocator);

View file

@ -90,6 +90,8 @@ static const option options[] = {
{ "verbose", 0, nullptr, IConfig::VerboseKey },
{ "proxy", 1, nullptr, IConfig::ProxyKey },
{ "data-dir", 1, nullptr, IConfig::DataDirKey },
{ "title", 1, nullptr, IConfig::TitleKey },
{ "no-title", 0, nullptr, IConfig::NoTitleKey },
# ifdef XMRIG_FEATURE_TLS
{ "tls", 0, nullptr, IConfig::TlsKey },
{ "tls-fingerprint", 1, nullptr, IConfig::FingerprintKey },

View file

@ -168,6 +168,11 @@ static inline const std::string &usage()
u += " --export-topology export hwloc topology to a XML file and exit\n";
# endif
# ifdef XMRIG_OS_WIN
u += " --title set custom console window title\n";
u += " --no-title disable setting console window title\n";
# endif
return u;
}