예제 #1
0
bool CAutoUpdateDialog::ExtractPatchInformation(SgmlElement *pRoot)
{
   m_csPatchUrl = "";
   m_nPatchLevel = 0;
   m_nPatchSizeBytes = 0;

   bool bDeMarkerExists = false;
   bool bIsDeVersion = false;

   CLsUpdt32Dll *pDll = (CLsUpdt32Dll *) AfxGetApp();

   CString csLanguage = pDll->GetLanguage();
   if (csLanguage.Compare(_T("de")) == 0)
   {
      bIsDeVersion = true;

      // check for marker file

      LString lsMarkerFile;
      lsMarkerFile.Allocate(MAX_PATH);
      DWORD dwSize = MAX_PATH;
      bool bRegSuccess = LRegistry::ReadSettingsString(
         _T(""), _T("InstallDir"), (LPTSTR)lsMarkerFile, &dwSize, NULL, true);

      if (bRegSuccess)
      {
         if (lsMarkerFile[lsMarkerFile.Length() - 1] != _T('\\'))
            lsMarkerFile += _T("\\");
         lsMarkerFile += _T("Backend\\marker_de.txt");

         if (_taccess(lsMarkerFile, 00) == 0)
            bDeMarkerExists = true;
      }
   }
      
   CString csOtherPatchUrl = _T("");
   int nOtherPatchSize = 0;

   CArray<SgmlElement *, SgmlElement *> aElements;
   pRoot->GetElements(aElements);
   for (int i = 0; i < aElements.GetSize(); ++i) {
       SgmlElement *pHelp = aElements[i];
       if (pHelp != NULL) {
           if (_tcsicmp(pHelp->GetName(), _T("patchlevel")) == 0) {
               m_nPatchLevel = _ttoi(pHelp->GetParameter());
           } else if (_tcsicmp(pHelp->GetName(), _T("url")) == 0) {
               m_csPatchUrl = pHelp->GetParameter();
           } else if (_tcsicmp(pHelp->GetName(), _T("url-other")) == 0) {
               csOtherPatchUrl = pHelp->GetParameter();
           } else if (_tcsicmp(pHelp->GetName(), _T("size")) == 0) {
               m_nPatchSizeBytes = _ttoi(pHelp->GetParameter());
           } else if (_tcsicmp(pHelp->GetName(), _T("size-other")) == 0) {
               nOtherPatchSize = _ttoi(pHelp->GetParameter());
           }
       }
   }

   // A german version downloads a german patchinfo.xml.
   // This patchinfo.xml links to the (old) German patch file with "url".
   // A new installation (>= 2.0.p3) is always based on the English install package.
   // So for a new installation (!bDeMarkerExists) in the 
   // German case (bIsDeVersion) the other url has to be used for the patch file.
   //
   if (bIsDeVersion && !bDeMarkerExists && csOtherPatchUrl.GetLength() > 0)
   {
      m_csPatchUrl = csOtherPatchUrl;
      m_nPatchSizeBytes = nOtherPatchSize;
   }

   return true;
}
예제 #2
0
bool CAutoUpdateDialog::ContactUpdateServer(LBuffer &lSgml)
{
   // Assemble the URL for the update file
   CLsUpdt32Dll *pDll = (CLsUpdt32Dll *) AfxGetApp();

   CString csUrlFormatDefault;
   csUrlFormatDefault.LoadString(IDS_URL);
   LString lsUrlFormat;
   lsUrlFormat.Allocate(1024);
   DWORD dwSize = 1024;
   LRegistry::ReadSettingsString(_T("AutoUpdate"), _T("URL"), (LPTSTR) lsUrlFormat, &dwSize, 
      (LPCTSTR) csUrlFormatDefault);

   CString csType = _T("eval");
   if (m_nVersionType == TYPE_FULL_VERSION || m_nVersionType == TYPE_CAMPUS_VERSION)
      csType = _T("full");

   CString csLanguage = pDll->GetLanguage();
   if (csLanguage.Compare(_T("de")) != 0)
      csLanguage = _T("en"); // en is the default, de the only possible exception

   CString csUrl;
   csUrl.Format((LPCTSTR) lsUrlFormat, pDll->GetVersion(), csLanguage, csType);

   // We store the ID of an error message in this
   // variable.
   LURESULT dwErrorCode = S_OK;
   DWORD dwSystemError  = 0;

   m_pInternet = new LInternet; // pointer: needed by OnCancel()

   dwErrorCode = m_pInternet->OpenUrl(csUrl, &dwSystemError);
   bool success = (dwErrorCode == S_OK);

   if (success)
   {
      DWORD dwBytesToRead = 2048;
      DWORD dwBytesRead   = 1;
      
      char pBuffer[2048];
      LURESULT ret = S_OK;
      while (dwBytesRead > 0)
      {
         ret = m_pInternet->Read(pBuffer, dwBytesToRead, &dwBytesRead, &dwSystemError);
         if (S_OK == ret)
         {
            if (dwBytesRead > 0)
            {
               lSgml.AddBuffer(pBuffer, dwBytesRead);
            }
         }
         else
         {
            success = false;
            dwBytesRead = 0;
         }
      }
   }

   // Is harmless if nothing is open
   m_pInternet->Close();

   delete m_pInternet;
   m_pInternet = NULL;

   if (success)
   {
      // probably nothing to be done:
      // data is in LBuffer and will be parsed outside

      /*
      // Transfer SGML data from LBuffer to char *
      int nAddedSize = lBuffer.GetAddedSize();
      lsSgml.Allocate(nAddedSize + 1);

      // Big fat note & later TODO: This assumes that LString contains a char * buffer;
      // this will not work with the UNICODE flag defined!
      // Possible later remedy: LString contains Unicode (UCS-2) characters, and the
      // buffer contains UTF-8 characters. Then use MultiByteToWideChar.
      memcpy((LPSTR) lsSgml, lBuffer.GetBuffer(), nAddedSize);

      ((LPSTR) lsSgml)[nAddedSize] = '\000';
      */
   }
   else if (!m_bCancelRequested) // error could occur because it was cancelled
   {
      // An error occurred; "translate" the error message into something
      // we can handle
      switch (dwErrorCode)
      {
      case LINTERNET_ERR_INTERNETATTEMPT:
         dwErrorCode = IDS_ERR_INTERNETATTEMPT;
         break;
      case LINTERNET_ERR_INTERNETOPEN:
         dwErrorCode = IDS_ERR_INTERNETOPEN;
         break;
      case LINTERNET_ERR_INTERNETURL:
         dwErrorCode = IDS_ERR_INTERNETURL;
         break;
      case LINTERNET_ERR_NOTFOUND:
         dwErrorCode = IDS_ERR_INTERNETNOTFOUND;
         break;
      case LINTERNET_ERR_READ:
         dwErrorCode = IDS_ERR_INTERNETREAD;
         break;
      }

      // Output an error message.
      CString csError;
      csError.LoadString(dwErrorCode);
      CString csSystemError;

      CString csMessage;

      if (dwSystemError != 0)
      {
         LPVOID lpMsgBuf;
         if (FormatMessage( 
            FORMAT_MESSAGE_ALLOCATE_BUFFER | 
            FORMAT_MESSAGE_FROM_SYSTEM | 
            FORMAT_MESSAGE_IGNORE_INSERTS,
            NULL,
            dwSystemError,
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
            (LPTSTR) &lpMsgBuf,
            0,
            NULL))
         {
            csSystemError.Format(IDS_ERR_SYSTEM, (LPCTSTR) lpMsgBuf);
            LocalFree(lpMsgBuf);
            csMessage.Format(_T("%s\n\n%s"), csError, csSystemError);
         }
         else
         {
            csMessage = csError;
         }
      }
      else
         csMessage = csError;


      // suppress the display of an error message in some cases
      // e.g. if it is an automatic update check during program start
      bool bSuppressErrorMessage = false;
      _TCHAR tszCallingName[MAX_PATH];
      DWORD dwCopied = GetModuleFileName(NULL, tszCallingName, MAX_PATH);

      // look if it is NOT "lsupdate.exe" calling us
      if (dwCopied > 0 && NULL == _tcsstr(tszCallingName, _T("lsupdate.exe")))
      {
         if (dwErrorCode == IDS_ERR_INTERNETATTEMPT ||
            dwErrorCode == IDS_ERR_INTERNETOPEN || dwErrorCode == IDS_ERR_INTERNETURL ||
            dwErrorCode == IDS_ERR_INTERNETNOTFOUND || dwErrorCode == IDS_ERR_INTERNETREAD)
            bSuppressErrorMessage = true;
      }


      if (!bSuppressErrorMessage)
         MessageBox(csMessage, _T("LECTURNITY Auto-Update"), MB_OK | MB_ICONERROR);
   }

   return success;
}