56 lines
2.3 KiB
C++
56 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <windows.h>
|
|
#include <shellapi.h>
|
|
#include <string>
|
|
|
|
namespace smart_app_control {
|
|
|
|
enum class State { Off, Enforced, Evaluation, Missing, Unavailable };
|
|
|
|
inline State read_policy() {
|
|
DWORD value = 0, bytes = sizeof(value);
|
|
const auto rc = RegGetValueW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\CI\\Policy",
|
|
L"VerifiedAndReputablePolicyState", RRF_RT_REG_DWORD, nullptr, &value, &bytes);
|
|
if (rc == ERROR_FILE_NOT_FOUND || rc == ERROR_PATH_NOT_FOUND) return State::Missing;
|
|
if (rc != ERROR_SUCCESS) return State::Unavailable;
|
|
switch (value) {
|
|
case 0: return State::Off;
|
|
case 1: return State::Enforced;
|
|
case 2: return State::Evaluation;
|
|
default: return State::Unavailable;
|
|
}
|
|
}
|
|
|
|
inline const char* describe(State state) {
|
|
switch (state) {
|
|
case State::Off: return "off (0)";
|
|
case State::Enforced: return "enforced (1)";
|
|
case State::Evaluation: return "evaluation (2)";
|
|
case State::Missing: return "not configured (key absent)";
|
|
default: return "unavailable";
|
|
}
|
|
}
|
|
|
|
inline constexpr wchar_t help_url[] = L"https://dl.hybridgateway.eu/client/smart-app-control.html";
|
|
inline constexpr wchar_t explanation[] =
|
|
L"Windows Smart App Control can block the game's self-signed gateway files. "
|
|
L"Windows Security shows the policy under App & browser control > Smart App Control settings. "
|
|
L"Turning it off affects every app on the device. Older Windows versions may require a reset or "
|
|
L"reinstall to turn it on again. Follow the warning shown on your PC.";
|
|
|
|
inline void show_help(HWND owner, const wchar_t* context) {
|
|
const std::wstring text = std::wstring(context) + L"\n\n" + explanation +
|
|
L"\n\nOpen the OctoWoW help page?\n" + help_url;
|
|
if (MessageBoxW(owner, text.c_str(), L"OctoWoW - Smart App Control",
|
|
MB_YESNO | MB_DEFBUTTON2 | MB_ICONINFORMATION) == IDYES)
|
|
ShellExecuteW(owner, L"open", help_url, nullptr, nullptr, SW_SHOWNORMAL);
|
|
}
|
|
|
|
inline bool mentions_error(const std::string& text) {
|
|
constexpr char utf16le[] = "0\0x\0c\0" "0\0e\0" "9\0" "0\0" "0\0" "0\0" "2\0";
|
|
return text.find("0xc0e90002") != std::string::npos ||
|
|
text.find(utf16le, 0, sizeof(utf16le) - 1) != std::string::npos;
|
|
}
|
|
}
|