home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / sysmgmt / setup / win9xmig / scrnsave / savecfg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-13  |  2.8 KB  |  143 lines

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