Back to index

lightning-sunbird  0.9+nobinonly
parser.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Sean Su <ssu@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "extern.h"
00041 #include "logkeys.h"
00042 #include "parser.h"
00043 #include "extra.h"
00044 #include "ifuncns.h"
00045 #include "dialogs.h"
00046 
00047 #define KEY_SHARED_DLLS "Software\\Microsoft\\Windows\\CurrentVersion\\SharedDlls"
00048 
00049 BOOL DeleteOnReboot(LPSTR szFile)
00050 {
00051   if(ulOSType & OS_NT)
00052     MoveFileEx(szFile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
00053   else
00054   {
00055     char szWinDir[MAX_BUF];
00056     char szWininitFile[MAX_BUF];
00057     BOOL bWriteRenameSection;
00058     FILE *ofp;
00059 
00060     if(GetWindowsDirectory(szWinDir, sizeof(szWinDir)) == 0)
00061       return(FALSE);
00062 
00063     lstrcpy(szWininitFile, szWinDir);
00064     AppendBackSlash(szWininitFile, sizeof(szWininitFile));
00065     lstrcat(szWininitFile, "wininit.ini");
00066 
00067     if(FileExists(szWininitFile) == FALSE)
00068       bWriteRenameSection = TRUE;
00069     else
00070       bWriteRenameSection = FALSE;
00071 
00072     if((ofp = fopen(szWininitFile, "a+")) == NULL)
00073       return(FALSE);
00074 
00075     if(bWriteRenameSection == TRUE)
00076       fprintf(ofp, "[RENAME]\n");
00077 
00078     fprintf(ofp, "NUL=%s\n", szFile);
00079     fclose(ofp);
00080   }
00081   return(TRUE);
00082 }
00083 
00084 BOOL DeleteOrDelayUntilReboot(LPSTR szFile)
00085 {
00086   FileDelete(szFile);
00087   if(FileExists(szFile))
00088     return DeleteOnReboot(szFile);
00089 
00090   return(TRUE);
00091 }
00092 
00093 sil *InitSilNodes(char *szInFile)
00094 {
00095   FILE      *ifp;
00096   char      szLineRead[MAX_BUF];
00097   sil       *silTemp;
00098   sil       *silHead;
00099   ULONGLONG ullLineCount;
00100 
00101   if(FileExists(szInFile) == FALSE)
00102     return(NULL);
00103 
00104   ullLineCount = 0;
00105   silHead      = NULL;
00106   if((ifp = fopen(szInFile, "r")) == NULL)
00107     exit(1);
00108 
00109   while(fgets(szLineRead, MAX_BUF, ifp) != NULL)
00110   {
00111     silTemp = CreateSilNode();
00112 
00113     silTemp->ullLineNumber = ++ullLineCount;
00114     lstrcpy(silTemp->szLine, szLineRead);
00115     if(silHead == NULL)
00116     {
00117       silHead = silTemp;
00118     }
00119     else
00120     {
00121       SilNodeInsert(silHead, silTemp);
00122     }
00123 
00124     ProcessWindowsMessages();
00125   }
00126   fclose(ifp);
00127   return(silHead);
00128 }
00129 
00130 void DeInitSilNodes(sil **silHead)
00131 {
00132   sil   *silTemp;
00133   
00134   if(*silHead == NULL)
00135   {
00136     return;
00137   }
00138   else if(((*silHead)->Prev == NULL) || ((*silHead)->Prev == *silHead))
00139   {
00140     SilNodeDelete(*silHead);
00141     return;
00142   }
00143   else
00144   {
00145     silTemp = (*silHead)->Prev;
00146   }
00147 
00148   while(silTemp != *silHead)
00149   {
00150     SilNodeDelete(silTemp);
00151     silTemp = (*silHead)->Prev;
00152 
00153     ProcessWindowsMessages();
00154   }
00155   SilNodeDelete(silTemp);
00156 }
00157 
00158 void DeleteWinRegKey(HKEY hkRootKey, LPSTR szKey, BOOL bAbsoluteDelete)
00159 {
00160   HKEY      hkResult;
00161   DWORD     dwErr;
00162   DWORD     dwTotalSubKeys;
00163   DWORD     dwTotalValues;
00164   DWORD     dwSubKeySize;
00165   FILETIME  ftLastWriteFileTime;
00166   char      szSubKey[MAX_BUF];
00167   char      szNewKey[MAX_BUF];
00168   long      lRv;
00169 
00170   dwErr = RegOpenKeyEx(hkRootKey, szKey, 0, KEY_QUERY_VALUE, &hkResult);
00171   if(dwErr == ERROR_SUCCESS)
00172   {
00173     dwTotalSubKeys = 0;
00174     dwTotalValues  = 0;
00175     RegQueryInfoKey(hkResult, NULL, NULL, NULL, &dwTotalSubKeys, NULL, NULL, &dwTotalValues, NULL, NULL, NULL, NULL);
00176     RegCloseKey(hkResult);
00177 
00178     if(((dwTotalSubKeys == 0) && (dwTotalValues == 0)) || bAbsoluteDelete)
00179     {
00180       if(dwTotalSubKeys && bAbsoluteDelete)
00181       {
00182         do
00183         {
00184           dwSubKeySize = sizeof(szSubKey);
00185           lRv = 0;
00186           if(RegOpenKeyEx(hkRootKey, szKey, 0, KEY_READ, &hkResult) == ERROR_SUCCESS)
00187           {
00188             if((lRv = RegEnumKeyEx(hkResult, 0, szSubKey, &dwSubKeySize, NULL, NULL, NULL, &ftLastWriteFileTime)) == ERROR_SUCCESS)
00189             {
00190               RegCloseKey(hkResult);
00191               lstrcpy(szNewKey, szKey);
00192               AppendBackSlash(szNewKey, sizeof(szNewKey));
00193               lstrcat(szNewKey, szSubKey);
00194               DeleteWinRegKey(hkRootKey, szNewKey, bAbsoluteDelete);
00195             }
00196             else
00197               RegCloseKey(hkResult);
00198           }
00199         } while(lRv != ERROR_NO_MORE_ITEMS);
00200       }
00201 
00202       dwErr = RegDeleteKey(hkRootKey, szKey);
00203     }
00204   }
00205 }
00206 
00207 void ParseForUninstallCommand(LPSTR szString, LPSTR szKeyStr, LPSTR szFile, DWORD dwFileBufSize, LPSTR szParam, DWORD dwParamBufSize)
00208 {
00209   LPSTR   szFirstNonSpace;
00210   LPSTR   szBeginParamStr;
00211   LPSTR   szEndOfFilePath;
00212   LPSTR   szEndQuote;
00213   char    *cmdStart;
00214   int     length;
00215 
00216   ZeroMemory(szFile, dwFileBufSize);
00217   ZeroMemory(szParam, dwParamBufSize);
00218 
00219   length = lstrlen(szString);
00220   if(szString[length - 1] == '\n')
00221     szString[length - 1] = '\0';
00222 
00223   // get to the beginning of the command given an install log string
00224   cmdStart = szString + lstrlen(szKeyStr);
00225   if((szFirstNonSpace = GetFirstNonSpace(cmdStart)) != NULL)
00226   {
00227     if(*szFirstNonSpace == '\"')
00228     {
00229       ++szFirstNonSpace;
00230       // found a beginning quote, look for the ending quote now
00231       if((szEndQuote = MozStrChar(szFirstNonSpace, '\"')) != NULL)
00232       {
00233         // found ending quote. copy file path string *not* including the quotes
00234         *szEndQuote = '\0';
00235         MozCopyStr(szFirstNonSpace, szFile, dwFileBufSize);
00236 
00237         // get the params substring now
00238         if((szBeginParamStr = GetFirstNonSpace(++szEndQuote)) != NULL)
00239         {
00240           // the params string should be the first non space char after the
00241           // quoted file path string to the end of the string.
00242           MozCopyStr(szBeginParamStr, szParam, dwParamBufSize);
00243         }
00244       }
00245       else
00246       {
00247         // could not find the ending quote.  assume the _entire_ string is the file path
00248         MozCopyStr(szFirstNonSpace, szFile, dwFileBufSize);
00249       }
00250     }
00251     else
00252     {
00253       // no beginning quote found.  file path is up to the first space character found
00254       if((szEndOfFilePath = GetFirstSpace(szFirstNonSpace)) != NULL)
00255       {
00256         // found the first space char
00257         *szEndOfFilePath = '\0';
00258         MozCopyStr(szFirstNonSpace, szFile, dwFileBufSize);
00259 
00260         // get the params substring now
00261         if((szBeginParamStr = GetFirstNonSpace(++szEndOfFilePath)) != NULL)
00262         {
00263           // the params string should be the first non space char after the
00264           // quoted file path string to the end of the string.
00265           MozCopyStr(szBeginParamStr, szParam, dwParamBufSize);
00266         }
00267       }
00268       else
00269       {
00270         // no space char found. assume the _entire_ string is the file path
00271         MozCopyStr(szFirstNonSpace, szFile, dwFileBufSize);
00272       }
00273     }
00274   }
00275 }
00276 
00277 void ParseForFile(LPSTR szString, LPSTR szKeyStr, LPSTR szFile, DWORD dwShortFilenameBufSize)
00278 {
00279   int     iLen;
00280   LPSTR   szFirstNonSpace;
00281   char    szBuf[MAX_BUF];
00282 
00283   if((szFirstNonSpace = GetFirstNonSpace(&(szString[lstrlen(szKeyStr)]))) != NULL)
00284   {
00285     iLen = lstrlen(szFirstNonSpace);
00286     if(szFirstNonSpace[iLen - 1] == '\n')
00287       szFirstNonSpace[iLen -1] = '\0';
00288 
00289     if(lstrcmpi(szKeyStr, KEY_WINDOWS_SHORTCUT) == 0)
00290     {
00291       lstrcpy(szBuf, szFirstNonSpace);
00292       lstrcat(szBuf, ".lnk");
00293       szFirstNonSpace = szBuf;
00294     }
00295 
00296     lstrcpy(szFile, szFirstNonSpace);
00297   }
00298 }
00299 
00300 void ParseForCopyFile(LPSTR szString, LPSTR szKeyStr, LPSTR szFile, DWORD dwShortFilenameBufSize)
00301 {
00302   int     iLen;
00303   LPSTR   szFirstNonSpace;
00304   LPSTR   szSubStr = NULL;
00305   char    szBuf[MAX_BUF];
00306 
00307   if((szSubStr = strstr(szString, " to ")) != NULL)
00308   {
00309     if((szFirstNonSpace = GetFirstNonSpace(&(szSubStr[lstrlen(" to ")]))) != NULL)
00310     {
00311       iLen = lstrlen(szFirstNonSpace);
00312       if(szFirstNonSpace[iLen - 1] == '\n')
00313         szFirstNonSpace[iLen -1] = '\0';
00314 
00315       if(lstrcmpi(szKeyStr, KEY_WINDOWS_SHORTCUT) == 0)
00316       {
00317         lstrcpy(szBuf, szFirstNonSpace);
00318         lstrcat(szBuf, ".lnk");
00319         szFirstNonSpace = szBuf;
00320       }
00321 
00322     lstrcpy(szFile, szFirstNonSpace);
00323     }
00324   }
00325 }
00326 
00327 HRESULT ParseForWinRegInfo(LPSTR szString, LPSTR szKeyStr, LPSTR szRootKey, DWORD dwRootKeyBufSize, LPSTR szKey, DWORD dwKeyBufSize, LPSTR szName, DWORD dwNameBufSize)
00328 {
00329   int     i;
00330   int     iLen;
00331   int     iBrackets;
00332   char    szStrCopy[MAX_BUF];
00333   LPSTR   szFirstNonSpace;
00334   LPSTR   szFirstBackSlash;
00335   BOOL    bFoundOpenBracket;
00336   BOOL    bFoundName;
00337 
00338   *szRootKey = '\0';
00339   *szKey = '\0';
00340   *szName = '\0';
00341 
00342   lstrcpy(szStrCopy, szString);
00343   if((szFirstNonSpace = GetFirstNonSpace(&(szStrCopy[lstrlen(szKeyStr)]))) != NULL)
00344   {
00345     iLen = lstrlen(szFirstNonSpace);
00346     if(szFirstNonSpace[iLen - 1] == '\n')
00347     {
00348       szFirstNonSpace[--iLen] = '\0';
00349     }
00350 
00351     szFirstBackSlash = strstr(szFirstNonSpace, "\\");
00352     if(!szFirstBackSlash)
00353       return(WIZ_ERROR_PARSING_UNINST_STRS);
00354 
00355     szFirstBackSlash[0] = '\0';
00356     lstrcpy(szRootKey, szFirstNonSpace);
00357     szFirstNonSpace = &(szFirstBackSlash[1]);
00358     iLen = lstrlen(szFirstNonSpace);
00359 
00360     iBrackets         = 0;
00361     bFoundName        = FALSE;
00362     bFoundOpenBracket = FALSE;
00363     for(i = iLen - 1; i >= 0; i--)
00364     {
00365       if(bFoundName == FALSE)
00366       {
00367         /* Find the Name created in the Windows registry key.
00368          * Since the Name can contain '[' and ']', we have to
00369          * parse for the brackets that denote the Name string in
00370          * szFirstNonSpace.  It parses from right to left.
00371          */
00372         if(szFirstNonSpace[i] == ']')
00373         {
00374           if(iBrackets == 0)
00375             szFirstNonSpace[i] = '\0';
00376 
00377           ++iBrackets;
00378         }
00379         else if(szFirstNonSpace[i] == '[')
00380         {
00381           bFoundOpenBracket = TRUE;
00382           --iBrackets;
00383         }
00384 
00385         if((bFoundOpenBracket) && (iBrackets == 0))
00386         {
00387           lstrcpy(szName, &(szFirstNonSpace[i + 1]));
00388           bFoundName = TRUE;
00389         }
00390       }
00391       else
00392       {
00393         /* locate the first non space to the left of the last '[' */
00394         if(!isspace(szFirstNonSpace[i]))
00395         {
00396           szFirstNonSpace[i + 1] = '\0';
00397           lstrcpy(szKey, szFirstNonSpace);
00398           break;
00399         }
00400       }
00401     }
00402   }
00403   return(WIZ_OK);
00404 }
00405 
00406 DWORD DecrementSharedFileCounter(char *file)
00407 {
00408   HKEY     keyHandle = 0;
00409   LONG     result;
00410   DWORD    type      = REG_DWORD;
00411   DWORD    valbuf    = 0;
00412   DWORD    valbufsize;
00413   DWORD    rv        = 0;
00414 
00415   valbufsize = sizeof(DWORD);
00416   result     = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KEY_SHARED_DLLS, 0, KEY_READ | KEY_WRITE, &keyHandle);
00417   if(ERROR_SUCCESS == result)
00418   {
00419     result = RegQueryValueEx(keyHandle, file, NULL, &type, (LPBYTE)&valbuf, (LPDWORD)&valbufsize);
00420     if((ERROR_SUCCESS == result) && (type == REG_DWORD))
00421     {
00422       rv = --valbuf;
00423     }
00424 
00425     RegSetValueEx(keyHandle, file, 0, REG_DWORD, (LPBYTE)&valbuf, valbufsize);
00426     RegCloseKey(keyHandle);
00427   }
00428 
00429   return(rv);
00430 }
00431 
00432 int GetSharedFileCount(char *file)
00433 {
00434   HKEY     keyHandle = 0;
00435   LONG     result;
00436   DWORD    type      = REG_DWORD;
00437   DWORD    valbuf    = 0;
00438   DWORD    valbufsize;
00439   int      rv        = -999;
00440 
00441   valbufsize = sizeof(DWORD);
00442   result     = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KEY_SHARED_DLLS, 0, KEY_READ, &keyHandle);
00443   if(ERROR_SUCCESS == result)
00444   {
00445     result = RegQueryValueEx(keyHandle, file, NULL, &type, (LPBYTE)&valbuf, (LPDWORD)&valbufsize);
00446     if((ERROR_SUCCESS == result) && (type == REG_DWORD))
00447       rv = valbuf;
00448 
00449     RegCloseKey(keyHandle);
00450   }
00451 
00452   return(rv);
00453 }
00454 
00455 BOOL UnregisterServer(char *file)
00456 {
00457   FARPROC   DllUnReg;
00458   HINSTANCE hLib;
00459   BOOL      bFailed = FALSE;
00460 
00461   if(file != NULL)
00462   {
00463     if((hLib = LoadLibraryEx(file, NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) != NULL)
00464     {
00465       if((DllUnReg = GetProcAddress(hLib, "DllUnregisterServer")) != NULL)
00466         DllUnReg();
00467       else
00468         bFailed = TRUE;
00469 
00470       FreeLibrary(hLib);
00471     }
00472     else
00473       bFailed = TRUE;
00474   }
00475   else
00476     bFailed = TRUE;
00477 
00478   return(bFailed);
00479 }
00480 
00481 BOOL DetermineUnRegisterServer(sil *silInstallLogHead, LPSTR szFile)
00482 {
00483   sil   *silInstallLogTemp;
00484   int   iSharedFileCount;
00485   char  szLCLine[MAX_BUF];
00486   char  szLCFile[MAX_BUF];
00487   BOOL  bRv;
00488 
00489   bRv = FALSE;
00490   if(silInstallLogHead != NULL)
00491   {
00492     silInstallLogTemp = silInstallLogHead;
00493     iSharedFileCount  = GetSharedFileCount(szFile);
00494     lstrcpy(szLCFile, szFile);
00495     CharLowerBuff(szLCFile, sizeof(szLCLine));
00496 
00497     do
00498     {
00499       silInstallLogTemp = silInstallLogTemp->Prev;
00500       lstrcpy(szLCLine, silInstallLogTemp->szLine);
00501       CharLowerBuff(szLCLine, sizeof(szLCLine));
00502 
00503       if((strstr(szLCLine, szLCFile) != NULL) &&
00504          (strstr(szLCLine, KEY_INSTALLING_SHARED_FILE) != NULL) &&
00505          (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00506       {
00507         --iSharedFileCount;
00508       }
00509       else if((strstr(szLCLine, szLCFile) != NULL) &&
00510               (strstr(szLCLine, KEY_INSTALLING) != NULL) &&
00511               (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00512       {
00513         bRv = TRUE;
00514         break;
00515       }
00516       else if((strstr(szLCLine, szLCFile) != NULL) &&
00517               (strstr(szLCLine, KEY_REPLACING_SHARED_FILE) != NULL) &&
00518               (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00519       {
00520         --iSharedFileCount;
00521       }
00522       else if((strstr(szLCLine, szLCFile) != NULL) &&
00523               (strstr(szLCLine, KEY_REPLACING) != NULL) &&
00524               (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00525       {
00526         bRv = TRUE;
00527         break;
00528       }
00529       else if((strstr(szLCLine, szLCFile) != NULL) &&
00530               (strstr(szLCLine, KEY_COPY_FILE) != NULL) &&
00531               (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00532       {
00533         bRv = TRUE;
00534         break;
00535       }
00536 
00537       ProcessWindowsMessages();
00538     } while(silInstallLogTemp != silInstallLogHead);
00539   }
00540 
00541   if((iSharedFileCount <= 0) && (iSharedFileCount != -999))
00542     bRv = TRUE;
00543 
00544   return(bRv);
00545 }
00546 
00547 DWORD Uninstall(sil* silInstallLogHead)
00548 {
00549   sil   *silInstallLogTemp;
00550   LPSTR szSubStr;
00551   char  szLCLine[MAX_BUF];
00552   char  szKey[MAX_BUF];
00553   char  szRootKey[MAX_BUF];
00554   char  szName[MAX_BUF];
00555   char  szFile[MAX_BUF];
00556   char  szParams[MAX_BUF];
00557   HKEY  hkRootKey;
00558   int   rv;
00559 
00560   if(silInstallLogHead != NULL)
00561   {
00562     silInstallLogTemp = silInstallLogHead;
00563     do
00564     {
00565       silInstallLogTemp = silInstallLogTemp->Prev;
00566       lstrcpy(szLCLine, silInstallLogTemp->szLine);
00567       CharLowerBuff(szLCLine, sizeof(szLCLine));
00568 
00569       if(((szSubStr = strstr(szLCLine, KEY_WINDOWS_REGISTER_SERVER)) != NULL) &&
00570           (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00571       {
00572         ParseForFile(szSubStr, KEY_WINDOWS_REGISTER_SERVER, szFile, sizeof(szFile));
00573         if(DetermineUnRegisterServer(silInstallLogHead, szFile) == TRUE)
00574           UnregisterServer(szFile);
00575       }
00576       else if(((szSubStr = strstr(szLCLine, KEY_INSTALLING_SHARED_FILE)) != NULL) &&
00577                (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00578       {
00579         /* check for "Installing Shared File: " string and delete the file */
00580         ParseForFile(szSubStr, KEY_INSTALLING_SHARED_FILE, szFile, sizeof(szFile));
00581         if(DecrementSharedFileCounter(szFile) == 0)
00582         {
00583           if((gdwWhatToDo != WTD_NO_TO_ALL) && (gdwWhatToDo != WTD_YES_TO_ALL))
00584           {
00585             MessageBeep(MB_ICONEXCLAMATION);
00586             gdwWhatToDo = DialogBoxParam(hInst, MAKEINTRESOURCE(DLG_WHAT_TO_DO), hDlgUninstall, DlgProcWhatToDo, (LPARAM)szFile);
00587           }
00588 
00589           if((gdwWhatToDo == WTD_YES) || (gdwWhatToDo == WTD_YES_TO_ALL))
00590           {
00591             DeleteWinRegValue(HKEY_LOCAL_MACHINE, KEY_SHARED_DLLS, szFile);
00592             DeleteOrDelayUntilReboot(szFile);
00593           }
00594           else if(gdwWhatToDo == WTD_CANCEL)
00595             return(WTD_CANCEL);
00596         }
00597       }
00598       else if(((szSubStr = strstr(szLCLine, KEY_INSTALLING)) != NULL) &&
00599                (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00600       {
00601         /* check for "Installing: " string and delete the file */
00602         ParseForFile(szSubStr, KEY_INSTALLING, szFile, sizeof(szFile));
00603         DeleteOrDelayUntilReboot(szFile);
00604       }
00605       else if(((szSubStr = strstr(szLCLine, KEY_REPLACING_SHARED_FILE)) != NULL) &&
00606                (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00607       {
00608         /* check for "Replacing Shared File: " string and delete the file */
00609         ParseForFile(szSubStr, KEY_REPLACING_SHARED_FILE, szFile, sizeof(szFile));
00610         if(DecrementSharedFileCounter(szFile) == 0)
00611         {
00612           if((gdwWhatToDo != WTD_NO_TO_ALL) && (gdwWhatToDo != WTD_YES_TO_ALL))
00613             gdwWhatToDo = DialogBoxParam(hInst, MAKEINTRESOURCE(DLG_WHAT_TO_DO), hDlgUninstall, DlgProcWhatToDo, (LPARAM)szFile);
00614 
00615           if((gdwWhatToDo == WTD_YES) || (gdwWhatToDo == WTD_YES_TO_ALL))
00616           {
00617             DeleteWinRegValue(HKEY_LOCAL_MACHINE, KEY_SHARED_DLLS, szFile);
00618             DeleteOrDelayUntilReboot(szFile);
00619           }
00620           else if(gdwWhatToDo == WTD_CANCEL)
00621             return(WTD_CANCEL);
00622         }
00623       }
00624       else if(((szSubStr = strstr(szLCLine, KEY_REPLACING)) != NULL) &&
00625                (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00626       {
00627         /* check for "Replacing: " string and delete the file */
00628         ParseForFile(szSubStr, KEY_REPLACING, szFile, sizeof(szFile));
00629         DeleteOrDelayUntilReboot(szFile);
00630       }
00631       else if(((szSubStr = strstr(szLCLine, KEY_STORE_REG_STRING)) != NULL) &&
00632                (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00633       {
00634         /* check for "Store Registry Value String: " string and remove the key */
00635         rv = ParseForWinRegInfo(szSubStr, KEY_STORE_REG_STRING, szRootKey, sizeof(szRootKey), szKey, sizeof(szKey), szName, sizeof(szName));
00636         if(WIZ_OK == rv)
00637         {
00638           hkRootKey = ParseRootKey(szRootKey);
00639           DeleteWinRegValue(hkRootKey, szKey, szName);
00640         }
00641       }
00642       else if(((szSubStr = strstr(szLCLine, KEY_STORE_REG_NUMBER)) != NULL) &&
00643                (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00644       {
00645         /* check for "Store Registry Value Number: " string and remove the key */
00646         rv = ParseForWinRegInfo(szSubStr, KEY_STORE_REG_NUMBER, szRootKey, sizeof(szRootKey), szKey, sizeof(szKey), szName, sizeof(szName));
00647         if(WIZ_OK == rv)
00648         {
00649           hkRootKey = ParseRootKey(szRootKey);
00650           DeleteWinRegValue(hkRootKey, szKey, szName);
00651         }
00652       }
00653       else if(((szSubStr = strstr(szLCLine, KEY_CREATE_REG_KEY)) != NULL) &&
00654                (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00655       {
00656         rv = ParseForWinRegInfo(szSubStr, KEY_CREATE_REG_KEY, szRootKey, sizeof(szRootKey), szKey, sizeof(szKey), szName, sizeof(szName));
00657         if(WIZ_OK == rv)
00658         {
00659           hkRootKey = ParseRootKey(szRootKey);
00660           DeleteWinRegKey(hkRootKey, szKey, FALSE);
00661         }
00662       }
00663       else if(((szSubStr = strstr(szLCLine, KEY_CREATE_FOLDER)) != NULL) &&
00664                (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00665       {
00666         ParseForFile(szSubStr, KEY_CREATE_FOLDER, szFile, sizeof(szFile));
00667         DirectoryRemove(szFile, FALSE);
00668       }
00669       else if(((szSubStr = strstr(szLCLine, KEY_WINDOWS_SHORTCUT)) != NULL) &&
00670                (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00671       {
00672         ParseForFile(szSubStr, KEY_WINDOWS_SHORTCUT, szFile, sizeof(szFile));
00673         DeleteOrDelayUntilReboot(szFile);
00674       }
00675       else if(((szSubStr = strstr(szLCLine, KEY_COPY_FILE)) != NULL) &&
00676                (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00677       {
00678         /* check for "copy file: " string and delete the file */
00679         ParseForCopyFile(szSubStr, KEY_COPY_FILE, szFile, sizeof(szFile));
00680         DeleteOrDelayUntilReboot(szFile);
00681       }
00682       else if(((szSubStr = strstr(szLCLine, KEY_UNINSTALL_COMMAND)) != NULL) &&
00683                (strstr(szLCLine, KEY_DO_NOT_UNINSTALL) == NULL))
00684       {
00685         ParseForUninstallCommand(szSubStr, KEY_UNINSTALL_COMMAND, szFile, sizeof(szFile), szParams, sizeof(szParams));
00686         //execute szFile with szParams here!
00687         if(FileExists(szFile))
00688             WinSpawn(szFile, szParams, NULL, SW_HIDE, TRUE);
00689       }
00690 
00691       ProcessWindowsMessages();
00692     } while(silInstallLogTemp != silInstallLogHead);
00693   }
00694 
00695   return(0);
00696 }
00697 
00698 DWORD GetLogFile(LPSTR szTargetPath, LPSTR szInFilename, LPSTR szOutBuf, DWORD dwOutBufSize)
00699 {
00700   int             iFilenameOnlyLen;
00701   char            szSearchFilename[MAX_BUF];
00702   char            szSearchTargetFullFilename[MAX_BUF];
00703   char            szFilenameOnly[MAX_BUF];
00704   char            szFilenameExtensionOnly[MAX_BUF];
00705   char            szNumber[MAX_BUF];
00706   long            dwNumber;
00707   long            dwMaxNumber;
00708   LPSTR           szDotPtr;
00709   HANDLE          hFile;
00710   WIN32_FIND_DATA fdFile;
00711   BOOL            bFound;
00712 
00713   if(FileExists(szTargetPath))
00714   {
00715     /* zero out the memory */
00716     ZeroMemory(szOutBuf,                dwOutBufSize);
00717     ZeroMemory(szSearchFilename,        sizeof(szSearchFilename));
00718     ZeroMemory(szFilenameOnly,          sizeof(szFilenameOnly));
00719     ZeroMemory(szFilenameExtensionOnly, sizeof(szFilenameExtensionOnly));
00720 
00721     /* parse for the filename w/o extention and also only the extension */
00722     if((szDotPtr = strstr(szInFilename, ".")) != NULL)
00723     {
00724       *szDotPtr = '\0';
00725       lstrcpy(szSearchFilename, szInFilename);
00726       lstrcpy(szFilenameOnly, szInFilename);
00727       lstrcpy(szFilenameExtensionOnly, &szDotPtr[1]);
00728       *szDotPtr = '.';
00729     }
00730     else
00731     {
00732       lstrcpy(szFilenameOnly, szInFilename);
00733       lstrcpy(szSearchFilename, szInFilename);
00734     }
00735 
00736     /* create the wild arg filename to search for in the szTargetPath */
00737     lstrcat(szSearchFilename, "*.*");
00738     lstrcpy(szSearchTargetFullFilename, szTargetPath);
00739     AppendBackSlash(szSearchTargetFullFilename, sizeof(szSearchTargetFullFilename));
00740     lstrcat(szSearchTargetFullFilename, szSearchFilename);
00741 
00742     iFilenameOnlyLen = lstrlen(szFilenameOnly);
00743     dwNumber         = 0;
00744     dwMaxNumber      = -1;
00745 
00746     /* find the largest numbered filename in the szTargetPath */
00747     if((hFile = FindFirstFile(szSearchTargetFullFilename, &fdFile)) == INVALID_HANDLE_VALUE)
00748       bFound = FALSE;
00749     else
00750       bFound = TRUE;
00751 
00752     while(bFound)
00753     {
00754        ZeroMemory(szNumber, sizeof(szNumber));
00755       if((lstrcmpi(fdFile.cFileName, ".") != 0) && (lstrcmpi(fdFile.cFileName, "..") != 0))
00756       {
00757         lstrcpy(szNumber, &fdFile.cFileName[iFilenameOnlyLen]);
00758         dwNumber = atoi(szNumber);
00759         if(dwNumber > dwMaxNumber)
00760           dwMaxNumber = dwNumber;
00761       }
00762 
00763       bFound = FindNextFile(hFile, &fdFile);
00764     }
00765 
00766     FindClose(hFile);
00767 
00768     lstrcpy(szOutBuf, szTargetPath);
00769     AppendBackSlash(szOutBuf, dwOutBufSize);
00770     lstrcat(szOutBuf, szFilenameOnly);
00771     itoa(dwMaxNumber, szNumber, 10);
00772     lstrcat(szOutBuf, szNumber);
00773 
00774     if(*szFilenameExtensionOnly != '\0')
00775     {
00776       lstrcat(szOutBuf, ".");
00777       lstrcat(szOutBuf, szFilenameExtensionOnly);
00778     }
00779   }
00780   else
00781     return(0);
00782 
00783   return(FileExists(szOutBuf));
00784 }
00785