Annotation of mstools/mssetup/sample/msshared.c, revision 1.1.1.1

1.1       root        1: #ifndef STF_LITE
                      2: 
                      3: #include <windows.h>
                      4: #include "setupapi.h"
                      5: #include "msdetect.h"
                      6: #include "msregdb.h"
                      7: #include "msshared.h"
                      8: 
                      9: VOID NewFindFileUsingFileOpen(LPSTR szFile, LPSTR szBuf, INT cbBuf);
                     10: 
                     11: 
                     12: /* REVIEW -- Language differences are not considered!!! */
                     13: INT SharedFileNeedsCopying = 0;
                     14: 
                     15: static char szWinIni[] = "WIN.INI";
                     16: static char szMsapps[] = "MSAPPS";
                     17: 
                     18: 
                     19: 
                     20: //  private to this file - needed in next api
                     21: /************************************************************************/
                     22: BOOL FixupOneMsappsEntry(LPSTR szKey, LPSTR szDef)
                     23: {
                     24:        char szBuf[256];
                     25: 
                     26:        if (!DoesIniKeyExist(szWinIni, szMsapps, szKey)
                     27:                        || !GetIniKeyString(szWinIni, szMsapps, szKey, szBuf, 255)
                     28:                        || !FValidDir(szBuf))
                     29:                {
                     30:                lstrcpy(szBuf, szDef);
                     31:                lstrcat(szBuf, szKey);
                     32:                return(FCreateIniKeyValue(szWinIni, szMsapps, szKey, szBuf,
                     33:                                cmoOverwrite));
                     34:                }
                     35: 
                     36:        return(TRUE);
                     37: }
                     38: 
                     39: 
                     40: /************************************************************************/
                     41: BOOL FixupWinIniMsappsSection(VOID)
                     42: {
                     43:        static BOOL fMsappsNeedsFixing = TRUE;
                     44:        char  szBuf[256];
                     45:        LPSTR sz;
                     46: 
                     47:        if (!fMsappsNeedsFixing)
                     48:                return(TRUE);
                     49: 
                     50:        fMsappsNeedsFixing = FALSE;
                     51: 
                     52:        if (!DoesIniKeyExist(szWinIni, szMsapps, szMsapps)
                     53:                        || !GetIniKeyString(szWinIni, szMsapps, szMsapps, szBuf, 255)
                     54:                        || !FValidDir(szBuf))
                     55:                {
                     56:                GetWindowsDir(szBuf, 255 - lstrlen(szMsapps) - 2);
                     57:                for (sz = szBuf; *(AnsiNext(sz)) != '\0'; sz = AnsiNext(sz))
                     58:                        ;
                     59:                if (*sz != '\\')
                     60:                        lstrcat(sz, "\\");
                     61:                lstrcat(sz, szMsapps);
                     62:                if (!FCreateIniKeyValue(szWinIni, szMsapps, szMsapps, szBuf,
                     63:                                cmoOverwrite))
                     64:                        return(FALSE);
                     65:                }
                     66: 
                     67:        if (!GetIniKeyString(szWinIni, szMsapps, szMsapps, szBuf, 255)
                     68:                        || !FValidDir(szBuf))
                     69:                return(FALSE);
                     70:        for (sz = szBuf; *(AnsiNext(sz)) != '\0'; sz = AnsiNext(sz))
                     71:                ;
                     72:        if (*sz != '\\')
                     73:                lstrcat(sz, "\\");
                     74: 
                     75:        return(FixupOneMsappsEntry("CLIPART",  szBuf)
                     76:                        && FixupOneMsappsEntry("EQUATION", szBuf)
                     77:                        && FixupOneMsappsEntry("GRPHFLT",  szBuf)
                     78:                        && FixupOneMsappsEntry("MSDRAW",   szBuf)
                     79:                        && FixupOneMsappsEntry("MSGRAPH",  szBuf)
                     80:                        && FixupOneMsappsEntry("PROOF",    szBuf)
                     81:                        && FixupOneMsappsEntry("TEXTCONV", szBuf)
                     82:                        && FixupOneMsappsEntry("WORDART",  szBuf));
                     83: }
                     84: 
                     85: 
                     86: /************************************************************************/
                     87: BOOL DoesSharedFileNeedCopying(VOID)
                     88: {
                     89:        return(SharedFileNeedsCopying != 0);
                     90: }
                     91: 
                     92: 
                     93: //  returns: 1 if szVer1 > szVer2;  0 if equal;  -1 if szVer1 < szVer2
                     94: /************************************************************************/
                     95: INT WCompareVersion(LPSTR szVer1, LPSTR szVer2)
                     96: {
                     97:        INT i;
                     98: 
                     99:        if (*szVer1 == '\0')
                    100:                if (*szVer2 == '\0')
                    101:                        return(0);
                    102:                else
                    103:                        return(-1);
                    104: 
                    105:        if (*szVer2 == '\0')
                    106:                return(1);
                    107: 
                    108:        for (i = 1; i <= 4; i++)
                    109:                {
                    110:                LONG piece1 = GetVersionNthField(szVer1, i);
                    111:                LONG piece2 = GetVersionNthField(szVer2, i);
                    112: 
                    113:                if (piece1 > piece2)
                    114:                        return(1);
                    115:                if (piece1 < piece2)
                    116:                        return(-1);
                    117:                }
                    118: 
                    119:        return(0);
                    120: }
                    121: 
                    122: 
                    123: //  private to this file - needed in next api
                    124: //  NOTE - Win3.1 OpenFile() uses Task EXE/DLL's dir for searching!!
                    125: //     also avoids OpenFile()'s check of CWD.
                    126: /************************************************************************/
                    127: VOID NewFindFileUsingFileOpen(LPSTR szFile, LPSTR szBuf, INT cbBuf)
                    128: {
                    129:        CHAR szTmp[256];
                    130: 
                    131:        GetWindowsDir(szTmp, 255);
                    132:        Assert(lstrlen(szTmp) + lstrlen(szFile) < 256);
                    133:        lstrcat(szTmp, szFile);
                    134:        if (!DoesFileExist(szTmp, femExists))
                    135:                {
                    136:                GetWindowsSysDir(szTmp, 255);
                    137:                Assert(lstrlen(szTmp) + lstrlen(szFile) < 256);
                    138:                lstrcat(szTmp, szFile);
                    139:                if (!DoesFileExist(szTmp, femExists))
                    140:                        FindTargetOnEnvVar(szFile, "PATH", szTmp, 255);
                    141:                }
                    142: 
                    143:        Assert(lstrlen(szTmp) < cbBuf);
                    144:        lstrcpy(szBuf, szTmp);
                    145: }
                    146: 
                    147: 
                    148: //  private to this file - needed in next api
                    149: /************************************************************************/
                    150: LPSTR FindSharedFileFromPath(LPSTR szField, LPSTR szVersion,
                    151:                LPSTR szBuf, INT cbBuf)
                    152: {
                    153:        CHAR szTmp[32];
                    154: 
                    155:        if (szBuf == NULL || cbBuf <= 0)
                    156:                return(NULL);
                    157: 
                    158:        *szBuf = '\0';
                    159:        if (lstrlen(szField) < cbBuf)
                    160:                lstrcpy(szBuf, szField);
                    161:        SharedFileNeedsCopying = 0;
                    162: 
                    163:        if (*szBuf != '\0' && !DoesFileExist(szBuf, femExists))
                    164:                {
                    165:                if (FValidPath(szBuf)
                    166:                                && FParsePathIntoPieces(szBuf, NULL, 0, NULL, 0, szTmp, 31))
                    167:                        NewFindFileUsingFileOpen(szTmp, szBuf, cbBuf);
                    168:                else
                    169:                        *szBuf = '\0';
                    170:                }
                    171: 
                    172:        if (*szBuf != '\0')
                    173:                {
                    174:                if (WCompareVersion(GetVersionOfFile(szBuf, szTmp, 31), szVersion) < 0)
                    175:                        {
                    176:                        if (IsFileWritable(szBuf))
                    177:                                SharedFileNeedsCopying = 1;
                    178:                        else
                    179:                                *szBuf = '\0';
                    180:                        }
                    181:                }
                    182: 
                    183:        return((*szBuf == '\0') ? NULL : szBuf);
                    184: }
                    185: 
                    186: 
                    187: /************************************************************************/
                    188: LPSTR SearchForLocationForSharedFile(LPSTR szRegDbKey,
                    189:                LPSTR szWinIniSect, LPSTR szWinIniKey, INT iWinIniField,
                    190:                LPSTR szDefault, LPSTR szVersion, LPSTR szBuf, INT cbBuf)
                    191: {
                    192:        CHAR szTmp[256];
                    193: 
                    194:        if (szBuf == NULL || cbBuf <= 0)
                    195:                return(NULL);
                    196: 
                    197: #ifdef REG_DB_ENABLED
                    198:        if (*szRegDbKey != '\0')
                    199:                {
                    200:                GetRegKeyValue(szRegDbKey, szTmp, 255);
                    201:                FindSharedFileFromPath(szTmp, szVersion, szBuf, cbBuf);
                    202:                if (*szBuf != '\0')
                    203:                        return(szBuf);
                    204:                }
                    205: #endif //  REG_DB_ENABLED
                    206: 
                    207:        if (*szWinIniSect != '\0' && *szWinIniKey != '\0')
                    208:                {
                    209:                GetIniKeyString("WIN.INI", szWinIniSect, szWinIniKey, szTmp, 255);
                    210:                if (*szTmp != '\0')
                    211:                        {
                    212:                        CHAR szField[256];
                    213: 
                    214:                        GetNthFieldFromIniString(szTmp, iWinIniField, szField, 255);
                    215:                        FindSharedFileFromPath(szField, szVersion, szBuf, cbBuf);
                    216:                        if (*szBuf != '\0')
                    217:                                return(szBuf);
                    218:                        }
                    219:                }
                    220: 
                    221:        *szBuf = '\0';
                    222:        if (lstrlen(szDefault) < cbBuf)
                    223:                lstrcpy(szBuf, szDefault);
                    224:        SharedFileNeedsCopying = 1;
                    225: 
                    226:        if (DoesFileExist(szBuf, femExists)
                    227:                        && WCompareVersion(GetVersionOfFile(szBuf, szTmp, 255), szVersion)
                    228:                                        >= 0)
                    229:                SharedFileNeedsCopying = 0;
                    230: 
                    231:        return((*szBuf == '\0') ? NULL : szBuf);
                    232: }
                    233: 
                    234: 
                    235: /*
                    236: **     szInfSection: INF Section which contains shared app description line.
                    237: **     szInfKey:     INF reference key which is for the shared app description
                    238: **                                     line.
                    239: **     szSubDir:     Shared App WIN.INI key (such as PROOF, TEXTCONV, MSDRAW).
                    240: **     szRegDbKey:   Registration DB key which might contain full path of an
                    241: **                                     existing copy of the Shared App.
                    242: **     szWinIniSect: WIN.INI section which might contain full path of an
                    243: **                                     existing copy of the Shared App (such as 'MS Proofing
                    244: **                                     Tools').
                    245: **     szWinIniKey:  WIN.INI key which might reference the full path of an
                    246: **                                     existing copy of the Shared App (such as 'Spelling 1033,0').
                    247: **     iWinIniField: index of path in above WIN.INI value (such as '1' for speller,
                    248: **                                     '2' for dictionary).
                    249: **     szBuf:        buffer to return full path of Shared App.
                    250: **     cbBuf:        size of szBuf.
                    251: **
                    252: *************************************************************************/
                    253: LPSTR HandleSharedFile(LPSTR szInfSection, LPSTR szInfKey,
                    254:                LPSTR szSubDir, LPSTR szRegDbKey, LPSTR szWinIniSect,
                    255:                LPSTR szWinIniKey, INT iWinIniField, LPSTR szBuf, INT cbBuf)
                    256: {
                    257:        CHAR  szDefault[256];
                    258:        CHAR  szVersion[32];
                    259:        LPSTR sz;
                    260: 
                    261:        FixupWinIniMsappsSection();
                    262: 
                    263:        if (!DoesIniKeyExist(szWinIni, szMsapps, szSubDir)
                    264:                        || !GetIniKeyString(szWinIni, szMsapps, szSubDir, szDefault, 255))
                    265:                {
                    266:                if (!DoesIniKeyExist(szWinIni, szMsapps, szMsapps)
                    267:                                || !GetIniKeyString(szWinIni, szMsapps, szMsapps, szDefault,
                    268:                                                255))
                    269:                        return(FALSE);
                    270: 
                    271:                for (sz = szDefault; *(AnsiNext(sz)) != '\0'; sz = AnsiNext(sz))
                    272:                        ;
                    273:                if (*sz != '\\')
                    274:                        lstrcat(sz, "\\");
                    275: 
                    276:                lstrcat(sz, szSubDir);
                    277: 
                    278:                FCreateIniKeyValue(szWinIni, szMsapps, szSubDir, szDefault,
                    279:                                cmoOverwrite);
                    280:                }
                    281:        
                    282:        for (sz = szDefault; *(AnsiNext(sz)) != '\0'; sz = AnsiNext(sz))
                    283:                ;
                    284:        if (*sz != '\\')
                    285:                lstrcat(sz, "\\");
                    286: 
                    287:        while (*sz != '\0')
                    288:                sz = AnsiNext(sz);
                    289: 
                    290:        /* Get file name from INF */
                    291:        if (CbGetInfSectionKeyField(szInfSection, szInfKey, 1, sz,
                    292:                        255 - lstrlen(szDefault)) == -1)
                    293:                return(FALSE);
                    294: 
                    295:        /* Get file version from INF */
                    296:        if (CbGetInfSectionKeyField(szInfSection, szInfKey, 19, szVersion, 31)
                    297:                        == -1)
                    298:                return(FALSE);
                    299: 
                    300:        return(SearchForLocationForSharedFile(szRegDbKey, szWinIniSect,
                    301:                        szWinIniKey, iWinIniField, szDefault, szVersion, szBuf, cbBuf));
                    302: }
                    303: #endif  /* !STF_LITE */

unix.superglobalmegacorp.com

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