#include #include #include #include #include // ReSharper disable once CppUnusedIncludeDirective #include #include #include #include "util.h" using namespace winrt; using namespace winrt::Windows::Media::Control; struct KBToGiB { u64 value; }; template <> struct fmt::formatter : formatter { template typename FormatContext::iterator format(const KBToGiB KTG, FormatContext& ctx) { typename FormatContext::iterator out = formatter::format( static_cast(KTG.value) / pow(1024, 2), ctx ); *out++ = 'G'; *out++ = 'i'; *out++ = 'B'; return out; } }; enum DateNum { Ones, Twos, Threes, Default }; DateNum ParseDate(std::string const& input) { if (input == "1" || input == "21" || input == "31") return Ones; if (input == "2" || input == "22") return Twos; if (input == "3" || input == "23") return Threes; return Default; } std::string GetNowPlaying() { using namespace winrt::Windows::Media::Control; using namespace winrt::Windows::Foundation; using MediaProperties = GlobalSystemMediaTransportControlsSessionMediaProperties; using Session = GlobalSystemMediaTransportControlsSession; using SessionManager = GlobalSystemMediaTransportControlsSessionManager; try { // Request the session manager asynchronously const IAsyncOperation sessionManagerOp = SessionManager::RequestAsync(); const SessionManager sessionManager = sessionManagerOp.get(); if (const Session currentSession = sessionManager.GetCurrentSession()) { // Try to get the media properties asynchronously const IAsyncOperation mediaPropertiesOp = currentSession.TryGetMediaPropertiesAsync(); const MediaProperties mediaProperties = mediaPropertiesOp.get(); // Convert the hstring title to std::string return to_string(mediaProperties.Title()); } // If we reach this point, there is no current session return "No current media session."; } catch (...) { return "Failed to get media properties."; } } std::string getRegistryValue( const HKEY& hKey, const std::string& subKey, const std::string& valueName ) { HKEY key; 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 ""; } std::string value(dataSize, '\0'); if (RegQueryValueExA( key, valueName.c_str(), nullptr, nullptr, reinterpret_cast(&value[0]), &dataSize ) != ERROR_SUCCESS) { RegCloseKey(key); return ""; } RegCloseKey(key); // Remove null terminator if present if (!value.empty() && value.back() == '\0') value.pop_back(); return value; } std::string getPrettyWindowsName() { std::string productName = getRegistryValue( HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "ProductName" ); const std::string displayVersion = getRegistryValue( HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "DisplayVersion" ); const std::string releaseId = getRegistryValue( HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "ReleaseId" ); const int buildNumber = stoi(getRegistryValue( HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "CurrentBuildNumber" )); fmt::println("Build number: {}", buildNumber); // Check if the build number is 22000 or higher if (buildNumber >= 22000 && productName.find("Windows 10") != std::string::npos) productName.replace(productName.find("Windows 10"), 10, "Windows 11"); if (!productName.empty()) { std::string result = productName; if (!displayVersion.empty()) result += " " + displayVersion; else if (!releaseId.empty()) result += " " + releaseId; return result; } return ""; } int main() { init_apartment(); u64 memInfo; GetPhysicallyInstalledSystemMemory(&memInfo); fmt::println("Installed RAM: {:.2f}", KBToGiB {memInfo}); fmt::println("Now playing: {}", GetNowPlaying()); const std::tm localTime = fmt::localtime(time(nullptr)); std::string date = fmt::format("{:%e}", localTime); auto start = date.begin(); while (start != date.end() && std::isspace(*start)) ++start; date.erase(date.begin(), start); switch (ParseDate(date)) { case Ones: date += "st"; break; case Twos: date += "nd"; break; case Threes: date += "rd"; break; case Default: date += "th"; break; } fmt::println("{:%B} {}, {:%-I:%0M %p}", localTime, date, localTime); fmt::println("Version: {}", getPrettyWindowsName()); uninit_apartment(); return 0; }