mirror of
https://github.com/VSCodium/policy-watcher.git
synced 2025-12-10 21:07:21 -06:00
Merge tag 'v1.1.10'
This commit is contained in:
commit
f39ea93244
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@vscodium/policy-watcher",
|
"name": "@vscodium/policy-watcher",
|
||||||
"version": "1.1.8-2501211616",
|
"version": "1.1.10-2503041159",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@ -8,9 +8,9 @@
|
|||||||
using namespace Napi;
|
using namespace Napi;
|
||||||
|
|
||||||
NumberPolicy::NumberPolicy(const std::string name, const std::string &vendorName, const std::string &productName)
|
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);
|
return *reinterpret_cast<long long *>(buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ public:
|
|||||||
NumberPolicy(const std::string name, const std::string &vendorName, const std::string &productName);
|
NumberPolicy(const std::string name, const std::string &vendorName, const std::string &productName);
|
||||||
|
|
||||||
protected:
|
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;
|
Value getJSValue(Env env, long long value) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,8 @@
|
|||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
#include "../Policy.hh"
|
#include "../Policy.hh"
|
||||||
|
|
||||||
using namespace Napi;
|
using namespace Napi;
|
||||||
@ -17,10 +19,10 @@ template <typename T>
|
|||||||
class RegistryPolicy : public Policy
|
class RegistryPolicy : public Policy
|
||||||
{
|
{
|
||||||
public:
|
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),
|
: Policy(name),
|
||||||
registryKey("Software\\Policies\\" + vendorName + "\\" + productName),
|
registryKey("Software\\Policies\\" + vendorName + "\\" + productName),
|
||||||
regType(regType) {}
|
supportedTypes(types) {}
|
||||||
|
|
||||||
bool refresh()
|
bool refresh()
|
||||||
{
|
{
|
||||||
@ -57,12 +59,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
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;
|
virtual Value getJSValue(Env env, T value) const = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string registryKey;
|
const std::string registryKey;
|
||||||
const DWORD regType;
|
const std::vector<DWORD> supportedTypes;
|
||||||
std::optional<T> value;
|
std::optional<T> value;
|
||||||
|
|
||||||
std::optional<T> read(HKEY root)
|
std::optional<T> read(HKEY root)
|
||||||
@ -72,17 +74,32 @@ private:
|
|||||||
if (ERROR_SUCCESS != RegOpenKeyEx(root, registryKey.c_str(), 0, KEY_READ, &hKey))
|
if (ERROR_SUCCESS != RegOpenKeyEx(root, registryKey.c_str(), 0, KEY_READ, &hKey))
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
BYTE buffer[1024];
|
DWORD bufferSize = 0;
|
||||||
DWORD bufferSize = sizeof(buffer);
|
|
||||||
DWORD type;
|
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);
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
if (ERROR_SUCCESS != readResult || type != regType)
|
if (ERROR_SUCCESS != result)
|
||||||
return std::nullopt;
|
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;
|
using namespace Napi;
|
||||||
|
|
||||||
StringPolicy::StringPolicy(const std::string name, const std::string &vendorName, const std::string &productName)
|
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);
|
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);
|
StringPolicy(const std::string name, const std::string &vendorName, const std::string &productName);
|
||||||
|
|
||||||
protected:
|
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;
|
Value getJSValue(Env env, std::string value) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user