@@ -59,7 +59,7 @@ public:
/** Declare the file storage cache as being invalid, also clears all stored files. */
void InvalidateFileList()
{
this->Clear();
this->clear();
this->file_list_valid = false;
}
@@ -403,7 +403,7 @@ DEF_CONSOLE_CMD(ConListFiles)
_console_file_list.ValidateFileList(true);
for (uint i = 0; i < _console_file_list.Length(); i++) {
for (uint i = 0; i < _console_file_list.size(); i++) {
IConsolePrintF(CC_DEFAULT, "%d) %s", i, _console_file_list[i].title);
@@ -63,11 +63,6 @@ bool FiosItem::operator< (const FiosItem
return (_savegame_sort_order & SORT_DESCENDING) ? r > 0 : r < 0;
FileList::~FileList()
/**
* Construct a file list with the given kind of files, for the stated purpose.
* @param abstract_filetype Kind of files to collect.
@@ -75,7 +70,7 @@ FileList::~FileList()
*/
void FileList::BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop)
assert(fop == SLO_LOAD || fop == SLO_SAVE);
switch (abstract_filetype) {
@@ -107,7 +102,8 @@ void FileList::BuildFileList(AbstractFil
const FiosItem *FileList::FindItem(const char *file)
for (const FiosItem *item = this->Begin(); item != this->End(); item++) {
for (const auto &it : *this) {
const FiosItem *item = ⁢
if (strcmp(file, item->name) == 0) return item;
if (strcmp(file, item->title) == 0) return item;
@@ -117,13 +113,14 @@ const FiosItem *FileList::FindItem(const
int i = strtol(file, &endptr, 10);
if (file == endptr || *endptr != '\0') i = -1;
if (IsInsideMM(i, 0, this->Length())) return this->Get(i);
if (IsInsideMM(i, 0, this->size())) return &this->at(i);
/* As a last effort assume it is an OpenTTD savegame and
* that the ".sav" part was not given. */
char long_file[MAX_PATH];
seprintf(long_file, lastof(long_file), "%s.sav", file);
if (strcmp(long_file, item->name) == 0) return item;
if (strcmp(long_file, item->title) == 0) return item;
@@ -302,11 +299,11 @@ bool FiosFileScanner::AddFile(const std:
FiosType type = this->callback_proc(this->fop, filename, ext.c_str(), fios_title, lastof(fios_title));
if (type == FIOS_TYPE_INVALID) return false;
for (const FiosItem *fios = file_list.Begin(); fios != file_list.End(); fios++) {
if (filename == fios->name) return false;
for (const auto &fios : file_list) {
if (filename == fios.name) return false;
FiosItem *fios = file_list.Append();
FiosItem *fios = &file_list.emplace_back();
#ifdef _WIN32
// Retrieve the file modified date using GetFileTime rather than stat to work around an obscure MSVC bug that affects Windows XP
HANDLE fh = CreateFile(OTTD2FS(filename).c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
@@ -367,13 +364,13 @@ static void FiosGetFileList(SaveLoadOper
size_t sort_start;
char d_name[sizeof(fios->name)];
file_list.Clear();
file_list.clear();
assert(_fios_path != nullptr);
/* A parent directory link exists if we are not in the root directory */
if (!FiosIsRoot(_fios_path->c_str())) {
fios = file_list.Append();
fios = &file_list.emplace_back();
fios->type = FIOS_TYPE_PARENT;
fios->mtime = 0;
strecpy(fios->name, "..", lastof(fios->name));
@@ -390,7 +387,7 @@ static void FiosGetFileList(SaveLoadOper
if (FiosIsValidFile(_fios_path->c_str(), dirent, &sb) && S_ISDIR(sb.st_mode) &&
(!FiosIsHiddenFile(dirent) || strncasecmp(d_name, PERSONAL_DIR, strlen(d_name)) == 0) &&
strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) {
fios->type = FIOS_TYPE_DIR;
strecpy(fios->name, d_name, lastof(fios->name));
@@ -407,12 +404,12 @@ static void FiosGetFileList(SaveLoadOper
SortingBits order = _savegame_sort_order;
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
std::sort(file_list.files.begin(), file_list.files.end());
std::sort(file_list.begin(), file_list.end());
_savegame_sort_order = order;
/* This is where to start sorting for the filenames */
sort_start = file_list.Length();
sort_start = file_list.size();
/* Show files */
FiosFileScanner scanner(fop, callback_proc, file_list);
@@ -422,12 +419,12 @@ static void FiosGetFileList(SaveLoadOper
scanner.Scan(nullptr, subdir, true, true);
std::sort(file_list.files.begin() + sort_start, file_list.files.end());
std::sort(file_list.begin() + sort_start, file_list.end());
/* Show drives */
FiosGetDrives(file_list);
file_list.Compact();
file_list.shrink_to_fit();
@@ -109,94 +109,10 @@ struct FiosItem {
};
/** List of file information. */
class FileList {
class FileList : public std::vector<FiosItem> {
public:
~FileList();
* Construct a new entry in the file list.
* @return Pointer to the new items to be initialized.
inline FiosItem *Append()
return &this->files.emplace_back();
* Get the number of files in the list.
* @return The number of files stored in the list.
inline size_t Length() const
return this->files.size();
* Get a pointer to the first file information.
* @return Address of the first file information.
inline const FiosItem *Begin() const
return this->files.data();
* Get a pointer behind the last file information.
* @return Address behind the last file information.
inline const FiosItem *End() const
return this->Begin() + this->Length();
* Get a pointer to the indicated file information. File information must exist.
* @return Address of the indicated existing file information.
inline const FiosItem *Get(size_t index) const
return this->files.data() + index;
inline FiosItem *Get(size_t index)
inline const FiosItem &operator[](size_t index) const
return this->files[index];
* Get a reference to the indicated file information. File information must exist.
* @return The requested file information.
inline FiosItem &operator[](size_t index)
/** Remove all items from the list. */
inline void Clear()
this->files.clear();
/** Compact the list down to the smallest block size boundary. */
inline void Compact()
this->files.shrink_to_fit();
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop);
const FiosItem *FindItem(const char *file);
std::vector<FiosItem> files; ///< The list of files.
enum SortingBits {
@@ -249,8 +249,8 @@ static void SortSaveGameList(FileList &f
* Drives (A:\ (windows only) are always under the files (FIOS_TYPE_DRIVE)
* Only sort savegames/scenarios, not directories
for (const FiosItem *item = file_list.Begin(); item != file_list.End(); item++) {
switch (item->type) {
for (const auto &item : file_list) {
switch (item.type) {
case FIOS_TYPE_DIR: sort_start++; break;
case FIOS_TYPE_PARENT: sort_start++; break;
case FIOS_TYPE_DRIVE: sort_end++; break;
@@ -258,7 +258,7 @@ static void SortSaveGameList(FileList &f
std::sort(file_list.files.begin() + sort_start, file_list.files.end() - sort_end);
std::sort(file_list.begin() + sort_start, file_list.end() - sort_end);
struct SaveLoadWindow : public Window {
@@ -437,14 +437,14 @@ public:
uint y = r.top + WD_FRAMERECT_TOP;
uint scroll_pos = this->vscroll->GetPosition();
for (uint row = 0; row < this->fios_items.Length(); row++) {
for (uint row = 0; row < this->fios_items.size(); row++) {
if (!this->fios_items_shown[row]) {
/* The current item is filtered out : we do not show it */
scroll_pos++;
continue;
if (row < scroll_pos) continue;
const FiosItem *item = this->fios_items.Get(row);
const FiosItem *item = &this->fios_items[row];
if (item == this->selected) {
GfxFillRect(r.left + 1, y, r.right, y + this->resize.step_height, PC_DARK_BLUE);
@@ -651,7 +651,7 @@ public:
if (!this->fios_items_shown[i]) y++;
i++;
const FiosItem *file = this->fios_items.Get(y);
const FiosItem *file = &this->fios_items[y];
const char *name = FiosBrowseTo(file);
if (name == nullptr) {
@@ -734,7 +734,7 @@ public:
if (file != this->highlighted) {
this->highlighted = file;
@@ -812,7 +812,7 @@ public:
_fios_path_changed = true;
this->fios_items.BuildFileList(this->abstract_filetype, this->fop);
this->vscroll->SetCount((uint)this->fios_items.Length());
this->vscroll->SetCount((uint)this->fios_items.size());
this->selected = nullptr;
_load_check_data.Clear();
@@ -852,10 +852,10 @@ public:
case SLIWD_FILTER_CHANGES:
/* Filter changes */
this->fios_items_shown.resize(this->fios_items.Length());
this->fios_items_shown.resize(this->fios_items.size());
uint items_shown_count = 0; ///< The number of items shown in the list
/* We pass through every fios item */
for (uint i = 0; i < this->fios_items.Length(); i++) {
for (uint i = 0; i < this->fios_items.size(); i++) {
if (this->string_filter.IsEmpty()) {
/* We don't filter anything out if the filter editbox is empty */
this->fios_items_shown[i] = true;
@@ -209,7 +209,7 @@ void FiosGetDrives(FileList &file_list)
GetLogicalDriveStrings(lengthof(drives), drives);
for (s = drives; *s != '\0';) {
fios->type = FIOS_TYPE_DRIVE;
seprintf(fios->name, lastof(fios->name), "%c:", s[0] & 0xFF);
Status change: