コード例 #1
0
bool CGameFiles::CheckFiles()
{
	// Loop through all files that need checking
	for (int i = 0; i < ARRAY_LENGTH(gameFiles); i++)
	{
		// Does the file not exist?
		if (!SharedUtility::Exists(gameFiles[i].szFile))
		{
			// Set the last error
			SetLastError(CString("Can't find the file '%s'.", gameFiles[i].szFile));

			return false;
		}

		// Create the file checksum
		CFileChecksum pFileChecksum;

		// Calculate the current file checksum
		pFileChecksum.Calculate(gameFiles[i].szFile);

		// Does the file checksum not match?
		if (pFileChecksum.GetChecksum() != gameFiles[i].uiChecksum)
		{
			// Set the last error
			SetLastError(CString("The file '%s' has been modified.", gameFiles[i].szFile));

			CLogFile::Printf("File Error: '%s', expected checksum 0x%p, got 0x%p", gameFiles[i].szFile, gameFiles[i].uiChecksum, pFileChecksum.GetChecksum());

			//return false;
		}

		// Does this file need decompressing?
		if (gameFiles[i].bCompressed)
		{
			// Decompress the file
			int iResult = CZlib::Decompress(gameFiles[i].szFile, gameFiles[i].szOutput);

			// Did the file fail to decompress?
			if (iResult != Z_OK)
			{
				// Set the last error
				SetLastError(CString("Failed to decompress the file %s. (Error: %d)", gameFiles[i].szFile, iResult));

				//return false;
			}

			// Should we delete this file?
			if (gameFiles[i].bDeleteAfterDecompress)
			{
				// Push the file onto the delete queue
				m_deleteFiles.push_back(gameFiles[i].szOutput);
			}
		}
	}

	return true;
}
コード例 #2
0
String CScriptingManager::Refresh(std::vector<CMetaFile> & scripts, CScriptTimerManager * stm)
{
	int nLoaded=0, nUloaded=0, nRefreshed=0;

	for(auto i = scripts.begin(); i != scripts.end(); i++)
	{
		auto s = Get(*i);
		if(s == NULL)
		{
			Load(*i);
			nLoaded++;
		}
		else
		{
			CFileChecksum cs;
			cs.Calculate(i->ToFullPath().Get());
			if(cs != s->GetFileChecksum())
			{
				stm->HandleScriptUnload(s);
				Unload(s);
				Load(*i);
				nRefreshed++;
			}
		}
	}

	for(auto i = m_scripts.begin(); i != m_scripts.end(); )
	{
		if(std::find_if(begin(scripts), end(scripts), [&i](CMetaFile & mf){ return mf == (*i)->GetMetaFile(); } ) == scripts.end())
		{
			Unload((*i++)->GetMetaFile());
			nUloaded++;
		}
		else
			i++;
	}
	return String("Loaded %d    Unloaded %d    Refreshed %d", nLoaded, nUloaded, nRefreshed);

}
コード例 #3
0
String CClientFileManager::Refresh(std::vector<CMetaFile> & files)
{
	int nLoaded=0, nUloaded=0, nRefreshed=0;

	for(auto i = files.begin(); i != files.end(); i++)
	{
		auto s = Get(*i);
		if(s == NULL)
		{
			Start(*i);
			nLoaded++;
		}
		else
		{
			CFileChecksum cs;
			cs.Calculate(i->ToFullPath().Get());
			if(cs != s->m_Checksum)
			{
				Stop(*i);
				Start(*i);
				nRefreshed++;
			}
		}
	}

	for(auto i = m_Files.begin(); i != m_Files.end(); )
	{
		if(std::find_if(begin(files), end(files), [&i](CMetaFile & mf){ return mf == i->m_MetaFile; } ) == files.end())
		{
			Stop((i++)->m_MetaFile);
			nUloaded++;
		}
		else
			i++;
	}
	
	return String("Loaded %d    Unloaded %d    Refreshed %d", nLoaded, nUloaded, nRefreshed);
}