Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Arteiii authored Feb 12, 2024
2 parents b838081 + 3924aea commit cee7b7f
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 29 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ClangFormat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Clang Format Checker and Auto-Fixer
on:
pull_request:
branches: [main]

jobs:
clang-format-checking:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2

- name: Install Clang
run: sudo apt-get update && sudo apt-get install -y clang

- name: Install GitHub CLI
run: |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
- name: Check and Auto-Fix Formatting
run: |
find . \( -name "*.h" -or -name "*.c" -or -name "*.cpp" -or -name "*.hpp" -or -name "*.cc" -or -name "*.cxx" -or -name "*.hxx" -or -name "*.inl" -or -name "*.ipp" \) \
| xargs clang-format -i -style=file
- name: Commit changes (if any)
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git diff --exit-code || (git add -A && git commit -m "Auto-fix formatting issues")
# Push changes to the current branch
git push origin HEAD
5 changes: 5 additions & 0 deletions .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
run: |
msbuild /p:Configuration=Release /t:RegistryHelper /p:Platform=x64 RegistryHelper.sln
- name: Copy .h file to Release folder
run: |
copy RegistryHelper\RegistryHelper.h x64\Release
- name: Upload to Release
uses: actions/upload-artifact@v2
with:
Expand All @@ -28,6 +32,7 @@ jobs:
RegistryHelper/RegistryHelper.h
x64/Release/RegistryHelper.lib
x64/Release/RegistryHelper.pdb
x64/Release/RegistryHelper.h
release:
needs: build
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ std::vector<std::pair<std::wstring, DWORD>> subKeys =
// Example 5: Enumerate values
std::vector<std::pair<std::wstring, DWORD>> values =
registryHelper.RegEnumValues(hKey, subKey);


// Set DWORD value under a non-existing key (will create the key first)
registryHelper.RegSetDword(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\NewApp",
L"NewDWORD",
123);
```

Adjust the registry keys, subkeys, and value names based on your specific use case.
Expand Down
56 changes: 37 additions & 19 deletions RegistryHelper/RegistryHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ RegistryHelper::RegEnumSubKeys(HKEY hKey, const std::wstring &subKey) {
throw RegistryError{
"RegQueryInfoKey failed while preparing for value enumeration",
retCode};

};
}

// Allocate a buffer for storing subkey names
Expand Down Expand Up @@ -238,46 +240,62 @@ RegistryHelper::RegEnumValues(HKEY hKey, const std::wstring &subKey) {

return valueInfo;
}
<<<<<<< Updated upstream
=======

void RegistryHelper::RegSetDword(HKEY hKey, const std::wstring &subKey,
const std::wstring &value, DWORD data) {
m_errorCode = ::RegSetKeyValue(hKey, subKey.c_str(), value.c_str(), REG_DWORD,
&data, sizeof(data));
void
RegistryHelper::RegSetDword(HKEY hKey,
const std::wstring& subKey,
const std::wstring& value,
DWORD data)
{
m_errorCode = ::RegSetKeyValue(
hKey, subKey.c_str(), value.c_str(), REG_DWORD, &data, sizeof(data));
if (m_errorCode != ERROR_SUCCESS) {
throw RegistryError("Cannot set DWORD value in registry.", m_errorCode);
}
}

void RegistryHelper::RegSetString(HKEY hKey, const std::wstring &subKey,
const std::wstring &value,
const std::wstring &data) {
m_errorCode = ::RegSetKeyValue(
hKey, subKey.c_str(), value.c_str(), REG_SZ, data.c_str(),
static_cast<DWORD>((data.length() + 1) * sizeof(wchar_t)));
void
RegistryHelper::RegSetString(HKEY hKey,
const std::wstring& subKey,
const std::wstring& value,
const std::wstring& data)
{
m_errorCode =
::RegSetKeyValue(hKey,
subKey.c_str(),
value.c_str(),
REG_SZ,
data.c_str(),
static_cast<DWORD>((data.length() + 1) * sizeof(wchar_t)));
if (m_errorCode != ERROR_SUCCESS) {
throw RegistryError("Cannot set string value in registry.", m_errorCode);
}
}

void RegistryHelper::RegSetMultiString(HKEY hKey, const std::wstring &subKey,
const std::wstring &value,
const std::vector<std::wstring> &data) {
void
RegistryHelper::RegSetMultiString(HKEY hKey,
const std::wstring& subKey,
const std::wstring& value,
const std::vector<std::wstring>& data)
{
// Concatenate the strings and add an extra null character at the end
std::wstring multiString;
for (const auto &str : data) {
for (const auto& str : data) {
multiString += str;
multiString.push_back(L'\0');
}
multiString.push_back(L'\0'); // Extra null character at the end

m_errorCode = ::RegSetKeyValue(
hKey, subKey.c_str(), value.c_str(), REG_MULTI_SZ, multiString.c_str(),
static_cast<DWORD>(multiString.length() * sizeof(wchar_t)));

hKey,
subKey.c_str(),
value.c_str(),
REG_MULTI_SZ,
multiString.c_str(),
static_cast<DWORD>(multiString.length() * sizeof(wchar_t)));
if (m_errorCode != ERROR_SUCCESS) {
throw RegistryError("Cannot set multi-string value in registry.",
m_errorCode);
}
}
>>>>>>> Stashed changes
22 changes: 12 additions & 10 deletions RegistryHelper/RegistryHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ class RegistryHelper {
std::vector<std::pair<std::wstring, DWORD>>
RegEnumValues(HKEY hKey, const std::wstring &subKey);

<<<<<<< Updated upstream
=======
void RegSetDword(HKEY hKey, const std::wstring &subKey,
const std::wstring &value, DWORD data);
void RegSetDword(HKEY hKey,
const std::wstring& subKey,
const std::wstring& value,
DWORD data);

void RegSetString(HKEY hKey, const std::wstring &subKey,
const std::wstring &value, const std::wstring &data);
void RegSetString(HKEY hKey,
const std::wstring& subKey,
const std::wstring& value,
const std::wstring& data);

void RegSetMultiString(HKEY hKey, const std::wstring &subKey,
const std::wstring &value,
const std::vector<std::wstring> &data);
void RegSetMultiString(HKEY hKey,
const std::wstring& subKey,
const std::wstring& value,
const std::vector<std::wstring>& data);

>>>>>>> Stashed changes
private:
LONG m_errorCode; // store the last error code
};

0 comments on commit cee7b7f

Please sign in to comment.