Skip to content
Permalink
Browse files

Change savegame sort order to modification time

* sort entries from most to least recent

Fixes Warzone2100#322
  • Loading branch information...
Forgon2100 committed Apr 3, 2019
1 parent efcff78 commit 76ebb54a8cc9aab1eedb687a983504d157d68b8b
Showing with 10 additions and 9 deletions.
  1. +10 −9 src/loadsave.cpp
@@ -303,14 +303,13 @@ bool addLoadSave(LOADSAVE_MODE savemode, const char *title)

// fill slots.
slotCount = 0;
std::vector<std::pair<int, time_t>> savegames;

debug(LOG_SAVE, "Searching \"%s\" for savegames", NewSaveGamePath);

// add savegame filenames minus extensions to buttons
files = PHYSFS_enumerateFiles(NewSaveGamePath);
for (i = files; *i != nullptr; ++i)
{
W_BUTTON *button;
time_t savetime;
struct tm *timeinfo;

@@ -321,23 +320,19 @@ bool addLoadSave(LOADSAVE_MODE savemode, const char *title)
continue;
}

button = (W_BUTTON *)widgGetFromID(psRequestScreen, LOADENTRY_START + slotCount);

debug(LOG_SAVE, "We found [%s]", *i);

/* Figure save-time */
snprintf(sSlotFile[slotCount], (sizeof sSlotFile[slotCount]), "%s/%s", NewSaveGamePath, *i);
savetime = WZ_PHYSFS_getLastModTime(sSlotFile[slotCount]);
savegames.push_back(std::make_pair(savetime, slotCount));
timeinfo = localtime(&savetime);
strftime(sSlotTips[slotCount], sizeof(sSlotTips[slotCount]), "%F %H:%M:%S", timeinfo);

/* Set the button-text */
(*i)[strlen(*i) - 4] = '\0'; // remove .gam extension
sstrcpy(sSlotCaps[slotCount], *i); //store it!

/* Add button */
button->pTip = sSlotTips[slotCount];
button->pText = WzString::fromUtf8(sSlotCaps[slotCount]);
slotCount++; // goto next but...
if (slotCount == totalslots)
{
@@ -346,9 +341,15 @@ bool addLoadSave(LOADSAVE_MODE savemode, const char *title)
}
PHYSFS_freeList(files);

for (int i = 0; i < slotCount; i++)
// sort savegames from most to least recent
std::sort(savegames.rbegin(), savegames.rend());

// assign entries to buttons
int buttonNumber;
for (int i = 0; i < savegames.size(); i++)
{
addGameSelectionButton(i, sSlotTips[i], sSlotCaps[i], sSlotFile[i]);
buttonNumber = savegames[i].second;
addGameSelectionButton(i, sSlotTips[buttonNumber], sSlotCaps[buttonNumber], sSlotFile[buttonNumber]);
}

bLoadSaveUp = true;

0 comments on commit 76ebb54

Please sign in to comment.
You can’t perform that action at this time.