Sync ConsoleLog class, base versions and TLS init.

This commit is contained in:
XMRig 2022-05-07 21:41:55 +07:00
parent 9a0cd68ea5
commit bc150fec04
No known key found for this signature in database
GPG key ID: 446A53638BE94409
6 changed files with 88 additions and 48 deletions

View file

@ -27,42 +27,34 @@
#include "base/io/log/backends/ConsoleLog.h"
#include "base/io/log/Log.h"
#include "base/kernel/private/Title.h"
#include "base/tools/Cvt.h"
#include "base/tools/Handle.h"
#include <cstdio>
xmrig::ConsoleLog::ConsoleLog(const Title &title)
xmrig::ConsoleLog::ConsoleLog()
{
if (!isSupported()) {
Log::setColors(false);
if (!init()) {
return;
}
m_tty = new uv_tty_t;
if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) {
Log::setColors(false);
return;
}
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
# ifdef XMRIG_OS_WIN
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
SetConsoleOutputCP(65001);
# endif
}
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
if (handle != INVALID_HANDLE_VALUE) { // NOLINT(cppcoreguidelines-pro-type-cstyle-cast, performance-no-int-to-ptr)
DWORD mode = 0;
if (GetConsoleMode(handle, &mode)) {
mode &= ~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(handle, mode | ENABLE_EXTENDED_FLAGS);
}
xmrig::ConsoleLog::ConsoleLog(const Title &title)
{
if (!init()) {
return;
}
# ifdef XMRIG_OS_WIN
if (title.isEnabled()) {
SetConsoleTitleA(title.value());
SetConsoleTitleW(Cvt::toUtf16(title.value().data()).c_str());
}
# endif
}
@ -104,6 +96,37 @@ bool xmrig::ConsoleLog::isSupported()
}
bool xmrig::ConsoleLog::init()
{
if (!isSupported()) {
return false;
}
m_tty = new uv_tty_t;
if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) {
return false;
}
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
# ifdef XMRIG_OS_WIN
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
if (handle != INVALID_HANDLE_VALUE) { // NOLINT(cppcoreguidelines-pro-type-cstyle-cast, performance-no-int-to-ptr)
DWORD mode = 0;
if (GetConsoleMode(handle, &mode)) {
mode &= ~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(handle, mode | ENABLE_EXTENDED_FLAGS);
}
}
# endif
return true;
}
#ifdef XMRIG_OS_WIN
bool xmrig::ConsoleLog::isWritable() const
{

View file

@ -47,6 +47,7 @@ class ConsoleLog : public ILogBackend
public:
XMRIG_DISABLE_COPY_MOVE(ConsoleLog)
ConsoleLog();
ConsoleLog(const Title &title);
~ConsoleLog() override;
@ -56,6 +57,8 @@ protected:
private:
static bool isSupported();
bool init();
uv_tty_t *m_tty = nullptr;
# ifdef XMRIG_OS_WIN