Merge pull request #3636 from kaienfr/fix_recent_gamelist

Update recent games list & remove redundant recent games from ini file
This commit is contained in:
Henrik Rydgård committed 2013-09-07 02:18:30 -07:00
commit f24a7c83f5
6 files changed
+46 -10

No files matched your search

+26 -8
View File
@@ -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");
@@ -273,12 +277,15 @@ 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 +405,19 @@ void Config::AddRecent(const std::string &file) {
void Config::CleanRecent() {
std::vector<std::string> 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<cleanedRecent.size();j++){
if (cleanedRecent[j]==recentIsos[i])
break; // skip if found redundant
if (j==cleanedRecent.size()-1){ // add if no redundant found
cleanedRecent.push_back(recentIsos[i]);
}
}
}
}
recentIsos = cleanedRecent;
}