diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b778966..63596938 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,6 +13,9 @@ target_sources(tomato PUBLIC ./main.cpp ./icon.rc + ./sys_check.hpp + ./sys_check.cpp + ./json_to_config.hpp ./json_to_config.cpp diff --git a/src/main.cpp b/src/main.cpp index 270b1699..f38e588e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,8 @@ #include "./theme.hpp" #include "./chat_gui/theme.hpp" +#include "./sys_check.hpp" + #include "./start_screen.hpp" #include @@ -24,6 +26,8 @@ int main(int argc, char** argv) { args.push_back(argv[i]); } + runSysCheck(); + #ifdef __ANDROID__ // change current working dir to internal storage std::filesystem::current_path(SDL_AndroidGetInternalStoragePath()); diff --git a/src/sys_check.cpp b/src/sys_check.cpp new file mode 100644 index 00000000..e6446d9e --- /dev/null +++ b/src/sys_check.cpp @@ -0,0 +1,46 @@ +#include "./sys_check.hpp" + +// use message boxes to notify the user of system failure +#include + +#include + +#if defined(_WIN32) || defined(WIN32) + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include + +typedef LONG NTSTATUS, *PNTSTATUS; +#define STATUS_SUCCESS (0x00000000) + +void runSysCheck(void) { + NTSTATUS(WINAPI *RtlGetVersion)(LPOSVERSIONINFOEXW); + OSVERSIONINFOEXW osInfo; + + *(FARPROC*)&RtlGetVersion = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion"); + + if (NULL != RtlGetVersion) { + osInfo.dwOSVersionInfoSize = sizeof(osInfo); + RtlGetVersion(&osInfo); + + // check + if ( + osInfo.dwBuildNumber >= 26000 // canary versions of 11 24H2 included + ) { + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Unsupported System", "Your version of windows is too new and endangers the privacy of all involved.", nullptr); + exit(0); + } + } +} + +#else + +void runSysCheck(void) { + // do nothing +} + +#endif + diff --git a/src/sys_check.hpp b/src/sys_check.hpp new file mode 100644 index 00000000..ea324b0c --- /dev/null +++ b/src/sys_check.hpp @@ -0,0 +1,4 @@ +#pragma once + +// perform system checks and potentially terminate +void runSysCheck(void);