Annotation of mstools/mssetup/source/setupapi.c, revision 1.1.1.1

1.1       root        1: //*************************************************************************
                      2: //*************************  Setup 'C' Wrappers  **************************
                      3: //*************************************************************************
                      4: 
                      5: 
                      6: // NOTE: setup code WinMain() must call InitSetupToolkit(szCmdLineArgs) at
                      7: // start and EndSetupToolkit() [CleaupTrap] at exit.  It must also define the
                      8: // routine SetupError() for error handling.
                      9: 
                     10: 
                     11: #include <windows.h>
                     12: #include <stdlib.h>            //atol
                     13: #include <direct.h>
                     14: #include "setupapi.h"
                     15: #include "msdetect.h"
                     16: #include "msregdb.h"
                     17: #include "msshared.h"
                     18: 
                     19: #define        cchMax  255
                     20: #define cchNum 10
                     21: 
                     22: 
                     23: /* GLOBALS */
                     24: INT  hSetup       = 0;
                     25: CHAR szCurDir[255];
                     26: 
                     27: 
                     28: // **************************************************************************
                     29: LPSTR lstrchr(LPSTR sz, CHAR ch)
                     30: {
                     31:        while (*sz)
                     32:                {
                     33:                if (ch == *sz)
                     34:                        return(sz);
                     35:                sz = AnsiNext(sz);
                     36:                }
                     37:        return(NULL);
                     38: }
                     39: 
                     40: 
                     41: 
                     42: #ifndef STF_LITE
                     43: // **************************************************************************
                     44: INT InStr(INT cch, LPSTR sz1, LPSTR sz2)
                     45: {
                     46:        LPSTR szTmp1, szTmp2;
                     47:        INT i = 1;
                     48: 
                     49:        if (cch == 0)
                     50:                return(0);
                     51: 
                     52:        while (cch > 1)
                     53:                {
                     54:                sz1 = AnsiNext(sz1);
                     55:                cch--;
                     56:                i++;
                     57:                }
                     58: 
                     59:        while (*sz1 != '\0')
                     60:                {
                     61:                szTmp1 = sz1;
                     62:                szTmp2 = sz2;
                     63:                while ((*szTmp1 != '\0') && (*szTmp2 != '\0'))
                     64:                        {
                     65:                        if (*szTmp1 != *szTmp2)
                     66:                                break;
                     67:                        szTmp1 = AnsiNext(szTmp1);
                     68:                        szTmp2 = AnsiNext(szTmp2);
                     69:                        }
                     70:                if (*szTmp2 == '\0')
                     71:                        return(i);
                     72:                if (*sz1 != '\0')
                     73:                        sz1 = AnsiNext(sz1);
                     74:                i++;
                     75:                }
                     76: 
                     77:        return(0);
                     78: }
                     79: #endif  /* !STF_LITE */
                     80: 
                     81: 
                     82: //**************************************************************************
                     83: INT InitSetupToolkit(LPSTR szCmdLine)
                     84: {
                     85:        INT  i;
                     86:        WORD wErrorModeSav;
                     87: 
                     88:        if (hSetup > 0)
                     89:                {
                     90: #ifdef DEBUG
                     91:                StfApiErr(saeInit, "InitSetupToolkit", szCmdLine);
                     92: #endif //DEBUG
                     93:                return(0);
                     94:                }
                     95: 
                     96:        if ((i = InitFrame(szCmdLine)) == -1)
                     97:                return(-1);
                     98: 
                     99:        /* do NOT call FInitRegDb() inside here since some Win3.0 apps don't
                    100:        ** use or ship it!  Your WinMain() should call it after this routine.
                    101:        */
                    102:        if (i == 0 || !InitInstall())
                    103:                {
                    104:                EndSetupToolkit();
                    105:                return(0);
                    106:                }
                    107: 
                    108:        hSetup = i;
                    109: 
                    110:        wErrorModeSav = SetErrorMode(1);
                    111:        getcwd(szCurDir, 255);             /* for C7 use _getcwd() */
                    112:        SetErrorMode(wErrorModeSav);
                    113:        OemToAnsi(szCurDir, szCurDir);
                    114: 
                    115:        i = lstrlen(szCurDir);
                    116:        if (szCurDir[i - 1] != '\\')
                    117:                {
                    118:                szCurDir[i] = '\\';
                    119:                szCurDir[i + 1] = '\0';
                    120:                }
                    121: 
                    122:        return(hSetup);
                    123: }
                    124: 
                    125: 
                    126: //**************************************************************************
                    127: INT InitFrame(LPSTR szCmdLine)
                    128: {
                    129:        if (hSetup > 0)
                    130:                {
                    131: #ifdef DEBUG
                    132:                StfApiErr(saeInit, "InitFrame", szCmdLine);
                    133: #endif //DEBUG
                    134:                return(0);
                    135:                }
                    136:        else
                    137:                {
                    138:                INT     i = InitializeFrame(szCmdLine);
                    139: 
                    140:                if (i == 0)
                    141:                        {
                    142: #ifdef DEBUG
                    143:                        StfApiErr(saeFail, "InitFrame", szCmdLine);
                    144: #endif //DEBUG
                    145:                        return(0);
                    146:                        }
                    147:                else
                    148:                        return(i);
                    149:                }
                    150: }
                    151: 
                    152: 
                    153: //**************************************************************************
                    154: VOID SetBitmap(LPSTR szDll, INT Bitmap)
                    155: {
                    156:        if (FSetBitmap(szDll, Bitmap) == 0)
                    157:                {
                    158: #ifdef DEBUG
                    159:                CHAR rgch[10];
                    160: 
                    161:                itoa(Bitmap, rgch, 10);    /* for C7 use _itoa() */
                    162:                StfApiErr(saeFail, "SetBitmap", SzCat2Str(szDll, ", ", rgch));
                    163: #endif //DEBUG
                    164:                SetupError(STFERR);
                    165:                }
                    166: }
                    167: 
                    168: 
                    169: //**************************************************************************
                    170: VOID SetAbout(LPSTR szAbout1, LPSTR szAbout2)
                    171: {
                    172:        if (FSetAbout(szAbout1, szAbout2) == 0)
                    173:                {
                    174: #ifdef DEBUG
                    175:                StfApiErr(saeFail, "SetAbout", SzCat2Str(szAbout1, ",", szAbout2));
                    176: #endif //DEBUG
                    177:                SetupError(STFERR);
                    178:                }
                    179: }
                    180: 
                    181: 
                    182: //*************************************************************************
                    183: VOID SetTitle(LPSTR sz)
                    184: {
                    185:        SetWindowText((HWND)HwndFrame(), sz);
                    186: }
                    187: 
                    188: 
                    189: //*************************************************************************
                    190: VOID ReadInfFile(LPSTR szFile)
                    191: {
                    192: #ifdef DEBUG
                    193:        if (FValidPath(szFile) == 0)
                    194:                BadArgErr(1, "ReadInfFile", szFile);
                    195: 
                    196:        if (FOpenInf(szFile, 1, 1) == 0)
                    197:                {
                    198:                StfApiErr(saeFail, "ReadInfFile", szFile);
                    199:                SetupError(STFERR);
                    200:                }
                    201: #else  //!DEBUG
                    202:        if (FOpenInf(szFile, 1, 0) == 0)
                    203:                SetupError(STFERR);
                    204: #endif //!DEBUG
                    205: }
                    206: 
                    207: 
                    208: //*************************************************************************
                    209: VOID OurYield()
                    210: {
                    211:        MSG msg;
                    212: 
                    213:        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
                    214:                {
                    215:                if (msg.message == WM_QUIT)
                    216:                        SetupError(STFQUIT);
                    217: 
                    218:                TranslateMessage(&msg);
                    219:                DispatchMessage(&msg);
                    220:                }
                    221: }
                    222: 
                    223: 
                    224: #ifndef STF_LITE
                    225: //*************************************************************************
                    226: LPSTR UIStartDlgExt(LPSTR szDll, INT Dlg, LPSTR szDlgProc,
                    227:                LPSTR szHelpDll, INT HelpDlg, LPSTR szHelpProc, LPSTR szBfr,
                    228:                INT cbBfrMax)
                    229: {
                    230: #ifdef DEBUG
                    231:        INT   n;
                    232:        LPSTR szTmp;
                    233:        CHAR  szDlg[cchNum], szHelpDlg[cchNum];
                    234: 
                    235:        if (FEmptySz(szDll))
                    236:                n = 1;
                    237:        else if (FEmptySz(szDlgProc))
                    238:                n = 3;
                    239:        else
                    240:                n = 0;
                    241: 
                    242:        if (n > 0)
                    243:                {
                    244:                wsprintf(szDlg, "%d", Dlg);
                    245:                wsprintf(szHelpDlg, "%d", HelpDlg);
                    246:                szTmp = SzCat3Str(szDll, szDlg, ", ", szDlgProc);
                    247:                szTmp = SzCat3Str(szTmp, ", ", szHelpDll, ", ");
                    248:                BadArgErr(n, "UIStartDlgExt", SzCat3Str(szTmp, szHelpDlg,", ",
                    249:                                szHelpProc));
                    250:                }
                    251: #endif //DEBUG
                    252: 
                    253:        if (FDoDialogExt((HWND)HwndFrame(), szDll, Dlg, szDlgProc, szHelpDll, HelpDlg,
                    254:                        szHelpProc) == 0)
                    255:                {
                    256: #ifdef DEBUG
                    257:                wsprintf(szDlg, "%d", Dlg);
                    258:                wsprintf(szHelpDlg, "%d", HelpDlg);
                    259:                szTmp = SzCat3Str(szDll, szDlg, ", ", szDlgProc);
                    260:                szTmp = SzCat3Str(szTmp, ", ", szHelpDll, ", ");
                    261:                StfApiErr(saeFail, "UIStartDlgExt", SzCat3Str(szTmp, szHelpDlg, ", ",
                    262:                                szHelpProc));
                    263: #endif //DEBUG
                    264:                SetupError(STFERR);
                    265:                }
                    266:        else
                    267:                {
                    268:                OurYield();
                    269:                return(GetSymbolValue("DLGEVENT", szBfr, cbBfrMax));
                    270:                }
                    271: }
                    272: #endif  /* !STF_LITE */
                    273: 
                    274: 
                    275: //*************************************************************************
                    276: LPSTR UIStartDlg(LPSTR szDll, INT Dlg, LPSTR szDlgProc, INT HelpDlg,
                    277:                                LPSTR szHelpProc, LPSTR szBfr, INT cbBfrMax)
                    278: {
                    279: #ifdef DEBUG
                    280:        INT   n;
                    281:        LPSTR szTmp;
                    282:        CHAR  szDlg[cchNum], szHelpDlg[cchNum];
                    283: 
                    284:        if (FEmptySz(szDll))
                    285:                n = 1;
                    286:        else if (FEmptySz(szDlgProc))
                    287:                n = 3;
                    288:        else
                    289:                n = 0;
                    290: 
                    291:        if (n > 0)
                    292:                {
                    293:                wsprintf(szDlg, "%d", Dlg);
                    294:                wsprintf(szHelpDlg, "%d", HelpDlg);
                    295:                szTmp = SzCat3Str(szDll, szDlg, ", ", szDlgProc);
                    296:                BadArgErr(n, "UIStartDlg", SzCat3Str(szTmp, szHelpDlg,", ",szHelpProc));
                    297:                }
                    298: #endif //DEBUG
                    299: 
                    300:        if (FDoDialogExt((HWND)HwndFrame(), szDll, Dlg, szDlgProc, szDll, HelpDlg,
                    301:                        szHelpProc) == 0)
                    302:                {
                    303: #ifdef DEBUG
                    304:                wsprintf(szDlg, "%d", Dlg);
                    305:                wsprintf(szHelpDlg, "%d", HelpDlg);
                    306:                szTmp = SzCat3Str(szDll, szDlg, ", ", szDlgProc);
                    307:                StfApiErr(saeFail, "UIStartDlg", SzCat3Str(szTmp, szHelpDlg, ", ",
                    308:                                szHelpProc));
                    309: #endif //DEBUG
                    310:                SetupError(STFERR);
                    311:                }
                    312:        else
                    313:                {
                    314:                OurYield();
                    315:                return(GetSymbolValue("DLGEVENT", szBfr, cbBfrMax));
                    316:                }
                    317: }
                    318: 
                    319: 
                    320: //*************************************************************************
                    321: void UIPop(INT n)
                    322: {
                    323:        if (FKillNDialogs(n) == 0)
                    324:                {
                    325: #ifdef DEBUG
                    326:                CHAR szNum[cchNum];
                    327: 
                    328:                wsprintf(szNum, "%d", n);
                    329:                StfApiErr(saeFail, "UIPop", szNum);
                    330: #endif //DEBUG
                    331:                SetupError(STFERR);
                    332:                }
                    333:        OurYield();
                    334: }
                    335: 
                    336: 
                    337: //*************************************************************************
                    338: VOID UIPopAll(VOID)
                    339: {
                    340:        if (FKillNDialogs(-1) == 0)
                    341:                {
                    342: #ifdef DEBUG
                    343:                StfApiErr(saeFail, "UIPopAll", "");
                    344: #endif //DEBUG
                    345:                SetupError(STFERR);
                    346:                }
                    347:        OurYield();
                    348: }
                    349: 
                    350: 
                    351: //*************************************************************************
                    352: LPSTR GetSymbolValue(LPSTR szSymbol, LPSTR szBfr, INT cbBfrMax)
                    353: {
                    354:        INT length;
                    355: 
                    356: #ifdef DEBUG
                    357:        if (FEmptySz(szSymbol))
                    358:                BadArgErr(1, "GetSymbolValue", szSymbol);
                    359: #endif //DEBUG
                    360: 
                    361:        if (szSymbol == NULL || *szSymbol == '\0')
                    362:                SetupError(STFERR);
                    363: 
                    364:        length = CbGetSymbolValue(szSymbol, szBfr, cbBfrMax);
                    365:        if (length >= cbBfrMax)
                    366:                {
                    367:                DoMsgBox("Buffer Overflow", "MS-Setup Error", MB_ICONHAND+MB_OK);
                    368:                SetupError(STFERR);
                    369:                }
                    370: 
                    371:        return(szBfr);
                    372: }
                    373: 
                    374: 
                    375: //*************************************************************************
                    376: INT GetListLength(LPSTR szSymbol)
                    377: {
                    378:        INT cb;
                    379: 
                    380: #ifdef DEBUG
                    381:        if (FEmptySz(szSymbol))
                    382:                BadArgErr(1, "GetListLength", szSymbol);
                    383: #endif //DEBUG
                    384: 
                    385:        if (szSymbol == NULL || *szSymbol == '\0')
                    386:                SetupError(STFERR);
                    387:        cb = UsGetListLength(szSymbol);
                    388: 
                    389:        return(cb);
                    390: }
                    391: 
                    392: 
                    393: //*************************************************************************
                    394: LPSTR GetListItem(LPSTR szListSymbol, INT nItem, LPSTR szBfr,
                    395:                INT cbBfrMax)
                    396: {
                    397:        INT     length;
                    398: 
                    399: #ifdef DEBUG
                    400:        CHAR szItem[cchNum];
                    401: 
                    402:        if (FEmptySz(szListSymbol))
                    403:                {
                    404:                wsprintf(szItem, "%d", nItem);
                    405:                BadArgErr(1, "GetListItem", SzCat2Str(szListSymbol,", ", szItem));
                    406:                }
                    407: 
                    408:        if ((nItem <= 0) || (nItem > GetListLength(szListSymbol)))
                    409:                {
                    410:                wsprintf(szItem, "%d", nItem);
                    411:                BadArgErr(2, "GetListItem",SzCat2Str(szListSymbol,", ",szItem));
                    412:                }
                    413: #endif //DEBUG
                    414: 
                    415:        if (szListSymbol == NULL || *szListSymbol == '\0')
                    416:                SetupError(STFERR);
                    417:        if ((nItem <= 0) || (nItem > GetListLength(szListSymbol)))
                    418:                SetupError(STFERR);
                    419:        length = CbGetListItem(szListSymbol, nItem, szBfr, cbBfrMax);
                    420:        if (length >= cbBfrMax)
                    421:                {
                    422:                DoMsgBox("Buffer Overflow", "MS-Setup Error", MB_ICONHAND+MB_OK);
                    423:                SetupError(STFERR);
                    424:                }
                    425: 
                    426:        return(szBfr);
                    427: }
                    428: 
                    429: 
                    430: //*************************************************************************
                    431: VOID AddListItem(LPSTR szSymbol, LPSTR szItem)
                    432: {
                    433: #ifdef DEBUG
                    434:        if (FEmptySz(szSymbol))
                    435:                BadArgErr(1, "AddListItem", SzCat2Str(szSymbol,", ",szItem));
                    436: #endif //DEBUG
                    437: 
                    438:        if (FAddListItem(szSymbol, szItem) == 0)
                    439:                {
                    440: #ifdef DEBUG
                    441:                StfApiErr(saeFail, "AddListItem",SzCat2Str(szSymbol,", ",szItem));
                    442: #endif //DEBUG
                    443:                SetupError(STFERR);
                    444:                }
                    445: }
                    446: 
                    447: 
                    448: //*************************************************************************
                    449: VOID ReplaceListItem(LPSTR szSymbol, INT n, LPSTR szItem)
                    450: {
                    451: #ifdef DEBUG
                    452:        INT   nArg;
                    453:        CHAR  szNum[cchNum];
                    454:        LPSTR szTmp;
                    455: 
                    456:        if (FEmptySz(szSymbol))
                    457:                nArg = 1;
                    458:        else if ((n <= 0) || (n > GetListLength(szSymbol)))
                    459:                nArg = 2;
                    460:        else
                    461:                nArg = 0;
                    462: 
                    463:        if (nArg > 0)
                    464:                {
                    465:                wsprintf(szNum,"%d", n);
                    466:                szTmp = SzCat3Str(szSymbol, ", ", szNum, ", ");
                    467:                BadArgErr(nArg, "ReplaceListItem", SzCatStr(szTmp,szItem));
                    468:                }
                    469: #endif //DEBUG
                    470: 
                    471:        if (FReplaceListItem(szSymbol, n, szItem) == 0)
                    472:                {
                    473: #ifdef DEBUG
                    474:                wsprintf(szNum,"%d", n);
                    475:                szTmp = SzCat3Str(szSymbol, ", ", szNum, ", ");
                    476:                StfApiErr(saeFail, "ReplaceListItem", SzCatStr(szTmp,szItem));
                    477: #endif //DEBUG
                    478:                SetupError(STFERR);
                    479:                }
                    480: }
                    481: 
                    482: 
                    483: //**************************************************************************
                    484: VOID MakeListFromSectionKeys(LPSTR szSymbol, LPSTR szSect)
                    485: {
                    486: #ifdef DEBUG
                    487:        INT n;
                    488: 
                    489:        if (FEmptySz(szSymbol))
                    490:                n = 1;
                    491:        else if (FValidInfSect(szSect) == 0)
                    492:                n = 2;
                    493:        else
                    494:                n = 0;
                    495:        if (n > 0)
                    496:                BadArgErr(n, "MakeListFromSectionKeys",SzCat2Str(szSymbol,", ",szSect));
                    497: #endif //DEBUG
                    498: 
                    499:        if (FSetSymbolToListOfInfKeys(szSymbol, szSect, 1) == 0)
                    500:                {
                    501: #ifdef DEBUG
                    502:                StfApiErr(saeFail, "MakeListFromSectionKeys", SzCat2Str(szSymbol, ", ",
                    503:                                szSect));
                    504: #endif //DEBUG
                    505:                SetupError(STFERR);
                    506:                }
                    507: }
                    508: 
                    509: 
                    510: //*************************************************************************
                    511: VOID SetSymbolValue(LPSTR szSymbol, LPSTR szValue)
                    512: {
                    513: #ifdef DEBUG
                    514:        if (FEmptySz(szSymbol))
                    515:                BadArgErr(1, "SetSymbolValue",SzCat2Str(szSymbol,", ",szValue));
                    516: #endif //DEBUG
                    517: 
                    518:        if (FSetSymbolValue(szSymbol, szValue) == 0)
                    519:                {
                    520: #ifdef DEBUG
                    521:                StfApiErr(saeFail, "SetSymbolValue", SzCat2Str(szSymbol,", ",szValue));
                    522: #endif //DEBUG
                    523:                SetupError(STFERR);
                    524:                }
                    525: }
                    526: 
                    527: 
                    528: //*************************************************************************
                    529: VOID RemoveSymbol(LPSTR szSym)
                    530: {
                    531: #ifdef DEBUG
                    532:        if (FEmptySz(szSym))
                    533:                BadArgErr(1, "RemoveSymbol", szSym);
                    534: #endif //DEBUG
                    535: 
                    536:        if (FRemoveSymbol(szSym) == 0)
                    537:                {
                    538: #ifdef DEBUG
                    539:                StfApiErr(saeFail, "RemoveSymbol", szSym);
                    540: #endif //DEBUG
                    541:                SetupError(STFERR);
                    542:                }
                    543: }
                    544: 
                    545: 
                    546: //*************************************************************************
                    547: INT ShowWaitCursor(VOID)
                    548: {
                    549:        return(HShowWaitCursor());
                    550: }
                    551: 
                    552: 
                    553: //*************************************************************************
                    554: VOID RestoreCursor(INT hPrev)
                    555: {
                    556:        if (FRestoreCursor(hPrev) == 0)
                    557:                {
                    558: #ifdef DEBUG
                    559:                StfApiErr(saeFail, "RestoreCursor", "");
                    560: #endif //DEBUG
                    561:                SetupError(STFERR);
                    562:                }
                    563: }
                    564: 
                    565: 
                    566: #ifndef STF_LITE
                    567: //*************************************************************************
                    568: INT SetBeepingMode(INT mode)
                    569: {
                    570:        return(FSetBeepingMode(mode));
                    571: }
                    572: 
                    573: 
                    574: //*************************************************************************
                    575: INT SetSilentMode(INT mode)
                    576: {
                    577:        return(FSetSilent(mode));
                    578: }
                    579: 
                    580: #endif  /* !STF_LITE */
                    581: 
                    582: //*************************************************************************
                    583: LPSTR GetSectionKeyDate(LPSTR szSect, LPSTR szKey, LPSTR szBfr,
                    584:                INT cbBfrMax)
                    585: {
                    586:        INT     length;
                    587: #ifdef DEBUG
                    588:        INT n;
                    589: 
                    590:        if (FValidInfSect(szSect) == 0)
                    591:                n = 1;
                    592:        else if (FEmptySz(szKey))
                    593:                n = 2;
                    594:        else
                    595:                n = 0;
                    596:        if (n > 0)
                    597:                BadArgErr(n, "GetSectionKeyDate",SzCat2Str(szSect,", ",szKey));
                    598: #endif //DEBUG
                    599: 
                    600:        length = CbGetInfSectionKeyField(szSect, szKey, 5, szBfr, cbBfrMax);
                    601:        if (length >= cbBfrMax)
                    602:                {
                    603:                DoMsgBox("Buffer Overflow", "MS-Setup Error", MB_ICONHAND+MB_OK);
                    604:                SetupError(STFERR);
                    605:                }
                    606: 
                    607:        if (length == -1)
                    608:                {
                    609: #ifdef DEBUG
                    610:                StfApiErr(saeFail, "GetSectionKeyDate",SzCat2Str(szSect,", ",szKey));
                    611: #endif //DEBUG
                    612:                SetupError(STFERR);
                    613:                }
                    614: 
                    615:        return(szBfr);
                    616: }
                    617: 
                    618: 
                    619: //*************************************************************************
                    620: LPSTR GetSectionKeyFilename(LPSTR szSect, LPSTR szKey, LPSTR szBfr,
                    621:                INT cbBfrMax)
                    622: {
                    623:        INT     length;
                    624: #ifdef DEBUG
                    625:        INT n;
                    626: 
                    627:        if (FValidInfSect(szSect) == 0)
                    628:                n = 1;
                    629:        else if (FEmptySz(szKey))
                    630:                n = 2;
                    631:        else
                    632:                n = 0;
                    633:        if (n > 0)
                    634:                BadArgErr(n, "GetSectionKeyFilename",SzCat2Str(szSect,", ",szKey));
                    635: #endif //DEBUG
                    636: 
                    637:        length = CbGetInfSectionKeyField(szSect, szKey, 1, szBfr, cbBfrMax);
                    638:        if (length >= cbBfrMax)
                    639:                {
                    640:                DoMsgBox("Buffer Overflow", "MS-Setup Error", MB_ICONHAND+MB_OK);
                    641:                SetupError(STFERR);
                    642:                }
                    643: 
                    644:        if (length == -1)
                    645:                {
                    646: #ifdef DEBUG
                    647:                StfApiErr(saeFail,"GetSectionKeyFilename",SzCat2Str(szSect,", ",szKey));
                    648: #endif //DEBUG
                    649:                SetupError(STFERR);
                    650:                }
                    651: 
                    652:        return(szBfr);
                    653: }
                    654: 
                    655: 
                    656: //*************************************************************************
                    657: LONG GetSectionKeySize(LPSTR szSect, LPSTR szKey)
                    658: {
                    659:        CHAR szBfr[128];
                    660:        INT      length;
                    661: #ifdef DEBUG
                    662:        INT  n;
                    663: 
                    664:        if (FValidInfSect(szSect) == 0)
                    665:                n = 1;
                    666:        else if (FEmptySz(szKey))
                    667:                n = 2;
                    668:        else
                    669:                n = 0;
                    670:        if (n > 0)
                    671:                BadArgErr(n, "GetSectionKeySize",SzCat2Str(szSect,", ",szKey));
                    672: #endif //DEBUG
                    673: 
                    674:        length = CbGetInfSectionKeyField(szSect, szKey, 15, szBfr, 128);
                    675:        if (length >= 128)
                    676:                {
                    677:                DoMsgBox("Buffer Overflow", "MS-Setup Error", MB_ICONHAND+MB_OK);
                    678:                SetupError(STFERR);
                    679:                }
                    680: 
                    681:        if (length == -1)
                    682:                {
                    683: #ifdef DEBUG
                    684:                StfApiErr(saeFail, "GetSectionKeySize",SzCat2Str(szSect,", ",szKey));
                    685: #endif //DEBUG
                    686:                SetupError(STFERR);
                    687:                }
                    688: 
                    689:        return(atol(szBfr));
                    690: }
                    691: 
                    692: 
                    693: #ifndef STF_LITE
                    694: //*************************************************************************
                    695: LPSTR GetSectionKeyVersion(LPSTR szSect, LPSTR szKey, LPSTR szBfr,
                    696:                INT cbBfrMax)
                    697: {
                    698:        INT     length;
                    699: #ifdef DEBUG
                    700:        INT n;
                    701: 
                    702:        if (FValidInfSect(szSect) == 0)
                    703:                n = 1;
                    704:        else if (FEmptySz(szKey))
                    705:                n = 2;
                    706:        else
                    707:                n = 0;
                    708:        if (n > 0)
                    709:                BadArgErr(n, "GetSectionKeyVersion",SzCat2Str( szSect,", ",szKey));
                    710: #endif //DEBUG
                    711: 
                    712:        length = CbGetInfSectionKeyField(szSect, szKey, 19, szBfr, cbBfrMax);
                    713:        if (length >= cbBfrMax)
                    714:                {
                    715:                DoMsgBox("Buffer Overflow", "MS-Setup Error", MB_ICONHAND+MB_OK);
                    716:                SetupError(STFERR);
                    717:                }
                    718: 
                    719:        if (length == -1)
                    720:                {
                    721: #ifdef DEBUG
                    722:                StfApiErr(saeFail, "GetSectionKeyVersion",SzCat2Str(szSect,", ",szKey));
                    723: #endif //DEBUG
                    724:                SetupError(STFERR);
                    725:                }
                    726: 
                    727:        return(szBfr);
                    728: }
                    729: #endif  /* !STF_LITE */
                    730: 
                    731: 
                    732: #ifndef STF_LITE
                    733: //*************************************************************************
                    734: VOID MakeListFromSectionDate(LPSTR szSym, LPSTR szSect)
                    735: {
                    736: #ifdef DEBUG
                    737:        INT n;
                    738: 
                    739:        if (FEmptySz(szSym))
                    740:                n = 1;
                    741:        else if (FValidInfSect(szSect) == 0)
                    742:                n = 2;
                    743:        else
                    744:                n = 0;
                    745:        if (n > 0)
                    746:                BadArgErr(n, "MakeListFromSectionDate",SzCat2Str( szSym,", ",szSect));
                    747: #endif //DEBUG
                    748: 
                    749:        if (FMakeListInfSectionField(szSym, szSect, 5) == 0)
                    750:                {
                    751: #ifdef DEBUG
                    752:                StfApiErr(saeFail, "MakeListFromSectionDate", SzCat2Str(szSym, ", ",
                    753:                                szSect));
                    754: #endif //DEBUG
                    755:                SetupError(STFERR);
                    756:                }
                    757: }
                    758: 
                    759: #endif  /* !STF_LITE */
                    760: 
                    761: //*************************************************************************
                    762: VOID MakeListFromSectionFilename(LPSTR szSym, LPSTR szSect)
                    763: {
                    764: #ifdef DEBUG
                    765:        INT n;
                    766: 
                    767:        if (FEmptySz(szSym))
                    768:                n = 1;
                    769:        else if (FValidInfSect(szSect) == 0)
                    770:                n = 2;
                    771:        else
                    772:                n = 0;
                    773:        if (n > 0)
                    774:                BadArgErr(n, "MakeListFromSectionFilename", SzCat2Str(szSym, ", ",
                    775:                                szSect));
                    776: #endif //DEBUG
                    777: 
                    778:        if (FMakeListInfSectionField(szSym, szSect, 1) == 0)
                    779:                {
                    780: #ifdef DEBUG
                    781:                StfApiErr(saeFail, "MakeListFromSectionFilename", SzCat2Str(szSym, ", ",
                    782:                                szSect));
                    783: #endif //DEBUG
                    784:                SetupError(STFERR);
                    785:                }
                    786: }
                    787: 
                    788: 
                    789: //*************************************************************************
                    790: VOID MakeListFromSectionSize(LPSTR szSym, LPSTR szSect)
                    791: {
                    792: #ifdef DEBUG
                    793:        INT n;
                    794: 
                    795:        if (FEmptySz(szSym))
                    796:                n = 1;
                    797:        else if (FValidInfSect(szSect) == 0)
                    798:                n = 2;
                    799:        else
                    800:                n = 0;
                    801:        if (n > 0)
                    802:                BadArgErr(n, "MakeListFromSectionSize",SzCat2Str( szSym,", ",szSect));
                    803: #endif //DEBUG
                    804: 
                    805:        if (FMakeListInfSectionField(szSym, szSect, 15) == 0)
                    806:                {
                    807: #ifdef DEBUG
                    808:                StfApiErr(saeFail, "MakeListFromSectionSize", SzCat2Str(szSym, ", ",
                    809:                                szSect));
                    810: #endif //DEBUG
                    811:                SetupError(STFERR);
                    812:                }
                    813: }
                    814: 
                    815: 
                    816: #ifndef STF_LITE
                    817: //*************************************************************************
                    818: VOID MakeListFromSectionVersion(LPSTR szSym, LPSTR szSect)
                    819: {
                    820: #ifdef DEBUG
                    821:        INT n;
                    822: 
                    823:        if (FEmptySz(szSym))
                    824:                n = 1;
                    825:        else if (FValidInfSect(szSect) == 0)
                    826:                n = 2;
                    827:        else
                    828:                n = 0;
                    829:        if (n > 0)
                    830:                BadArgErr(n, "MakeListFromSectionVersion",SzCat2Str(szSym,", ",szSect));
                    831: #endif //DEBUG
                    832: 
                    833:        if (FMakeListInfSectionField(szSym, szSect, 19) == 0)
                    834:                {
                    835: #ifdef DEBUG
                    836:                StfApiErr(saeFail, "MakeListFromSectionVersion", SzCat2Str(szSym, ", ",
                    837:                                szSect));
                    838: #endif //DEBUG
                    839:                SetupError(STFERR);
                    840:                }
                    841: }
                    842: #endif  /* !STF_LITE */
                    843: 
                    844: 
                    845: //*************************************************************************
                    846: INT InitInstall()
                    847: {
                    848:        HWND hFrame;
                    849:        HINSTANCE hInsta;
                    850: 
                    851:        if (hSetup > 0)
                    852:                {
                    853: #ifdef DEBUG
                    854:                StfApiErr(saeInit, "InitInstall", "");
                    855: #endif //DEBUG
                    856:                return(0);
                    857:                }
                    858:        
                    859:        hFrame = HwndFrame();
                    860:        hInsta = HinstFrame();
                    861: 
                    862: 
                    863:        if (FInitializeInstall((HANDLE)hInsta, hFrame) == 0)
                    864:                {
                    865: #ifdef DEBUG
                    866:                StfApiErr(saeFail, "InitInstall", "");
                    867: #endif //DEBUG
                    868:                return(0);
                    869:                }
                    870: 
                    871:        return(1);
                    872: }
                    873: 
                    874: 
                    875: //*************************************************************************
                    876: VOID CreateDir(LPSTR szDir, INT cmo)
                    877: {
                    878: #ifdef DEBUG
                    879:        CHAR szCmo[cchNum];
                    880: 
                    881:        if (FValidDir(szDir) == 0)
                    882:                {
                    883:                wsprintf(szCmo, "%d", cmo);
                    884:                BadArgErr(1, "CreateDir",SzCat2Str(szDir,", ",szCmo));
                    885:                }
                    886: #endif //DEBUG
                    887: 
                    888:        if (FCreateDir(szDir, cmo) == 0)
                    889:                {
                    890: #ifdef DEBUG
                    891:                CHAR szCmo[cchNum];
                    892: 
                    893:                wsprintf(szCmo, "%d", cmo);
                    894:                StfApiErr(saeFail, "CreateDir",SzCat2Str(szDir,", ",szCmo));
                    895: #endif //DEBUG
                    896:                SetupError(STFERR);
                    897:                }
                    898: }
                    899: 
                    900: 
                    901: #ifndef STF_LITE
                    902: //*************************************************************************
                    903: VOID RemoveDir(LPSTR szDir, INT cmo)
                    904: {
                    905: #ifdef DEBUG
                    906:        CHAR szCmo[cchNum];
                    907: 
                    908:        if (FValidDir(szDir) == 0)
                    909:                {
                    910:                wsprintf(szCmo, "%d", cmo);
                    911:                BadArgErr(1, "RemoveDir",SzCat2Str(szDir,", ",szCmo));
                    912:                }
                    913: #endif //DEBUG
                    914: 
                    915:        if (FRemoveDir(szDir, cmo) == 0)
                    916:                {
                    917: #ifdef DEBUG
                    918:                wsprintf(szCmo, "%d", cmo);
                    919:                StfApiErr(saeFail, "RemoveDir",SzCat2Str(szDir,", ",szCmo));
                    920: #endif //DEBUG
                    921:                SetupError(STFERR);
                    922:                }
                    923: }
                    924: 
                    925: 
                    926: //*************************************************************************
                    927: VOID RemoveIniSection(LPSTR szFile, LPSTR szSect, INT cmo)
                    928: {
                    929: #ifdef DEBUG
                    930:        INT   n;
                    931:        CHAR  szCmo[cchNum];
                    932:        LPSTR szTmp;
                    933: 
                    934:        if (FValidIniFile(szFile) == 0)
                    935:                n = 1;
                    936:        else if (FValidInfSect(szSect) == 0)
                    937:                n = 2;
                    938:        else
                    939:                n = 0;
                    940:        if (n > 0)
                    941:                {
                    942:                wsprintf(szCmo, "%d", cmo);
                    943:                szTmp = SzCat3Str(szFile, ", ", szSect, ", ");
                    944:                BadArgErr(n, "RemoveIniSection",SzCatStr(szTmp,szCmo));
                    945:                }
                    946: #endif //DEBUG
                    947: 
                    948:        if (FRemoveIniSection(szFile, szSect, cmo) == 0)
                    949:                {
                    950: #ifdef DEBUG
                    951:                wsprintf(szCmo, "%d", cmo);
                    952:                szTmp = SzCat3Str(szFile, ", ", szSect, ", ");
                    953:                StfApiErr(saeFail, "RemoveIniSection", SzCatStr(szTmp,szCmo));
                    954: #endif //DEBUG
                    955:                SetupError(STFERR);
                    956:                }
                    957: }
                    958: #endif  /* !STF_LITE */
                    959: 
                    960: 
                    961: //*************************************************************************
                    962: VOID CreateIniKeyValue(LPSTR szFile, LPSTR szSect, LPSTR szKey,
                    963:                LPSTR szValue, INT cmo)
                    964: {
                    965: #ifdef DEBUG
                    966:        CHAR  szCmo[cchNum];
                    967:        LPSTR szTmp1;
                    968:        INT   n;
                    969: 
                    970:        if (FValidIniFile(szFile) == 0)
                    971:                n = 1;
                    972:        else if (FValidInfSect(szSect) == 0)
                    973:                n = 2;
                    974:        else
                    975:                n = 0;
                    976:        if (n > 0)
                    977:                {
                    978:                wsprintf(szCmo, "%d", cmo);
                    979:                szTmp1 = SzCat3Str(szFile, ", ", szSect, ", ");
                    980:                szTmp1 = SzCat3Str(szTmp1, szKey, ", ", szValue);
                    981:                BadArgErr(n, "CreateIniKeyValue", SzCat2Str(szTmp1, ", ", szCmo));
                    982:                }
                    983: #endif //DEBUG
                    984: 
                    985:        if (FCreateIniKeyValue(szFile, szSect, szKey, szValue, cmo) == 0)
                    986:                {
                    987: #ifdef DEBUG
                    988:                wsprintf(szCmo, "%d", cmo);
                    989:                szTmp1 = SzCat3Str(szFile, ", ", szSect, ", ");
                    990:                szTmp1 = SzCat3Str(szTmp1, szKey, ", ", szValue);
                    991:                StfApiErr(saeFail, "CreateIniKeyValue", SzCat2Str(szTmp1, ", ", szCmo));
                    992: #endif //DEBUG
                    993:                SetupError(STFERR);
                    994:                }
                    995: }
                    996: 
                    997: 
                    998: #ifndef STF_LITE
                    999: //*************************************************************************
                   1000: VOID RemoveIniKey(LPSTR szFile, LPSTR szSect, LPSTR szKey, INT cmo)
                   1001: {
                   1002: #ifdef DEBUG
                   1003:        CHAR  szCmo[cchNum];
                   1004:        LPSTR szTmp1;
                   1005:        INT   n;
                   1006: 
                   1007:        if (FValidIniFile(szFile) == 0)
                   1008:                n = 1;
                   1009:        else if (FValidInfSect(szSect) == 0)
                   1010:                n = 2;
                   1011:        else if (FEmptySz(szKey))
                   1012:                n = 3;
                   1013:        else
                   1014:                n = 0;
                   1015:        if (n > 0)
                   1016:                {
                   1017:                wsprintf(szCmo, "%d", cmo);
                   1018:                szTmp1 = SzCat3Str(szFile, ", ", szSect, ", ");
                   1019:                szTmp1 = SzCat3Str(szTmp1, szKey, ", ", szCmo);
                   1020:                BadArgErr(n, "RemoveIniKey", szTmp1);
                   1021:                }
                   1022: #endif //DEBUG
                   1023: 
                   1024:        if (FRemoveIniKey(szFile, szSect, szKey, cmo) == 0)
                   1025:                {
                   1026: #ifdef DEBUG
                   1027:                wsprintf(szCmo, "%d", cmo);
                   1028:                szTmp1 = SzCat3Str(szFile, ", ", szSect, ", ");
                   1029:                szTmp1 = SzCat3Str(szTmp1, szKey, ", ", szCmo);
                   1030:                StfApiErr(saeFail, "RemoveIniKey", szTmp1);
                   1031: #endif //DEBUG
                   1032:                SetupError(STFERR);
                   1033:                }
                   1034: }
                   1035: #endif  /* !STF_LITE */
                   1036: 
                   1037: 
                   1038: #ifndef STF_LITE
                   1039: //*************************************************************************
                   1040: VOID CreateSysIniKeyValue(LPSTR szFile, LPSTR szSect, LPSTR szKey,
                   1041:                                LPSTR szValue, INT cmo)
                   1042: {
                   1043: #ifdef DEBUG
                   1044:        CHAR  szCmo[cchNum];
                   1045:        LPSTR szTmp1;
                   1046:        INT   n;
                   1047: 
                   1048:        if (FValidPath(szFile) == 0)
                   1049:                n = 1;
                   1050:        else if (FValidInfSect(szSect) == 0)
                   1051:                n = 2;
                   1052:        else if (FEmptySz(szKey))
                   1053:                n = 3;
                   1054:        else
                   1055:                n = 0;
                   1056:        if (n > 0)
                   1057:                {
                   1058:                wsprintf(szCmo, "%d", cmo);
                   1059:                szTmp1 = SzCat3Str(szFile, ", ", szSect, ", ");
                   1060:                szTmp1 = SzCat3Str(szTmp1, szKey, ", ", szValue);
                   1061:                BadArgErr(n, "CreateSysIniKeyValue", SzCat2Str(szTmp1, ", ", szCmo));
                   1062:                }
                   1063: #endif //DEBUG
                   1064: 
                   1065:        if (FCreateSysIniKeyValue(szFile, szSect, szKey, szValue, cmo) == 0)
                   1066:                {
                   1067: #ifdef DEBUG
                   1068:                wsprintf(szCmo, "%d", cmo);
                   1069:                szTmp1 = SzCat3Str(szFile, ", ", szSect, ", ");
                   1070:                szTmp1 = SzCat3Str(szTmp1, szKey, ", ", szValue);
                   1071:                StfApiErr(saeFail, "CreateSysIniKeyValue",SzCat2Str(szTmp1, ", ",
                   1072:                                szCmo));
                   1073: #endif //DEBUG
                   1074:                SetupError(STFERR);
                   1075:                }
                   1076: }
                   1077: #endif  /* !STF_LITE */
                   1078: 
                   1079: 
                   1080: //*************************************************************************
                   1081: VOID CreateProgmanGroup(LPSTR szGroup, LPSTR szPath, INT cmo)
                   1082: {
                   1083: #ifdef DEBUG
                   1084:        CHAR  szCmo[cchNum];
                   1085:        LPSTR szTmp;
                   1086: 
                   1087:        if (FEmptySz(szGroup) || (lstrlen(szGroup) > 24))
                   1088:                {
                   1089:                szTmp = SzCat3Str(szGroup, ", ", szPath, ", ");
                   1090:                BadArgErr(1, "CreateProgmanGroup",SzCatStr(szTmp, szCmo));
                   1091:                }
                   1092: #endif //DEBUG
                   1093: 
                   1094:        if (FCreateProgManGroup(szGroup, szPath, cmo) == 0)
                   1095:                {
                   1096: #ifdef DEBUG
                   1097:                szTmp = SzCat3Str(szGroup, ", ", szPath, ", ");
                   1098:                StfApiErr(saeFail, "CreateProgmanGroup",SzCatStr(szTmp,szCmo));
                   1099: #endif //DEBUG
                   1100:                SetupError(STFERR);
                   1101:                }
                   1102: }
                   1103: 
                   1104: #ifdef WIN32
                   1105: //*************************************************************************
                   1106: VOID CreateProgmanGroupEx(LPSTR szGroup, BOOL fCommon, INT cmo)
                   1107: {
                   1108: #ifdef DEBUG
                   1109:        CHAR  szCmo[cchNum];
                   1110:        LPSTR szTmp;
                   1111: 
                   1112:        if (FEmptySz(szGroup) || (lstrlen(szGroup) > 24))
                   1113:                {
                   1114:                szTmp = SzCat3Str(szGroup, ", ", fCommon?"Common":"Private", ", ");
                   1115:                BadArgErr(1, "CreateProgmanGroupEx",SzCatStr(szTmp, szCmo));
                   1116:                }
                   1117: #endif //DEBUG
                   1118: 
                   1119:        if (FCreateProgManGroupEx(szGroup, fCommon, cmo) == 0)
                   1120:                {
                   1121: #ifdef DEBUG
                   1122:                szTmp = SzCat3Str(szGroup, ", ", fCommon?"Common":"Private", ", ");
                   1123:                StfApiErr(saeFail, "CreateProgmanGroupEx",SzCatStr(szTmp,szCmo));
                   1124: #endif //DEBUG
                   1125:                SetupError(STFERR);
                   1126:                }
                   1127: }
                   1128: #endif //WIN32
                   1129: 
                   1130: 
                   1131: //*************************************************************************
                   1132: VOID ShowProgmanGroup(LPSTR szGroup, INT Cmd, INT cmo)
                   1133: {
                   1134:        CHAR  szT[255];
                   1135: #ifdef DEBUG
                   1136:        CHAR  szCmo[cchNum];
                   1137:        CHAR  szCmd[cchNum];
                   1138:        LPSTR szTmp;
                   1139: 
                   1140:        if (FEmptySz(szGroup) || (lstrlen(szGroup) > 24))
                   1141:                {
                   1142:                wsprintf(szCmo, "%d", cmo);
                   1143:                wsprintf(szCmd, "%d", Cmd);
                   1144:                szTmp = SzCat3Str(szGroup, ", ", szCmd, ", ");
                   1145:                BadArgErr(1, "ShowProgmanGroup",SzCatStr(szTmp, szCmo));
                   1146:                }
                   1147: #endif //DEBUG
                   1148: 
                   1149:        /* for C7 use _itoa() */
                   1150:        if (FShowProgManGroup(szGroup, itoa(Cmd, szT, 10), cmo) == 0)
                   1151:                {
                   1152: #ifdef DEBUG
                   1153:                wsprintf(szCmo, "%d", cmo);
                   1154:                wsprintf(szCmd, "%d", Cmd);
                   1155:                szTmp = SzCat3Str(szGroup, ", ", szCmd, ", ");
                   1156:                StfApiErr(saeFail, "ShowProgmanGroup",SzCatStr(szTmp, szCmo));
                   1157: #endif //DEBUG
                   1158:                SetupError(STFERR);
                   1159:                }
                   1160: }
                   1161: 
                   1162: 
                   1163: #ifdef WIN32
                   1164: //*************************************************************************
                   1165: VOID ShowProgmanGroupEx(LPSTR szGroup, BOOL fCommon, INT Cmd, INT cmo)
                   1166: {
                   1167:        CHAR  szT[255];
                   1168: #ifdef DEBUG
                   1169:        CHAR  szCmo[cchNum];
                   1170:        CHAR  szCmd[cchNum];
                   1171:        LPSTR szTmp;
                   1172: 
                   1173:        if (FEmptySz(szGroup) || (lstrlen(szGroup) > 24))
                   1174:                {
                   1175:                wsprintf(szCmo, "%d", cmo);
                   1176:                wsprintf(szCmd, "%d", Cmd);
                   1177:                szTmp = SzCat3Str(szGroup, ", ", szCmd, ", ");
                   1178:                BadArgErr(1, "ShowProgmanGroup",SzCatStr(szTmp, szCmo));
                   1179:                }
                   1180: #endif //DEBUG
                   1181: 
                   1182:        /* for C7 use _itoa() */
                   1183:        if (FShowProgManGroupEx(szGroup, fCommon, itoa(Cmd, szT, 10), cmo) == 0)
                   1184:                {
                   1185: #ifdef DEBUG
                   1186:                wsprintf(szCmo, "%d", cmo);
                   1187:                wsprintf(szCmd, "%d", Cmd);
                   1188:                szTmp = SzCat3Str(szGroup, ", ", szCmd, ", ");
                   1189:                StfApiErr(saeFail, "ShowProgmanGroupEx",SzCatStr(szTmp, szCmo));
                   1190: #endif //DEBUG
                   1191:                SetupError(STFERR);
                   1192:                }
                   1193: }
                   1194: #endif
                   1195: 
                   1196: 
                   1197: //*************************************************************************
                   1198: VOID StampResource(LPSTR szSect, LPSTR szKey, LPSTR szDst,
                   1199:                INT wResType, INT wResId, LPSTR szData, INT cbData)
                   1200: {
                   1201: #ifdef DEBUG
                   1202:        INT   n;
                   1203:        CHAR  szResType[cchNum], szResId[cchNum], szcbData[cchNum];
                   1204:        LPSTR szTmp1;
                   1205: 
                   1206:        if (FValidInfSect(szSect) == 0)
                   1207:                n = 1;
                   1208:        else if (FEmptySz(szKey))
                   1209:                n = 2;
                   1210:        else if (FValidDir(szDst) == 0)
                   1211:                n = 3;
                   1212:        else
                   1213:                n = 0;
                   1214:        if (n > 0)
                   1215:                {
                   1216:                wsprintf(szResType, "%d", wResType);
                   1217:                wsprintf(szResId, "%d", wResId);
                   1218:                wsprintf(szcbData, "%d", cbData);
                   1219:                szTmp1 = SzCat3Str(szSect, ", ", szKey, ", ");
                   1220:                szTmp1 = SzCat3Str(szTmp1, szDst, ", ", szResType);
                   1221:                szTmp1 = SzCat3Str(szTmp1, ", ", szResId, ", ");
                   1222:                BadArgErr(n,"StampResource",SzCat3Str(szTmp1, szData, ", ",szcbData));
                   1223:                }
                   1224: #endif //DEBUG
                   1225: 
                   1226:        if (FStampResource(szSect,szKey,szDst,wResType,wResId,szData,cbData) == 0)
                   1227:                {
                   1228: #ifdef DEBUG
                   1229:                wsprintf(szResType, "%d", wResType);
                   1230:                wsprintf(szResId, "%d", wResId);
                   1231:                wsprintf(szcbData, "%d", cbData);
                   1232:                szTmp1 = SzCat3Str(szSect, ", ", szKey, ", ");
                   1233:                szTmp1 = SzCat3Str(szTmp1, szDst, ", ", szResType);
                   1234:                szTmp1 = SzCat3Str(szTmp1, ", ", szResId, ", ");
                   1235:                StfApiErr(saeFail,"StampResource",SzCat3Str(szTmp1, szData, ", ",
                   1236:                                szcbData));
                   1237: #endif //DEBUG
                   1238:                SetupError(STFERR);
                   1239:                }
                   1240: }
                   1241: 
                   1242: #ifndef STF_LITE
                   1243: 
                   1244: //*************************************************************************
                   1245: VOID DumpCopyList(LPSTR szFile)
                   1246: {
                   1247: #ifdef DEBUG
                   1248:        if (FEmptySz(szFile))
                   1249:                BadArgErr(1, "DumpCopyList", szFile);
                   1250: #endif //DEBUG
                   1251: 
                   1252:        if (FDumpCopyListToFile(szFile) == 0)
                   1253:                {
                   1254: #ifdef DEBUG
                   1255:                StfApiErr(saeFail, "DumpCopyList", szFile);
                   1256: #endif //DEBUG
                   1257:                SetupError(STFERR);
                   1258:                }
                   1259: }
                   1260: #endif  /* !STF_LITE */
                   1261: 
                   1262: //*************************************************************************
                   1263: VOID ClearCopyList(VOID)
                   1264: {
                   1265:        ResetCopyList();
                   1266: }
                   1267: 
                   1268: 
                   1269: //*************************************************************************
                   1270: LONG GetCopyListCost(LPSTR szExtraList, LPSTR szCostList,
                   1271:                LPSTR szNeedList)
                   1272: {
                   1273:        LONG lNeed = LcbGetCopyListCost(szExtraList, szCostList, szNeedList);
                   1274: 
                   1275:        if (lNeed < 0)
                   1276:                {
                   1277: #ifdef DEBUG
                   1278:        LPSTR szTmp;
                   1279:                szTmp = SzCat3Str(szExtraList, ", ", szCostList, ", ");
                   1280:                StfApiErr(saeFail, "GetCopyListCost", SzCatStr(szTmp,szNeedList));
                   1281: #endif //DEBUG
                   1282:                SetupError(STFERR);
                   1283:                }
                   1284: 
                   1285:        return(lNeed);
                   1286: }
                   1287: 
                   1288: 
                   1289: //*************************************************************************
                   1290: VOID CreateProgmanItem(LPSTR szGroup, LPSTR szItem, LPSTR szCmd,
                   1291:                LPSTR szOther, INT cmo)
                   1292: {
                   1293:        LPSTR szItemNew = szItem;
                   1294: #ifdef DEBUG
                   1295:        CHAR  szCmo[cchNum];
                   1296:        LPSTR szTmp1;
                   1297: #endif //DEBUG
                   1298: 
                   1299:        if (szOther != NULL && *szOther != '\0')
                   1300:                szItemNew = SzCat2Str(szItem, ",", szOther);
                   1301: 
                   1302: #ifdef DEBUG
                   1303:        if (FEmptySz(szGroup) || (lstrlen(szGroup) > 24))
                   1304:                {
                   1305:                wsprintf(szCmo, "%d", cmo);
                   1306:                szTmp1 = SzCat3Str(szGroup, ", ", szCmd, ", ");
                   1307:                BadArgErr(1, "CreateProgmanItem",SzCatStr(szTmp1,szCmo));
                   1308:                }
                   1309: #endif //DEBUG
                   1310: 
                   1311:        if (FCreateProgManItem(szGroup, szItemNew, szCmd, cmo) == 0)
                   1312:                {
                   1313: #ifdef DEBUG
                   1314:                wsprintf(szCmo, "%d", cmo);
                   1315:                szTmp1 = SzCat3Str(szGroup, ", ", szItem, ", ");
                   1316:                szTmp1 = SzCat3Str(szTmp1, szCmd, ", ", szOther);
                   1317:                StfApiErr(saeFail,"CreateProgmanItem", SzCat2Str(szTmp1, ", ", szCmo));
                   1318: #endif //DEBUG
                   1319:                SetupError(STFERR);
                   1320:                }
                   1321: }
                   1322: 
                   1323: #ifdef WIN32
                   1324: //*************************************************************************
                   1325: VOID CreateProgmanItemEx(LPSTR szGroup, BOOL fCommon, LPSTR szItem, LPSTR szCmd,
                   1326:                LPSTR szOther, INT cmo)
                   1327: {
                   1328:        LPSTR szItemNew = szItem;
                   1329: #ifdef DEBUG
                   1330:        CHAR  szCmo[cchNum];
                   1331:        LPSTR szTmp1;
                   1332: #endif //DEBUG
                   1333: 
                   1334:        if (szOther != NULL && *szOther != '\0')
                   1335:                szItemNew = SzCat2Str(szItem, ",", szOther);
                   1336: 
                   1337: #ifdef DEBUG
                   1338:        if (FEmptySz(szGroup) || (lstrlen(szGroup) > 24))
                   1339:                {
                   1340:                wsprintf(szCmo, "%d", cmo);
                   1341:                szTmp1 = SzCat3Str(szGroup, ", ", szCmd, ", ");
                   1342:                BadArgErr(1, "CreateProgmanItemEx",SzCatStr(szTmp1,szCmo));
                   1343:                }
                   1344: #endif //DEBUG
                   1345: 
                   1346:        if (FCreateProgManItemEx(szGroup, fCommon, szItemNew, szCmd, cmo) == 0)
                   1347:                {
                   1348: #ifdef DEBUG
                   1349:                wsprintf(szCmo, "%d", cmo);
                   1350:                szTmp1 = SzCat3Str(szGroup, ", ", szItem, ", ");
                   1351:                szTmp1 = SzCat3Str(szTmp1, szCmd, ", ", szOther);
                   1352:                StfApiErr(saeFail,"CreateProgmanItemEx", SzCat2Str(szTmp1, ", ", szCmo));
                   1353: #endif //DEBUG
                   1354:                SetupError(STFERR);
                   1355:                }
                   1356: }
                   1357: #endif //WIN32
                   1358: 
                   1359: 
                   1360: #ifndef STF_LITE
                   1361: //*************************************************************************
                   1362: VOID AddDos5Help(LPSTR szProgName, LPSTR szProgHelp, INT cmo)
                   1363: {
                   1364: #ifndef WIN32
                   1365: #ifdef DEBUG
                   1366:        INT   n;
                   1367:        CHAR  szCmo[cchNum];
                   1368:        LPSTR szTmp;
                   1369: 
                   1370:        if (FEmptySz(szProgName)
                   1371:                        || (szProgName[0] == '@')
                   1372:                        || (lstrlen(szProgName) > 8))
                   1373:                n = 1;
                   1374:        else if ((lstrchr(szProgName, ' ') != NULL)
                   1375:                        || (lstrchr(szProgName,'\t') != NULL))
                   1376:                n = 1;
                   1377:        else if (FEmptySz(szProgHelp))
                   1378:                n = 2;
                   1379:        else
                   1380:                n = 0;
                   1381:        if (n > 0)
                   1382:                {
                   1383:                wsprintf(szCmo, "%d", cmo);
                   1384:                szTmp = SzCat3Str(szProgName, ", ",szProgHelp, ", ");
                   1385:                BadArgErr(n, "AddDos5Help", SzCatStr(szTmp,szCmo));
                   1386:                }
                   1387: #endif //DEBUG
                   1388: 
                   1389:        if (FAddDos5Help(szProgName, szProgHelp, cmo) == 0)
                   1390:                {
                   1391: #ifdef DEBUG
                   1392:                wsprintf(szCmo, "%d", cmo);
                   1393:                szTmp = SzCat3Str(szProgName, ", ",szProgHelp, ", ");
                   1394:                StfApiErr(saeFail, "AddDos5Help",SzCatStr(szTmp, szCmo));
                   1395: #endif //DEBUG
                   1396:                SetupError(STFERR);
                   1397:                }
                   1398: #endif
                   1399: }
                   1400: #endif  /* !STF_LITE */
                   1401: 
                   1402: 
                   1403: //*************************************************************************
                   1404: VOID CopyFilesInCopyList(VOID)
                   1405: {
                   1406:        INT     grc = GrcCopyFilesInCopyList((HANDLE)HinstFrame());
                   1407: 
                   1408:        if (grc == grcUserQuit)
                   1409:                SetupError(STFQUIT);
                   1410:        else if (grc > 0)
                   1411:                {
                   1412: #ifdef DEBUG
                   1413:                StfApiErr(saeFail, "CopyFilesInCopyList", "");
                   1414: #endif //DEBUG
                   1415:                SetupError(STFERR);
                   1416:                }
                   1417: }
                   1418: 
                   1419: 
                   1420: //*************************************************************************
                   1421: VOID CopyAFile(LPSTR szFullPathSrc, LPSTR szFullPathDst, INT cmo,
                   1422:                INT fAppend)
                   1423: {
                   1424: #ifdef DEBUG
                   1425:        INT   n;
                   1426:        CHAR  szCmo[cchNum], szAppend[cchNum];
                   1427:        LPSTR szTmp;
                   1428: 
                   1429:        if (FValidPath(szFullPathSrc) == 0)
                   1430:                n = 1;
                   1431:        else if (FValidPath(szFullPathDst) == 0)
                   1432:                n = 2;
                   1433:        else
                   1434:                n = 0;
                   1435:        if (n > 0)
                   1436:                {
                   1437:                wsprintf(szCmo, "%d", cmo);
                   1438:                wsprintf(szAppend, "%d", fAppend);
                   1439:                szTmp = SzCat3Str(szFullPathSrc, ", ", szFullPathDst, ", ");
                   1440:                BadArgErr(n, "CopyAFile",SzCat3Str(szTmp,szCmo,", ",szAppend));
                   1441:                }
                   1442: #endif //DEBUG
                   1443: 
                   1444:        if (FCopyOneFile(szFullPathSrc, szFullPathDst, (cmo|cmoCopy), fAppend) == 0)
                   1445:                {
                   1446: #ifdef DEBUG
                   1447:                wsprintf(szCmo, "%d", cmo);
                   1448:                wsprintf(szAppend, "%d", fAppend);
                   1449:                szTmp = SzCat3Str(szFullPathSrc, ", ", szFullPathDst, ", ");
                   1450:                StfApiErr(saeFail, "CopyAFile",SzCat3Str(szTmp, szCmo,", ",szAppend));
                   1451: #endif //DEBUG
                   1452:                SetupError(STFERR);
                   1453:                }
                   1454: }
                   1455: 
                   1456: 
                   1457: //*************************************************************************
                   1458: VOID RemoveFile(LPSTR szFullPathSrc, INT cmo)
                   1459: {
                   1460: #ifdef DEBUG
                   1461:        CHAR szCmo[cchNum];
                   1462: 
                   1463:        if (FValidPath(szFullPathSrc) == 0)
                   1464:                {
                   1465:                wsprintf(szCmo, "%d", cmo);
                   1466:                BadArgErr(1, "RemoveFile",SzCat2Str(szFullPathSrc,", ",szCmo));
                   1467:                }
                   1468: #endif //DEBUG
                   1469: 
                   1470:        if (YnrcRemoveFile(szFullPathSrc, cmo) == ynrcNo)
                   1471:                {
                   1472: #ifdef DEBUG
                   1473:                StfApiErr(saeFail, "RemoveFile",SzCat2Str(szFullPathSrc,", ",szCmo));
                   1474: #endif //DEBUG
                   1475:                SetupError(STFERR);
                   1476:                }
                   1477: }
                   1478: 
                   1479: 
                   1480: #ifndef STF_LITE
                   1481: //*************************************************************************
                   1482: VOID BackupFile(LPSTR szFullPath, LPSTR szBackup)
                   1483: {
                   1484: #ifdef DEBUG
                   1485:        INT n;
                   1486: 
                   1487:        if (FValidPath(szFullPath) == 0)
                   1488:                n = 1;
                   1489:        else if (FEmptySz(szBackup))
                   1490:                n = 2;
                   1491:        else
                   1492:                n = 0;
                   1493:        if (n > 0)
                   1494:                BadArgErr(n, "BackupFile",SzCat2Str(szFullPath,", ",szBackup));
                   1495: #endif //DEBUG
                   1496: 
                   1497:        if (YnrcBackupFile(szFullPath, szBackup, cmoNone) == ynrcNo)
                   1498:                {
                   1499: #ifdef DEBUG
                   1500:                StfApiErr(saeFail, "BackupFile",SzCat2Str(szFullPath,", ",szBackup));
                   1501: #endif //DEBUG
                   1502:                SetupError(STFERR);
                   1503:                }
                   1504: }
                   1505: 
                   1506: 
                   1507: //*************************************************************************
                   1508: VOID RenameFile(LPSTR szFullPath, LPSTR szBackup)
                   1509: {
                   1510: #ifdef DEBUG
                   1511:        INT n;
                   1512: 
                   1513:        if (FValidPath(szFullPath) == 0)
                   1514:                n = 1;
                   1515:        else if (FEmptySz(szBackup))
                   1516:                n = 2;
                   1517:        else
                   1518:                n = 0;
                   1519:        if (n > 0)
                   1520:                BadArgErr(n, "RenameFile",SzCat2Str(szFullPath,", ",szBackup));
                   1521: #endif //DEBUG
                   1522: 
                   1523:        if (YnrcBackupFile(szFullPath, szBackup, cmoNone) == ynrcNo)
                   1524:                {
                   1525: #ifdef DEBUG
                   1526:                StfApiErr(saeFail, "RenameFile",SzCat2Str(szFullPath,", ",szBackup));
                   1527: #endif //DEBUG
                   1528:                SetupError(STFERR);
                   1529:                }
                   1530: }
                   1531: #endif  /* !STF_LITE */
                   1532: 
                   1533: 
                   1534: //*************************************************************************
                   1535: VOID AddSectionFilesToCopyList(LPSTR szSect, LPSTR szSrc,
                   1536:                LPSTR szDest)
                   1537: {
                   1538: #ifdef DEBUG
                   1539:        INT   n;
                   1540:        LPSTR szTmp;
                   1541: 
                   1542:        if (FValidInfSect(szSect) == 0)
                   1543:                n = 1;
                   1544:        else if (FValidDir(szSrc) == 0)
                   1545:                n = 2;
                   1546:        else if (FValidDir(szDest) == 0)
                   1547:                n = 3;
                   1548:        else
                   1549:                n = 0;
                   1550:        if (n > 0)
                   1551:                {
                   1552:                szTmp = SzCat3Str(szSect, ", ", szSrc, ", ");
                   1553:                BadArgErr(n, "AddSectionFilesToCopyList",SzCatStr(szTmp,szDest));
                   1554:                }
                   1555: #endif //DEBUG
                   1556: 
                   1557:        if (FAddSectionFilesToCopyList(szSect, szSrc, szDest) == 0)
                   1558:                {
                   1559: #ifdef DEBUG
                   1560:                szTmp = SzCat3Str(szSect, ", ", szSrc, ", ");
                   1561:                StfApiErr(saeFail, "AddSectionFilesToCopyList",SzCatStr(szTmp, szDest));
                   1562: #endif //DEBUG
                   1563:                SetupError(STFERR);
                   1564:                }
                   1565: }
                   1566: 
                   1567: 
                   1568: //*************************************************************************
                   1569: VOID AddSectionKeyFileToCopyList(LPSTR szSect, LPSTR szKey,
                   1570:                LPSTR szSrc, LPSTR szDest)
                   1571: {
                   1572: #ifdef DEBUG
                   1573:        INT   n;
                   1574:        LPSTR szTmp;
                   1575: 
                   1576:        if (FValidInfSect(szSect) == 0)
                   1577:                n = 1;
                   1578:        else if (FEmptySz(szKey))
                   1579:                n = 2;
                   1580:        else if (FValidDir(szSrc) == 0)
                   1581:                n = 3;
                   1582:        else if (FValidDir(szDest) == 0)
                   1583:                n = 4;
                   1584:        else
                   1585:                n = 0;
                   1586:        if (n > 0)
                   1587:                {
                   1588:                szTmp = SzCat3Str(szSect, ", ", szKey, ", ");
                   1589:                BadArgErr(n, "AddSectionKeyFileToCopyList", SzCat3Str(szTmp, szSrc,
                   1590:                                ", ", szDest));
                   1591:                }
                   1592: #endif //DEBUG
                   1593: 
                   1594:        if (FAddSectionKeyFileToCopyList(szSect, szKey, szSrc, szDest) == 0)
                   1595:                {
                   1596: #ifdef DEBUG
                   1597:                szTmp = SzCat3Str(szSect, ", ", szKey, ", ");
                   1598:                StfApiErr(saeFail, "AddSectionKeyFileToCopyList", SzCat3Str(szTmp,
                   1599:                                szSrc, ", ", szDest));
                   1600: #endif //DEBUG
                   1601:                SetupError(STFERR);
                   1602:                }
                   1603: }
                   1604: 
                   1605: 
                   1606: #ifndef STF_LITE
                   1607: //*************************************************************************
                   1608: VOID AddSpecialFileToCopyList(LPSTR szSect, LPSTR szKey, LPSTR szSrc,
                   1609:                                LPSTR szDest)
                   1610: {
                   1611: #ifdef DEBUG
                   1612:        INT   n;
                   1613:        LPSTR szTmp;
                   1614: 
                   1615:        if (FValidInfSect(szSect) == 0)
                   1616:                n = 1;
                   1617:        else if (FEmptySz(szKey))
                   1618:                n = 2;
                   1619:        else if (FValidDir(szSrc) == 0)
                   1620:                n = 3;
                   1621:        else if (FValidPath(szDest) == 0)
                   1622:                n = 4;
                   1623:        else
                   1624:                n = 0;
                   1625:        if (n > 0)
                   1626:                {
                   1627:                szTmp = SzCat3Str(szSect, ", ", szKey, ", ");
                   1628:                BadArgErr(n, "AddSpecialFileToCopyList", SzCat3Str(szTmp, szSrc, ", ",
                   1629:                                szDest));
                   1630:                }
                   1631: #endif //DEBUG
                   1632: 
                   1633:        if (FAddSpecialFileToCopyList(szSect, szKey, szSrc, szDest) == 0)
                   1634:                {
                   1635: #ifdef DEBUG
                   1636:                szTmp = SzCat3Str(szSect, ", ", szKey, ", ");
                   1637:                StfApiErr(saeFail, "AddSpecialFileToCopyList", SzCat3Str(szTmp, szSrc,
                   1638:                                ", ", szDest));
                   1639: #endif //DEBUG
                   1640:                SetupError(STFERR);
                   1641:                }
                   1642: }
                   1643: #endif  /* !STF_LITE */
                   1644: 
                   1645: 
                   1646: //*************************************************************************
                   1647: VOID AddToBillboardList(LPSTR szDll, INT idDlg, LPSTR szProc,
                   1648:                LONG lTicks)
                   1649: {
                   1650: #ifdef DEBUG
                   1651:        INT   n;
                   1652:        CHAR  szidDlg[cchNum], szlTicks[cchNum];
                   1653:        LPSTR szTmp;
                   1654: 
                   1655:        if (FEmptySz(szDll))
                   1656:                n = 1;
                   1657:        else if (idDlg == 0)
                   1658:                n = 2;
                   1659:        else if (FEmptySz(szProc))
                   1660:                n = 3;
                   1661:        else if (lTicks <= 0)
                   1662:                n = 4;
                   1663:        else
                   1664:                n = 0;
                   1665:        if (n > 0)
                   1666:                {
                   1667:                wsprintf(szidDlg, "%d", idDlg);
                   1668:                wsprintf(szlTicks, "%d", lTicks);
                   1669:                szTmp = SzCat3Str(szDll,", ", szidDlg,", ");
                   1670:                BadArgErr(n,"AddToBillboardList",SzCat3Str(szTmp,szProc,", ",szlTicks));
                   1671:                }
                   1672: #endif //DEBUG
                   1673: 
                   1674:        if (FAddToBillboardList(szDll, idDlg, szProc, lTicks) == 0)
                   1675:                {
                   1676: #ifdef DEBUG
                   1677:                wsprintf(szidDlg, "%d", idDlg);
                   1678:                wsprintf(szlTicks, "%d", lTicks);
                   1679:                szTmp = SzCat3Str(szDll,", ", szidDlg,", ");
                   1680:                StfApiErr(saeFail, "AddToBillboardList", SzCat3Str(szTmp, szProc, ", ",
                   1681:                                szlTicks));
                   1682: #endif //DEBUG
                   1683:                SetupError(STFERR);
                   1684:                }
                   1685: }
                   1686: 
                   1687: 
                   1688: #ifndef STF_LITE
                   1689: //*************************************************************************
                   1690: VOID AddBlankToBillboardList(LONG lTicks)
                   1691: {
                   1692: #ifdef DEBUG
                   1693:        CHAR szlTicks[cchNum];
                   1694: 
                   1695:        if (lTicks <= 0)
                   1696:                {
                   1697:                wsprintf(szlTicks, "%d", lTicks);
                   1698:                BadArgErr(1, "AddBlankToBillboardList", szlTicks);
                   1699:                }
                   1700: #endif //DEBUG
                   1701: 
                   1702:        if (FAddToBillboardList(NULL, 0, NULL, lTicks) == 0)
                   1703:                {
                   1704: #ifdef DEBUG
                   1705:                wsprintf(szlTicks, "%d", lTicks);
                   1706:                StfApiErr(saeFail, "AddBlankToBillboardList",szlTicks);
                   1707: #endif //DEBUG
                   1708:                SetupError(STFERR);
                   1709:                }
                   1710: }
                   1711: 
                   1712: 
                   1713: //*************************************************************************
                   1714: VOID ClearBillboardList(VOID)
                   1715: {
                   1716:        if (FClearBillboardList() == 0)
                   1717:                {
                   1718: #ifdef DEBUG
                   1719:                StfApiErr(saeFail, "ClearBillboardList", "");
                   1720: #endif //DEBUG
                   1721:                SetupError(STFERR);
                   1722:                }
                   1723: }
                   1724: #endif  /* !STF_LITE */
                   1725: 
                   1726: 
                   1727: #ifndef STF_LITE
                   1728: //*************************************************************************
                   1729: VOID OpenLogFile(LPSTR szFile, INT fAppend)
                   1730: {
                   1731: #ifdef DEBUG
                   1732:        CHAR szAppend[cchNum];
                   1733: 
                   1734:        if (FValidPath(szFile) == 0)
                   1735:                {
                   1736:                wsprintf(szAppend, "%d", fAppend);
                   1737:                BadArgErr(1, "OpenLogFile",SzCat2Str(szFile,", ",szAppend));
                   1738:                }
                   1739: #endif //DEBUG
                   1740: 
                   1741:        if (FOpenLogFile(szFile, fAppend) == 0)
                   1742:                {
                   1743: #ifdef DEBUG
                   1744:                wsprintf(szAppend, "%d", fAppend);
                   1745:                StfApiErr(saeFail, "OpenLogFile",SzCat2Str(szFile,", ",szAppend));
                   1746: #endif //DEBUG
                   1747:                SetupError(STFERR);
                   1748:                }
                   1749: }
                   1750: 
                   1751: 
                   1752: //*************************************************************************
                   1753: VOID CloseLogFile(VOID)
                   1754: {
                   1755:        if (FCloseLogFile() == 0)
                   1756:                {
                   1757: #ifdef DEBUG
                   1758:                StfApiErr(saeFail, "CloseLogFile", "");
                   1759: #endif //DEBUG
                   1760:                SetupError(STFERR);
                   1761:                }
                   1762: }
                   1763: 
                   1764: 
                   1765: //*************************************************************************
                   1766: VOID WriteToLogFile(LPSTR szStr)
                   1767: {
                   1768:        if (FWriteToLogFile(szStr, 1) == 0)
                   1769:                {
                   1770: #ifdef DEBUG
                   1771:                StfApiErr(saeFail, "WriteToLogFile", szStr);
                   1772: #endif //DEBUG
                   1773:                SetupError(STFERR);
                   1774:                }
                   1775: }
                   1776: #endif  /* !STF_LITE */
                   1777: 
                   1778: 
                   1779: //'' -1 in either parameter will mean 'center in frame client area'
                   1780: //*************************************************************************
                   1781: VOID SetCopyGaugePosition(INT x, INT y)
                   1782: {
                   1783:        ProSetPos(x, y);
                   1784: }
                   1785: 
                   1786: 
                   1787: #ifndef STF_LITE
                   1788: //*************************************************************************
                   1789: LPSTR FindFileUsingFileOpen(LPSTR szFile, LPSTR szBfr, INT cbBfrMax)
                   1790: {
                   1791:        INT     wRet;
                   1792: 
                   1793:        if (szBfr)
                   1794:                *szBfr = ' ';           //REVIEW: KLUDGE: See POOF Bug #635
                   1795:        wRet = WFindFileUsingFileOpen(szFile, szBfr, cbBfrMax);
                   1796: 
                   1797:        if (wRet == 1)
                   1798:                {
                   1799:                szBfr[0] = '\0';
                   1800:                return(szBfr);
                   1801:                }
                   1802:        if (wRet == 0)
                   1803:                return(szBfr);
                   1804:        else
                   1805:                {
                   1806:                szBfr[0] = '\0';
                   1807: #ifdef DEBUG
                   1808:                StfApiErr(saeFail, "FindFileUsingFileOpen", szFile);
                   1809: #endif //DEBUG
                   1810:                SetupError(STFERR);
                   1811:                }
                   1812: }
                   1813: #endif  /* !STF_LITE */
                   1814: 
                   1815: 
                   1816: //*************************************************************************
                   1817: INT IsDirWritable(LPSTR szDir)
                   1818: {
                   1819:        return(FIsDirWritable(szDir));
                   1820: }
                   1821: 
                   1822: 
                   1823: //*************************************************************************
                   1824: INT IsFileWritable(LPSTR szFile)
                   1825: {
                   1826: #ifdef DEBUG
                   1827:        if (FValidDir(szFile) == 0)
                   1828:                BadArgErr(1, "IsFileWritable", szFile);
                   1829: #endif //DEBUG
                   1830: 
                   1831:        return(FIsFileWritable(szFile));
                   1832: }
                   1833: 
                   1834: 
                   1835: //*************************************************************************
                   1836: INT GetWindowsMajorVersion(VOID)
                   1837: {
                   1838:        DWORD dw = GetVersion();
                   1839: 
                   1840:        return((INT)(LOBYTE(LOWORD(dw))));
                   1841: }
                   1842: 
                   1843: 
                   1844: //*************************************************************************
                   1845: INT GetWindowsMinorVersion(VOID)
                   1846: {
                   1847:        DWORD dw = GetVersion();
                   1848: 
                   1849:        return((INT)(HIBYTE(LOWORD(dw))));
                   1850: }
                   1851: 
                   1852: 
                   1853: #ifndef STF_LITE
                   1854: //*************************************************************************
                   1855: LPSTR GetNthFieldFromIniString(LPSTR szLine, INT iField, LPSTR szBfr,
                   1856:                INT cbBfrMax)
                   1857: {
                   1858:        LPSTR szEnd;
                   1859: 
                   1860:        if (iField < 1)
                   1861:                {
                   1862: #ifdef DEBUG
                   1863:                CHAR szField[cchNum];
                   1864: 
                   1865:                wsprintf(szField, "%d", iField);
                   1866:                StfApiErr(saeFail, "GetNthFieldFromIniString", SzCat2Str(szLine, ", ",
                   1867:                                szField));
                   1868: #endif //DEBUG
                   1869:                SetupError(STFERR);
                   1870:                }
                   1871: 
                   1872:        while (--iField > 0)
                   1873:                {
                   1874:                while (*szLine != '\0' && *szLine != ',')
                   1875:                        szLine = AnsiNext(szLine);
                   1876:                szLine = AnsiNext(szLine);
                   1877:                }
                   1878: 
                   1879:        while (*szLine == ' ' || *szLine == '\t')
                   1880:                szLine = AnsiNext(szLine);
                   1881: 
                   1882:        szEnd = szLine;
                   1883:        while (*szEnd != '\0' && *szEnd != ',')
                   1884:                szEnd = AnsiNext(szEnd);
                   1885: 
                   1886:        if (cbBfrMax < szEnd - szLine)
                   1887:                {
                   1888:                DoMsgBox("Buffer Overflow","MS-Setup Error",MB_ICONHAND+MB_OK);
                   1889:                SetupError(STFERR);
                   1890:                }
                   1891: 
                   1892:        if (*szEnd != '\0')
                   1893:                {
                   1894:                Assert(*szEnd == ',');
                   1895:                *szEnd = '\0';
                   1896:                lstrcpy(szBfr, szLine);
                   1897:                *szEnd = ',';
                   1898:                }
                   1899:        else
                   1900:                lstrcpy(szBfr, szLine);
                   1901: 
                   1902:        return(szBfr);
                   1903: }
                   1904: 
                   1905: 
                   1906: //*************************************************************************
                   1907: INT GetWindowsMode(VOID)
                   1908: {
                   1909: #if defined(WIN16)
                   1910:        LONG longTmp = GetWinFlags();
                   1911: 
                   1912:        if (longTmp & WF_WINNT)
                   1913:                return(3);
                   1914:        else if (longTmp & WF_STANDARD)
                   1915:                return(1);
                   1916:        else if (longTmp & WF_ENHANCED)
                   1917:                return(2);
                   1918:        else
                   1919:                return(0);
                   1920: #elif defined(WIN32)
                   1921:        return(2);
                   1922: #endif
                   1923: }
                   1924: #endif  /* !STF_LITE */
                   1925: 
                   1926: 
                   1927: //*************************************************************************
                   1928: LPSTR GetWindowsDir(LPSTR szBuf, INT cbBufMax)
                   1929: {
                   1930:        CHAR szBufT[255];
                   1931:        INT  cbBuf = GetWindowsDirectory(szBufT, 255);
                   1932:        INT  dch;
                   1933: 
                   1934:        if (cbBuf == 0)
                   1935:                {
                   1936:                *szBuf = '\0';
                   1937: #ifdef DEBUG
                   1938:                StfApiErr(saeFail, "GetWindowsDir", "");
                   1939: #endif //DEBUG
                   1940:                SetupError(STFERR);
                   1941:                }
                   1942:        else
                   1943:                {
                   1944:                if (cbBuf > 255)
                   1945:                        {
                   1946:                        DoMsgBox("Buffer Overflow", "MS-Setup Error", MB_ICONHAND+MB_OK);
                   1947:                        SetupError(STFERR);
                   1948:                        }
                   1949:                if (szBufT[0] == '\\')
                   1950:                        {
                   1951:                        if (cbBufMax < 2)
                   1952:                                {
                   1953:                                DoMsgBox("Buffer Overflow","MS-Setup Error",MB_ICONHAND+MB_OK);
                   1954:                                SetupError(STFERR);
                   1955:                                }
                   1956:                        lstrcpy(szBuf, szCurDir);
                   1957:                        dch = 2;
                   1958:                        }
                   1959:                else if (szBufT[1] != ':')
                   1960:                        {
                   1961:                        if (cbBufMax < 3)
                   1962:                                {
                   1963:                                DoMsgBox("Buffer Overflow","MS-Setup Error",MB_ICONHAND+MB_OK);
                   1964:                                SetupError(STFERR);
                   1965:                                }
                   1966:                        lstrcpy(szBuf, szCurDir);
                   1967:                        dch = 3;
                   1968:                        }
                   1969:                else
                   1970:                        dch = 0;
                   1971: 
                   1972:                if (cbBufMax - dch < (INT)lstrlen(szBufT))
                   1973:                        {
                   1974:                        DoMsgBox("Buffer Overflow","MS-Setup Error",MB_ICONHAND+MB_OK);
                   1975:                        SetupError(STFERR);
                   1976:                        }
                   1977:                lstrcpy(szBuf + dch, szBufT);
                   1978: 
                   1979:                if (szBufT[lstrlen(szBufT) - 1] != '\\')
                   1980:                        {
                   1981:                        if (cbBufMax < (INT)lstrlen(szBuf) + 1)
                   1982:                                {
                   1983:                                DoMsgBox("Buffer Overflow","MS-Setup Error",MB_ICONHAND+MB_OK);
                   1984:                                SetupError(STFERR);
                   1985:                                }
                   1986:                        lstrcat(szBuf, "\\");
                   1987:                        }
                   1988: 
                   1989:                return(szBuf);
                   1990:                }
                   1991: }
                   1992: 
                   1993: 
                   1994: //*************************************************************************
                   1995: LPSTR GetWindowsSysDir(LPSTR szBuf, INT cbBufMax)
                   1996: {
                   1997:        CHAR szBufT[255];
                   1998:        INT  cbBuf = GetSystemDirectory(szBufT, 255);
                   1999:        INT  dch;
                   2000: 
                   2001:        if (cbBuf == 0)
                   2002:                {
                   2003: #ifdef DEBUG
                   2004:                StfApiErr(saeFail, "GetWindowsSysDir", "");
                   2005: #endif //DEBUG
                   2006:                SetupError(STFERR);
                   2007:                }
                   2008:        else
                   2009:                {
                   2010:                if (cbBuf > 255)
                   2011:                        {
                   2012:                        DoMsgBox("Buffer Overflow", "MS-Setup Error", MB_ICONHAND+MB_OK);
                   2013:                        SetupError(STFERR);
                   2014:                        }
                   2015:                if (szBufT[0] == '\\')
                   2016:                        {
                   2017:                        if (cbBufMax < 2)
                   2018:                                {
                   2019:                                DoMsgBox("Buffer Overflow","MS-Setup Error",MB_ICONHAND+MB_OK);
                   2020:                                SetupError(STFERR);
                   2021:                                }
                   2022:                        lstrcpy(szBuf, szCurDir);
                   2023:                        dch = 2;
                   2024:                        }
                   2025:                else if (szBufT[1] != ':')
                   2026:                        {
                   2027:                        if (cbBufMax < 3)
                   2028:                                {
                   2029:                                DoMsgBox("Buffer Overflow","MS-Setup Error",MB_ICONHAND+MB_OK);
                   2030:                                SetupError(STFERR);
                   2031:                                }
                   2032:                        lstrcpy(szBuf, szCurDir);
                   2033:                        dch = 3;
                   2034:                        }
                   2035:                else
                   2036:                        dch = 0;
                   2037: 
                   2038:                if (cbBufMax - dch < (INT)lstrlen(szBufT))
                   2039:                        {
                   2040:                        DoMsgBox("Buffer Overflow","MS-Setup Error",MB_ICONHAND+MB_OK);
                   2041:                        SetupError(STFERR);
                   2042:                        }
                   2043:                lstrcpy(szBuf + dch, szBufT);
                   2044: 
                   2045:                if (szBufT[lstrlen(szBufT) - 1] != '\\')
                   2046:                        {
                   2047:                        if (cbBufMax < (INT)lstrlen(szBuf) + 1)
                   2048:                                {
                   2049:                                DoMsgBox("Buffer Overflow","MS-Setup Error",MB_ICONHAND+MB_OK);
                   2050:                                SetupError(STFERR);
                   2051:                                }
                   2052:                        lstrcat(szBuf, "\\");
                   2053:                        }
                   2054: 
                   2055:                return(szBuf);
                   2056:                }
                   2057: }
                   2058: 
                   2059: 
                   2060: #ifndef STF_LITE
                   2061: //*************************************************************************
                   2062: INT IsWindowsShared(VOID)
                   2063: {
                   2064:        CHAR  szWin[255];
                   2065:        CHAR  szSys[255];
                   2066:        LPSTR szWinT;
                   2067:        LPSTR szSysT;
                   2068: 
                   2069:        GetWindowsDir(szWin, 255);
                   2070:        GetWindowsSysDir(szSys, 255);
                   2071: 
                   2072:        AnsiUpper(szWin);
                   2073:        AnsiUpper(szSys);
                   2074: 
                   2075:        if (lstrlen((LPSTR)szWin) == 0)
                   2076:                {
                   2077: #ifdef DEBUG
                   2078:                StfApiErr(saeFail, "IsWindowsShared", "");
                   2079: #endif //DEBUG
                   2080:                SetupError(STFERR);
                   2081:                }
                   2082: 
                   2083:        for (szWinT = szWin, szSysT = szSys; *szWinT; szWinT++, szSysT++)
                   2084:                if (*szWinT != *szSysT)
                   2085:                        return(TRUE);
                   2086: 
                   2087:        return(FALSE);
                   2088: }
                   2089: 
                   2090: 
                   2091: //*************************************************************************
                   2092: INT GetScreenWidth(VOID)
                   2093: {
                   2094:        return(GetSystemMetrics(SM_CXSCREEN));
                   2095: }
                   2096: 
                   2097: 
                   2098: //*************************************************************************
                   2099: INT GetScreenHeight(VOID)
                   2100: {
                   2101:        return(GetSystemMetrics(SM_CYSCREEN));
                   2102: }
                   2103: 
                   2104: 
                   2105: //*************************************************************************
                   2106: VOID SetRestartDir(LPSTR szDir)
                   2107: {
                   2108: #ifdef DEBUG
                   2109:        if (FValidDir(szDir) == 0)
                   2110:                BadArgErr(1, "SetRestartDir", szDir);
                   2111: #endif //DEBUG
                   2112: 
                   2113:        if (FSetRestartDir(szDir) == 0)
                   2114:                {
                   2115: #ifdef DEBUG
                   2116:                StfApiErr(saeFail, "SetRestartDir", szDir);
                   2117: #endif //DEBUG
                   2118:                SetupError(STFERR);
                   2119:                }
                   2120: }
                   2121: 
                   2122: 
                   2123: //*************************************************************************
                   2124: INT RestartListEmpty(VOID)
                   2125: {
                   2126:        return(FRestartListEmpty());
                   2127: }
                   2128: 
                   2129: 
                   2130: //*************************************************************************
                   2131: INT ExitExecRestart(VOID)
                   2132: {
                   2133:        return(FExitExecRestart());
                   2134: }
                   2135: #endif  /* !STF_LITE */
                   2136: 
                   2137: 
                   2138: #ifndef STF_LITE
                   2139: //*************************************************************************
                   2140: VOID PrependToPath(LPSTR szSrc, LPSTR szDst, LPSTR szDir, INT cmo)
                   2141: {
                   2142: #ifdef DEBUG
                   2143:        INT   n;
                   2144:        CHAR  szCmo[cchNum];
                   2145:        LPSTR szTmp;
                   2146: 
                   2147:        if ((FValidPath(szSrc) == 0) && (FValidSz(szSrc)))
                   2148:                n = 1;
                   2149:        else if (FValidPath(szDst) == 0)
                   2150:                n = 2;
                   2151:        else if (FValidDir(szDir) == 0)
                   2152:                n = 3;
                   2153:        else
                   2154:                n = 0;
                   2155: 
                   2156:        if (n > 0)
                   2157:                {
                   2158:                wsprintf(szCmo, "%d", cmo);
                   2159:                szTmp = SzCat3Str(szSrc, ", ", szDst, ", ");
                   2160:                BadArgErr(n, "PrependToPath",SzCat3Str(szTmp,szDir,", ",szCmo));
                   2161:                }
                   2162: #endif //DEBUG
                   2163: 
                   2164:        if (FPrependToPath(szSrc, szDst, szDir, cmo) == 0)
                   2165:                {
                   2166: #ifdef DEBUG
                   2167:                wsprintf(szCmo, "%d", cmo);
                   2168:                szTmp = SzCat3Str(szSrc, ", ", szDst, ", ");
                   2169:                StfApiErr(saeFail, "PrependToPath",SzCat3Str(szTmp,szDir,", ",szCmo));
                   2170: #endif //DEBUG
                   2171:                SetupError(STFERR);
                   2172:                }
                   2173: }
                   2174: #endif  /* !STF_LITE */
                   2175: 
                   2176: 
                   2177: 
                   2178: //**************************************************************************
                   2179: //***************************  Error Handlers  *****************************
                   2180: //**************************************************************************
                   2181: 
                   2182: #ifdef DEBUG
                   2183: 
                   2184: //**************************************************************************
                   2185: VOID StfApiErr(INT nMsg, LPSTR szApi, LPSTR szArgs)
                   2186: {
                   2187:        CHAR rgchCapion[] = "MS-Setup Toolkit API Error";
                   2188:        CHAR rgchText[cchMax * 2];
                   2189: 
                   2190:        if (szApi == NULL)
                   2191:                *szApi = '\0';
                   2192:        if (szArgs == NULL)
                   2193:                *szArgs = '\0';
                   2194: 
                   2195:        switch(nMsg)
                   2196:                {
                   2197:        case saeFail:
                   2198:                lstrcpy(rgchText, "Failed");
                   2199:                break;
                   2200:        case saeInit:
                   2201:                lstrcpy(rgchText, "Already Initialized");
                   2202:                break;
                   2203:        case saeNYI:
                   2204:                lstrcpy(rgchText, "NYI");
                   2205:                break;
                   2206:        default:
                   2207:                lstrcpy(rgchText, "Bad Arg ");
                   2208:                /* for C7 use _itoa() */
                   2209:                itoa(nMsg - saeArg, (CHAR *)(rgchText+lstrlen(rgchText)), 10);
                   2210:                break;
                   2211:                }
                   2212: 
                   2213:        lstrcat(rgchText, ": ");
                   2214:        lstrcat(rgchText, szApi);
                   2215:        if (*szArgs != '\0')
                   2216:                {
                   2217:                lstrcat(rgchText, " (");
                   2218:                lstrcat(rgchText, szArgs);
                   2219:                lstrcat(rgchText, ")");
                   2220:                }
                   2221: #ifndef STF_LITE
                   2222:        Assert(lstrlen(rgchText) < cchMax * 2);
                   2223: #endif  /* !STF_LITE */
                   2224:        DoMsgBox(rgchText, rgchCapion, MB_TASKMODAL+MB_ICONHAND+MB_OK);
                   2225: }
                   2226: 
                   2227: 
                   2228: //**************************************************************************
                   2229: VOID BadArgErr(INT nArg, LPSTR szApi, LPSTR szArgs)
                   2230: {
                   2231:        StfApiErr(nArg+saeArg, szApi, szArgs);
                   2232:        SetupError(STFERR);
                   2233: }
                   2234: 
                   2235: 
                   2236: //**************************************************************************
                   2237: INT FValidInfSect(LPSTR szSect)
                   2238: {
                   2239:        if (szSect == NULL || *szSect == '\0')
                   2240:                return(0);
                   2241: 
                   2242:        while (*szSect)
                   2243:                {
                   2244:                if (*szSect == ']')
                   2245:                        return(0);
                   2246:                szSect = AnsiNext(szSect);
                   2247:                }
                   2248: 
                   2249:        return(1);
                   2250: }
                   2251: 
                   2252: 
                   2253: //**************************************************************************
                   2254: INT FValidIniFile(LPSTR szFile)
                   2255: {
                   2256:        if (!FValidPath(szFile) && lstrcmpi(szFile, "WIN.INI") != 0)
                   2257:                return(0);
                   2258: 
                   2259:        return(1);
                   2260: }
                   2261: 
                   2262: 
                   2263: //**************************************************************************
                   2264: INT FValidDrive(LPSTR szDrive)
                   2265: {
                   2266:        if (szDrive == NULL || *szDrive == '\0')
                   2267:                return(0);
                   2268:        if (szDrive[0] == '\\' && szDrive[1] == '\\')   /* UNC path */
                   2269:                return(1);
                   2270:        if ((*szDrive < 'a' || *szDrive > 'z')
                   2271:                && (*szDrive < 'A' || *szDrive > 'Z'))
                   2272:                return(0);
                   2273:        if (lstrlen(szDrive) == 1)
                   2274:                return(1);
                   2275:        if (szDrive[1] == ':')
                   2276:                return(1);
                   2277: 
                   2278:        return(0);
                   2279: }
                   2280: 
                   2281: #endif //DEBUG
                   2282: 
                   2283: 
                   2284: LPSTR SzCatStr(LPSTR sz1, LPSTR sz2)
                   2285: {
                   2286:        static CHAR szT[cchMax * 2];
                   2287: 
                   2288: #ifndef STF_LITE
                   2289:        Assert(lstrlen(sz1)+lstrlen(sz2) < cchMax * 2);
                   2290: #endif  /* !STF_LITE */
                   2291:        lstrcpy(szT, sz1);
                   2292:        lstrcat(szT, sz2);
                   2293: 
                   2294:        return(szT);
                   2295: }
                   2296: 
                   2297: 
                   2298: LPSTR SzCat2Str(LPSTR sz1, LPSTR sz2, LPSTR sz3)
                   2299: {
                   2300:        static CHAR szT[cchMax * 3];
                   2301: 
                   2302: #ifndef STF_LITE
                   2303:        Assert(lstrlen(sz1)+lstrlen(sz2)+lstrlen(sz3) < cchMax * 3);
                   2304: #endif  /* !STF_LITE */
                   2305:        lstrcpy(szT, sz1);
                   2306:        lstrcat(szT, sz2);
                   2307:        lstrcat(szT, sz3);
                   2308: 
                   2309:        return(szT);
                   2310: }
                   2311: 
                   2312: 
                   2313: LPSTR SzCat3Str(LPSTR sz1, LPSTR sz2, LPSTR sz3, LPSTR sz4)
                   2314: {
                   2315:        static CHAR szT[cchMax * 4];
                   2316: 
                   2317: #ifndef STF_LITE
                   2318:        Assert(lstrlen(sz1)+lstrlen(sz2)+lstrlen(sz3)+lstrlen(sz4) < cchMax * 4);
                   2319: #endif  /* !STF_LITE */
                   2320:        lstrcpy(szT, sz1);
                   2321:        lstrcat(szT, sz2);
                   2322:        lstrcat(szT, sz3);
                   2323:        lstrcat(szT, sz4);
                   2324: 
                   2325:        return(szT);
                   2326: }
                   2327: 
                   2328: 
                   2329: VOID EndSetupToolkit()
                   2330: {
                   2331:        TerminateFrame();
                   2332:        TerminateInstall();
                   2333: #ifndef STF_LITE
                   2334:        TerminateRegDb();
                   2335: #endif
                   2336: }
                   2337: 
                   2338: 
                   2339: // **************************************************************************
                   2340: void RightTrim(LPSTR sz)
                   2341: {
                   2342:        LPSTR szBlank = NULL;
                   2343: 
                   2344:        while (*sz != '\0')
                   2345:                {
                   2346:                if (*sz != ' ')
                   2347:                        szBlank = NULL;
                   2348:                else if (szBlank == NULL)
                   2349:                        szBlank = sz;
                   2350:                sz = AnsiNext(sz);
                   2351:                }
                   2352: 
                   2353:        if (szBlank != NULL)
                   2354:                *szBlank = '\0';
                   2355: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.