A Silent Component Update for Internet Explorer 

by Zuoliu Ding





Example 1: 



localhost/ieupdate/

                   ieupdate.xml

                   cmpbar2.dll

                   _blocker2.dll

                   tbconfig2.xml

                   image/

                         mainhot2.ico

                         maincool2.ico



Example 2:



<!-- ieupdate.xml -->

<ieupdate>

<cmpbar.dll>2.0.0.0|133120|http://localhost/ieupdate/

        cmpbar2.dll|Remove,Copy</cmpbar.dll>

<_blocker.dll>2.0.0.0|82432|http://localhost/ieupdate/

         _blocker2.dll|Copy,Register</_blocker.dll>

<tbconfig.xml>2.0.0.0|2163|http://localhost/ieupdate/

         tbconfig2.xml|Remove,Copy</tbconfig.xml>

<mainhot.ico>1.8.0.0|318|http://localhost/ieupdate/

         image/mainhot2.ico|Copy</mainhot.ico>

<maincool.ico>1.8.0.0|318|http://localhost/ieupdate/

         image/maincool2.ico|Copy</maincool.ico>

</ieupdate>





Example 3:



<?xml version="1.0" encoding="utf-8" ?> 

<ToolbarConfig>



<!-- Company  -->

   <MainName>News</MainName>

   <DemoVersion>2.0</DemoVersion>

   <SiteDomain>mysite.verizon.net/zqding</SiteDomain>



<!-- Dynamic Menuitems: Pos|Menu|Sub|URL -->

   <DynamicMenu>0|CNet News||http://news.com.com/</DynamicMenu> 

   <DynamicMenu>1|Time Online||http://www.time.com/time/</DynamicMenu>  

   <DynamicMenu>2|Government|White House|

                               http://www.whitehouse.gov/</DynamicMenu>

   <DynamicMenu>2|Government|U.S. Department of State|

                               http://www.state.gov/</DynamicMenu>  

   <DynamicMenu>2|Government|Federal legislative information|

                               http://thomas.loc.gov/</DynamicMenu> 

   <DynamicMenu>2|Government|Internal Revenue Service|

                               http://www.irs.gov/</DynamicMenu>    

   <DynamicMenu>2|Government|Social Security Online|

                               http://www.ssa.gov/</DynamicMenu>    

   <DynamicMenu>2|Government|U.S. Citizenship and Immigration Services|

                               http://uscis.gov/</DynamicMenu>  

   <DynamicMenu>3|Company|Microsoft|

                               http://www.microsoft.com/</DynamicMenu>  

   <DynamicMenu>3|Company|IBM|http://www.ibm.com/us/</DynamicMenu>  

   <DynamicMenu>3|Company|Intel|http://www.intel.com/</DynamicMenu> 

   <DynamicMenu>4|University|UCLA|http://www.ucla.edu/</DynamicMenu>    

   <DynamicMenu>4|University|CalTech|http://www.caltech.edu/</DynamicMenu>

   <DynamicMenu>4|University|USC|http://www.usc.edu/</DynamicMenu>  

   <DynamicMenu>5|World News||http://www.worldnews.com/</DynamicMenu>   



<!-- Search Menuitems: Menu|URL -->

   <SearchMenu>Google|http://www.google.com/search?q=</SearchMenu>  

   <SearchMenu>Yahoo!|http://search.yahoo.com/bin/search?p=</SearchMenu>

   <SearchMenu>CMP Media|http://www.cmp.com/search?queryText=</SearchMenu>

   <SearchMenu>AOL|http://search.aol.com/aolcom/search?query=</SearchMenu>

   <SearchMenu>Microsoft|

          http://search.microsoft.com/search/results.aspx?qu=</SearchMenu>

<!--  Buttons: Menu|URL -->

   <Button>CNN|http://www.cnn.com/|CNN.com</Button> 

   <Button>CBS|http://www.cbsnews.com/|CBSNews.com</Button> 

   <Button>BBC|http://news.bbc.co.uk/|BBC News</Button> 

   <Button>LA Times|http://www.latimes.com/|Los Angeles Times</Button>  

   <Button>Fox|http://www.foxnews.com/|Fox News</Button>    



</ToolbarConfig>





Listing One



/*--------------------------------------------------------------

Toolbar Update Main Procedure

--------------------------------------------------------------*/

void UpdateBrowserBar(DWORD dw)

{

   if (CBarBand::s_bUpdating) return;

   static CString str = dw==2? _UpdateLocal:_UpdateSite;

   DWORD dwThreadId;

   HANDLE h = ::CreateThread(NULL, 0, ThreadUpdateBrowserBar, 

                                  (LPVOID)&str, 0, &dwThreadId);

   CloseHandle(h);

}

DWORD WINAPI ThreadUpdateBrowserBar(void *p)

{

   CString sInfo = *((CString*)p);

   if (sInfo =="") Return;



   CAppInfo AppInfo;

   CBarBand::s_bUpdating = TRUE;



   sInfo = StreamDownload(sInfo);

   if (sInfo.IsEmpty()) Return;



   if (!AppInfo.LoadUpdateXml(sInfo)) Return;

   if (!DownloadFiles(&AppInfo)) Return;

   if (!RemoveFiles(&AppInfo)) Return;

   if (!CopyFiles(&AppInfo)) Return;

   if (!RegisterFiles(&AppInfo)) Return;



   AppInfo.SaveAllFileVersions();

   PromptUpdatedInfo();



   CBarBand::s_bUpdating = FALSE;

   Return;

}



Listing Two



/*--------------------------------------------------------------

Helper function RemoveFiles() 

--------------------------------------------------------------*/

BOOL RemoveFiles(CAppInfo* pAppInfo)

{

   CString sFile;

   for (int i=0; i<APPINFO_COUNT; i++)

   {

      if (-1 !=pAppInfo->GetUpdate(szFiles[i], Command).

         Find("Remove"))

      {

         sFile = GetModulePath()+szFiles[i];

         DeleteFile(sFile+_OLD);   // if any



         if (!MoveFileEx(sFile, sFile+_OLD, NULL) ||

             !MoveFileEx(sFile+_OLD, NULL, MOVEFILE_DELAY_UNTIL_REBOOT))

         {  

            ResumeFiles(pAppInfo);

            DeleteFiles(_NEW);

            return FALSE;

         }

      }

   }

   return TRUE;

}

void DeleteFiles(CString sType)

{

   CString sFile;

   for (int i=0; i<APPINFO_COUNT; i++)

   {

      sFile = GetModulePath()+szFiles[i] +sType;

      DeleteFile(sFile);

   }

}

void ResumeFiles(CAppInfo* pAppInfo)

{

   CString sFile;

   for (int i=0; i<APPINFO_COUNT; i++)

   {

      if (-1 !=pAppInfo->GetUpdate(szFiles[i], Command).

         Find("Remove"))

      {

         sFile = GetModulePath()+szFiles[i];

         CopyFile(sFile+_OLD, sFile, FALSE);

      }

   }

}





Listing Three



/*--------------------------------------------------------------

IDispatch Method in Toolbar Update

--------------------------------------------------------------*/

STDMETHODIMP CBarBand::Invoke(DISPID dispidMember, REFIID, LCID, WORD,

                       DISPPARAMS* pDispParams, VARIANT*, EXCEPINFO*, UINT*)

{

   if (!pDispParams) return E_INVALIDARG;

   switch (dispidMember)

   {

      case DISPID_DOCUMENTCOMPLETE:

      {

         if (!m_bUpdated) 

         {

            DWORD dw =0;

            ReadRegDW("SUpdate", dw);



            if (dw==1 || dw==2) 

            {

               UpdateBrowserBar(dw);

               m_bUpdated =TRUE;

            }

         }

         break;

      }

      case DISPID_NEWWINDOW2:

      {

         if (CBarBand::s_bUpdating)

            *pDispParams->rgvarg[0].pboolVal= VARIANT_TRUE;   

         break;

      }

      case DISPID_ONQUIT:

      {

         while (s_bUpdating) Sleep(3000);

         Disconnect();

         break;

      }

   }

   return S_OK;

}









4



