2006-08-04 23:41:13 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/** @file fios.h Declarations for savegames operations */
|
|
|
|
|
2006-08-04 23:41:13 +00:00
|
|
|
#ifndef FIOS_H
|
|
|
|
#define FIOS_H
|
|
|
|
|
2010-06-05 19:02:29 +00:00
|
|
|
#include "gfx_type.h"
|
2010-06-13 14:15:36 +00:00
|
|
|
#include "company_base.h"
|
2010-06-13 14:15:58 +00:00
|
|
|
#include "newgrf_config.h"
|
2012-08-20 21:01:40 +00:00
|
|
|
#include "network/core/tcp_content.h"
|
2008-01-13 01:21:35 +00:00
|
|
|
|
2010-06-13 14:13:23 +00:00
|
|
|
|
2018-11-25 19:54:25 +00:00
|
|
|
/** Special values for save-load window for the data parameter of #InvalidateWindowData. */
|
|
|
|
enum SaveLoadInvalidateWindowData {
|
|
|
|
SLIWD_RESCAN_FILES, ///< Rescan all files (when changed directory, ...)
|
|
|
|
SLIWD_SELECTION_CHANGES, ///< File selection has changed (user click, ...)
|
|
|
|
SLIWD_FILTER_CHANGES, ///< The filename filter has changed (via the editbox)
|
|
|
|
};
|
|
|
|
|
2010-06-13 14:15:36 +00:00
|
|
|
typedef SmallMap<uint, CompanyProperties *> CompanyPropertiesMap;
|
|
|
|
|
2010-06-13 14:13:23 +00:00
|
|
|
/**
|
|
|
|
* Container for loading in mode SL_LOAD_CHECK.
|
|
|
|
*/
|
|
|
|
struct LoadCheckData {
|
|
|
|
bool checkable; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
|
|
|
|
StringID error; ///< Error message from loading. INVALID_STRING_ID if no error.
|
|
|
|
char *error_data; ///< Data to pass to SetDParamStr when displaying #error.
|
|
|
|
|
2010-06-13 14:13:49 +00:00
|
|
|
uint32 map_size_x, map_size_y;
|
2010-06-13 14:14:20 +00:00
|
|
|
Date current_date;
|
2010-06-13 14:13:49 +00:00
|
|
|
|
2010-06-13 14:14:37 +00:00
|
|
|
GameSettings settings;
|
|
|
|
|
2010-06-13 14:15:36 +00:00
|
|
|
CompanyPropertiesMap companies; ///< Company information.
|
|
|
|
|
2010-06-13 14:15:58 +00:00
|
|
|
GRFConfig *grfconfig; ///< NewGrf configuration from save.
|
|
|
|
GRFListCompatibility grf_compatibility; ///< Summary state of NewGrfs, whether missing files or only compatible found.
|
|
|
|
|
2011-10-30 13:47:45 +00:00
|
|
|
struct LoggedAction *gamelog_action; ///< Gamelog actions
|
|
|
|
uint gamelog_actions; ///< Number of gamelog actions
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
LoadCheckData() : error_data(nullptr), grfconfig(nullptr),
|
|
|
|
grf_compatibility(GLC_NOT_FOUND), gamelog_action(nullptr), gamelog_actions(0)
|
2010-06-13 14:13:23 +00:00
|
|
|
{
|
|
|
|
this->Clear();
|
|
|
|
}
|
|
|
|
|
2010-09-06 15:47:11 +00:00
|
|
|
/**
|
|
|
|
* Don't leak memory at program exit
|
|
|
|
*/
|
|
|
|
~LoadCheckData()
|
|
|
|
{
|
|
|
|
this->Clear();
|
|
|
|
}
|
|
|
|
|
2010-06-13 14:17:26 +00:00
|
|
|
/**
|
|
|
|
* Check whether loading the game resulted in errors.
|
|
|
|
* @return true if errors were encountered.
|
|
|
|
*/
|
|
|
|
bool HasErrors()
|
|
|
|
{
|
|
|
|
return this->checkable && this->error != INVALID_STRING_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the game uses any NewGrfs.
|
|
|
|
* @return true if NewGrfs are used.
|
|
|
|
*/
|
|
|
|
bool HasNewGrfs()
|
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != nullptr;
|
2010-06-13 14:17:26 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 14:13:23 +00:00
|
|
|
void Clear();
|
|
|
|
};
|
|
|
|
|
|
|
|
extern LoadCheckData _load_check_data;
|
|
|
|
|
|
|
|
|
2010-05-13 09:44:44 +00:00
|
|
|
enum FileSlots {
|
2007-10-29 23:02:31 +00:00
|
|
|
/**
|
2017-01-14 13:12:49 +00:00
|
|
|
* Slot used for the GRF scanning and such.
|
|
|
|
* This slot is used for all temporary accesses to files when scanning/testing files,
|
|
|
|
* and thus cannot be used for files, which are continuously accessed during a game.
|
2007-10-29 23:02:31 +00:00
|
|
|
*/
|
|
|
|
CONFIG_SLOT = 0,
|
|
|
|
/** Slot for the sound. */
|
|
|
|
SOUND_SLOT = 1,
|
2013-01-08 22:46:42 +00:00
|
|
|
/** First slot usable for (New)GRFs used during the game. */
|
2007-10-29 23:02:31 +00:00
|
|
|
FIRST_GRF_SLOT = 2,
|
2017-02-14 00:35:15 +00:00
|
|
|
/** Maximum number of GRFs in single-player */
|
|
|
|
MAX_NEWGRFS = 256,
|
2007-10-29 23:02:31 +00:00
|
|
|
/** Maximum number of slots. */
|
2017-02-14 00:35:15 +00:00
|
|
|
MAX_FILE_SLOTS = 300,
|
2007-10-29 23:02:31 +00:00
|
|
|
};
|
|
|
|
|
2011-05-27 21:20:07 +00:00
|
|
|
/** Deals with finding savegames */
|
2007-12-28 03:14:55 +00:00
|
|
|
struct FiosItem {
|
2008-04-23 12:03:47 +00:00
|
|
|
FiosType type;
|
2007-12-28 03:14:55 +00:00
|
|
|
uint64 mtime;
|
|
|
|
char title[64];
|
2009-03-04 01:09:48 +00:00
|
|
|
char name[MAX_PATH];
|
2019-04-11 20:52:41 +00:00
|
|
|
bool operator< (const FiosItem &other) const;
|
2007-12-28 03:14:55 +00:00
|
|
|
};
|
|
|
|
|
2016-09-04 12:50:22 +00:00
|
|
|
/** List of file information. */
|
|
|
|
class FileList {
|
|
|
|
public:
|
|
|
|
~FileList();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new entry in the file list.
|
|
|
|
* @return Pointer to the new items to be initialized.
|
|
|
|
*/
|
|
|
|
inline FiosItem *Append()
|
|
|
|
{
|
2019-02-18 22:39:06 +00:00
|
|
|
/*C++17: return &*/ this->files.emplace_back();
|
|
|
|
return &this->files.back();
|
2016-09-04 12:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of files in the list.
|
|
|
|
* @return The number of files stored in the list.
|
|
|
|
*/
|
2019-03-27 23:09:33 +00:00
|
|
|
inline size_t Length() const
|
2016-09-04 12:50:22 +00:00
|
|
|
{
|
2018-09-23 11:23:54 +00:00
|
|
|
return this->files.size();
|
2016-09-04 12:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a pointer to the first file information.
|
|
|
|
* @return Address of the first file information.
|
|
|
|
*/
|
|
|
|
inline const FiosItem *Begin() const
|
|
|
|
{
|
2019-02-17 11:20:52 +00:00
|
|
|
return this->files.data();
|
2016-09-04 12:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a pointer behind the last file information.
|
|
|
|
* @return Address behind the last file information.
|
|
|
|
*/
|
|
|
|
inline const FiosItem *End() const
|
|
|
|
{
|
2019-02-17 11:20:52 +00:00
|
|
|
return this->Begin() + this->Length();
|
2016-09-04 12:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a pointer to the indicated file information. File information must exist.
|
|
|
|
* @return Address of the indicated existing file information.
|
|
|
|
*/
|
2019-03-27 23:09:33 +00:00
|
|
|
inline const FiosItem *Get(size_t index) const
|
2016-09-04 12:50:22 +00:00
|
|
|
{
|
2018-09-25 20:20:24 +00:00
|
|
|
return this->files.data() + index;
|
2016-09-04 12:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a pointer to the indicated file information. File information must exist.
|
|
|
|
* @return Address of the indicated existing file information.
|
|
|
|
*/
|
2019-03-27 23:09:33 +00:00
|
|
|
inline FiosItem *Get(size_t index)
|
2016-09-04 12:50:22 +00:00
|
|
|
{
|
2018-09-25 20:01:56 +00:00
|
|
|
return this->files.data() + index;
|
2016-09-04 12:50:22 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 23:09:33 +00:00
|
|
|
inline const FiosItem &operator[](size_t index) const
|
2016-09-04 12:50:22 +00:00
|
|
|
{
|
|
|
|
return this->files[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a reference to the indicated file information. File information must exist.
|
|
|
|
* @return The requested file information.
|
|
|
|
*/
|
2019-03-27 23:09:33 +00:00
|
|
|
inline FiosItem &operator[](size_t index)
|
2016-09-04 12:50:22 +00:00
|
|
|
{
|
|
|
|
return this->files[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Remove all items from the list. */
|
|
|
|
inline void Clear()
|
|
|
|
{
|
2018-09-20 22:44:14 +00:00
|
|
|
this->files.clear();
|
2016-09-04 12:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Compact the list down to the smallest block size boundary. */
|
|
|
|
inline void Compact()
|
|
|
|
{
|
2018-09-21 21:45:44 +00:00
|
|
|
this->files.shrink_to_fit();
|
2016-09-04 12:50:22 +00:00
|
|
|
}
|
|
|
|
|
2016-09-04 16:06:50 +00:00
|
|
|
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop);
|
2016-09-04 12:54:52 +00:00
|
|
|
const FiosItem *FindItem(const char *file);
|
|
|
|
|
2019-03-03 17:30:09 +00:00
|
|
|
std::vector<FiosItem> files; ///< The list of files.
|
2007-12-28 03:14:55 +00:00
|
|
|
};
|
|
|
|
|
2010-05-13 09:44:44 +00:00
|
|
|
enum SortingBits {
|
2008-05-29 09:54:47 +00:00
|
|
|
SORT_ASCENDING = 0,
|
|
|
|
SORT_DESCENDING = 1,
|
|
|
|
SORT_BY_DATE = 0,
|
|
|
|
SORT_BY_NAME = 2
|
|
|
|
};
|
2010-06-05 18:44:31 +00:00
|
|
|
DECLARE_ENUM_AS_BIT_SET(SortingBits)
|
2008-05-29 09:54:47 +00:00
|
|
|
|
2006-08-05 00:59:45 +00:00
|
|
|
/* Variables to display file lists */
|
2010-06-05 18:44:31 +00:00
|
|
|
extern SortingBits _savegame_sort_order;
|
2007-12-27 17:29:27 +00:00
|
|
|
|
2016-09-04 16:06:50 +00:00
|
|
|
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
|
2006-08-05 00:59:45 +00:00
|
|
|
|
2016-09-04 16:06:50 +00:00
|
|
|
void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list);
|
|
|
|
void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list);
|
|
|
|
void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list);
|
2011-05-27 21:20:07 +00:00
|
|
|
|
2009-03-04 00:13:52 +00:00
|
|
|
const char *FiosBrowseTo(const FiosItem *item);
|
2011-05-27 21:20:07 +00:00
|
|
|
|
2009-01-16 12:59:47 +00:00
|
|
|
StringID FiosGetDescText(const char **path, uint64 *total_free);
|
2006-08-05 00:59:45 +00:00
|
|
|
bool FiosDelete(const char *name);
|
2014-04-23 21:23:21 +00:00
|
|
|
void FiosMakeHeightmapName(char *buf, const char *name, const char *last);
|
|
|
|
void FiosMakeSavegameName(char *buf, const char *name, const char *last);
|
2011-05-27 21:20:07 +00:00
|
|
|
|
2016-09-04 16:06:50 +00:00
|
|
|
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last);
|
2006-08-05 00:59:45 +00:00
|
|
|
|
2006-08-04 23:41:13 +00:00
|
|
|
#endif /* FIOS_H */
|