3 #define STR_PENDING_DELETION "(Pending Removal)"
17 Directive(unsigned int which_directive) {
18 Init_Directive(which_directive);
27 string bound_val[NUM_BOUND_VAL];
31 bool Set_Path(string new_path)
33 if (new_path.length() && new_path.at(0) == '/') {
43 bool WriteValue(string RegPath)
45 if (type == D_BOUND_INT || type == D_FREE_INT) {
46 return WriteRegInt(RegPath.c_str(), name.c_str(), new_value.c_str());
48 return WriteRegString(RegPath.c_str(), name.c_str(), new_value.c_str());
52 void Directive::Init_Directive(unsigned int w) {
54 if (w >= NUM_DIRECTIVES) {
58 name = directives[w].name;
59 type = directives[w].type;
60 value = directives[w].value;
61 defined_in = directives[w].defined_in;
62 description = directives[w].description;
63 for (int i=0;i<NUM_BOUND_VAL;i++) {
64 bound_val[i] = directives[w].bound_val[i];
70 new_value = STR_PENDING_DELETION;
73 bool Directive::DeleteRegVal(string Key)
77 if ((hKey=OpenKey(Key.c_str(),KEY_ALL_ACCESS))) {
78 if (RegDeleteValue(hKey,name.c_str()) == ERROR_SUCCESS) {
89 HKEY Directive::OpenKey(LPCTSTR szKey, REGSAM samDesired) {
92 _TCHAR localname[MAX_PATH];
93 DWORD lsize = MAX_PATH;
95 //Support for Remote Registries
96 GetComputerName(localname,&lsize);
97 if (!_tcsicmp(localname,MachineName.c_str())) {
98 rhKey = HKEY_LOCAL_MACHINE;
100 if (RegConnectRegistry(MachineName.c_str(),HKEY_LOCAL_MACHINE, &rhKey) != ERROR_SUCCESS) {
101 //MessageBox(hwndDlg,L"Error opening remote registry. Values displayed may not be accurate.",L"Error",MB_ICONERROR);
105 if (samDesired == KEY_READ) {
106 // Open existing key.
107 if( RegOpenKeyEx(rhKey,
111 &hKey) != ERROR_SUCCESS)
117 // Create and open key and subkey.
118 if( RegCreateKeyEx(rhKey,
120 0, NULL, REG_OPTION_NON_VOLATILE,
122 &hKey, NULL) != ERROR_SUCCESS)
132 void Directive::ReadValAsString(string key, LPCTSTR defined_in_val) {
134 char RegBuff[MAX_REG_BUFF];
136 DWORD dwRead=MAX_REG_BUFF*sizeof(char);
138 if (hKey = OpenKey(key.c_str(),KEY_READ)) {
139 if ((debug = RegQueryValueEx (hKey,name.c_str(), NULL, NULL, (LPBYTE)RegBuff, &dwRead)) == ERROR_SUCCESS) {
140 if (type == D_FREE_INT || type == D_BOUND_INT) {
142 value = itoa(*(DWORD *)RegBuff,tmpw,10);
146 defined_in = defined_in_val;
152 bool Directive::WriteRegInt(const _TCHAR* szKey,
153 const _TCHAR* szValueName,
154 const _TCHAR* szValue)
159 if (!(hKey=OpenKey(szKey,KEY_ALL_ACCESS)))
165 value = _ttoi(szValue);
166 RegSetValueEx(hKey, szValueName, 0, REG_DWORD,
176 bool Directive::WriteRegString(const _TCHAR* szKey,
177 const _TCHAR* szValueName,
178 const _TCHAR* szValue)
182 if (!(hKey=OpenKey(szKey,KEY_ALL_ACCESS)))
188 RegSetValueEx(hKey, szValueName, 0, REG_SZ,
190 ((DWORD)_tcslen(szValue)+1)*sizeof(_TCHAR)) ;
197 void Directive::Get_Value() {
199 string key, node, defined_in_val;
204 value = directives[d_index].value;
205 defined_in = directives[d_index].defined_in;
207 key = SHIB_DEFAULT_WEB_KEY;
211 pos = path.find('/',opos); // while we still have a '/' left to deal with
213 if (pos != string::npos) {
214 node = path.substr(opos,pos-opos);
217 node = path.substr(opos);
220 if (defined_in_val[defined_in_val.length()-1] != '/') {
221 defined_in_val += "/";
225 defined_in_val += node;
228 ReadValAsString(key,defined_in_val.c_str());