Skip to content

Commit

Permalink
add system check and block on new windows versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky committed Jun 7, 2024
1 parent a2001b3 commit 6b96be7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "./theme.hpp"
#include "./chat_gui/theme.hpp"

#include "./sys_check.hpp"

#include "./start_screen.hpp"

#include <filesystem>
Expand All @@ -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());
Expand Down
46 changes: 46 additions & 0 deletions src/sys_check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "./sys_check.hpp"

// use message boxes to notify the user of system failure
#include <SDL3/SDL.h>

#include <cstdlib>

#if defined(_WIN32) || defined(WIN32)

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <windows.h>

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

4 changes: 4 additions & 0 deletions src/sys_check.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

// perform system checks and potentially terminate
void runSysCheck(void);

0 comments on commit 6b96be7

Please sign in to comment.