home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / xwphescr.zip / XWPH0208.ZIP / src / helpers / prfh2.c < prev    next >
C/C++ Source or Header  |  2002-06-05  |  23KB  |  644 lines

  1.  
  2. /*
  3.  *@@sourcefile prfh2.c:
  4.  *      contains more Presentation Manager helper functions
  5.  *      which deal with Profile (Prf*) functions.
  6.  *
  7.  *      This file is new with V0.9.4 (2000-07-26) [umoeller].
  8.  *
  9.  *      As opposed to the functions in prfh.c, these require
  10.  *      linking against other helpers. As a result, these have
  11.  *      been separated from prfh.c to allow linking against
  12.  *      prfh.obj only.
  13.  *
  14.  *      Function prefixes:
  15.  *      --  prfh*   Prf (profile, INI) helper functions
  16.  *
  17.  *      Note: Version numbering in this file relates to XWorkplace version
  18.  *            numbering.
  19.  *
  20.  *@@header "helpers\prfh.h"
  21.  *@@added V0.9.4 (2000-07-27) [umoeller]
  22.  */
  23.  
  24. /*
  25.  *      Copyright (C) 1997-2000 Ulrich Möller.
  26.  *      This file is part of the "XWorkplace helpers" source package.
  27.  *      This is free software; you can redistribute it and/or modify
  28.  *      it under the terms of the GNU General Public License as published
  29.  *      by the Free Software Foundation, in version 2 as it comes in the
  30.  *      "COPYING" file of the XWorkplace main distribution.
  31.  *      This program is distributed in the hope that it will be useful,
  32.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  33.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  34.  *      GNU General Public License for more details.
  35.  */
  36.  
  37. #define OS2EMX_PLAIN_CHAR
  38.     // this is needed for "os2emx.h"; if this is defined,
  39.     // emx will define PSZ as _signed_ char, otherwise
  40.     // as unsigned char
  41.  
  42. #define INCL_DOSERRORS
  43. #define INCL_WINSHELLDATA
  44. #include <os2.h>
  45.  
  46. #include <stdlib.h>
  47. #include <stdio.h>
  48. #include <string.h>
  49.  
  50. #include "setup.h"                      // code generation and debugging options
  51.  
  52. #include "helpers\dosh.h"
  53. #include "helpers\stringh.h"
  54.  
  55. #include "helpers\prfh.h"
  56.  
  57. #pragma hdrstop
  58.  
  59. /*
  60.  *@@category: Helpers\Profile (INI) helpers
  61.  */
  62.  
  63. /*
  64.  * prfhINIError:
  65.  *      this is called whenever an error occurs saving a
  66.  *      profile. This will compose an error string and
  67.  *      all the callback func fncbError.
  68.  *
  69.  *@@changed V0.9.0 [umoeller]: changed prototype's logfile to stdio FILE*
  70.  */
  71.  
  72. ULONG prfhINIError(ULONG ulOptions,
  73.                    FILE* fLog,
  74.                    PFNWP fncbError,
  75.                    PSZ pszErrorString)
  76. {
  77.     ULONG ulrc;
  78.     CHAR szError2[2000];
  79.  
  80.     if (fncbError)
  81.     {
  82.         if (ulOptions == MB_ABORTRETRYIGNORE)
  83.             sprintf(szError2, "%s"
  84.                               "\nPress 'Abort' to abort saving the INI files. This will restart the WPS to avoid loss of data."
  85.                               "\nPress 'Retry' to attempt saving this INI file again. "
  86.                               "\nPress 'Ignore' to ignore this error. This might help, but "
  87.                               "also lead to more errors or loss of the currently processed data.",
  88.                               pszErrorString);
  89.         else
  90.             sprintf(szError2, "%s\nPress 'Cancel' to abort shutdown. ", pszErrorString);
  91.         ulrc = ( (ULONG)(*fncbError)(0, 0, szError2, (MPARAM)ulOptions) );
  92.  
  93.     }
  94.     else
  95.         ulrc = (MBID_ABORT);
  96.  
  97.     if (fLog)
  98.     {
  99.         fprintf(fLog, "    Error occured: %s\n    Return code: %s (%lu)\n",
  100.                 pszErrorString,
  101.                     (ulrc == MBID_ABORT) ? "MBID_ABORT"
  102.                     : (ulrc == MBID_IGNORE) ? "MBID_IGNORE"
  103.                     : (ulrc == MBID_RETRY) ? "MBID_RETRY"
  104.                     : "unknown",
  105.                 ulrc);
  106.         fflush(fLog);
  107.     }
  108.  
  109.     return (ulrc);
  110. }
  111.  
  112. /*
  113.  * prfhINIError2:
  114.  *      like the previous func, but with additional info
  115.  *      for the error string.
  116.  *
  117.  *@@changed V0.9.0 [umoeller]: changed prototype's logfile to stdio FILE*
  118.  */
  119.  
  120. ULONG prfhINIError2(ULONG ulOptions,
  121.                     const char *pcszINI,
  122.                     FILE* fLog,
  123.                     PFNWP fncbError,
  124.                     PSZ pszErrorString)
  125. {
  126.     CHAR szError2[2000];
  127.     sprintf(szError2, "An error occured copying the profile %s: \n%s",
  128.             pcszINI, pszErrorString);
  129.     return (prfhINIError(ulOptions, fLog, fncbError, szError2));
  130. }
  131.  
  132. /*
  133.  *@@ prfhCopyProfile:
  134.  *      this function copies a given profile entirely into a
  135.  *      new file. hOld is the handle, pszOld the filename
  136.  *      of the profile to be copied (e.g. HINI_USERPROFILE
  137.  *      and "?:\OS2\OS2.INI"; pszNew must point to a
  138.  *      buffer which will contain the new filename ending
  139.  *      in ".XFL" after prfhCopyProfile returns
  140.  *      (e.g. "?:\OS2\OS2.XFL").
  141.  *
  142.  *      You may specify a callback procedure which gets
  143.  *      called upon every copied application in the INI
  144.  *      file; this way, you can provide a progress bar.
  145.  *      The second callback, fncbError, gets called upon
  146.  *      errors.
  147.  *
  148.  *@@changed V0.9.0 [umoeller]: this now calls prfhCopyApp.
  149.  *@@changed V0.9.0 [umoeller]: fixed crashes with lower-case INI file names.
  150.  *@@changed V0.9.0 [umoeller]: changed prototype's logfile to stdio FILE*
  151.  *@@changed V0.9.4 (2000-07-15) [umoeller]: this never reported any errors, causing 0-byte INI files without warning. Fixed.
  152.  */
  153.  
  154. BOOL prfhCopyProfile(HAB hab,               // in:  anchor block
  155.                      FILE* fLog,            // in:  stdio logfile or NULL for no log
  156.                      HINI hOld,             // in:  HINI to copy
  157.                      PSZ pszOld,            // in:  fully qualif. filename of hOld
  158.                      PSZ pszNew,            // out: new filename
  159.                      PFNWP fncbUpdate,      // in:  progress callback
  160.                      HWND hwnd, ULONG msg, ULONG ulCount, ULONG ulMax,
  161.                                             // in:  passed to fncbUpdate
  162.                      PFNWP fncbError)       // in:  error callback
  163. {
  164.     // BOOL    rc = TRUE;
  165.     HINI    hNew;
  166.     PSZ     pApps, // pKeys,
  167.             pApp2; // , pKey2;
  168.     ULONG   ulSizeOfAppsList; // , ulSizeOfKeysList; // , ulSizeOfData;
  169.     // CHAR    szLog[1000];     // removed V0.9.0
  170.     #define MBID_NOERROR 999
  171.     ULONG   ulErrorStatus = MBID_NOERROR;
  172.     PSZ     p_;
  173.     CHAR    szError2[2000];
  174.  
  175.     if (fLog)
  176.     {
  177.         fprintf(fLog, "    Entering prfhCopyProfile, params: "
  178.                       "hiniOld 0x%lX, pszOld %s, pfnwpCallback 0x%lX, "
  179.                       "hwnd 0x%lX, msg 0x%lX, ulCount 0x%lX, ulMax 0x%lX\n",
  180.                 hOld,
  181.                 pszOld,
  182.                 (ULONG)fncbUpdate,
  183.                 hwnd,
  184.                 msg,
  185.                 ulCount,
  186.                 ulMax);
  187.         fflush(fLog);
  188.     }
  189.  
  190.     if ( (!pszOld) || (!pszNew) )
  191.         ulErrorStatus = prfhINIError2(MB_CANCEL, pszOld, fLog, fncbError,
  192.                                       "Invalid name buffers given.");
  193.  
  194.     if (ulErrorStatus == MBID_NOERROR)
  195.     {
  196.         strupr(pszOld);
  197.         strcpy(pszNew, pszOld);
  198.         p_ = strhistr(pszNew, ".INI");
  199.         if (!p_)
  200.             ulErrorStatus = prfhINIError2(MB_CANCEL, pszNew, fLog, fncbError,
  201.                                           "Error composing new filename.");
  202.     }
  203.  
  204.     if (ulErrorStatus == MBID_NOERROR)
  205.     {
  206.         strcpy(p_, ".XFL");
  207.  
  208.         // delete new profile, in case something's left
  209.         if (fLog)
  210.             fprintf(fLog, "    DEL %s\n", pszNew);
  211.  
  212.         DosDelete(pszNew);
  213.  
  214.         // open new profile
  215.         if (fLog)
  216.             fprintf(fLog, "    PrfOpenProfile %s\n", pszNew);
  217.  
  218.         hNew = PrfOpenProfile(hab, pszNew);
  219.         if (!hNew)
  220.             ulErrorStatus = prfhINIError2(MB_CANCEL, pszNew, fLog, fncbError,
  221.                                           "Error creating temporary profile.");
  222.     }
  223.  
  224.     // get size of applications list
  225.     if (ulErrorStatus == MBID_NOERROR)
  226.     {
  227.         if (!PrfQueryProfileSize(hOld, NULL, NULL, &ulSizeOfAppsList))
  228.             ulErrorStatus = prfhINIError2(MB_CANCEL, pszNew, fLog, fncbError,
  229.                     "Error querying applications list size.");
  230.         else
  231.         if (ulSizeOfAppsList == 0)
  232.             ulErrorStatus = prfhINIError2(MB_CANCEL, pszNew, fLog, fncbError,
  233.                 "Size of applications list cannot be 0.");
  234.     }
  235.  
  236.     if (ulErrorStatus == MBID_NOERROR)
  237.     {
  238.         // do-while loop in case of MBID_RETRY
  239.         do
  240.         {
  241.             ulErrorStatus = MBID_NOERROR; // if we have a retry in the do-while loop
  242.  
  243.             // get applications list
  244.             pApps = (PSZ)malloc(ulSizeOfAppsList);
  245.             pApp2 = pApps;
  246.             if (!PrfQueryProfileData(hOld,
  247.                                      NULL,
  248.                                      NULL,
  249.                                      pApps,
  250.                                      &ulSizeOfAppsList))
  251.                 ulErrorStatus = prfhINIError2(MB_CANCEL, pszNew, fLog, fncbError,
  252.                                               "Could not query application list.");
  253.  
  254.             // applications loop
  255.  
  256.             while (   (*pApp2 != 0)
  257.                    && (ulErrorStatus == MBID_NOERROR)
  258.                   )
  259.             {
  260.                 CHAR szErrorKey[1000];
  261.                 // copy application (this will call prfhCopyKey in turn)
  262.                 ULONG ulrc = prfhCopyApp(hOld,
  263.                                          pApp2,
  264.                                          hNew,
  265.                                          pApp2,
  266.                                          szErrorKey);
  267.  
  268.                 ulErrorStatus = MBID_ABORT;
  269.  
  270.                 switch (ulrc)
  271.                 {
  272.                     case 0: // no error
  273.                         ulErrorStatus = MBID_NOERROR;
  274.                     break;
  275.  
  276.                     case PRFERR_KEYSLIST:
  277.                         // couldn't query keys list
  278.                         sprintf(szError2,
  279.                                 "Error querying keys list for \"%s\".",
  280.                                 pApp2);
  281.                     break;
  282.  
  283.                     case PRFERR_DATASIZE:
  284.                         // couldn't query data size for key
  285.                         sprintf(szError2,
  286.                                 "Error querying data size for \"%s\"/\"%s\".",
  287.                                 pApp2, szErrorKey);
  288.                     break;
  289.  
  290.                     case ERROR_NOT_ENOUGH_MEMORY:
  291.                         // couldn't allocate memory
  292.                         sprintf(szError2,
  293.                                 "Error allocating memory for copying \"%s\"/\"%s\".",
  294.                                 pApp2, szErrorKey);
  295.                     break;
  296.  
  297.                     case PRFERR_READ:
  298.                         // couldn't read data from source (PrfQueryProfileData error)
  299.                         sprintf(szError2,
  300.                                 "Error reading data from app \"%s\", key \"%s\".",
  301.                                 pApp2, szErrorKey);
  302.                     break;
  303.  
  304.                     case PRFERR_WRITE:
  305.                         // couldn't write data to target (PrfWriteProfileData error)
  306.                         sprintf(szError2,
  307.                                 "Error writing data to app \"%s\", key \"%s\".",
  308.                                 pApp2, szErrorKey);
  309.                     break;
  310.                 }
  311.  
  312.                 if (ulErrorStatus != MBID_NOERROR) // V0.9.4 (2000-07-15) [umoeller]
  313.                 {
  314.                     ulErrorStatus = prfhINIError2(MB_ABORTRETRYIGNORE, pszNew, fLog, fncbError,
  315.                                                   szError2);
  316.                 }
  317.  
  318.                 if (fncbUpdate)
  319.                 {
  320.                     ULONG ulNow2, ulMax2;
  321.                     ulNow2 = ((1000*(pApp2-pApps))/ulSizeOfAppsList) + (ulCount*1000);
  322.                     ulMax2 = (ulMax+1)*1000; // ulAppsSize;
  323.                     (*fncbUpdate)(hwnd, msg, (MPARAM)ulNow2, (MPARAM)ulMax2);
  324.                 }
  325.  
  326.                 // go for next app
  327.                 pApp2 += strlen(pApp2)+1;
  328.  
  329.                 if (ulErrorStatus == MBID_IGNORE)
  330.                     // error occured, but user pressed "Ignore":
  331.                     // skip this app
  332.                     ulErrorStatus = MBID_NOERROR;
  333.  
  334.             } // end while (*pApp2 != 0) && MBID_NOERROR
  335.  
  336.             if (pApps)
  337.                 free(pApps);
  338.  
  339.             if (fLog)
  340.                 fprintf(fLog, "    Done copying apps\n");
  341.  
  342.         } while (ulErrorStatus == MBID_RETRY);
  343.     } // end if (ulErrorOccured == MBID_NOERROR)
  344.  
  345.     if (fLog)
  346.         fprintf(fLog, "    PrfCloseProfile %s\n", pszNew);
  347.  
  348.     PrfCloseProfile(hNew);
  349.     if (fncbUpdate)
  350.         (*fncbUpdate)(hwnd, msg, (MPARAM)(ulCount+1), (MPARAM)(ulMax+1));
  351.  
  352.     if (fLog)
  353.     {
  354.         fprintf(fLog, "    Leaving prfhCopyProfile.\n");
  355.         fflush(fLog);
  356.     }
  357.  
  358.     return (ulErrorStatus == MBID_NOERROR); // FALSE if error occured
  359. }
  360.  
  361. /*
  362.  *@@ prfhSaveINIs:
  363.  *      this will enforce saving of OS2.INI and OS2SYS.INI
  364.  *      by calling prfhCopyProfile (above) on them; the therefrom
  365.  *      resulting ".XFL" files will replace the original
  366.  *      ".INI" files.
  367.  *      Specify fncbUpdate and fncbError like in prfhCopyProfile.
  368.  *
  369.  *@@changed V0.9.0 [umoeller]: fixed crashes with lower-case INI file names.
  370.  *@@changed V0.9.0 [umoeller]: changed prototype's logfile to stdio FILE*
  371.  */
  372.  
  373. APIRET prfhSaveINIs(HAB hab,               // in:  anchor block
  374.                     FILE* fLog,            // in:  stdio logfile or NULL for no log
  375.                     PFNWP fncbUpdate,      // in:  progress callback
  376.                     HWND hwnd, ULONG msg,  // in:  params passed to fncbUpdate
  377.                     PFNWP fncbError)       // in:  error callback
  378. {
  379.     PRFPROFILE Profiles;
  380.     APIRET  arc = NO_ERROR, arc2;
  381.     BOOL    brc = TRUE;
  382.  
  383.     // FILESTATUS3 fs3;
  384.     CHAR    szSysNew[CCHMAXPATH],
  385.             szUserNew[CCHMAXPATH],
  386.             szSysBackup[CCHMAXPATH],
  387.             szUserBackup[CCHMAXPATH];
  388.  
  389.     // the following flag may be one of the following:
  390.     //        MBID_NOERROR--- everything's fine, continue
  391.     //        MBID_IGNORE --- error occured, but ignore
  392.     //        MBID_RETRY  --- error occured, but retry
  393.     //        MBID_ABORT  --- error occured, abort saving
  394.     ULONG   ulErrorOccured = MBID_IGNORE;
  395.  
  396.     if (fLog)
  397.         fprintf(fLog, "  Entering prfhSaveINIs...\n");
  398.  
  399.     /*
  400.      * get system profiles:
  401.      *
  402.      */
  403.  
  404.     Profiles.cchUserName = Profiles.cchSysName = 0;
  405.     brc = PrfQueryProfile(hab, &Profiles);
  406.  
  407.     if (!brc)
  408.         ulErrorOccured = prfhINIError(MB_CANCEL, fLog, fncbError,
  409.                                       "Error querying system profiles size.");
  410.  
  411.     if (ulErrorOccured == MBID_IGNORE)
  412.     {
  413.         Profiles.pszUserName  = (PSZ)malloc(Profiles.cchUserName);
  414.         Profiles.pszSysName  = (PSZ)malloc(Profiles.cchSysName);
  415.         if (    (Profiles.pszSysName == NULL)
  416.              || (Profiles.pszUserName == NULL)
  417.            )
  418.             ulErrorOccured = prfhINIError(MB_CANCEL, fLog, fncbError,
  419.                     "Error allocating memory (1).");
  420.     }
  421.  
  422.     if (ulErrorOccured == MBID_IGNORE)
  423.     {
  424.         if (!PrfQueryProfile(hab, &Profiles))
  425.             ulErrorOccured = prfhINIError(MB_CANCEL, fLog, fncbError,
  426.                     "Error querying profiles (2).");
  427.     }
  428.  
  429.     if (ulErrorOccured == MBID_IGNORE)
  430.     {
  431.         if (fLog)
  432.             fprintf(fLog, "  System profiles are %s, %s\n",
  433.                     Profiles.pszUserName, Profiles.pszSysName);
  434.  
  435.         /*
  436.          * create new profile names:
  437.          *
  438.          */
  439.  
  440.         strcpy(szSysBackup, Profiles.pszSysName);
  441.         strcpy(strhistr(szSysBackup, ".INI"), ".BAK");
  442.         strcpy(szUserBackup, Profiles.pszUserName);
  443.         strcpy(strhistr(szUserBackup, ".INI"), ".BAK");
  444.  
  445.         /*
  446.          * create OS2SYS.XFL:
  447.          *
  448.          */
  449.  
  450.         if (fLog)
  451.             fprintf(fLog, "  Storing %s in *.XFL\n",
  452.                     Profiles.pszSysName);
  453.  
  454.         if (!prfhCopyProfile(hab,
  455.                              fLog,
  456.                              HINI_SYSTEMPROFILE,
  457.                              Profiles.pszSysName,   // old filename
  458.                              szSysNew,              // new filename
  459.                              fncbUpdate, hwnd, msg, 0, 1,
  460.                              fncbError))
  461.         {
  462.             // abort, since prfhCopyProfile already has error handling
  463.             ulErrorOccured = MBID_ABORT;
  464.         }
  465.     }
  466.  
  467.     if (ulErrorOccured == MBID_IGNORE)
  468.     {
  469.         // create OS2.XFL
  470.  
  471.         if (fLog)
  472.             fprintf(fLog, "  Storing %s in *.XFL\n",
  473.                     Profiles.pszUserName);
  474.  
  475.         if (!prfhCopyProfile(hab,
  476.                              fLog,
  477.                              HINI_USERPROFILE,
  478.                              Profiles.pszUserName, szUserNew,
  479.                              fncbUpdate, hwnd, msg, 1, 1,
  480.                              fncbError))
  481.         {
  482.             // abort, since prfhCopyProfile already has error handling
  483.             ulErrorOccured = MBID_ABORT;
  484.         }
  485.     }
  486.  
  487.     /*
  488.      * renaming stuff for OS2SYS.INI
  489.      *
  490.      */
  491.  
  492.     if (ulErrorOccured == MBID_IGNORE)
  493.     {
  494.         do
  495.         {
  496.             ulErrorOccured = MBID_IGNORE; // if we have a retry in the do-while loop
  497.  
  498.             if (ulErrorOccured == MBID_IGNORE)
  499.             {
  500.                 // attrib -r -s -h -a OS2SYS.BAK
  501.                 if (fLog)
  502.                     fprintf(fLog, "  ATTRIB -R -S -H -A %s\n",
  503.                             szSysBackup);
  504.  
  505.                 arc2 = doshSetPathAttr(szSysBackup, FILE_NORMAL);
  506.                 if (fLog)
  507.                     fprintf(fLog, "    rc2: %lu\n", arc2);
  508.  
  509.                 // delete OS2SYS.BAK
  510.                 if (fLog)
  511.                     fprintf(fLog, "  DEL %s\n",
  512.                             szSysBackup);
  513.  
  514.                 arc2 = DosDelete(szSysBackup);
  515.                 if (fLog)
  516.                     fprintf(fLog, "    rc2: %lu\n", arc2);
  517.  
  518.                 // attrib -r -s -h -a OS2SYS.INI
  519.                 if (fLog)
  520.                     fprintf(fLog, "  ATTRIB -R -S -H -A %s\n",
  521.                             Profiles.pszSysName);
  522.  
  523.                 arc2 = doshSetPathAttr(Profiles.pszSysName, FILE_NORMAL);
  524.                 if (fLog)
  525.                     fprintf(fLog, "    rc2: %lu\n", arc2);
  526.  
  527.                 // move OS2SYS.INI OS2SYS.BAK
  528.                 if (fLog)
  529.                     fprintf(fLog, "  MOVE %s %s\n",
  530.                             Profiles.pszSysName, szSysBackup);
  531.                 arc = DosMove(Profiles.pszSysName, szSysBackup);
  532.                 if (fLog)
  533.                     fprintf(fLog, "    rc: %lu\n", arc);
  534.  
  535.                 if (arc)
  536.                     ulErrorOccured = prfhINIError(MB_ABORTRETRYIGNORE, fLog, fncbError, "Error moving original system profile to backup.");
  537.             }
  538.  
  539.             if (ulErrorOccured == MBID_IGNORE)
  540.             {
  541.                 if (fLog)
  542.                     fprintf(fLog, "  MOVE %s %s\n",
  543.                             szSysNew, Profiles.pszSysName);
  544.                 arc = DosMove(szSysNew, Profiles.pszSysName);
  545.                 if (fLog)
  546.                     fprintf(fLog, "    rc: %lu\n", arc);
  547.                 if (arc)
  548.                     ulErrorOccured = prfhINIError(MB_ABORTRETRYIGNORE, fLog, fncbError, "Error moving newly created profile to system profile.");
  549.             }
  550.         } while (ulErrorOccured == MBID_RETRY);
  551.     }
  552.  
  553.     /*
  554.      * renaming stuff for OS2.INI
  555.      *
  556.      */
  557.  
  558.     if (ulErrorOccured == MBID_IGNORE)
  559.     {
  560.         do
  561.         {
  562.             ulErrorOccured = MBID_IGNORE; // if we have a retry in the do-while loop
  563.  
  564.             if (ulErrorOccured == MBID_IGNORE)
  565.             {
  566.                 // attrib -r -s -h -a OS2.BAK
  567.                 if (fLog)
  568.                     fprintf(fLog, "  ATTRIB -R -S -H -A %s\n",
  569.                             szUserBackup);
  570.  
  571.                 arc2 = doshSetPathAttr(szUserBackup, FILE_NORMAL);
  572.                 if (fLog)
  573.                     fprintf(fLog, "    rc2: %lu\n", arc2);
  574.  
  575.                 // delete OS2.BAK
  576.                 if (fLog)
  577.                     fprintf(fLog,"  DEL %s\n",
  578.                             szUserBackup);
  579.  
  580.                 arc2 = DosDelete(szUserBackup);
  581.                 if (fLog)
  582.                     fprintf(fLog, "    rc2: %lu\n", arc2);
  583.  
  584.                 // attrib -r -s -h -a OS2.INI
  585.                 if (fLog)
  586.                     fprintf(fLog, "  ATTRIB -R -S -H -A %s\n",
  587.                             Profiles.pszUserName);
  588.                 arc2 = doshSetPathAttr(Profiles.pszUserName, FILE_NORMAL);
  589.                 if (fLog)
  590.                     fprintf(fLog, "    rc2: %lu\n", arc2);
  591.  
  592.                 // move OS2.INI OS2.BAK
  593.                 if (fLog)
  594.                     fprintf(fLog, "  MOVE %s %s\n",
  595.                             Profiles.pszUserName, szUserBackup);
  596.                 arc = DosMove(Profiles.pszUserName, szUserBackup);
  597.                 if (fLog)
  598.                     fprintf(fLog, "    rc: %lu\n", arc);
  599.  
  600.                 if (arc)
  601.                     ulErrorOccured = prfhINIError(MB_ABORTRETRYIGNORE, fLog, fncbError, "Error moving original user profile to backup.");
  602.             }
  603.  
  604.             if (ulErrorOccured == MBID_IGNORE)
  605.             {
  606.                 // move OS2.XFL OS2.INI
  607.                 if (fLog)
  608.                     fprintf(fLog, "  MOVE %s %s\n",
  609.                             szUserNew, Profiles.pszUserName);
  610.  
  611.                 arc = DosMove(szUserNew, Profiles.pszUserName);
  612.                 if (fLog)
  613.                     fprintf(fLog, "    rc: %lu\n", arc);
  614.  
  615.                 if (arc)
  616.                     ulErrorOccured = prfhINIError(MB_ABORTRETRYIGNORE, fLog, fncbError, "Error moving newly created profile to user profile.");
  617.             }
  618.         } while (ulErrorOccured == MBID_RETRY);
  619.     }
  620.  
  621.     // DosExitCritSec();
  622.  
  623.     if (ulErrorOccured != MBID_IGNORE)
  624.     {
  625.         DosMove(szSysBackup, Profiles.pszSysName);
  626.         DosMove(szUserBackup, Profiles.pszUserName);
  627.     }
  628.  
  629.     if (Profiles.pszSysName)
  630.         free(Profiles.pszSysName);
  631.     if (Profiles.pszUserName)
  632.         free(Profiles.pszUserName);
  633.  
  634.     if (fLog)
  635.         fprintf(fLog, "  Done with prfhSaveINIs\n");
  636.  
  637.     if (ulErrorOccured != MBID_IGNORE)
  638.         return (999);
  639.     else
  640.         return NO_ERROR;
  641. }
  642.  
  643.  
  644.