Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. savecfg.c
  5. Abstract:
  6. This source file implements code to save the Win9x environment to
  7. a settings file. It writes a copy of all screen saver settings on
  8. a per-user basis.
  9. Author:
  10. Jim Schmidt (jimschm) 11-Apr-1997
  11. Revision History:
  12. --*/
  13. #include "pch.h"
  14. BOOL
  15. SaveDatFileKeyAndVal (
  16. IN LPCSTR Key,
  17. IN LPCSTR Val
  18. )
  19. {
  20. //
  21. // This function is a wrapper to simplify writing to our settings file
  22. //
  23. return WritePrivateProfileString (g_User, Key, Val, g_SettingsFile);
  24. }
  25. BOOL
  26. CopyRegValueToDatFile (
  27. IN HKEY RegKey,
  28. IN LPCSTR ValueName
  29. )
  30. {
  31. LPCSTR DataPtr;
  32. DWORD rc;
  33. //
  34. // Obtain registry value data and copy it to our settings file
  35. //
  36. DataPtr = GetRegValueString (RegKey, ValueName);
  37. if (DataPtr) {
  38. return SaveDatFileKeyAndVal (ValueName, DataPtr);
  39. }
  40. // If not found or wrong data type, don't sweat it
  41. rc = GetLastError();
  42. return rc == ERROR_FILE_NOT_FOUND || rc == ERROR_SUCCESS;
  43. }
  44. #define WIN9X_MAX_SECTION 32768
  45. BOOL
  46. SaveControlIniSection (
  47. IN LPCSTR ControlIniSection,
  48. IN LPCSTR ScreenSaverName
  49. )
  50. {
  51. LPSTR Buffer;
  52. LPSTR p;
  53. CHAR NewKey[MAX_PATH];
  54. BOOL b = TRUE;
  55. CHAR DataBuf[MAX_PATH];
  56. //
  57. // This function copies an entire section in control.ini to our
  58. // settings file. It may not be necessary because control.ini will
  59. // still be around, but this guarantees if someone modifies
  60. // control.ini later, our migration will not break.
  61. //
  62. //
  63. // Allocate a generous buffer to hold all key names
  64. //
  65. Buffer = HeapAlloc (g_hHeap, 0, WIN9X_MAX_SECTION);
  66. if (!Buffer) {
  67. return FALSE;
  68. }
  69. //
  70. // Retrieve the key names
  71. //
  72. GetPrivateProfileString (
  73. ControlIniSection,
  74. NULL,
  75. S_EMPTY,
  76. Buffer,
  77. WIN9X_MAX_SECTION,
  78. S_CONTROL_INI
  79. );
  80. //
  81. // For each key name, copy it to our settings file
  82. //
  83. p = Buffer;
  84. while (*p) {
  85. if (CreateScreenSaverParamKey (ScreenSaverName, p, NewKey)) {
  86. GetPrivateProfileString (
  87. ControlIniSection,
  88. p,
  89. S_EMPTY,
  90. DataBuf,
  91. MAX_PATH,
  92. S_CONTROL_INI
  93. );
  94. if (!SaveDatFileKeyAndVal (NewKey, DataBuf)) {
  95. b = FALSE;
  96. break;
  97. }
  98. }
  99. p = _mbschr (p, 0);
  100. p++;
  101. }
  102. //
  103. // Cleanup
  104. //
  105. HeapFree (g_hHeap, 0, Buffer);
  106. return b;
  107. }