当前位置: 首页>>代码示例>>C++>>正文


C++ LString::Allocate方法代码示例

本文整理汇总了C++中LString::Allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ LString::Allocate方法的具体用法?C++ LString::Allocate怎么用?C++ LString::Allocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LString的用法示例。


在下文中一共展示了LString::Allocate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ExtractPatchInformation

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;
}
开发者ID:identity0815,项目名称:os45,代码行数:71,代码来源:AutoUpdateDialog.cpp

示例2: ContactUpdateServer

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:
//.........这里部分代码省略.........
开发者ID:identity0815,项目名称:os45,代码行数:101,代码来源:AutoUpdateDialog.cpp


注:本文中的LString::Allocate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。