Cockatrice/libcockatrice_utility/libcockatrice/utility/system_memory_querier.h
Lukas Brübach d5094a8d00 [Oracle] Fix Qt6 build and treat unknown memory as sufficient
Use QRegularExpression behind the same Qt version guard as
totalMemoryBytes() in availableMemoryBytes(), where a bare QRegExp
broke every Qt6 Linux build. hasAtLeastGiB() now treats a 0 reading
(unsupported platform or failed query) as unknown and skips the
low-memory prompt instead of misreading it as low memory.
2026-10-13 07:19:45 +02:00

25 lines
738 B
C++

#ifndef COCKATRICE_SYSTEM_MEMORY_QUERIER_H
#define COCKATRICE_SYSTEM_MEMORY_QUERIER_H
#include <QtGlobal>
class SystemMemoryQuerier
{
public:
static qulonglong totalMemoryBytes();
static qulonglong availableMemoryBytes();
static bool hasAtLeastGiB(int gib)
{
const qulonglong total = totalMemoryBytes();
// 0 means the amount could not be determined (unsupported platform or failed query).
// Treat it as unknown and skip the check instead of misreading it as low memory.
if (total == 0) {
return true;
}
const qulonglong GiB = 1024ull * 1024ull * 1024ull;
return total >= (qulonglong)gib * GiB;
}
};
#endif // COCKATRICE_SYSTEM_MEMORY_QUERIER_H