From 137df18a00bb419bc51d894a4d4e28ad6eaff69f Mon Sep 17 00:00:00 2001 From: kaienfr Date: Thu, 5 Sep 2013 00:04:24 +0200 Subject: [PATCH 1/2] Update recent games list & remove redundant recent games from ini file --- Core/Config.cpp | 24 ++++++++++++++++++------ UI/GameSettingsScreen.cpp | 7 +++++++ UI/GameSettingsScreen.h | 3 ++- UI/MainScreen.cpp | 3 +++ Windows/WndMainWindow.cpp | 5 +++++ Windows/WndMainWindow.h | 1 + 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index bb958935c0..3bb174408b 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -273,12 +273,13 @@ void Config::Save() { IniFile::Section *recent = iniFile.GetOrCreateSection("Recent"); recent->Set("MaxRecent", iMaxRecent); - for (int i = 0; i < (int)recentIsos.size(); i++) - { + for (int i = 0; i < iMaxRecent; i++) { char keyName[64]; - sprintf(keyName,"FileName%d",i); - recent->Set(keyName,recentIsos[i]); + if (i < recentIsos.size()){ + recent->Set(keyName, recentIsos[i]);} + else{ + recent->Delete(keyName);} // delete the nonexisting FileName } IniFile::Section *cpu = iniFile.GetOrCreateSection("CPU"); @@ -398,8 +399,19 @@ void Config::AddRecent(const std::string &file) { void Config::CleanRecent() { std::vector cleanedRecent; for (size_t i = 0; i < recentIsos.size(); i++) { - if (File::Exists(recentIsos[i])) - cleanedRecent.push_back(recentIsos[i]); + if (File::Exists(recentIsos[i])){ + // clean the redundant recent games' list. + if (cleanedRecent.size()==0){ // add first one + cleanedRecent.push_back(recentIsos[i]); + } + for (size_t j=0; j Date: Thu, 5 Sep 2013 18:45:41 +0200 Subject: [PATCH 2/2] New update in code style & fix load function The load function can not load all recent games list if the Key is skeeped as: FileName0 = ... FileName2 = ... ... In this case, only FileName0 is loaded. Now the function is fixed and load all list. --- Core/Config.cpp | 20 +++++++++++++------- UI/GameSettingsScreen.cpp | 5 +++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 3bb174408b..d4edc21263 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -99,8 +99,12 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) std::string fileName; sprintf(keyName,"FileName%d",i); - if (!recent->Get(keyName,&fileName,"") || fileName.length() == 0) break; - recentIsos.push_back(fileName); + if (!recent->Get(keyName,&fileName,"") || fileName.length() == 0) { + // just skip it to get the next key + } + else { + recentIsos.push_back(fileName); + } } IniFile::Section *cpu = iniFile.GetOrCreateSection("CPU"); @@ -276,10 +280,12 @@ void Config::Save() { for (int i = 0; i < iMaxRecent; i++) { char keyName[64]; sprintf(keyName,"FileName%d",i); - if (i < recentIsos.size()){ - recent->Set(keyName, recentIsos[i]);} - else{ - recent->Delete(keyName);} // delete the nonexisting FileName + if (i < recentIsos.size()) { + recent->Set(keyName, recentIsos[i]); + } + else { + recent->Delete(keyName); // delete the nonexisting FileName + } } IniFile::Section *cpu = iniFile.GetOrCreateSection("CPU"); @@ -405,7 +411,7 @@ void Config::CleanRecent() { cleanedRecent.push_back(recentIsos[i]); } for (size_t j=0; j