home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: WPS_PM / WPS_PM.zip / xfld085s.zip / helpers / prfh.c < prev    next >
C/C++ Source or Header  |  1999-02-23  |  29KB  |  758 lines

  1.  
  2. /*
  3.  *@@sourcefile prfh.c:
  4.  *      contains those Presentation Manager helper functions
  5.  *      which deal with Profile (Prf*) functions. These can be
  6.  *      used w/out the rest of the XFolder source in any PM
  7.  *      program.
  8.  *      This file is new with V0.82.
  9.  *
  10.  *      Function prefixes:
  11.  *      --  prfh*   Prf (profile, INI) helper functions
  12.  *
  13.  *@@include #define INCL_WINWINDOWMGR
  14.  *@@include #define INCL_WINSHELLDATA
  15.  *@@include #include <os2.h>
  16.  *@@include #include "prfh.h"
  17.  */
  18.  
  19. /*
  20.  *      Copyright (C) 1997-99 Ulrich Möller.
  21.  *      This file is part of the XFolder source package.
  22.  *      XFolder is free software; you can redistribute it and/or modify
  23.  *      it under the terms of the GNU General Public License as published
  24.  *      by the Free Software Foundation, in version 2 as it comes in the
  25.  *      "COPYING" file of the XFolder main distribution.
  26.  *      This program is distributed in the hope that it will be useful,
  27.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  28.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  29.  *      GNU General Public License for more details.
  30.  */
  31.  
  32. #define INCL_DOS
  33. #define INCL_DOSERRORS
  34. #define INCL_WIN
  35. #include <os2.h>
  36.  
  37. #include <stdlib.h>
  38. #include <stdio.h>
  39. #include <string.h>
  40.  
  41. #include "dosh.h"
  42.  
  43. #include "prfh.h"
  44.  
  45. /*
  46.  *@@ prfhQueryKeysForApp:
  47.  *      returns the keys list for an INI application. This
  48.  *      list is copied into a newly allocated buffer, of which
  49.  *      the address is returned.  You should free() this buffer
  50.  *      when you're done. Returns NULL upon errors.
  51.  */
  52.  
  53. PSZ prfhQueryKeysForApp(HINI hIni,      // in: INI handle
  54.                         PSZ pszApp)     // in: application to query
  55. {
  56.     PSZ     pKeys = NULL;
  57.     ULONG   ulSizeOfKeysList = 0;
  58.  
  59.     // get size of keys list for pszApp
  60.     if (PrfQueryProfileSize(hIni, pszApp, NULL, &ulSizeOfKeysList))
  61.     {
  62.         pKeys = (PSZ)malloc(ulSizeOfKeysList);
  63.         if (!PrfQueryProfileData(hIni, pszApp, NULL, pKeys, &ulSizeOfKeysList)) {
  64.             free(pKeys);
  65.             pKeys = NULL;
  66.         }
  67.     }
  68.     return (pKeys);
  69. }
  70.  
  71. /*
  72.  * prfhINIError:
  73.  *      this is called whenever an error occurs saving a
  74.  *      profile. This will compose an error string and
  75.  *      all the callback func fncbError.
  76.  */
  77.  
  78. ULONG prfhINIError(ULONG ulOptions, HAB hab, HFILE hfLog, PFNWP fncbError, PSZ pszErrorString)
  79. {
  80.     ULONG ulrc;
  81.     CHAR szError2[2000];
  82.  
  83.     if (fncbError) {
  84.         if (ulOptions == MB_ABORTRETRYIGNORE)
  85.             sprintf(szError2, "%s"
  86.                               "\nWinGetLastError: 0x%lX"
  87.                               "\nPress 'Abort' to abort saving the INI files. This will restart the WPS to avoid loss of data."
  88.                               "\nPress 'Retry' to attempt saving this INI file again. "
  89.                               "\nPress 'Ignore' to ignore this error. This might help, but "
  90.                               "also lead to more errors or loss of the currently processed data.",
  91.                               pszErrorString,
  92.                               WinGetLastError(hab));
  93.         else
  94.             sprintf(szError2, "%s\nPress 'Cancel' to abort shutdown. ", pszErrorString);
  95.         ulrc = ( (ULONG)(*fncbError)(0, 0, szError2, (MPARAM)ulOptions) );
  96.  
  97.     } else
  98.         ulrc = (MBID_ABORT);
  99.  
  100.     if (hfLog) {
  101.         CHAR szLog[2000];
  102.         sprintf(szLog, "    Error occured: %s\n    Return code: %s (%d)\n    WinGetLastError: %lX\n",
  103.                 pszErrorString,
  104.                     (ulrc == MBID_ABORT) ? "MBID_ABORT"
  105.                     : (ulrc == MBID_IGNORE) ? "MBID_IGNORE"
  106.                     : (ulrc == MBID_RETRY) ? "MBID_RETRY"
  107.                     : "unknown",
  108.                 ulrc,
  109.                 WinGetLastError(hab));
  110.         doshWriteToLogFile(hfLog, szLog);
  111.     }
  112.     return (ulrc);
  113. }
  114.  
  115. /*
  116.  * prfhINIError2:
  117.  *      like the previous func, but with additional info
  118.  *      for the error string.
  119.  */
  120.  
  121. ULONG prfhINIError2(ULONG ulOptions, PSZ pszINI, HAB hab, HFILE hfLog, PFNWP fncbError, PSZ pszErrorString)
  122. {
  123.     CHAR szError2[2000];
  124.     sprintf(szError2, "An error occured copying the profile %s: \n%s",
  125.             pszINI, pszErrorString);
  126.     return (prfhINIError(ulOptions, hab, hfLog, fncbError, szError2));
  127. }
  128.  
  129. /*
  130.  *@@ prfhCopyProfile:
  131.  *      this function copies a given profile into a
  132.  *      new file. hOld is the handle, pszOld the filename
  133.  *      of the profile to be copied (e.g. HINI_USERPROFILE
  134.  *      and "?:\OS2\OS2.INI"; pszNew must point to a
  135.  *      buffer which will contain the new filename ending
  136.  *      in ".XFL" after prfhCopyProfile returns
  137.  *      (e.g. "?:\OS2\OS2.XFL").
  138.  *      You may specify a Callback procedure which gets
  139.  *      called upon every copied application in the INI
  140.  *      file; this way, you can provide a progress bar.
  141.  *      fncbError gets called upon errors.
  142.  */
  143.  
  144. BOOL prfhCopyProfile(HAB hab,               // in:  anchor block
  145.                      HFILE hfLog,           // in:  logfile handle
  146.                                             // or NULLHANDLE for no log
  147.                      HINI hOld,             // in:  HINI to copy
  148.                      PSZ pszOld,            // in:  fully qualif. filename of hOld
  149.                      PSZ pszNew,            // out: new filename
  150.                      PFNWP fncbUpdate,      // in:  progress callback
  151.                      HWND hwnd, ULONG msg, ULONG ulCount, ULONG ulMax,
  152.                                             // in:  passed to fncbUpdate
  153.                      PFNWP fncbError,       // in:  error callback
  154.                      PULONG pulFunc2)       // in:  passed to fncbError
  155. {
  156.     // BOOL    rc = TRUE;
  157.     HINI    hNew;
  158.     PSZ     pApps, pKeys, pData,
  159.             pApp2, pKey2;
  160.     ULONG   ulSizeOfAppsList, ulSizeOfKeysList, ulSizeOfData;
  161.     CHAR    szLog[1000];
  162.     #define MBID_NOERROR 999
  163.     ULONG   ulErrorStatus = MBID_NOERROR;
  164.     PSZ     p_;
  165.     CHAR    szError2[2000];
  166.  
  167.     *pulFunc2 = 20000;
  168.     if (hfLog) {
  169.         sprintf(szLog, "    Entering prfhCopyProfile, params: "
  170.                     "hiniOld 0x%lX, pszOld %s, pfnwpCallback 0x%lX, "
  171.                     "hwnd 0x%lX, msg 0x%lX, ulCount 0x%lX, ulMax 0x%lX\n",
  172.                     hOld, pszOld, fncbUpdate, hwnd, msg, ulCount, ulMax);
  173.         doshWriteToLogFile(hfLog, szLog);
  174.     }
  175.  
  176.     *pulFunc2 = 20010;
  177.     if ( (!pszOld) || (!pszNew) )
  178.         ulErrorStatus = prfhINIError2(MB_CANCEL, pszOld, hab, hfLog, fncbError,
  179.                 "Invalid name buffers given.");
  180.  
  181.     *pulFunc2 = 20020;
  182.     if (ulErrorStatus == MBID_NOERROR) {
  183.         strupr(pszOld);
  184.         strcpy(pszNew, pszOld);
  185.         p_ = strstr(pszNew, ".INI");
  186.         if (!p_)
  187.             ulErrorStatus = prfhINIError2(MB_CANCEL, pszNew, hab, hfLog, fncbError,
  188.                     "Error composing new filename.");
  189.     }
  190.  
  191.     *pulFunc2 = 20030;
  192.     if (ulErrorStatus == MBID_NOERROR) {
  193.         strcpy(p_, ".XFL");
  194.         if (hfLog) {
  195.             sprintf(szLog, "    DEL %s\n", pszNew);
  196.             doshWriteToLogFile(hfLog, szLog);
  197.         }
  198.         DosDelete(pszNew);
  199.  
  200.         if (hfLog) {
  201.             sprintf(szLog, "    PrfOpenProfile %s\n", pszNew);
  202.             doshWriteToLogFile(hfLog, szLog);
  203.         }
  204.  
  205.         *pulFunc2 = 20040;
  206.         hNew = PrfOpenProfile(hab, pszNew);
  207.         if (!hNew)
  208.             ulErrorStatus = prfhINIError2(MB_CANCEL, pszNew, hab, hfLog, fncbError,
  209.                     "Error creating temporary profile.");
  210.     }
  211.  
  212.     // get size of applications list
  213.     *pulFunc2 = 20100;
  214.     if (ulErrorStatus == MBID_NOERROR) {
  215.         if (!PrfQueryProfileSize(hOld, NULL, NULL, &ulSizeOfAppsList))
  216.             ulErrorStatus = prfhINIError2(MB_CANCEL, pszNew, hab, hfLog, fncbError,
  217.                     "Error querying applications list size.");
  218.         else
  219.         if (ulSizeOfAppsList == 0)
  220.             ulErrorStatus = prfhINIError2(MB_CANCEL, pszNew, hab, hfLog, fncbError,
  221.                 "Size of applications list cannot be 0.");
  222.     }
  223.  
  224.     if (ulErrorStatus == MBID_NOERROR) {
  225.  
  226.         // do-while loop in case of MBID_RETRY
  227.         do {
  228.             ulErrorStatus = MBID_NOERROR; // if we have a retry in the do-while loop
  229.  
  230.             // get applications list
  231.             *pulFunc2 = 20110;
  232.             pApps = (PSZ)malloc(ulSizeOfAppsList);
  233.             pApp2 = pApps;
  234.             if (!PrfQueryProfileData(hOld, NULL, NULL, pApps, &ulSizeOfAppsList))
  235.                 ulErrorStatus = prfhINIError2(MB_CANCEL, pszNew, hab, hfLog, fncbError,
  236.                             "Could not query application list.");
  237.  
  238.             // applications loop
  239.  
  240.             *pulFunc2 = 20200;
  241.             while (   (*pApp2 != 0)
  242.                    && (ulErrorStatus == MBID_NOERROR)
  243.                   )
  244.             {
  245.                 *pulFunc2 = 20210;
  246.                 if (hfLog) {
  247.                     sprintf(szLog, "    Copying app %s... ", pApp2);
  248.                     doshWriteToLogFile(hfLog, szLog);
  249.                 }
  250.  
  251.                 // get size of keys list for pApp2
  252.                 *pulFunc2 = 20220;
  253.                 if (!PrfQueryProfileSize(hOld, pApp2, NULL, &ulSizeOfKeysList)) {
  254.                     sprintf(szError2, "Error querying size of keys list for \"%s\".",
  255.                             pApp2);
  256.                     ulErrorStatus = prfhINIError2(MB_ABORTRETRYIGNORE, pszNew, hab, hfLog, fncbError,
  257.                             szError2);
  258.                 }
  259.                 else if (ulSizeOfKeysList == 0) {
  260.                     sprintf(szError2, "Size of keys list for \"%s\" should not be 0.",
  261.                             pApp2);
  262.                     ulErrorStatus = prfhINIError2(MB_ABORTRETRYIGNORE, pszNew, hab, hfLog, fncbError,
  263.                                 szError2);
  264.                 }
  265.  
  266.                 if (ulErrorStatus == MBID_NOERROR) {
  267.                     *pulFunc2 = 20250;
  268.                     pKeys = (PSZ)malloc(ulSizeOfKeysList);
  269.                     pKey2 = pKeys;
  270.                     if (!PrfQueryProfileData(hOld, pApp2, NULL, pKeys, &ulSizeOfKeysList)) {
  271.                         sprintf(szError2, "Error querying keys list for %s (size: %d bytes).",
  272.                                 pApp2, ulSizeOfKeysList);
  273.                         ulErrorStatus = prfhINIError2(MB_ABORTRETRYIGNORE, pszNew, hab, hfLog, fncbError,
  274.                                 szError2);
  275.                     }
  276.  
  277.                     // keys loop
  278.  
  279.                     *pulFunc2 = 20300;
  280.                     while (   (*pKey2 != 0)
  281.                            && (ulErrorStatus == MBID_NOERROR)
  282.                                 // if "ignore" was pressed on error, the whole
  283.                                 // application is skipped
  284.                           )
  285.                     {
  286.                         *pulFunc2 = 20310;
  287.                         if (!PrfQueryProfileSize(hOld, pApp2, pKey2, &ulSizeOfData)) {
  288.                             sprintf(szError2, "Error querying data size of \"%s\"/\"%s\".",
  289.                                     pApp2, pKey2);
  290.                             ulErrorStatus = prfhINIError2(MB_ABORTRETRYIGNORE, pszNew, hab, hfLog, fncbError,
  291.                                     szError2);
  292.                         }
  293.  
  294.                         if (ulErrorStatus == MBID_NOERROR) {
  295.  
  296.                             // finally, copy data
  297.  
  298.                             if (ulSizeOfData != 0)
  299.                             {
  300.                                 // valid data:
  301.                                 *pulFunc2 = 20400;
  302.                                 pData = (PSZ)malloc(ulSizeOfData);
  303.                                 if (!pData) {
  304.                                     sprintf(szError2, "Error allocating memory for data from key %s (app %s, size %d bytes).",
  305.                                             pKey2, pApp2, ulSizeOfData);
  306.                                     ulErrorStatus = prfhINIError2(MB_ABORTRETRYIGNORE, pszNew, hab, hfLog, fncbError,
  307.                                             szError2);
  308.                                 }
  309.  
  310.                                 if (ulErrorStatus == MBID_NOERROR) {
  311.                                     *pulFunc2 = 20410;
  312.                                     if (    (!PrfQueryProfileData(hOld, pApp2, pKey2,
  313.                                                     pData, &ulSizeOfData))
  314.                                          // || (TRUE) // *** debug!!!
  315.                                        )
  316.                                     {
  317.                                         sprintf(szError2, "Error reading data from app \"%s\", key \"%s\" (size %d bytes).",
  318.                                                 pApp2, pKey2, ulSizeOfData);
  319.                                         ulErrorStatus = prfhINIError2(MB_ABORTRETRYIGNORE, pszNew, hab, hfLog, fncbError,
  320.                                                 szError2);
  321.                                     }
  322.                                 }
  323.                             } else {
  324.                                 // data size == 0: this shouldn't really happen,
  325.                                 // but if it does, we'll just create a NULL string.
  326.                                 // Users have reported that some INI files seem to
  327.                                 // contain those "empty" keys. I don't see how these
  328.                                 // can exist, but they seem to...
  329.                                 pData = (PSZ)malloc(1);
  330.                                 *pData = 0;
  331.                             }
  332.  
  333.                             if (ulErrorStatus == MBID_NOERROR) {
  334.                                 *pulFunc2 = 20420;
  335.                                 if (!PrfWriteProfileData(hNew, pApp2, pKey2, pData, ulSizeOfData)) {
  336.                                     sprintf(szError2, "Error writing data to app \"%s\", key \"%s\" (size %d bytes).",
  337.                                             pApp2, pKey2, ulSizeOfData);
  338.                                     ulErrorStatus = prfhINIError2(MB_ABORTRETRYIGNORE, pszNew, hab, hfLog, fncbError,
  339.                                             szError2);
  340.                                 }
  341.                             }
  342.  
  343.                             *pulFunc2 = 20430;
  344.                             if (pData)
  345.                                 free(pData);
  346.                         }
  347.  
  348.                         // go for next key
  349.                         *pulFunc2 = 20490;
  350.                         pKey2 += strlen(pKey2)+1;
  351.                         *pulFunc2 = 20491;
  352.  
  353.                         if (ulErrorStatus == MBID_IGNORE)
  354.                             // skip this key
  355.                             ulErrorStatus = MBID_NOERROR;
  356.  
  357.                     } // end while (*pKey2 != 0)
  358.  
  359.                     *pulFunc2 = 20500;
  360.                     if (pKeys)
  361.                         free(pKeys);
  362.  
  363.                     if (ulErrorStatus == MBID_NOERROR) {
  364.                         *pulFunc2 = 20510;
  365.                         if (hfLog)
  366.                             doshWriteToLogFile(hfLog, "OK\n");
  367.                     }
  368.  
  369.                 } // end if (ulErrorOccured == MBID_NOERROR)
  370.  
  371.                 *pulFunc2 = 20520;
  372.                 if (fncbUpdate) {
  373.                     ULONG ulNow2, ulMax2;
  374.                     ulNow2 = ((1000*(pApp2-pApps))/ulSizeOfAppsList) + (ulCount*1000);
  375.                     ulMax2 = (ulMax+1)*1000; // ulAppsSize;
  376.                     (*fncbUpdate)(hwnd, msg, (MPARAM)ulNow2, (MPARAM)ulMax2);
  377.                 }
  378.  
  379.                 *pulFunc2 = 20530;
  380.                 // go for next app
  381.                 pApp2 += strlen(pApp2)+1;
  382.                 *pulFunc2 = 20531;
  383.  
  384.                 if (ulErrorStatus == MBID_IGNORE)
  385.                     // skip this app
  386.                     ulErrorStatus = MBID_NOERROR;
  387.  
  388.             } // end while (*pApp2 != 0)
  389.  
  390.             *pulFunc2 = 20610;
  391.             if (pApps)
  392.                 free(pApps);
  393.  
  394.             if (hfLog) {
  395.                 sprintf(szLog, "    Done copying apps\n");
  396.                 doshWriteToLogFile(hfLog, szLog);
  397.             }
  398.         } while (ulErrorStatus == MBID_RETRY);
  399.     } // end if (ulErrorOccured == MBID_NOERROR)
  400.  
  401.     *pulFunc2 = 20620;
  402.     if (hfLog) {
  403.         sprintf(szLog, "    PrfCloseProfile %s\n", pszNew);
  404.         doshWriteToLogFile(hfLog, szLog);
  405.     }
  406.  
  407.     *pulFunc2 = 20630;
  408.     PrfCloseProfile(hNew);
  409.     *pulFunc2 = 20640;
  410.     if (fncbUpdate)
  411.         (*fncbUpdate)(hwnd, msg, (MPARAM)(ulCount+1), (MPARAM)(ulMax+1));
  412.  
  413.     *pulFunc2 = 20650;
  414.     if (hfLog)
  415.         doshWriteToLogFile(hfLog, "    Exiting prfhCopyProfile.\n");
  416.  
  417.     *pulFunc2 = 20660;
  418.  
  419.     return (ulErrorStatus == MBID_NOERROR); // FALSE if error occured
  420. }
  421.  
  422. /*
  423.  *@@ prfhSaveINIs:
  424.  *      this will enforce saving of OS2.INI and OS2SYS.INI
  425.  *      by calling prfhCopyProfile (above) on them; the therefrom
  426.  *      resulting ".XFL" files will replace the original
  427.  *      ".INI" files.
  428.  *      Specify fncbUpdate and fncbError like in prfhCopyProfile.
  429.  */
  430.  
  431. APIRET prfhSaveINIs(HAB hab,                // in:  anchor block
  432.                      HFILE hfLog,           // in:  logfile handle or NULLHANDLE for no log
  433.                      PFNWP fncbUpdate,      // in:  progress callback
  434.                      HWND hwnd, ULONG msg,  // in:  params passed to fncbUpdate
  435.                      PFNWP fncbError,       // in:  error callback
  436.                      PULONG pulFunc2)       // in:  passed to fncbError
  437. {
  438.     PRFPROFILE Profiles;
  439.     APIRET  arc = NO_ERROR, arc2;
  440.     BOOL    brc = TRUE;
  441.  
  442.     // FILESTATUS3 fs3;
  443.     CHAR    szSysNew[CCHMAXPATH],
  444.             szUserNew[CCHMAXPATH],
  445.             szSysBackup[CCHMAXPATH],
  446.             szUserBackup[CCHMAXPATH],
  447.             szLog[1000];
  448.  
  449.     // PSZ     p;
  450.  
  451.     // the following flag may be one of the following:
  452.     //        MBID_NOERROR--- everything's fine, continue
  453.     //        MBID_IGNORE --- error occured, but ignore
  454.     //        MBID_RETRY  --- error occured, but retry
  455.     //        MBID_ABORT  --- error occured, abort saving
  456.     ULONG   ulErrorOccured = MBID_IGNORE;
  457.  
  458.     // DosEnterCritSec();
  459.  
  460.     *pulFunc2 = 10000;
  461.  
  462.     if (hfLog)
  463.         doshWriteToLogFile(hfLog, "  Entering prfhSaveINIs...\n");
  464.  
  465.     Profiles.cchUserName = Profiles.cchSysName = 0;
  466.     brc = PrfQueryProfile(hab, &Profiles);
  467.  
  468.     *pulFunc2 = 10010;
  469.     if (!brc) {
  470.         ulErrorOccured = prfhINIError(MB_CANCEL, hab, hfLog, fncbError,
  471.                 "Error querying system profiles size.");
  472.     }
  473.  
  474.     *pulFunc2 = 10020;
  475.     if (ulErrorOccured == MBID_IGNORE) {
  476.         Profiles.pszUserName  = (PSZ)malloc(Profiles.cchUserName);
  477.         Profiles.pszSysName  = (PSZ)malloc(Profiles.cchSysName);
  478.         if (    (Profiles.pszSysName == NULL)
  479.              || (Profiles.pszUserName == NULL)
  480.            )
  481.             ulErrorOccured = prfhINIError(MB_CANCEL, hab, hfLog, fncbError,
  482.                     "Error allocating memory (1).");
  483.     }
  484.  
  485.     *pulFunc2 = 10030;
  486.     if (ulErrorOccured == MBID_IGNORE) {
  487.         if (!PrfQueryProfile(hab, &Profiles))
  488.             ulErrorOccured = prfhINIError(MB_CANCEL, hab, hfLog, fncbError,
  489.                     "Error querying profiles (2).");
  490.     }
  491.  
  492.     *pulFunc2 = 10040;
  493.     if (ulErrorOccured == MBID_IGNORE) {
  494.         if (hfLog) {
  495.             sprintf(szLog, "  System profiles are %s, %s\n",
  496.                     Profiles.pszUserName, Profiles.pszSysName);
  497.             doshWriteToLogFile(hfLog, szLog);
  498.         }
  499.  
  500.         // create filenames
  501.         strcpy(szSysBackup, Profiles.pszSysName);
  502.         strcpy(strstr(szSysBackup, ".INI"), ".BAK");
  503.         strcpy(szUserBackup, Profiles.pszUserName);
  504.         strcpy(strstr(szUserBackup, ".INI"), ".BAK");
  505.  
  506.         *pulFunc2 = 10050;
  507.         // create OS2SYS.XFL
  508.         if (hfLog) {
  509.             sprintf(szLog, "  Storing %s in *.XFL\n",
  510.                     Profiles.pszSysName);
  511.             doshWriteToLogFile(hfLog, szLog);
  512.         }
  513.         if (!prfhCopyProfile(hab, hfLog, HINI_SYSTEMPROFILE,
  514.                 Profiles.pszSysName, szSysNew,
  515.                 fncbUpdate, hwnd, msg, 0, 1,
  516.                 fncbError, pulFunc2))
  517.         {
  518.             // abort, since prfhCopyProfile already has error handling
  519.             ulErrorOccured = MBID_ABORT;
  520.         }
  521.     }
  522.  
  523.     *pulFunc2 = 10060;
  524.     if (ulErrorOccured == MBID_IGNORE) {
  525.         // create OS2.XFL
  526.         if (hfLog) {
  527.             sprintf(szLog, "  Storing %s in *.XFL\n",
  528.                     Profiles.pszUserName);
  529.             doshWriteToLogFile(hfLog, szLog);
  530.         }
  531.         if (!prfhCopyProfile(hab, hfLog,
  532.                 HINI_USERPROFILE, Profiles.pszUserName, szUserNew,
  533.                 fncbUpdate, hwnd, msg, 1, 1,
  534.                 fncbError, pulFunc2))
  535.         {
  536.             // abort, since prfhCopyProfile already has error handling
  537.             ulErrorOccured = MBID_ABORT;
  538.         }
  539.     }
  540.  
  541.     /*
  542.      * renaming stuff for OS2SYS.INI
  543.      *
  544.      */
  545.  
  546.     if (ulErrorOccured == MBID_IGNORE) {
  547.         do {
  548.             ulErrorOccured = MBID_IGNORE; // if we have a retry in the do-while loop
  549.  
  550.             *pulFunc2 = 10070;
  551.             if (ulErrorOccured == MBID_IGNORE) {
  552.                 // attrib -r -s -h -a OS2SYS.BAK
  553.                 if (hfLog) {
  554.                     sprintf(szLog, "  ATTRIB -R -S -H -A %s\n",
  555.                             szSysBackup);
  556.                     doshWriteToLogFile(hfLog, szLog);
  557.                 }
  558.                 arc2 = doshSetPathAttr(szSysBackup, FILE_NORMAL);
  559.                 if (hfLog) {
  560.                     sprintf(szLog, "    rc2: %d\n", arc2);
  561.                     doshWriteToLogFile(hfLog, szLog);
  562.                 }
  563.  
  564.                 // delete OS2SYS.BAK
  565.                 if (hfLog) {
  566.                     sprintf(szLog, "  DEL %s\n",
  567.                             szSysBackup);
  568.                     doshWriteToLogFile(hfLog, szLog);
  569.                 }
  570.                 arc2 = DosDelete(szSysBackup);
  571.                 if (hfLog) {
  572.                     sprintf(szLog, "    rc2: %d\n", arc2);
  573.                     doshWriteToLogFile(hfLog, szLog);
  574.                 }
  575.  
  576.                 // attrib -r -s -h -a OS2SYS.INI
  577.                 if (hfLog) {
  578.                     sprintf(szLog, "  ATTRIB -R -S -H -A %s\n",
  579.                             Profiles.pszSysName);
  580.                     doshWriteToLogFile(hfLog, szLog);
  581.                 }
  582.                 arc2 = doshSetPathAttr(Profiles.pszSysName, FILE_NORMAL);
  583.                 if (hfLog) {
  584.                     sprintf(szLog, "    rc2: %d\n", arc2);
  585.                     doshWriteToLogFile(hfLog, szLog);
  586.                 }
  587.  
  588.                 // move OS2SYS.INI OS2SYS.BAK
  589.                 if (hfLog) {
  590.                     sprintf(szLog, "  MOVE %s %s\n",
  591.                             Profiles.pszSysName, szSysBackup);
  592.                     doshWriteToLogFile(hfLog, szLog);
  593.                 }
  594.                 arc = DosMove(Profiles.pszSysName, szSysBackup);
  595.                 if (hfLog) {
  596.                     sprintf(szLog, "    rc: %d\n", arc);
  597.                     doshWriteToLogFile(hfLog, szLog);
  598.                 }
  599.  
  600.                 if (arc)
  601.                     ulErrorOccured = prfhINIError(MB_ABORTRETRYIGNORE, hab, hfLog, fncbError, "Error moving original system profile to backup.");
  602.             }
  603.  
  604.             *pulFunc2 = 10200;
  605.             if (ulErrorOccured == MBID_IGNORE) {
  606.                 if (hfLog) {
  607.                     sprintf(szLog, "  MOVE %s %s\n",
  608.                             szSysNew, Profiles.pszSysName);
  609.                     doshWriteToLogFile(hfLog, szLog);
  610.                 }
  611.                 *pulFunc2 = 10210;
  612.                 arc = DosMove(szSysNew, Profiles.pszSysName);
  613.                 if (hfLog) {
  614.                     sprintf(szLog, "    rc: %d\n", arc);
  615.                     doshWriteToLogFile(hfLog, szLog);
  616.                 }
  617.                 if (arc)
  618.                     ulErrorOccured = prfhINIError(MB_ABORTRETRYIGNORE, hab, hfLog, fncbError, "Error moving newly created profile to system profile.");
  619.             }
  620.         } while (ulErrorOccured == MBID_RETRY);
  621.     }
  622.  
  623.     /*
  624.      * renaming stuff for OS2.INI
  625.      *
  626.      */
  627.  
  628.     if (ulErrorOccured == MBID_IGNORE) {
  629.         do {
  630.             ulErrorOccured = MBID_IGNORE; // if we have a retry in the do-while loop
  631.  
  632.             *pulFunc2 = 10300;
  633.             if (ulErrorOccured == MBID_IGNORE) {
  634.                 // attrib -r -s -h -a OS2.BAK
  635.                 if (hfLog) {
  636.                     sprintf(szLog, "  ATTRIB -R -S -H -A %s\n",
  637.                             szUserBackup);
  638.                     doshWriteToLogFile(hfLog, szLog);
  639.                 }
  640.                 arc2 = doshSetPathAttr(szUserBackup, FILE_NORMAL);
  641.                 if (hfLog) {
  642.                     sprintf(szLog, "    rc2: %d\n", arc2);
  643.                     doshWriteToLogFile(hfLog, szLog);
  644.                 }
  645.  
  646.                 // delete OS2.BAK
  647.                 *pulFunc2 = 10310;
  648.                 if (hfLog) {
  649.                     sprintf(szLog, "  DEL %s\n",
  650.                             szUserBackup);
  651.                     doshWriteToLogFile(hfLog, szLog);
  652.                 }
  653.                 arc2 = DosDelete(szUserBackup);
  654.                 if (hfLog) {
  655.                     sprintf(szLog, "    rc2: %d\n", arc2);
  656.                     doshWriteToLogFile(hfLog, szLog);
  657.                 }
  658.  
  659.                 // attrib -r -s -h -a OS2.INI
  660.                 if (hfLog) {
  661.                     sprintf(szLog, "  ATTRIB -R -S -H -A %s\n",
  662.                             Profiles.pszUserName);
  663.                     doshWriteToLogFile(hfLog, szLog);
  664.                 }
  665.                 arc2 = doshSetPathAttr(Profiles.pszUserName, FILE_NORMAL);
  666.                 if (hfLog) {
  667.                     sprintf(szLog, "    rc2: %d\n", arc2);
  668.                     doshWriteToLogFile(hfLog, szLog);
  669.                 }
  670.  
  671.                 // move OS2.INI OS2.BAK
  672.                 if (hfLog) {
  673.                     sprintf(szLog, "  MOVE %s %s\n",
  674.                             Profiles.pszUserName, szUserBackup);
  675.                     doshWriteToLogFile(hfLog, szLog);
  676.                 }
  677.                 arc = DosMove(Profiles.pszUserName, szUserBackup);
  678.                 if (hfLog) {
  679.                     sprintf(szLog, "    rc: %d\n", arc);
  680.                     doshWriteToLogFile(hfLog, szLog);
  681.                 }
  682.  
  683.                 if (arc)
  684.                     ulErrorOccured = prfhINIError(MB_ABORTRETRYIGNORE, hab, hfLog, fncbError, "Error moving original user profile to backup.");
  685.             }
  686.  
  687.             *pulFunc2 = 10350;
  688.             if (ulErrorOccured == MBID_IGNORE) {
  689.                 // move OS2.XFL OS2.INI
  690.                 if (hfLog) {
  691.                     sprintf(szLog, "  MOVE %s %s\n",
  692.                             szUserNew, Profiles.pszUserName);
  693.                     doshWriteToLogFile(hfLog, szLog);
  694.                 }
  695.                 arc = DosMove(szUserNew, Profiles.pszUserName);
  696.                 if (hfLog) {
  697.                     sprintf(szLog, "    rc: %d\n", arc);
  698.                     doshWriteToLogFile(hfLog, szLog);
  699.                 }
  700.  
  701.                 if (arc)
  702.                     ulErrorOccured = prfhINIError(MB_ABORTRETRYIGNORE, hab, hfLog, fncbError, "Error moving newly created profile to user profile.");
  703.             }
  704.         } while (ulErrorOccured == MBID_RETRY);
  705.     }
  706.  
  707.     // DosExitCritSec();
  708.  
  709.     *pulFunc2 = 10400;
  710.     if (ulErrorOccured != MBID_IGNORE) {
  711.         DosMove(szSysBackup, Profiles.pszSysName);
  712.         DosMove(szUserBackup, Profiles.pszUserName);
  713.     }
  714.  
  715.     *pulFunc2 = 10410;
  716.     if (    (Profiles.pszSysName)
  717.          && (Profiles.pszUserName)
  718.        )
  719.     {
  720.         *pulFunc2 = 10420;
  721.         free(Profiles.pszSysName);
  722.         *pulFunc2 = 10430;
  723.         free(Profiles.pszUserName);
  724.     }
  725.  
  726.     *pulFunc2 = 10430;
  727.     if (hfLog) {
  728.         doshWriteToLogFile(hfLog, "  Done with prfhSaveINIs\n");
  729.     }
  730.  
  731.     if (ulErrorOccured != MBID_IGNORE)
  732.         return (999);
  733.     else
  734.         return (NO_ERROR);
  735. }
  736.  
  737. /*
  738.  *@@ prfhQueryColor:
  739.  *      returns a system color in OS2.INI's PM_Colors as a LONG.
  740.  */
  741.  
  742. LONG prfhQueryColor(PSZ pszKeyName, PSZ pszDefault)
  743. {
  744.     CHAR szColor[30];
  745.     LONG r, g, b;
  746.     PrfQueryProfileString(
  747.                 HINI_USER,
  748.                 "PM_Colors",
  749.                 pszKeyName,
  750.                 pszDefault,
  751.                 szColor,
  752.                 sizeof(szColor)-1);
  753.     sscanf(szColor, "%d %d %d ", &r, &g, &b);
  754.     return (r*0x10000 + g*0x100 + b);
  755. }
  756.  
  757.  
  758.