예제 #1
0
bool CSavestateWriter::Initialize(const CGameClient* gameClient, uint64_t frameHistoryCount)
{
  m_savestate.Reset();
  m_fps = 0.0;

  m_fps = gameClient->Timing().GetFrameRate();

  CDateTime now = CDateTime::GetCurrentDateTime();
  std::string label = now.GetAsLocalizedDateTime();

  m_savestate.SetType(SAVETYPE::MANUAL);
  m_savestate.SetLabel(label);
  m_savestate.SetGameClient(gameClient->ID());
  m_savestate.SetGamePath(gameClient->GetGamePath());
  m_savestate.SetTimestamp(now);
  m_savestate.SetPlaytimeFrames(frameHistoryCount);
  m_savestate.SetPlaytimeWallClock(frameHistoryCount / m_fps); //! @todo Accumulate playtime instead of deriving it

  //! @todo Get CRC from game data instead of filename
  Crc32 crc;
  crc.Compute(gameClient->GetGamePath());
  m_savestate.SetGameCRC(StringUtils::Format("%08x", (unsigned __int32)crc));

  m_savestate.SetPath(CSavestateUtils::MakePath(m_savestate));
  if (m_savestate.Path().empty())
    CLog::Log(LOGDEBUG, "Failed to calculate savestate path");

  if (m_fps == 0.0)
    return false; // Sanity check

  return !m_savestate.Path().empty();
}
예제 #2
0
 String getCacheThumbName(const String& path)
 {
   XBMC_TRACE;
   Crc32 crc;
   crc.ComputeFromLowerCase(path);
   return StringUtils::Format("%08x.tbn", (unsigned __int32)crc);
 }
예제 #3
0
파일: TestCrc32.cpp 프로젝트: nikkpap/SPMC
TEST(TestCrc32, Compute_1)
{
    Crc32 a;
    uint32_t varcrc;
    a.Compute(refdata, sizeof(refdata) - 1);
    varcrc = a;
    EXPECT_EQ(0xa4eb60e3, varcrc);
}
예제 #4
0
void NameKey::setHash()
 {
  Crc32 crc;

  for(auto cur=getCur(); cur.next() ;) crc.add(*cur);

  hash=crc;
 }
예제 #5
0
CStdString CTextureCache::GetCacheFile(const CStdString &url)
{
  Crc32 crc;
  crc.ComputeFromLowerCase(url);
  CStdString hex = StringUtils::Format("%08x", (unsigned int)crc);
  CStdString hash = StringUtils::Format("%c/%s", hex[0], hex.c_str());
  return hash;
}
예제 #6
0
파일: TestCrc32.cpp 프로젝트: nikkpap/SPMC
TEST(TestCrc32, Compute_2)
{
    Crc32 a;
    uint32_t varcrc;
    CStdString s = refdata;
    a.Compute(s);
    varcrc = a;
    EXPECT_EQ(0xa4eb60e3, varcrc);
}
예제 #7
0
파일: TestCrc32.cpp 프로젝트: nikkpap/SPMC
TEST(TestCrc32, ComputeFromLowerCase)
{
    Crc32 a;
    uint32_t varcrc;
    CStdString s = refdata;
    a.ComputeFromLowerCase(s);
    varcrc = a;
    EXPECT_EQ((uint32_t)0x7f045b3e, varcrc);
}
예제 #8
0
 String getCacheThumbName(const String& path)
 {
   TRACE;
   Crc32 crc;
   crc.ComputeFromLowerCase(path);
   CStdString strPath;
   strPath.Format("%08x.tbn", (unsigned __int32)crc);
   return strPath;
 }
예제 #9
0
bool CGUIDialogVideoBookmarks::AddBookmark(CVideoInfoTag* tag)
{
  CVideoDatabase videoDatabase;
  CBookmark bookmark;
  bookmark.timeInSeconds = (int)g_application.GetTime();
  bookmark.totalTimeInSeconds = (int)g_application.GetTotalTime();

  if( g_application.m_pPlayer->HasPlayer() )
    bookmark.playerState = g_application.m_pPlayer->GetPlayerState();
  else
    bookmark.playerState.clear();

  bookmark.player = CPlayerCoreFactory::GetInstance().GetPlayerName(g_application.GetCurrentPlayer());

  // create the thumbnail image
#ifdef HAS_VIDEO_PLAYBACK
  float aspectRatio = g_renderManager.GetAspectRatio();
#else
  float aspectRatio = 1.0f;
#endif
  int width = BOOKMARK_THUMB_WIDTH;
  int height = (int)(BOOKMARK_THUMB_WIDTH / aspectRatio);
  if (height > (int)BOOKMARK_THUMB_WIDTH)
  {
    height = BOOKMARK_THUMB_WIDTH;
    width = (int)(BOOKMARK_THUMB_WIDTH * aspectRatio);
  }
  {
#ifdef HAS_VIDEO_PLAYBACK
    CRenderCapture* thumbnail = g_renderManager.AllocRenderCapture();

    if (thumbnail)
    {
      g_renderManager.Capture(thumbnail, width, height, CAPTUREFLAG_IMMEDIATELY);

#if !defined(HAS_LIBAMCODEC)
      if (thumbnail->GetUserState() == CAPTURESTATE_DONE)
      {
#else//HAS_LIBAMCODEC
      {
        CScreenshotAML::CaptureVideoFrame(thumbnail->GetPixels(), width, height, false);
#endif
        Crc32 crc;
        crc.ComputeFromLowerCase(g_application.CurrentFile());
        bookmark.thumbNailImage = StringUtils::Format("%08x_%i.jpg", (unsigned __int32) crc, (int)bookmark.timeInSeconds);
        bookmark.thumbNailImage = URIUtils::AddFileToFolder(CProfilesManager::GetInstance().GetBookmarksThumbFolder(), bookmark.thumbNailImage);
        if (!CPicture::CreateThumbnailFromSurface(thumbnail->GetPixels(), width, height, thumbnail->GetWidth() * 4,
                                            bookmark.thumbNailImage))
          bookmark.thumbNailImage.clear();
      }
#if !defined(HAS_LIBAMCODEC)
      else
        CLog::Log(LOGERROR,"CGUIDialogVideoBookmarks: failed to create thumbnail");
#endif

      g_renderManager.ReleaseRenderCapture(thumbnail);
    }
예제 #10
0
void CBackgroundInfoLoader::LoadCustomImages(CFileItem* pItem, bool bCanBlock)
{
  //CLog::Log(LOGDEBUG,"CBackgroundInfoLoader::LoadCustomImages - Enter function with item [path=%s][label=%s]. [bCanBlock=%d] (custi)",(pItem->m_strPath).c_str(),(pItem->GetLabel()).c_str(),bCanBlock);
  
  for (int nImage=0; nImage < 10; nImage++)
  {
    CStdString strPropName;
    strPropName.Format("Image%d", nImage);
    if (!pItem->HasProperty(strPropName))
    {
      break;
    }
    
    CStdString strImagePath = pItem->GetProperty(strPropName);
    
    //CLog::Log(LOGDEBUG,"CBackgroundInfoLoader::LoadCustomImages - [%d] Going to try and download property [%s] value [ImagePath=%s] for item [path=%s][label=%s]. [bCanBlock=%d] (custi)",nImage,strPropName.c_str(),strImagePath.c_str(),(pItem->m_strPath).c_str(),(pItem->GetLabel()).c_str(),bCanBlock);

    // Get path for cache picture
    Crc32 crc;
    crc.ComputeFromLowerCase(strImagePath);
    CStdString hex;
    hex.Format("%08x", (unsigned __int32) crc);
    CStdString cacheImagePath;
    cacheImagePath.Format("%s\\%c\\%s_image.tbn", g_settings.GetPicturesThumbFolder().c_str(), hex[0], hex.c_str());
    
    cacheImagePath = _P(cacheImagePath);
    
    //CLog::Log(LOGDEBUG,"CBackgroundInfoLoader::LoadCustomImages - [%d] For image [ImagePath=%s] the cacheImagePath is [%s]. Item [path=%s][label=%s]. [bCanBlock=%d] (custi)",nImage,strImagePath.c_str(),cacheImagePath.c_str(),(pItem->m_strPath).c_str(),(pItem->GetLabel()).c_str(),bCanBlock);

    if(CFile::Exists(cacheImagePath))
    {
      // Picture exist in cache
      pItem->SetProperty(strPropName, cacheImagePath);
      
      //CLog::Log(LOGDEBUG,"CBackgroundInfoLoader::LoadCustomImages - [%d] cacheImagePath [%s] already exist and was set to property [%s=%s]. item [path=%s][label=%s]. [bCanBlock=%d] (custi)",nImage,cacheImagePath.c_str(),strPropName.c_str(),(pItem->GetProperty(strPropName)).c_str(),(pItem->m_strPath).c_str(),(pItem->GetLabel()).c_str(),bCanBlock);
    }
    else
    {
      // Picture doesn't exist in cache -> Need to download it
      
      BOXEE::BXCurl http;
      bool success = http.HttpDownloadFile(strImagePath,cacheImagePath,"");
      
      if(success)
      {
        pItem->SetProperty(strPropName, cacheImagePath);
        
        //CLog::Log(LOGDEBUG,"CBackgroundInfoLoader::LoadCustomImages - [%d] successed downloading image. cacheImagePath [%s]  was set to property [%s=%s]. item [path=%s][label=%s]. [bCanBlock=%d] (custi)",nImage,cacheImagePath.c_str(),strPropName.c_str(),(pItem->GetProperty(strPropName)).c_str(),(pItem->m_strPath).c_str(),(pItem->GetLabel()).c_str(),bCanBlock);
      }
      else
      {
        CLog::Log(LOGERROR,"CBackgroundInfoLoader::LoadCustomImages - [%d] Failed to download [ImagePath=%s] for item [path=%s][label=%s]. [bCanBlock=%d] (pthumb)(custi)",nImage,strImagePath.c_str(),(pItem->m_strPath).c_str(),(pItem->GetLabel()).c_str(),bCanBlock);
      }
    }
  }  
}
예제 #11
0
CStdString CTextureCache::GetUniqueImage(const CStdString &url, const CStdString &extension)
{
  Crc32 crc;
  crc.ComputeFromLowerCase(url);
  CStdString hex;
  hex.Format("%08x", (unsigned int)crc);
  CStdString hash;
  hash.Format("generated/%c/%s%s", hex[0], hex.c_str(), extension.c_str());
  return GetCachedPath(hash);
}
예제 #12
0
파일: TestCrc32.cpp 프로젝트: nikkpap/SPMC
TEST(TestCrc32, Reset)
{
    Crc32 a;
    uint32_t varcrc;
    CStdString s = refdata;
    a.ComputeFromLowerCase(s);
    a.Reset();
    varcrc = a;
    EXPECT_EQ(0xffffffff, varcrc);
}
CStdString CTextureCache::GetCacheFile(const CStdString &url)
{
  Crc32 crc;
  crc.ComputeFromLowerCase(url);
  CStdString hex;
  hex.Format("%08x", (unsigned int)crc);
  CStdString hash;
  hash.Format("%c/%s%s", hex[0], hex.c_str(), CUtil::GetExtension(url).c_str());
  return hash;
}
예제 #14
0
void CGUIDialogVideoBookmarks::AddBookmark(CVideoInfoTag* tag)
{
  CVideoDatabase videoDatabase;
  CBookmark bookmark;
  bookmark.timeInSeconds = (int)g_application.GetTime();
  bookmark.totalTimeInSeconds = (int)g_application.GetTotalTime();

  if( g_application.m_pPlayer )
    bookmark.playerState = g_application.m_pPlayer->GetPlayerState();
  else
    bookmark.playerState.Empty();

  bookmark.player = CPlayerCoreFactory::GetPlayerName(g_application.GetCurrentPlayer());

  // create the thumbnail image
#ifdef HAS_VIDEO_PLAYBACK
  float aspectRatio = g_renderManager.GetAspectRatio();
#else
  float aspectRatio = 1.0f;
#endif
  int width = BOOKMARK_THUMB_WIDTH;
  int height = (int)(BOOKMARK_THUMB_WIDTH / aspectRatio);
  if (height > BOOKMARK_THUMB_WIDTH)
  {
    height = BOOKMARK_THUMB_WIDTH;
    width = (int)(BOOKMARK_THUMB_WIDTH * aspectRatio);
  }
  {
#ifdef HAS_VIDEO_PLAYBACK
    CRenderCapture* thumbnail = g_renderManager.AllocRenderCapture();
    g_renderManager.Capture(thumbnail, width, height, CAPTUREFLAG_IMMEDIATELY);
    if (thumbnail->GetUserState() == CAPTURESTATE_DONE)
    {
      Crc32 crc;
      crc.ComputeFromLowerCase(g_application.CurrentFile());
      bookmark.thumbNailImage.Format("%08x_%i.jpg", (unsigned __int32) crc, m_vecItems->Size() + 1);
      bookmark.thumbNailImage = URIUtils::AddFileToFolder(g_settings.GetBookmarksThumbFolder(), bookmark.thumbNailImage);
      if (!CPicture::CreateThumbnailFromSurface(thumbnail->GetPixels(), width, height, thumbnail->GetWidth() * 4,
                                          bookmark.thumbNailImage))
        bookmark.thumbNailImage.Empty();
    }
    else
      CLog::Log(LOGERROR,"CGUIDialogVideoBookmarks: failed to create thumbnail");

    g_renderManager.ReleaseRenderCapture(thumbnail);
#endif
  }
  videoDatabase.Open();
  if (tag)
    videoDatabase.AddBookMarkForEpisode(*tag, bookmark);
  else
    videoDatabase.AddBookMarkToFile(g_application.CurrentFile(), bookmark, CBookmark::STANDARD);
  videoDatabase.Close();
  Update();
}
예제 #15
0
void ReadsLayout::save(ostream& out_bin)
{
    unsigned int crcCheck;
    Crc32 CRC;
  
    tabSize = R->getEffectiveNReads() + 1;
    
    CRC.AddData((uint8_t*) & tabSize, sizeof (unsigned int));
    CRC.AddData((uint8_t*) lastIdentical, sizeof (unsigned int) *tabSize);
    CRC.AddData((uint8_t*) next, sizeof (unsigned int) *tabSize);
    CRC.AddData((uint8_t*) previous, sizeof (unsigned int) *tabSize);
    CRC.AddData((uint8_t*) nodeId, sizeof (unsigned int) *tabSize);
    CRC.AddData((uint8_t*) position, sizeof (int) *tabSize);
    CRC.AddData((uint8_t*) flags, sizeof (unsigned char) *tabSize);

    crcCheck=CRC.GetCrc32();
    
    out_bin.write((char*) &crcCheck, sizeof (unsigned int));
      
    out_bin.write((char*) &tabSize, sizeof (unsigned int));
    out_bin.write((char*) lastIdentical, sizeof (unsigned int) *tabSize);
    out_bin.write((char*) next, sizeof (unsigned int) *tabSize);
    out_bin.write((char*) previous, sizeof (unsigned int) *tabSize);
    out_bin.write((char*) nodeId, sizeof (unsigned int) *tabSize);
    out_bin.write((char*) position, sizeof (int) *tabSize);
    out_bin.write((char*) flags, sizeof (unsigned char) *tabSize);
}
예제 #16
0
void CMusicDatabaseDirectory::ClearDirectoryCache(const CStdString& strDirectory)
{
  CStdString path = CLegacyPathTranslation::TranslateMusicDbPath(strDirectory);
  URIUtils::RemoveSlashAtEnd(path);

  Crc32 crc;
  crc.ComputeFromLowerCase(path);

  CStdString strFileName = StringUtils::Format("special://temp/%08x.fi", (unsigned __int32) crc);
  CFile::Delete(strFileName);
}
void CVideoDatabaseDirectory::ClearDirectoryCache(const CStdString& strDirectory)
{
  CStdString path(strDirectory);
  URIUtils::RemoveSlashAtEnd(path);

  Crc32 crc;
  crc.ComputeFromLowerCase(path);

  CStdString strFileName;
  strFileName.Format("special://temp/%08x.fi", (unsigned __int32) crc);
  CFile::Delete(strFileName);
}
예제 #18
0
CStdString CThumbnailCache::GetMusicThumb(const CStdString& path)
{
  Crc32 crc;
  CStdString noSlashPath(path);
  URIUtils::RemoveSlashAtEnd(noSlashPath);
  crc.ComputeFromLowerCase(noSlashPath);
  CStdString hex;
  hex.Format("%08x", (unsigned __int32) crc);
  CStdString thumb;
  thumb.Format("%c/%s.tbn", hex[0], hex.c_str());
  return URIUtils::AddFileToFolder(g_settings.GetMusicThumbFolder(), thumb);
}
예제 #19
0
void CMusicDatabaseDirectory::ClearDirectoryCache(const CStdString& strDirectory)
{
  CFileItem directory(strDirectory, true);
  if (CUtil::HasSlashAtEnd(directory.m_strPath))
    directory.m_strPath.Delete(directory.m_strPath.size() - 1);

  Crc32 crc;
  crc.ComputeFromLowerCase(directory.m_strPath);

  CStdString strFileName;
  strFileName.Format("Z:\\%08x.fi", (unsigned __int32) crc);
  CFile::Delete(_P(strFileName));
}
예제 #20
0
CStdString CThumbnailCache::GetMusicThumbHashPath(const CStdString &path, bool split) {
  Crc32 crc;
  crc.ComputeFromLowerCase(path);
  CStdString thumb;
  if (split) {
    CStdString hex;
    hex.Format("%08x", (__int32)crc);
    thumb.Format("%s\\%c\\%08x.tbn", g_settings.GetMusicThumbFolder(), hex[0], (unsigned __int32)crc);
  } else {
    thumb.Format("%s\\%08x.tbn", g_settings.GetMusicThumbFolder(), (unsigned __int32)crc);
  }
  return thumb;
}
예제 #21
0
void CGUIDialogVideoBookmarks::AddBookmark(CVideoInfoTag* tag)
{
  CVideoDatabase videoDatabase;
  CBookmark bookmark;
  bookmark.timeInSeconds = (int)g_application.GetTime();
  bookmark.totalTimeInSeconds = (int)g_application.GetTotalTime();

  if( g_application.m_pPlayer )
    bookmark.playerState = g_application.m_pPlayer->GetPlayerState();
  else
    bookmark.playerState.Empty();

  bookmark.player = CPlayerCoreFactory::GetPlayerName(g_application.GetCurrentPlayer());

  // create the thumbnail image
#ifdef HAS_VIDEO_PLAYBACK
  float aspectRatio = g_renderManager.GetAspectRatio();
#else
  float aspectRatio = 1.0f;
#endif
  int width = BOOKMARK_THUMB_WIDTH;
  int height = (int)(BOOKMARK_THUMB_WIDTH / aspectRatio);
  if (height > BOOKMARK_THUMB_WIDTH)
  {
    height = BOOKMARK_THUMB_WIDTH;
    width = (int)(BOOKMARK_THUMB_WIDTH * aspectRatio);
  }
  {
    CSingleLock lock(g_graphicsContext);
    // we're really just using the CTexture here as a pixel buffer
    CTexture texture(width, height, XB_FMT_B8G8R8A8);
#ifdef HAS_VIDEO_PLAYBACK
    //g_renderManager.CreateThumbnail(&texture, width, height);
#endif
    Crc32 crc;
    crc.ComputeFromLowerCase(g_application.CurrentFile());
    bookmark.thumbNailImage.Format("%08x_%i.jpg", (unsigned __int32) crc, m_vecItems->Size() + 1);
    bookmark.thumbNailImage = CUtil::AddFileToFolder(g_settings.GetBookmarksThumbFolder(), bookmark.thumbNailImage);
    if (!CPicture::CreateThumbnailFromSurface(texture.GetPixels(), width, height, texture.GetPitch(),
                                        bookmark.thumbNailImage))
      bookmark.thumbNailImage.Empty();
  }
  videoDatabase.Open();
  if (tag)
    videoDatabase.AddBookMarkForEpisode(*tag, bookmark);
  else
    videoDatabase.AddBookMarkToFile(g_application.CurrentFile(), bookmark, CBookmark::STANDARD);
  videoDatabase.Close();
  Update();
}
예제 #22
0
  PyObject* XBMC_GetCacheThumbName(PyObject *self, PyObject *args)
  {
    PyObject *pObjectText;
    if (!PyArg_ParseTuple(args, (char*)"O", &pObjectText)) return NULL;
 
    string strText;
    if (!PyGetUnicodeString(strText, pObjectText, 1)) return NULL;

    Crc32 crc;
    CStdString strPath;
    crc.ComputeFromLowerCase(strText);
    strPath.Format("%08x.tbn", (unsigned __int32)crc);
    return Py_BuildValue((char*)"s", strPath.c_str());
  }
예제 #23
0
void CLastFmManager::CacheTrackThumb(const int nrInitialTracksToAdd)
{
  unsigned int start = CTimeUtils::GetTimeMS();
  CSingleLock lock(m_lockCache);
  int iNrCachedTracks = m_RadioTrackQueue->size();
  CFileCurl http;
  for (int i = 0; i < nrInitialTracksToAdd && i < iNrCachedTracks; i++)
  {
    CFileItemPtr item = (*m_RadioTrackQueue)[i];
    if (!item->GetMusicInfoTag()->Loaded())
    {
      //cache albumthumb, GetThumbnailImage contains the url to cache
      if (item->HasThumbnail())
      {
        CStdString coverUrl = item->GetThumbnailImage();
        CStdString crcFile;
        CStdString cachedFile;
        CStdString thumbFile;

        Crc32 crc;
        crc.ComputeFromLowerCase(coverUrl);
        crcFile.Format("%08x.tbn", (__int32)crc);
        URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath, crcFile, cachedFile);
        URIUtils::AddFileToFolder(g_settings.GetLastFMThumbFolder(), crcFile, thumbFile);
        item->SetThumbnailImage("");
        try
        {
          //download to temp, then make a thumb
          if (CFile::Exists(thumbFile) || (http.Download(coverUrl, cachedFile) && CPicture::CreateThumbnail(cachedFile, thumbFile)))
          {
            if (CFile::Exists(cachedFile))
              CFile::Delete(cachedFile);
            item->SetThumbnailImage(thumbFile);
          }
        }
        catch(...)
        {
          CLog::Log(LOGERROR, "LastFmManager: exception while caching %s to %s.", coverUrl.c_str(), thumbFile.c_str());
        }
      }
      if (!item->HasThumbnail())
      {
        item->SetThumbnailImage("DefaultAlbumCover.png");
      }
      item->GetMusicInfoTag()->SetLoaded();
    }
  }
  CLog::Log(LOGDEBUG, "%s: Done (time: %i ms)", __FUNCTION__, (int)(CTimeUtils::GetTimeMS() - start));
}
예제 #24
0
char* Interface_Filesystem::get_cache_thumb_name(void* kodiBase, const char* filename)
{
  CAddonDll* addon = static_cast<CAddonDll*>(kodiBase);
  if (addon == nullptr || filename == nullptr)
  {
    CLog::Log(LOGERROR, "Interface_Filesystem::%s - invalid data (addon='%p', filename='%p)", __FUNCTION__, kodiBase, filename);
    return nullptr;
  }

  Crc32 crc;
  crc.ComputeFromLowerCase(filename);
  std::string string = StringUtils::Format("%08x.tbn", static_cast<unsigned int>(crc));
  char* buffer = strdup(string.c_str());
  return buffer;
}
예제 #25
0
CStdString CEdenVideoArtUpdater::GetThumb(const CStdString &path, const CStdString &path2, bool split)
{
  // get the locally cached thumb
  Crc32 crc;
  crc.ComputeFromLowerCase(path);

  CStdString thumb;
  if (split)
  {
    CStdString hex = StringUtils::Format("%08x", (__int32)crc);
    thumb = StringUtils::Format("%c\\%08x.tbn", hex[0], (unsigned __int32)crc);
  }
  else
    thumb = StringUtils::Format("%08x.tbn", (unsigned __int32)crc);

  return URIUtils::AddFileToFolder(path2, thumb);
}
예제 #26
0
CStdString CThumbnailCache::GetThumb(const CStdString &path, const CStdString &path2, bool split /* = false */)
{
  // get the locally cached thumb
  Crc32 crc;
  crc.ComputeFromLowerCase(path);

  CStdString thumb;
  if (split)
  {
    CStdString hex;
    hex.Format("%08x", (__int32)crc);
    thumb.Format("%c\\%08x.tbn", hex[0], (unsigned __int32)crc);
  }
  else
    thumb.Format("%08x.tbn", (unsigned __int32)crc);

  return URIUtils::AddFileToFolder(path2, thumb);
}
예제 #27
0
/*  
@	功能:	分析字符串
@	参数:	lpszString:	要分析的字符串
			vecTokens:	分析结果
@	返回值:如果分析失败,返回false
@	注:	
*/
bool CLexicalAnalyzer::Analyse( const char * lpszString, TLexTokens & vecTokens )
{
	static Crc32 crcGen;
	unsigned int crc = crcGen.GetCRC( lpszString );
	std::map<unsigned int,TLexTokens>::iterator iter = m_Tokens.find( crc );
	if( iter != m_Tokens.end() )
	{
		vecTokens = iter->second;
		return true;
	}

	vecTokens.clear();
	if( NULL == lpszString )
		return false;

	m_nStringLen	= (int)strlen( lpszString );
	if( m_nStringLen == 0 )
		return true;

	char * pszStr = new char[m_nStringLen+1];
	memcpy( pszStr, lpszString, m_nStringLen );
	pszStr[m_nStringLen] = '\0';

	m_nCurCharPos	= 0;
	m_lpszString = lpszString;
	
	while( true )
	{
		m_curState	= ELexState_Start;
		if( ! GetNextToken() )
		{
			vecTokens.clear();
			return false;
		}

		if( m_curToken.m_eTokenType == EToken_Complete )
			break;

		vecTokens.push_back( m_curToken );
		m_curToken.m_eTokenType = EToken_Invalid;
	}
	m_Tokens.insert( make_pair( crc, vecTokens ) );
	return true;
}
예제 #28
0
uint32 ParCheckerMock::CalcFileCrc(const char* filename)
{
	FILE* infile = fopen(filename, FOPEN_RB);
	REQUIRE(infile);

	CharBuffer buffer(1024 * 64);
	Crc32 downloadCrc;

	int cnt = buffer.Size();
	while (cnt == buffer.Size())
	{
		cnt = (int)fread(buffer, 1, buffer.Size(), infile);
		downloadCrc.Append((uchar*)(char*)buffer, cnt);
	}

	fclose(infile);

	return downloadCrc.Finish();
}
예제 #29
0
파일: Distri.cpp 프로젝트: phohale/ResEdit
void UpdateCRC(Crc32 &crc, const String &str)
{
	Int32 lLen = str.GetCStringLen();
	Char* pchString = NewMem(Char,lLen + 2);
	if (!pchString)
		return;
	str.GetCString(pchString, lLen + 1);
	crc.Update(pchString, lLen);
	DeleteMem(pchString);
}
예제 #30
0
bool ReadsLayout::load(istream& in_bin, ReadsStorage*r) {
    
  
    unsigned int crcCheck;
    Crc32 CRC;
    
    
    cleanMemory();
    unsigned int tabsize;

    in_bin.read((char*) &crcCheck, sizeof (unsigned int));
    
    in_bin.read((char*) &tabsize, sizeof (unsigned int));

    init(r, tabsize);

    in_bin.read((char*) lastIdentical, sizeof (unsigned int) *tabSize);
    in_bin.read((char*) next, sizeof (unsigned int) *tabSize);
    in_bin.read((char*) previous, sizeof (unsigned int) *tabSize);
    in_bin.read((char*) nodeId, sizeof (unsigned int) *tabSize);
    in_bin.read((char*) position, sizeof (int) *tabSize);
    in_bin.read((char*) flags, sizeof (unsigned char) *tabSize);
    
    CRC.AddData((uint8_t*) & tabSize, sizeof (unsigned int));
    CRC.AddData((uint8_t*) lastIdentical, sizeof (unsigned int) *tabSize);
    CRC.AddData((uint8_t*) next, sizeof (unsigned int) *tabSize);
    CRC.AddData((uint8_t*) previous, sizeof (unsigned int) *tabSize);
    CRC.AddData((uint8_t*) nodeId, sizeof (unsigned int) *tabSize);
    CRC.AddData((uint8_t*) position, sizeof (int) *tabSize);
    CRC.AddData((uint8_t*) flags, sizeof (unsigned char) *tabSize);
    
    unsigned int crc2=CRC.GetCrc32();
    
    if (crc2 != crcCheck)
        return false;
    
    return true;
}