-fixed possible codedump in cover downloader

-added debug prints to see if crc32 is correctly cached
This commit is contained in:
fix94.1 2012-06-17 11:12:07 +00:00
parent 8f16156768
commit a87244c93a
2 changed files with 23 additions and 16 deletions

View File

@ -495,7 +495,7 @@ int CMenu::_coverDownloader(bool missingOnly)
} }
Config m_checksums; Config m_checksums;
m_checksums.load(fmt("%s/" PLUGIN_CRCS_FILENAME, m_settingsDir.c_str())); m_checksums.load(fmt("%s/%s", m_settingsDir.c_str(), PLUGIN_CRCS_FILENAME));
if (m_coverDLGameId.empty()) if (m_coverDLGameId.empty())
{ {
@ -1218,7 +1218,7 @@ void CMenu::_download(string gameId)
m_thrdStop = false; m_thrdStop = false;
m_thrdMessageAdded = false; m_thrdMessageAdded = false;
if((m_cf.getHdr()->type == TYPE_PLUGIN) && gameId.size()) if(gameId.size() && m_cf.getHdr()->type == TYPE_PLUGIN)
{ {
char gamePath[256]; char gamePath[256];
if(string(m_cf.getHdr()->path).find_last_of("/") != string::npos) if(string(m_cf.getHdr()->path).find_last_of("/") != string::npos)

View File

@ -297,24 +297,31 @@ string Plugin::GenerateCoverLink(dir_discHdr gameHeader, string url, Config &Che
string cachedCRC = Checksums.getString("CHECKSUMS", gamePath, emptyString); string cachedCRC = Checksums.getString("CHECKSUMS", gamePath, emptyString);
char crc_string[9]; char crc_string[9];
if(cachedCRC != emptyString) if(cachedCRC != emptyString)
snprintf(crc_string, sizeof(crc_string), "%s", cachedCRC.c_str());
else if(strstr(gameHeader.path, ".zip") == NULL)
{ {
snprintf(crc_string, sizeof(crc_string), "%08x", crc32file(gameHeader.path)); gprintf("CRC32 of %s is cached\n", gamePath);
Checksums.setString("CHECKSUMS", gamePath, crc_string); snprintf(crc_string, sizeof(crc_string), "%s", cachedCRC.c_str());
Checksums.save();
} }
else else
{ {
u32 crc_buffer; gprintf("Generating CRC32 for %s\n", gamePath);
ifstream infile; if(strstr(gameHeader.path, ".zip") == NULL)
infile.open(gameHeader.path, ios::binary); {
infile.seekg(0x0e, ios::beg); snprintf(crc_string, sizeof(crc_string), "%08x", crc32file(gameHeader.path));
infile.read((char*)&crc_buffer, 8); Checksums.setString("CHECKSUMS", gamePath, crc_string);
infile.close(); Checksums.save();
snprintf(crc_string, sizeof(crc_string), "%08x", SWAP32(crc_buffer)); }
Checksums.setString("CHECKSUMS", gamePath, crc_string); else
Checksums.save(); {
u32 crc_buffer;
ifstream infile;
infile.open(gameHeader.path, ios::binary);
infile.seekg(0x0e, ios::beg);
infile.read((char*)&crc_buffer, 8);
infile.close();
snprintf(crc_string, sizeof(crc_string), "%08x", SWAP32(crc_buffer));
Checksums.setString("CHECKSUMS", gamePath, crc_string);
Checksums.save();
}
} }
url.replace(url.find(TAG_GAME_ID), strlen(TAG_GAME_ID), upperCase(crc_string).c_str()); url.replace(url.find(TAG_GAME_ID), strlen(TAG_GAME_ID), upperCase(crc_string).c_str());
gprintf("URL: %s\n", url.c_str()); gprintf("URL: %s\n", url.c_str());