From c4971479f868935e73097b67b881ddf443ea0a0a Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 8 Nov 2025 18:22:52 +0000 Subject: [PATCH 1/3] Remove systeminfo Signed-off-by: TheKodeToad --- CMakeLists.txt | 1 - launcher/Application.cpp | 1 - launcher/CMakeLists.txt | 3 - launcher/SysInfo.cpp | 111 +++++++- launcher/SysInfo.h | 7 + launcher/filelink/FileLink.cpp | 2 - launcher/launch/steps/CheckJava.cpp | 1 - .../flame/FlameInstanceCreationTask.cpp | 4 +- launcher/ui/pages/global/JavaPage.cpp | 1 - launcher/ui/setupwizard/JavaWizardPage.cpp | 2 - launcher/ui/widgets/JavaSettingsWidget.cpp | 4 +- launcher/ui/widgets/JavaWizardWidget.cpp | 6 +- .../updater/prismupdater/PrismUpdater.cpp | 2 - libraries/README.md | 6 - libraries/systeminfo/CMakeLists.txt | 28 -- libraries/systeminfo/include/distroutils.h | 22 -- libraries/systeminfo/include/sys.h | 45 ---- libraries/systeminfo/src/distroutils.cpp | 242 ------------------ libraries/systeminfo/src/sys_apple.cpp | 57 ----- libraries/systeminfo/src/sys_test.cpp | 28 -- libraries/systeminfo/src/sys_unix.cpp | 93 ------- libraries/systeminfo/src/sys_win32.cpp | 34 --- 22 files changed, 112 insertions(+), 588 deletions(-) delete mode 100644 libraries/systeminfo/CMakeLists.txt delete mode 100644 libraries/systeminfo/include/distroutils.h delete mode 100644 libraries/systeminfo/include/sys.h delete mode 100644 libraries/systeminfo/src/distroutils.cpp delete mode 100644 libraries/systeminfo/src/sys_apple.cpp delete mode 100644 libraries/systeminfo/src/sys_test.cpp delete mode 100644 libraries/systeminfo/src/sys_unix.cpp delete mode 100644 libraries/systeminfo/src/sys_win32.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1360b82ba..02d7300d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -467,7 +467,6 @@ option(NBT_USE_ZLIB "Build NBT library with zlib support" OFF) option(NBT_BUILD_TESTS "Build NBT library tests" OFF) #FIXME: fix unit tests. add_subdirectory(libraries/libnbtplusplus) -add_subdirectory(libraries/systeminfo) # system information library add_subdirectory(libraries/launcher) # java based launcher part for Minecraft add_subdirectory(libraries/javacheck) # java compatibility checker if(FORCE_BUNDLED_ZLIB) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 2570beb3c..a011e1465 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -127,7 +127,6 @@ #include #include -#include #include #include "SysInfo.h" diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 6d6e2ae7f..f5133b299 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -1290,7 +1290,6 @@ set_project_warnings(Launcher_logic target_include_directories(Launcher_logic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_definitions(Launcher_logic PUBLIC LAUNCHER_APPLICATION) target_link_libraries(Launcher_logic - systeminfo Launcher_murmur2 nbt++ ${ZLIB_LIBRARIES} @@ -1393,7 +1392,6 @@ if(Launcher_BUILD_UPDATER) target_link_libraries(prism_updater_logic QuaZip::QuaZip ${ZLIB_LIBRARIES} - systeminfo BuildConfig Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core @@ -1436,7 +1434,6 @@ if(WIN32 OR (DEFINED Launcher_BUILD_FILELINKER AND Launcher_BUILD_FILELINKER)) target_include_directories(filelink_logic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(filelink_logic - systeminfo BuildConfig Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core diff --git a/launcher/SysInfo.cpp b/launcher/SysInfo.cpp index cfcf63805..c0e69c722 100644 --- a/launcher/SysInfo.cpp +++ b/launcher/SysInfo.cpp @@ -1,13 +1,60 @@ -#include -#include -#include "sys.h" -#ifdef Q_OS_MACOS -#include -#endif + +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2022 r58Playz + * Copyright (C) 2024 timoreo + * Copyright (C) 2024 Trial97 + * Copyright (C) 2025 TheKodeToad + * + * 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, version 3. + * + * 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 . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include #include #include #include +#include + +#if defined(Q_OS_WINDOWS) +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#elif defined(Q_OS_LINUX) +#include +#elif defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) +#include +#elif defined(Q_OS_APPLE) +#include +#endif #ifdef Q_OS_MACOS bool rosettaDetect() @@ -51,18 +98,58 @@ QString useQTForArch() return QSysInfo::currentCpuArchitecture(); } +uint64_t getSystemRamMiB() +{ +#if defined(Q_OS_WINDOWS) + MEMORYSTATUSEX status; + status.dwLength = sizeof status; + + if (GlobalMemoryStatusEx(&status)) { + // transforming bytes -> mib + return (uint64_t)status.ullTotalPhys / 1024 / 1024; + } +#elif defined(Q_OS_LINUX) + struct sysinfo info; + + if (sysinfo(&info) != -1) { + // transforming bytes -> mib + return info.totalram / 1024 / 1024; + } +#elif defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) + char buff[512]; + FILE* fp = popen("sysctl hw.physmem", "r"); + if (fp != NULL) { + if (fgets(buff, 512, fp) != NULL) { + std::string str(buff); + uint64_t mem = std::stoull(str.substr(12, std::string::npos)); + + // transforming kib -> mib + return mem / 1024; + } + } +#elif defined(Q_OS_APPLE) + uint64_t memsize; + size_t memsizesize = sizeof memsize; + + if (!sysctlbyname("hw.memsize", &memsize, &memsizesize, NULL, 0)) { + // transforming bytes -> mib + return memsize / 1024 / 1024; + } +#elif defined(__GNUC__) +#warning getSystemRam not implemented on this platform; detecting amount of installed RAM will not work +#endif + return 0; +} + int suitableMaxMem() { - float totalRAM = (float)Sys::getSystemRam() / (float)Sys::mebibyte; - int maxMemoryAlloc; + int totalRAM = getSystemRamMiB(); // If totalRAM < 6GB, use (totalRAM / 1.5), else 4GB if (totalRAM < (4096 * 1.5)) - maxMemoryAlloc = (int)(totalRAM / 1.5); + return totalRAM / 1.5; else - maxMemoryAlloc = 4096; - - return maxMemoryAlloc; + return 4096; } QString getSupportedJavaArchitecture() diff --git a/launcher/SysInfo.h b/launcher/SysInfo.h index f6c04d702..83c5ab476 100644 --- a/launcher/SysInfo.h +++ b/launcher/SysInfo.h @@ -1,9 +1,16 @@ #pragma once + +#include + #include namespace SysInfo { QString currentSystem(); QString useQTForArch(); QString getSupportedJavaArchitecture(); +/** + * @return Total system memory in mebibytes, or 0 if it could not be determined. + */ +uint64_t getSystemRamMiB(); int suitableMaxMem(); } // namespace SysInfo diff --git a/launcher/filelink/FileLink.cpp b/launcher/filelink/FileLink.cpp index 1494fa8cc..168830b6c 100644 --- a/launcher/filelink/FileLink.cpp +++ b/launcher/filelink/FileLink.cpp @@ -34,8 +34,6 @@ #include -#include - #if defined Q_OS_WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN diff --git a/launcher/launch/steps/CheckJava.cpp b/launcher/launch/steps/CheckJava.cpp index 0f8d27e94..59e8da7fe 100644 --- a/launcher/launch/steps/CheckJava.cpp +++ b/launcher/launch/steps/CheckJava.cpp @@ -36,7 +36,6 @@ #include "CheckJava.h" #include #include -#include #include #include #include diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index caf75fe6c..d47418060 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -54,7 +54,7 @@ #include "settings/INISettingsObject.h" -#include "sys.h" +#include "SysInfo.h" #include "tasks/ConcurrentTask.h" #include "ui/dialogs/BlockedModsDialog.h" #include "ui/dialogs/CustomMessageBox.h" @@ -423,7 +423,7 @@ bool FlameCreationTask::createInstance() // only set memory if this is a fresh instance if (m_instance == nullptr && recommendedRAM > 0) { - const uint64_t sysMiB = Sys::getSystemRam() / Sys::mebibyte; + const uint64_t sysMiB = SysInfo::getSystemRamMiB(); const uint64_t max = sysMiB * 0.9; if (static_cast(recommendedRAM) > max) { diff --git a/launcher/ui/pages/global/JavaPage.cpp b/launcher/ui/pages/global/JavaPage.cpp index 6a44c9290..d780ad542 100644 --- a/launcher/ui/pages/global/JavaPage.cpp +++ b/launcher/ui/pages/global/JavaPage.cpp @@ -55,7 +55,6 @@ #include "java/JavaUtils.h" #include -#include #include "Application.h" #include "settings/SettingsObject.h" diff --git a/launcher/ui/setupwizard/JavaWizardPage.cpp b/launcher/ui/setupwizard/JavaWizardPage.cpp index 6b8ece9f7..06b8a89a9 100644 --- a/launcher/ui/setupwizard/JavaWizardPage.cpp +++ b/launcher/ui/setupwizard/JavaWizardPage.cpp @@ -10,8 +10,6 @@ #include #include -#include - #include "JavaCommon.h" #include "ui/widgets/JavaWizardWidget.h" diff --git a/launcher/ui/widgets/JavaSettingsWidget.cpp b/launcher/ui/widgets/JavaSettingsWidget.cpp index 0a0d1968b..c3fb4eb36 100644 --- a/launcher/ui/widgets/JavaSettingsWidget.cpp +++ b/launcher/ui/widgets/JavaSettingsWidget.cpp @@ -46,7 +46,7 @@ #include "java/JavaInstallList.h" #include "java/JavaUtils.h" #include "settings/Setting.h" -#include "sys.h" +#include "SysInfo.h" #include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/VersionSelectDialog.h" #include "ui/java/InstallJavaDialog.h" @@ -285,7 +285,7 @@ void JavaSettingsWidget::onJavaAutodetect() } void JavaSettingsWidget::updateThresholds() { - auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; + auto sysMiB = SysInfo::getSystemRamMiB(); unsigned int maxMem = m_ui->maxMemSpinBox->value(); unsigned int minMem = m_ui->minMemSpinBox->value(); diff --git a/launcher/ui/widgets/JavaWizardWidget.cpp b/launcher/ui/widgets/JavaWizardWidget.cpp index 955bc5334..b924c810c 100644 --- a/launcher/ui/widgets/JavaWizardWidget.cpp +++ b/launcher/ui/widgets/JavaWizardWidget.cpp @@ -12,8 +12,6 @@ #include #include -#include - #include "DesktopServices.h" #include "FileSystem.h" #include "JavaCommon.h" @@ -31,7 +29,7 @@ JavaWizardWidget::JavaWizardWidget(QWidget* parent) : QWidget(parent) { - m_availableMemory = Sys::getSystemRam() / Sys::mebibyte; + m_availableMemory = SysInfo::getSystemRamMiB(); goodIcon = QIcon::fromTheme("status-good"); yellowIcon = QIcon::fromTheme("status-yellow"); @@ -556,4 +554,4 @@ void JavaWizardWidget::onSpinBoxValueChanged(int) JavaWizardWidget::~JavaWizardWidget() { delete m_verticalSpacer; -}; \ No newline at end of file +}; diff --git a/launcher/updater/prismupdater/PrismUpdater.cpp b/launcher/updater/prismupdater/PrismUpdater.cpp index 815924d52..5275b3179 100644 --- a/launcher/updater/prismupdater/PrismUpdater.cpp +++ b/launcher/updater/prismupdater/PrismUpdater.cpp @@ -40,8 +40,6 @@ #include #include -#include - #if defined Q_OS_WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN diff --git a/libraries/README.md b/libraries/README.md index be41e549f..6fac77a97 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -119,12 +119,6 @@ Color functions extracted from [KGuiAddons](https://inqlude.org/libraries/kguiad Available either under LGPL version 2.1 or later. -## systeminfo - -A Prism Launcher-specific library for probing system information. - -Apache 2.0 - ## tomlplusplus A TOML language parser. Used by Forge 1.14+ to store mod metadata. diff --git a/libraries/systeminfo/CMakeLists.txt b/libraries/systeminfo/CMakeLists.txt deleted file mode 100644 index 80b6b8094..000000000 --- a/libraries/systeminfo/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -project(systeminfo) - -if(Launcher_QT_VERSION_MAJOR EQUAL 6) - find_package(Qt6 COMPONENTS Core Core5Compat REQUIRED) - list(APPEND systeminfo_LIBS Qt${QT_VERSION_MAJOR}::Core5Compat) -endif() - -set(systeminfo_SOURCES -include/sys.h -include/distroutils.h -src/distroutils.cpp -) - -if (WIN32) - list(APPEND systeminfo_SOURCES src/sys_win32.cpp) -elseif (UNIX) - if(APPLE) - list(APPEND systeminfo_SOURCES src/sys_apple.cpp) - else() - list(APPEND systeminfo_SOURCES src/sys_unix.cpp) - endif() -endif() - -add_library(systeminfo STATIC ${systeminfo_SOURCES}) -target_link_libraries(systeminfo Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Network ${systeminfo_LIBS}) -target_include_directories(systeminfo PUBLIC include) - -ecm_add_test(src/sys_test.cpp LINK_LIBRARIES systeminfo Qt${QT_VERSION_MAJOR}::Test TEST_NAME sys) diff --git a/libraries/systeminfo/include/distroutils.h b/libraries/systeminfo/include/distroutils.h deleted file mode 100644 index caa2688cf..000000000 --- a/libraries/systeminfo/include/distroutils.h +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include "sys.h" - -namespace Sys { -struct LsbInfo { - QString distributor; - QString version; - QString description; - QString codename; -}; - -bool main_lsb_info(LsbInfo& out); -bool fallback_lsb_info(Sys::LsbInfo& out); -void lsb_postprocess(Sys::LsbInfo& lsb, Sys::DistributionInfo& out); -Sys::DistributionInfo read_lsb_release(); - -QString _extract_distribution(const QString& x); -QString _extract_version(const QString& x); -Sys::DistributionInfo read_legacy_release(); - -Sys::DistributionInfo read_os_release(); -} // namespace Sys diff --git a/libraries/systeminfo/include/sys.h b/libraries/systeminfo/include/sys.h deleted file mode 100644 index dfebbe90b..000000000 --- a/libraries/systeminfo/include/sys.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once -#include - -namespace Sys { -const uint64_t mebibyte = 1024ull * 1024ull; - -enum class KernelType { Undetermined, Windows, Darwin, Linux }; - -struct KernelInfo { - QString kernelName; - QString kernelVersion; - - KernelType kernelType = KernelType::Undetermined; - int kernelMajor = 0; - int kernelMinor = 0; - int kernelPatch = 0; - bool isCursed = false; -}; - -KernelInfo getKernelInfo(); - -struct DistributionInfo { - DistributionInfo operator+(const DistributionInfo& rhs) const - { - DistributionInfo out; - if (!distributionName.isEmpty()) { - out.distributionName = distributionName; - } else { - out.distributionName = rhs.distributionName; - } - if (!distributionVersion.isEmpty()) { - out.distributionVersion = distributionVersion; - } else { - out.distributionVersion = rhs.distributionVersion; - } - return out; - } - QString distributionName; - QString distributionVersion; -}; - -DistributionInfo getDistributionInfo(); - -uint64_t getSystemRam(); -} // namespace Sys diff --git a/libraries/systeminfo/src/distroutils.cpp b/libraries/systeminfo/src/distroutils.cpp deleted file mode 100644 index 294dfadbb..000000000 --- a/libraries/systeminfo/src/distroutils.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/* - -Code has been taken from https://github.com/natefoo/lionshead and loosely -translated to C++ laced with Qt. - -MIT License - -Copyright (c) 2017 Nate Coraor - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#include "distroutils.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -static const QRegularExpression s_distoSplitRegex("\\s+"); - -Sys::DistributionInfo Sys::read_os_release() -{ - Sys::DistributionInfo out; - QStringList files = { "/etc/os-release", "/usr/lib/os-release" }; - QString name; - QString version; - for (auto& file : files) { - if (!QFile::exists(file)) { - continue; - } - QSettings settings(file, QSettings::IniFormat); - if (settings.contains("ID")) { - name = settings.value("ID").toString().toLower(); - } else if (settings.contains("NAME")) { - name = settings.value("NAME").toString().toLower(); - } else { - continue; - } - - if (settings.contains("VERSION_ID")) { - version = settings.value("VERSION_ID").toString().toLower(); - } else if (settings.contains("VERSION")) { - version = settings.value("VERSION").toString().toLower(); - } - break; - } - if (name.isEmpty()) { - return out; - } - out.distributionName = name; - out.distributionVersion = version; - return out; -} - -bool Sys::main_lsb_info(Sys::LsbInfo& out) -{ - int status = 0; - QProcess lsbProcess; - QStringList arguments; - arguments << "-a"; - lsbProcess.start("lsb_release", arguments); - lsbProcess.waitForFinished(); - status = lsbProcess.exitStatus(); - QString output = lsbProcess.readAllStandardOutput(); - qDebug() << output; - lsbProcess.close(); - if (status == 0) { - auto lines = output.split('\n'); - for (auto line : lines) { - int index = line.indexOf(':'); - auto key = line.left(index).trimmed(); - auto value = line.mid(index + 1).toLower().trimmed(); - if (key == "Distributor ID") - out.distributor = value; - else if (key == "Release") - out.version = value; - else if (key == "Description") - out.description = value; - else if (key == "Codename") - out.codename = value; - } - return !out.distributor.isEmpty(); - } - return false; -} - -bool Sys::fallback_lsb_info(Sys::LsbInfo& out) -{ - // running lsb_release failed, try to read the file instead - // /etc/lsb-release format, if the file even exists, is non-standard. - // Only the `lsb_release` command is specified by LSB. Nonetheless, some - // distributions install an /etc/lsb-release as part of the base - // distribution, but `lsb_release` remains optional. - QString file = "/etc/lsb-release"; - if (QFile::exists(file)) { - QSettings settings(file, QSettings::IniFormat); - if (settings.contains("DISTRIB_ID")) { - out.distributor = settings.value("DISTRIB_ID").toString().toLower(); - } - if (settings.contains("DISTRIB_RELEASE")) { - out.version = settings.value("DISTRIB_RELEASE").toString().toLower(); - } - return !out.distributor.isEmpty(); - } - return false; -} - -void Sys::lsb_postprocess(Sys::LsbInfo& lsb, Sys::DistributionInfo& out) -{ - QString dist = lsb.distributor; - QString vers = lsb.version; - if (dist.startsWith("redhatenterprise")) { - dist = "rhel"; - } else if (dist == "archlinux") { - dist = "arch"; - } else if (dist.startsWith("suse")) { - if (lsb.description.startsWith("opensuse")) { - dist = "opensuse"; - } else if (lsb.description.startsWith("suse linux enterprise")) { - dist = "sles"; - } - } else if (dist == "debian" and vers == "testing") { - vers = lsb.codename; - } else { - // ubuntu, debian, gentoo, scientific, slackware, ... ? - auto parts = dist.split(s_distoSplitRegex, Qt::SkipEmptyParts); - if (parts.size()) { - dist = parts[0]; - } - } - if (!dist.isEmpty()) { - out.distributionName = dist; - out.distributionVersion = vers; - } -} - -Sys::DistributionInfo Sys::read_lsb_release() -{ - LsbInfo lsb; - if (!main_lsb_info(lsb)) { - if (!fallback_lsb_info(lsb)) { - return Sys::DistributionInfo(); - } - } - Sys::DistributionInfo out; - lsb_postprocess(lsb, out); - return out; -} - -QString Sys::_extract_distribution(const QString& x) -{ - QString release = x.toLower(); - if (release.startsWith("red hat enterprise")) { - return "rhel"; - } - if (release.startsWith("suse linux enterprise")) { - return "sles"; - } - QStringList list = release.split(s_distoSplitRegex, Qt::SkipEmptyParts); - if (list.size()) { - return list[0]; - } - return QString(); -} - -QString Sys::_extract_version(const QString& x) -{ - static const QRegularExpression s_versionishString(QRegularExpression::anchoredPattern("\\d+(?:\\.\\d+)*$")); - QStringList list = x.split(s_distoSplitRegex, Qt::SkipEmptyParts); - for (int i = list.size() - 1; i >= 0; --i) { - QString chunk = list[i]; - if (s_versionishString.match(chunk).hasMatch()) { - return chunk; - } - } - return QString(); -} - -Sys::DistributionInfo Sys::read_legacy_release() -{ - struct checkEntry { - QString file; - std::function extract_distro; - std::function extract_version; - }; - QList checks = { - { "/etc/arch-release", [](const QString&) { return "arch"; }, [](const QString&) { return "rolling"; } }, - { "/etc/slackware-version", &Sys::_extract_distribution, &Sys::_extract_version }, - { QString(), &Sys::_extract_distribution, &Sys::_extract_version }, - { "/etc/debian_version", [](const QString&) { return "debian"; }, [](const QString& x) { return x; } }, - }; - for (auto& check : checks) { - QStringList files; - if (check.file.isNull()) { - QDir etcDir("/etc"); - etcDir.setNameFilters({ "*-release" }); - etcDir.setFilter(QDir::Files | QDir::NoDot | QDir::NoDotDot | QDir::Readable | QDir::Hidden); - files = etcDir.entryList(); - } else { - files.append(check.file); - } - for (auto file : files) { - QFile relfile(file); - if (!relfile.open(QIODevice::ReadOnly | QIODevice::Text)) - continue; - QString contents = QString::fromUtf8(relfile.readLine()).trimmed(); - QString dist = check.extract_distro(contents); - QString vers = check.extract_version(contents); - if (!dist.isEmpty()) { - Sys::DistributionInfo out; - out.distributionName = dist; - out.distributionVersion = vers; - return out; - } - } - } - return Sys::DistributionInfo(); -} diff --git a/libraries/systeminfo/src/sys_apple.cpp b/libraries/systeminfo/src/sys_apple.cpp deleted file mode 100644 index 5cf70f1aa..000000000 --- a/libraries/systeminfo/src/sys_apple.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "sys.h" - -#include - -#include -#include -#include - -Sys::KernelInfo Sys::getKernelInfo() -{ - Sys::KernelInfo out; - struct utsname buf; - uname(&buf); - out.kernelType = KernelType::Darwin; - out.kernelName = buf.sysname; - QString release = out.kernelVersion = buf.release; - - // TODO: figure out how to detect cursed-ness (macOS emulated on linux via mad hacks and so on) - out.isCursed = false; - - out.kernelMajor = 0; - out.kernelMinor = 0; - out.kernelPatch = 0; - auto sections = release.split('-'); - if (sections.size() >= 1) { - auto versionParts = sections[0].split('.'); - if (versionParts.size() >= 3) { - out.kernelMajor = versionParts[0].toInt(); - out.kernelMinor = versionParts[1].toInt(); - out.kernelPatch = versionParts[2].toInt(); - } else { - qWarning() << "Not enough version numbers in " << sections[0] << " found " << versionParts.size(); - } - } else { - qWarning() << "Not enough '-' sections in " << release << " found " << sections.size(); - } - return out; -} - -#include - -uint64_t Sys::getSystemRam() -{ - uint64_t memsize; - size_t memsizesize = sizeof(memsize); - if (!sysctlbyname("hw.memsize", &memsize, &memsizesize, NULL, 0)) { - return memsize; - } else { - return 0; - } -} - -Sys::DistributionInfo Sys::getDistributionInfo() -{ - DistributionInfo result; - return result; -} diff --git a/libraries/systeminfo/src/sys_test.cpp b/libraries/systeminfo/src/sys_test.cpp deleted file mode 100644 index 50c75eb77..000000000 --- a/libraries/systeminfo/src/sys_test.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include - -#include - -class SysTest : public QObject { - Q_OBJECT - private slots: - - void test_kernelNotNull() - { - auto kinfo = Sys::getKernelInfo(); - QVERIFY(!kinfo.kernelName.isEmpty()); - QVERIFY(kinfo.kernelVersion != "0.0"); - } - /* - void test_systemDistroNotNull() - { - auto kinfo = Sys::getDistributionInfo(); - QVERIFY(!kinfo.distributionName.isEmpty()); - QVERIFY(!kinfo.distributionVersion.isEmpty()); - qDebug() << "Distro: " << kinfo.distributionName << "version" << kinfo.distributionVersion; - } - */ -}; - -QTEST_GUILESS_MAIN(SysTest) - -#include "sys_test.moc" diff --git a/libraries/systeminfo/src/sys_unix.cpp b/libraries/systeminfo/src/sys_unix.cpp deleted file mode 100644 index 4e075959a..000000000 --- a/libraries/systeminfo/src/sys_unix.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "sys.h" - -#include "distroutils.h" - -#include -#include -#include - -#include -#include -#include - -Sys::KernelInfo Sys::getKernelInfo() -{ - Sys::KernelInfo out; - struct utsname buf; - uname(&buf); - // NOTE: we assume linux here. this needs further elaboration - out.kernelType = KernelType::Linux; - out.kernelName = buf.sysname; - QString release = out.kernelVersion = buf.release; - - // linux binary running on WSL is cursed. - out.isCursed = release.contains("WSL", Qt::CaseInsensitive) || release.contains("Microsoft", Qt::CaseInsensitive); - - out.kernelMajor = 0; - out.kernelMinor = 0; - out.kernelPatch = 0; - auto sections = release.split('-'); - if (sections.size() >= 1) { - auto versionParts = sections[0].split('.'); - if (versionParts.size() >= 3) { - out.kernelMajor = versionParts[0].toInt(); - out.kernelMinor = versionParts[1].toInt(); - out.kernelPatch = versionParts[2].toInt(); - } else { - qWarning() << "Not enough version numbers in " << sections[0] << " found " << versionParts.size(); - } - } else { - qWarning() << "Not enough '-' sections in " << release << " found " << sections.size(); - } - return out; -} - -uint64_t Sys::getSystemRam() -{ - std::string token; -#ifdef Q_OS_LINUX - std::ifstream file("/proc/meminfo"); - while (file >> token) { - if (token == "MemTotal:") { - uint64_t mem; - if (file >> mem) { - return mem * 1024ull; - } else { - return 0; - } - } - // ignore rest of the line - file.ignore(std::numeric_limits::max(), '\n'); - } -#elif defined(Q_OS_FREEBSD) - char buff[512]; - FILE* fp = popen("sysctl hw.physmem", "r"); - if (fp != NULL) { - while (fgets(buff, 512, fp) != NULL) { - std::string str(buff); - uint64_t mem = std::stoull(str.substr(12, std::string::npos)); - return mem * 1024ull; - } - } -#endif - return 0; // nothing found -} - -Sys::DistributionInfo Sys::getDistributionInfo() -{ - DistributionInfo systemd_info = read_os_release(); - DistributionInfo lsb_info = read_lsb_release(); - DistributionInfo legacy_info = read_legacy_release(); - DistributionInfo result = systemd_info + lsb_info + legacy_info; - if (result.distributionName.isNull()) { - result.distributionName = "unknown"; - } - if (result.distributionVersion.isNull()) { - if (result.distributionName == "arch") { - result.distributionVersion = "rolling"; - } else { - result.distributionVersion = "unknown"; - } - } - return result; -} diff --git a/libraries/systeminfo/src/sys_win32.cpp b/libraries/systeminfo/src/sys_win32.cpp deleted file mode 100644 index 2627761d1..000000000 --- a/libraries/systeminfo/src/sys_win32.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "sys.h" - -#include - -Sys::KernelInfo Sys::getKernelInfo() -{ - Sys::KernelInfo out; - out.kernelType = KernelType::Windows; - out.kernelName = "Windows"; - OSVERSIONINFOW osvi; - ZeroMemory(&osvi, sizeof(OSVERSIONINFOW)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW); - GetVersionExW(&osvi); - out.kernelVersion = QString("%1.%2").arg(osvi.dwMajorVersion).arg(osvi.dwMinorVersion); - out.kernelMajor = osvi.dwMajorVersion; - out.kernelMinor = osvi.dwMinorVersion; - out.kernelPatch = osvi.dwBuildNumber; - return out; -} - -uint64_t Sys::getSystemRam() -{ - MEMORYSTATUSEX status; - status.dwLength = sizeof(status); - GlobalMemoryStatusEx(&status); - // bytes - return (uint64_t)status.ullTotalPhys; -} - -Sys::DistributionInfo Sys::getDistributionInfo() -{ - DistributionInfo result; - return result; -} From 7f7649f13daba4c2b03e4b2689e8ed506059950b Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 8 Nov 2025 19:38:30 +0000 Subject: [PATCH 2/3] Replace some NULLs with nullptr Signed-off-by: TheKodeToad --- launcher/SysInfo.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/launcher/SysInfo.cpp b/launcher/SysInfo.cpp index c0e69c722..a0891b538 100644 --- a/launcher/SysInfo.cpp +++ b/launcher/SysInfo.cpp @@ -61,7 +61,7 @@ bool rosettaDetect() { int ret = 0; size_t size = sizeof(ret); - if (sysctlbyname("sysctl.proc_translated", &ret, &size, NULL, 0) == -1) { + if (sysctlbyname("sysctl.proc_translated", &ret, &size, nullptr, 0) == -1) { return false; } return ret == 1; @@ -118,8 +118,8 @@ uint64_t getSystemRamMiB() #elif defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) char buff[512]; FILE* fp = popen("sysctl hw.physmem", "r"); - if (fp != NULL) { - if (fgets(buff, 512, fp) != NULL) { + if (fp != nullptr) { + if (fgets(buff, 512, fp) != nullptr) { std::string str(buff); uint64_t mem = std::stoull(str.substr(12, std::string::npos)); @@ -131,7 +131,7 @@ uint64_t getSystemRamMiB() uint64_t memsize; size_t memsizesize = sizeof memsize; - if (!sysctlbyname("hw.memsize", &memsize, &memsizesize, NULL, 0)) { + if (!sysctlbyname("hw.memsize", &memsize, &memsizesize, nullptr, 0)) { // transforming bytes -> mib return memsize / 1024 / 1024; } From 5465f17916eb2da886c2e53e264402cf5434422b Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 15 Nov 2025 10:33:27 +0000 Subject: [PATCH 3/3] Check for __clang__ too Signed-off-by: TheKodeToad --- launcher/SysInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/SysInfo.cpp b/launcher/SysInfo.cpp index a0891b538..0e2eb2ff7 100644 --- a/launcher/SysInfo.cpp +++ b/launcher/SysInfo.cpp @@ -135,7 +135,7 @@ uint64_t getSystemRamMiB() // transforming bytes -> mib return memsize / 1024 / 1024; } -#elif defined(__GNUC__) +#elif defined(__GNUC__) || defined(__clang__) #warning getSystemRam not implemented on this platform; detecting amount of installed RAM will not work #endif return 0;