window s
This commit is contained in:
parent
3fbe24c3bb
commit
c42265e36d
37
meson.build
37
meson.build
|
@ -1,11 +1,12 @@
|
||||||
project(
|
project(
|
||||||
'draconis++', 'cpp',
|
'draconis++',
|
||||||
|
'cpp',
|
||||||
version: '0.1.0',
|
version: '0.1.0',
|
||||||
default_options: [
|
default_options: [
|
||||||
'default_library=static',
|
'default_library=static',
|
||||||
'warning_level=everything',
|
'warning_level=everything',
|
||||||
'buildtype=debugoptimized'
|
'buildtype=debugoptimized',
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
cpp = meson.get_compiler('cpp')
|
cpp = meson.get_compiler('cpp')
|
||||||
|
@ -14,7 +15,8 @@ if host_machine.system() == 'darwin'
|
||||||
add_languages('objcpp')
|
add_languages('objcpp')
|
||||||
objcpp = meson.get_compiler('objcpp')
|
objcpp = meson.get_compiler('objcpp')
|
||||||
add_project_arguments(
|
add_project_arguments(
|
||||||
objcpp.get_supported_arguments([
|
objcpp.get_supported_arguments(
|
||||||
|
[
|
||||||
'-std=c++2b',
|
'-std=c++2b',
|
||||||
'-Wno-c++20-compat',
|
'-Wno-c++20-compat',
|
||||||
'-Wno-c++20-extensions',
|
'-Wno-c++20-extensions',
|
||||||
|
@ -26,9 +28,10 @@ if host_machine.system() == 'darwin'
|
||||||
'-Wno-pre-c++20-compat-pedantic',
|
'-Wno-pre-c++20-compat-pedantic',
|
||||||
'-Wno-switch-default',
|
'-Wno-switch-default',
|
||||||
'-Wunused-function',
|
'-Wunused-function',
|
||||||
'-fvisibility=hidden'
|
'-fvisibility=hidden',
|
||||||
]),
|
],
|
||||||
language: 'objcpp'
|
),
|
||||||
|
language: 'objcpp',
|
||||||
)
|
)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -44,23 +47,16 @@ common_cpp_args = [
|
||||||
'-Wno-pre-c++20-compat-pedantic',
|
'-Wno-pre-c++20-compat-pedantic',
|
||||||
'-Wno-switch-default',
|
'-Wno-switch-default',
|
||||||
'-Wunused-function',
|
'-Wunused-function',
|
||||||
'-fvisibility=hidden'
|
'-fvisibility=hidden',
|
||||||
]
|
]
|
||||||
|
|
||||||
if host_machine.system() == 'windows'
|
if host_machine.system() == 'windows'
|
||||||
common_cpp_args += ['-DCURL_STATICLIB']
|
common_cpp_args += ['-DCURL_STATICLIB']
|
||||||
endif
|
endif
|
||||||
|
|
||||||
add_project_arguments(
|
add_project_arguments(cpp.get_supported_arguments(common_cpp_args), language: 'cpp')
|
||||||
cpp.get_supported_arguments(common_cpp_args),
|
|
||||||
language: 'cpp'
|
|
||||||
)
|
|
||||||
|
|
||||||
source_file_names = [
|
source_file_names = ['src/main.cpp', 'src/config/config.cpp', 'src/config/weather.cpp']
|
||||||
'src/main.cpp',
|
|
||||||
'src/config/config.cpp',
|
|
||||||
'src/config/weather.cpp'
|
|
||||||
]
|
|
||||||
|
|
||||||
if host_machine.system() == 'linux'
|
if host_machine.system() == 'linux'
|
||||||
source_file_names += ['src/os/linux.cpp']
|
source_file_names += ['src/os/linux.cpp']
|
||||||
|
@ -86,8 +82,8 @@ deps = [
|
||||||
dependency('libcurl'),
|
dependency('libcurl'),
|
||||||
dependency('tomlplusplus'),
|
dependency('tomlplusplus'),
|
||||||
dependency('yyjson'),
|
dependency('yyjson'),
|
||||||
dependency('ftxui'),
|
dependency('ftxui', modules: ['ftxui::screen', 'ftxui::dom', 'ftxui::component']),
|
||||||
dependency('reflectcpp')
|
dependency('reflectcpp'),
|
||||||
]
|
]
|
||||||
|
|
||||||
if host_machine.system() == 'darwin'
|
if host_machine.system() == 'darwin'
|
||||||
|
@ -114,6 +110,5 @@ executable(
|
||||||
sources,
|
sources,
|
||||||
objc_args: objc_args,
|
objc_args: objc_args,
|
||||||
link_args: link_args,
|
link_args: link_args,
|
||||||
dependencies: deps
|
dependencies: deps,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winrt/Windows.Foundation.h>
|
#include <winrt/Windows.Foundation.h>
|
||||||
#include <winrt/Windows.Media.Control.h>
|
#include <winrt/Windows.Media.Control.h>
|
||||||
|
@ -9,6 +10,36 @@
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
using RtlGetVersionPtr = NTSTATUS(WINAPI*)(PRTL_OSVERSIONINFOW);
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
fn GetRegistryValue(const HKEY& hKey, const string& subKey, const string& valueName) -> string {
|
||||||
|
HKEY key = nullptr;
|
||||||
|
if (RegOpenKeyExA(hKey, subKey.c_str(), 0, KEY_READ, &key) != ERROR_SUCCESS)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
DWORD dataSize = 0;
|
||||||
|
if (RegQueryValueExA(key, valueName.c_str(), nullptr, nullptr, nullptr, &dataSize) != ERROR_SUCCESS) {
|
||||||
|
RegCloseKey(key);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
string value(dataSize, '\0');
|
||||||
|
if (RegQueryValueExA(key, valueName.c_str(), nullptr, nullptr, std::bit_cast<LPBYTE>(value.data()), &dataSize) !=
|
||||||
|
ERROR_SUCCESS) {
|
||||||
|
RegCloseKey(key);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
RegCloseKey(key);
|
||||||
|
// Remove null terminator if present
|
||||||
|
if (!value.empty() && value.back() == '\0')
|
||||||
|
value.pop_back();
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn GetMemInfo() -> u64 {
|
fn GetMemInfo() -> u64 {
|
||||||
u64 mem = 0;
|
u64 mem = 0;
|
||||||
GetPhysicallyInstalledSystemMemory(&mem);
|
GetPhysicallyInstalledSystemMemory(&mem);
|
||||||
|
@ -37,60 +68,27 @@ fn GetNowPlaying() -> string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we reach this point, there is no current session
|
// If we reach this point, there is no current session
|
||||||
return "No current media session.";
|
|
||||||
} catch (...) { return "Failed to get media properties."; }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn GetRegistryValue(const HKEY& hKey, const string& subKey, const string& valueName) -> string {
|
|
||||||
HKEY key = nullptr;
|
|
||||||
if (RegOpenKeyExA(hKey, subKey.c_str(), 0, KEY_READ, &key) != ERROR_SUCCESS)
|
|
||||||
return "";
|
return "";
|
||||||
|
} catch (const winrt::hresult_error& e) {
|
||||||
DWORD dataSize = 0;
|
ERROR_LOG("Error: {}", to_string(e.message()));
|
||||||
if (RegQueryValueExA(key, valueName.c_str(), nullptr, nullptr, nullptr, &dataSize) !=
|
|
||||||
ERROR_SUCCESS) {
|
|
||||||
RegCloseKey(key);
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
string value(dataSize, '\0');
|
|
||||||
if (RegQueryValueExA(
|
|
||||||
key,
|
|
||||||
valueName.c_str(),
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
reinterpret_cast<LPBYTE>(value.data()), // NOLINT(*-reinterpret-cast)
|
|
||||||
&dataSize
|
|
||||||
) != ERROR_SUCCESS) {
|
|
||||||
RegCloseKey(key);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
RegCloseKey(key);
|
|
||||||
// Remove null terminator if present
|
|
||||||
if (!value.empty() && value.back() == '\0')
|
|
||||||
value.pop_back();
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn GetOSVersion() -> string {
|
fn GetOSVersion() -> string {
|
||||||
string productName = GetRegistryValue(
|
string productName =
|
||||||
HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "ProductName"
|
GetRegistryValue(HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "ProductName");
|
||||||
);
|
|
||||||
|
|
||||||
const string displayVersion = GetRegistryValue(
|
const string displayVersion =
|
||||||
HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "DisplayVersion"
|
GetRegistryValue(HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "DisplayVersion");
|
||||||
);
|
|
||||||
|
|
||||||
const string releaseId = GetRegistryValue(
|
const string releaseId =
|
||||||
HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "ReleaseId"
|
GetRegistryValue(HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "ReleaseId");
|
||||||
);
|
|
||||||
|
|
||||||
// Check for Windows 11
|
// Check for Windows 11
|
||||||
if (const i32 buildNumber = stoi(GetRegistryValue(
|
if (const i32 buildNumber = stoi(
|
||||||
HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "CurrentBuildNumber"
|
GetRegistryValue(HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "CurrentBuildNumber")
|
||||||
));
|
);
|
||||||
buildNumber >= 22000 && productName.find("Windows 10") != string::npos)
|
buildNumber >= 22000 && productName.find("Windows 10") != string::npos)
|
||||||
productName.replace(productName.find("Windows 10"), 10, "Windows 11");
|
productName.replace(productName.find("Windows 10"), 10, "Windows 11");
|
||||||
|
|
||||||
|
@ -108,4 +106,33 @@ fn GetOSVersion() -> string {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn GetHost() -> string {
|
||||||
|
string hostName = GetRegistryValue(HKEY_LOCAL_MACHINE, R"(SYSTEM\HardwareConfig\Current)", "SystemFamily");
|
||||||
|
|
||||||
|
if (hostName.empty())
|
||||||
|
hostName = GetRegistryValue(
|
||||||
|
HKEY_LOCAL_MACHINE, R"(SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName)", "ComputerName"
|
||||||
|
);
|
||||||
|
|
||||||
|
return hostName;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn GetKernelVersion() -> string {
|
||||||
|
std::stringstream versionStream;
|
||||||
|
HMODULE ntdllHandle = GetModuleHandleW(L"ntdll.dll");
|
||||||
|
|
||||||
|
if (ntdllHandle) {
|
||||||
|
auto rtlGetVersion = std::bit_cast<RtlGetVersionPtr>(GetProcAddress(ntdllHandle, "RtlGetVersion"));
|
||||||
|
if (rtlGetVersion) {
|
||||||
|
RTL_OSVERSIONINFOW osInfo = {};
|
||||||
|
osInfo.dwOSVersionInfoSize = sizeof(osInfo);
|
||||||
|
if (rtlGetVersion(&osInfo) == 0)
|
||||||
|
versionStream << osInfo.dwMajorVersion << "." << osInfo.dwMinorVersion << "." << osInfo.dwBuildNumber << "."
|
||||||
|
<< osInfo.dwPlatformId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return versionStream.str();
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// probably stupid but it fixes the issue with windows.h defining ERROR
|
||||||
|
#undef ERROR
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fmt/chrono.h>
|
#include <fmt/chrono.h>
|
||||||
#include <fmt/color.h>
|
#include <fmt/color.h>
|
||||||
|
@ -14,19 +17,13 @@ namespace log_colors {
|
||||||
using fmt::terminal_color;
|
using fmt::terminal_color;
|
||||||
constexpr fmt::terminal_color debug = terminal_color::cyan, info = terminal_color::green,
|
constexpr fmt::terminal_color debug = terminal_color::cyan, info = terminal_color::green,
|
||||||
warn = terminal_color::yellow, error = terminal_color::red,
|
warn = terminal_color::yellow, error = terminal_color::red,
|
||||||
timestamp = terminal_color::bright_white,
|
timestamp = terminal_color::bright_white, file_info = terminal_color::bright_white;
|
||||||
file_info = terminal_color::bright_white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class LogLevel : u8 { DEBUG, INFO, WARN, ERROR };
|
enum class LogLevel : u8 { DEBUG, INFO, WARN, ERROR };
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void LogImpl(
|
void LogImpl(LogLevel level, const std::source_location& loc, fmt::format_string<Args...> fmt, Args&&... args) {
|
||||||
LogLevel level,
|
|
||||||
const std::source_location& loc,
|
|
||||||
fmt::format_string<Args...> fmt,
|
|
||||||
Args&&... args
|
|
||||||
) {
|
|
||||||
const time_t now = std::time(nullptr);
|
const time_t now = std::time(nullptr);
|
||||||
const auto [color, levelStr] = [&] {
|
const auto [color, levelStr] = [&] {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
|
|
Loading…
Reference in a new issue