Delete the cached mappings if they are empty or corrupt

This commit is contained in:
Cameron Gutman
2020-11-23 18:34:53 -06:00
parent 861ebc151a
commit 3485983553
2 changed files with 23 additions and 8 deletions
+6 -1
View File
@@ -32,9 +32,14 @@ void MappingFetcher::start()
// Only download the file if it's newer than what we have // Only download the file if it's newer than what we have
QFileInfo existingFileInfo = Path::getCacheFileInfo("gamecontrollerdb.txt"); QFileInfo existingFileInfo = Path::getCacheFileInfo("gamecontrollerdb.txt");
if (existingFileInfo.exists() && existingFileInfo.size() > 0) { if (existingFileInfo.exists()) {
if (existingFileInfo.size() > 0) {
request.setHeader(QNetworkRequest::IfModifiedSinceHeader, existingFileInfo.lastModified().toUTC()); request.setHeader(QNetworkRequest::IfModifiedSinceHeader, existingFileInfo.lastModified().toUTC());
} }
else {
Path::deleteCacheFile("gamecontrollerdb.txt");
}
}
// We'll get a callback when this is finished // We'll get a callback when this is finished
m_Nam.get(request); m_Nam.get(request);
+14 -4
View File
@@ -72,15 +72,25 @@ void MappingManager::applyMappings()
if (!mappingData.isEmpty()) { if (!mappingData.isEmpty()) {
int newMappings = SDL_GameControllerAddMappingsFromRW( int newMappings = SDL_GameControllerAddMappingsFromRW(
SDL_RWFromConstMem(mappingData.constData(), mappingData.size()), 1); SDL_RWFromConstMem(mappingData.constData(), mappingData.size()), 1);
if (newMappings > 0) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Loaded %d new gamepad mappings",
newMappings);
}
else {
if (newMappings < 0) { if (newMappings < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Error loading gamepad mappings: %s", "Error loading gamepad mappings: %s",
SDL_GetError()); SDL_GetError());
} }
else { else if (newMappings == 0) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Loaded %d new gamepad mappings", "0 new mappings found in gamecontrollerdb.txt. Is it corrupt?");
newMappings); }
// Try deleting the cached mapping list just in case it's corrupt
Path::deleteCacheFile("gamecontrollerdb.txt");
} }
} }
else { else {