mirror of
https://github.com/VSCodium/policy-watcher.git
synced 2025-12-10 03:53:55 -06:00
Merge tag 'v1.1.10'
This commit is contained in:
commit
f39ea93244
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vscodium/policy-watcher",
|
||||
"version": "1.1.8-2501211616",
|
||||
"version": "1.1.10-2503041159",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
|
||||
@ -8,9 +8,9 @@
|
||||
using namespace Napi;
|
||||
|
||||
NumberPolicy::NumberPolicy(const std::string name, const std::string &vendorName, const std::string &productName)
|
||||
: RegistryPolicy(name, vendorName, productName, REG_QWORD) {}
|
||||
: RegistryPolicy(name, vendorName, productName, {REG_QWORD}) {}
|
||||
|
||||
long long NumberPolicy::parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const
|
||||
long long NumberPolicy::parseRegistryValue(LPBYTE buffer, DWORD bufferSize, DWORD type) const
|
||||
{
|
||||
return *reinterpret_cast<long long *>(buffer);
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ public:
|
||||
NumberPolicy(const std::string name, const std::string &vendorName, const std::string &productName);
|
||||
|
||||
protected:
|
||||
long long parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const;
|
||||
long long parseRegistryValue(LPBYTE buffer, DWORD bufferSize, DWORD type) const;
|
||||
Value getJSValue(Env env, long long value) const;
|
||||
};
|
||||
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
#include <napi.h>
|
||||
#include <windows.h>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "../Policy.hh"
|
||||
|
||||
using namespace Napi;
|
||||
@ -17,10 +19,10 @@ template <typename T>
|
||||
class RegistryPolicy : public Policy
|
||||
{
|
||||
public:
|
||||
RegistryPolicy(const std::string name, const std::string &vendorName, const std::string &productName, const DWORD regType)
|
||||
RegistryPolicy(const std::string name, const std::string &vendorName, const std::string &productName, const std::vector<DWORD>& types)
|
||||
: Policy(name),
|
||||
registryKey("Software\\Policies\\" + vendorName + "\\" + productName),
|
||||
regType(regType) {}
|
||||
supportedTypes(types) {}
|
||||
|
||||
bool refresh()
|
||||
{
|
||||
@ -57,12 +59,12 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual T parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const = 0;
|
||||
virtual T parseRegistryValue(LPBYTE buffer, DWORD bufferSize, DWORD type) const = 0;
|
||||
virtual Value getJSValue(Env env, T value) const = 0;
|
||||
|
||||
private:
|
||||
const std::string registryKey;
|
||||
const DWORD regType;
|
||||
const std::vector<DWORD> supportedTypes;
|
||||
std::optional<T> value;
|
||||
|
||||
std::optional<T> read(HKEY root)
|
||||
@ -72,17 +74,32 @@ private:
|
||||
if (ERROR_SUCCESS != RegOpenKeyEx(root, registryKey.c_str(), 0, KEY_READ, &hKey))
|
||||
return std::nullopt;
|
||||
|
||||
BYTE buffer[1024];
|
||||
DWORD bufferSize = sizeof(buffer);
|
||||
DWORD bufferSize = 0;
|
||||
DWORD type;
|
||||
|
||||
auto readResult = RegQueryValueEx(hKey, name.c_str(), 0, &type, buffer, &bufferSize);
|
||||
// First query to get required buffer size
|
||||
auto result = RegQueryValueEx(hKey, name.c_str(), 0, &type, nullptr, &bufferSize);
|
||||
|
||||
if (ERROR_SUCCESS != result && ERROR_MORE_DATA != result)
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (std::find(supportedTypes.begin(), supportedTypes.end(), type) == supportedTypes.end())
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::vector<BYTE> buffer(bufferSize);
|
||||
result = RegQueryValueEx(hKey, name.c_str(), 0, &type, buffer.data(), &bufferSize);
|
||||
RegCloseKey(hKey);
|
||||
|
||||
if (ERROR_SUCCESS != readResult || type != regType)
|
||||
if (ERROR_SUCCESS != result)
|
||||
return std::nullopt;
|
||||
|
||||
return std::optional<T>{parseRegistryValue(buffer, bufferSize)};
|
||||
return std::optional<T>{parseRegistryValue(buffer.data(), bufferSize, type)};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -8,10 +8,31 @@
|
||||
using namespace Napi;
|
||||
|
||||
StringPolicy::StringPolicy(const std::string name, const std::string &vendorName, const std::string &productName)
|
||||
: RegistryPolicy(name, vendorName, productName, REG_SZ) {}
|
||||
: RegistryPolicy(name, vendorName, productName, {REG_SZ, REG_MULTI_SZ}) {}
|
||||
|
||||
std::string StringPolicy::parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const
|
||||
std::string StringPolicy::parseRegistryValue(LPBYTE buffer, DWORD bufferSize, DWORD type) const
|
||||
{
|
||||
if (type == REG_MULTI_SZ)
|
||||
{
|
||||
std::string result;
|
||||
const char *current = reinterpret_cast<char *>(buffer);
|
||||
const char *end = reinterpret_cast<char *>(buffer) + bufferSize;
|
||||
|
||||
while (current < end && *current != '\0')
|
||||
{
|
||||
std::string line(current);
|
||||
if (!result.empty())
|
||||
{
|
||||
result += '\n';
|
||||
}
|
||||
result += line;
|
||||
current += line.length() + 1; // Skip past null terminator
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// REG_SZ handling
|
||||
return std::string(reinterpret_cast<char *>(buffer), bufferSize - 1);
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ public:
|
||||
StringPolicy(const std::string name, const std::string &vendorName, const std::string &productName);
|
||||
|
||||
protected:
|
||||
std::string parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const;
|
||||
std::string parseRegistryValue(LPBYTE buffer, DWORD bufferSize, DWORD type) const;
|
||||
Value getJSValue(Env env, std::string value) const;
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user