win32_registry.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include <windows.h>
  9. #include "app/registry.hh"
  10. i4_bool i4_get_registry(i4_registry_type type,
  11. char *path,
  12. char *key_name,
  13. char *buffer, int buf_length)
  14. {
  15. HKEY key;
  16. if (RegOpenKeyEx(type==I4_REGISTRY_MACHINE ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
  17. path,
  18. 0,
  19. KEY_READ,
  20. &key)==ERROR_SUCCESS)
  21. {
  22. for (int i=0; 1; i++)
  23. {
  24. char name[256];
  25. DWORD name_size=256, type;
  26. DWORD data_size=buf_length;
  27. if (RegEnumValue(key, i, name, &name_size, 0,
  28. &type,
  29. (LPBYTE)buffer,
  30. &data_size)==ERROR_SUCCESS)
  31. {
  32. if (strcmp(name, key_name)==0)
  33. {
  34. RegCloseKey(key);
  35. return i4_T;
  36. }
  37. }
  38. else
  39. {
  40. RegCloseKey(key);
  41. return i4_F;
  42. }
  43. }
  44. }
  45. return i4_F;
  46. }
  47. i4_bool i4_set_registry(i4_registry_type type,
  48. char *path,
  49. char *key_name,
  50. char *buffer)
  51. {
  52. HKEY key;
  53. if (RegCreateKey(type==I4_REGISTRY_MACHINE ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
  54. path,
  55. &key)==ERROR_SUCCESS)
  56. {
  57. RegSetValueEx(key, key_name, 0, REG_SZ, (w8 *)buffer, strlen(buffer)+1);
  58. RegCloseKey(key);
  59. return i4_T;
  60. }
  61. return i4_F;
  62. }