Commit d6dfb718 authored by jan.koester's avatar jan.koester
Browse files

inital support regedit

parent 08e6a749
Loading
Loading
Loading
Loading
+136 −93
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include <algorithm>
#include <stdexcept>
#include <memory> 
#include <stack>

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@@ -45,6 +46,12 @@

namespace confplus {

    struct KeyState {
        HKEY hKey;
        std::string configPath;
        bool closeHandle;
    };
    
    // -------------------------------------------------------------------------
    // HILFSFUNKTIONEN (unverändert)
    // -------------------------------------------------------------------------
@@ -76,7 +83,25 @@ namespace confplus {
        return it == s.end();
    }
    
  void loadKeyRecursiveA(Config* conf, HKEY hKey, const std::string& currentConfigPath) {
  /**
 * @brief Iterative Funktion zum Laden von Werten und Subkeys aus der Registry.
 * Verwendet einen Stack anstelle von Rekursion.
 */
    void Registry::loadsubKey(Config* conf, HKEY hRootKey, const std::string& rootConfigPath) {
    
        std::stack<KeyState> keyStack;
    
        // Initialisiere den Stack mit dem Startschlüssel.
        // Dieser Handle wird in Registry::loadConfig geöffnet und geschlossen.
        keyStack.push({hRootKey, rootConfigPath, false}); 

        while (!keyStack.empty()) {
            
            KeyState currentState = keyStack.top();
            keyStack.pop();

            HKEY hKey = currentState.hKey;
            const std::string currentConfigPath = currentState.configPath;
            
            DWORD dwValues, dwSubKeys, dwMaxValueNameLen, dwMaxValueLen, dwMaxSubKeyLen;
            
@@ -89,10 +114,14 @@ namespace confplus {
            );

            if (lRes != ERROR_SUCCESS) {
            return; 
                if (currentState.closeHandle) {
                    RegCloseKey(hKey);
                }
                continue; 
            }
            
            // --- 2. Werte (Values) laden ---
            // Puffergrößen bestimmen
            DWORD maxNameSize = dwMaxValueNameLen > 0 ? dwMaxValueNameLen + 1 : 1;
            DWORD maxDataSize = dwMaxValueLen > 0 ? dwMaxValueLen + 1 : 1;

@@ -122,15 +151,15 @@ namespace confplus {
                    std::string cname = currentConfigPath; 
                    std::string cvalue;

                // 1. Normalisierung der Groß-/Kleinschreibung (Case-Insensitivity)
                    // KORREKTUR 1: Normalisierung zu Kleinbuchstaben (Case-Insensitivity)
                    std::transform(valueNameStr.begin(), valueNameStr.end(), valueNameStr.begin(),
                               [](unsigned char c){ return std::toupper(c); });
                                [](unsigned char c){ return std::tolower(c); });
                    
                    if (!valueNameStr.empty()) {
                    // Benannter Wert: wird ein Kind-Knoten unterhalb des Pfades
                        // Benannter Wert
                        cname += "/" + valueNameStr;
                    } else {
                    // 2. KORREKTUR des Standardwerts: Expliziter Name, um den "path not key"-Fehler zu umgehen.
                        // KORREKTUR 2: Standardwert (leerer Name) explizit benennen.
                        cname += "/@default"; 
                    }
                    
@@ -146,8 +175,7 @@ namespace confplus {
                            continue;
                        }
                    } else {
                    // Ignoriere alle anderen Registry-Typen
                    continue;
                        continue; // Ignoriere andere Registry-Typen
                    }
                    
                    Config::ConfigData* ckey = conf->setKey(cname);
@@ -155,10 +183,9 @@ namespace confplus {
                }
            }

        // --- 3. Subkeys (Unterschlüssel) rekursiv laden ---
            // --- 3. Subkeys (Unterschlüssel) zur Stack hinzufügen ---
            DWORD maxSubKeySize = dwMaxSubKeyLen > 0 ? dwMaxSubKeyLen + 1 : 1;
            std::unique_ptr<char[]> subKeyNameBuffer(new char[maxSubKeySize]);
        HKEY hSubKey;
            
            // ** ROBUSTE ITERATION ÜBER SUBKEYS **
            for (DWORD i = 0; ; ++i) { 
@@ -175,16 +202,32 @@ namespace confplus {
                }
                
                if (lRes == ERROR_SUCCESS) {
                    HKEY hSubKey;
                    
                    // Öffne den Unterschlüssel (RegOpenKeyExA verwendet den Originalnamen)
                    lRes = RegOpenKeyExA(
                        hKey, subKeyNameBuffer.get(), 0, KEY_READ, &hSubKey
                    );

                    if (lRes == ERROR_SUCCESS) {
                    std::string nextConfigPath = currentConfigPath + "/" + std::string(subKeyNameBuffer.get());
                    loadKeyRecursiveA(conf, hSubKey, nextConfigPath);
                    RegCloseKey(hSubKey);
                        std::string subKeyNameStr = std::string(subKeyNameBuffer.get());
                        
                        // KORREKTUR 3: Normalisierung des Subkey-Namens zu Kleinbuchstaben
                        std::transform(subKeyNameStr.begin(), subKeyNameStr.end(), subKeyNameStr.begin(),
                                    [](unsigned char c){ return std::tolower(c); });
                        
                        std::string nextConfigPath = currentConfigPath + "/" + subKeyNameStr;
                        
                        // Schlüssel auf den Stack legen. closeHandle = true, da wir ihn hier geöffnet haben.
                        keyStack.push({hSubKey, nextConfigPath, true});
                    }
                }
            }
            
            // Den Handle des aktuellen Zustands schließen, WENN er in der Schleife geöffnet wurde
            if (currentState.closeHandle) {
                RegCloseKey(hKey);
            }
        }
    }

@@ -405,7 +448,7 @@ namespace confplus {
        }

        // Starte die rekursive Ladefunktion.
        loadKeyRecursiveA(conf, hKey, "");
        loadsubKey(conf, hKey, "");
        
        RegCloseKey(hKey);
    }
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ namespace confplus {
    private:
        // Rekursive Hilfsfunktion zur Speicherung der Config-Datenstruktur
        void saveKeyRecursive(HKEY hRootKey, std::string currentPath,const Config::ConfigData* currentData, const Config *conf);
        void loadsubKey(Config* conf, HKEY hRootKey, const std::string& rootConfigPath);
    };
}