1 /* 2 * Tools for dealing with save game previews. 3 */ 4 5 #ifndef SAVEGAMEPREVIEW_H 6 #define SAVEGAMEPREVIEW_H 7 8 #include <vector> 9 #include <string> 10 11 #include <boost/serialization/version.hpp> 12 13 #include <GG/Clr.h> 14 15 #include "MultiplayerCommon.h" 16 #include "Export.h" 17 #include "Serialize.h" 18 #include "Directories.h" 19 20 /** Contains preview information about a savegame. 21 * Stored the beginning of a savefile for quick access. */ 22 struct FO_COMMON_API SaveGamePreviewData { 23 SaveGamePreviewData(); /// Initialize with unknown markers. 24 25 bool Valid() const; /// Checks that this is a valid preview 26 void SetBinary(bool bin = true); /// Sets the description string appropriate for a binary or XML save file header 27 28 static const short PREVIEW_PRESENT_MARKER = 0xDA; /// A marker for the presence of the header 29 short magic_number; /// This should always contain PREVIEW_PRESENT_MARKER 30 31 std::string description; /// Bit of text explaining what this file contains as human-readable text 32 std::string freeorion_version; /// By what version of FreeOrion was this save generated 33 34 std::string main_player_name; /// The name of the hosting player, or the single human player in single player games 35 std::string main_player_empire_name; /// The name of the empire of the main player 36 GG::Clr main_player_empire_colour; /// The colour of the empire of the main player 37 int current_turn; /// The turn the game as saved one 38 std::string save_time; /// The time the game was saved as ISO 8601 YYYY-MM-DD"T"HH:MM:SS±HH:MM or Z 39 short number_of_empires; /// The number of empires in the game 40 short number_of_human_players; /// The number of human players in the game 41 42 std::string save_format_marker = ""; /// What format was used for this save? 43 unsigned int uncompressed_text_size = 0; /// How many bytes capacity does the uncompressed save text take up? (ie. the part that was / will be compressed with zlib for compressed xml format saves) 44 unsigned int compressed_text_size = 0; /// How many bytes capacity does the compressed save text take up? 45 46 template <typename Archive> 47 void serialize(Archive& ar, unsigned int version); 48 }; 49 50 BOOST_CLASS_VERSION(SaveGamePreviewData, 4); 51 52 extern template FO_COMMON_API void SaveGamePreviewData::serialize<freeorion_bin_oarchive>(freeorion_bin_oarchive&, unsigned int); 53 extern template FO_COMMON_API void SaveGamePreviewData::serialize<freeorion_bin_iarchive>(freeorion_bin_iarchive&, unsigned int); 54 extern template FO_COMMON_API void SaveGamePreviewData::serialize<freeorion_xml_oarchive>(freeorion_xml_oarchive&, unsigned int); 55 extern template FO_COMMON_API void SaveGamePreviewData::serialize<freeorion_xml_iarchive>(freeorion_xml_iarchive&, unsigned int); 56 57 /** Stores all aggregated information about a save file */ 58 struct FO_COMMON_API FullPreview { 59 std::string filename; 60 SaveGamePreviewData preview; 61 GalaxySetupData galaxy; 62 private: 63 friend class boost::serialization::access; 64 template <typename Archive> 65 void serialize(Archive& ar, const unsigned int version); 66 }; 67 68 /** The preview information the server sends to the client. */ 69 struct FO_COMMON_API PreviewInformation { 70 std::vector<std::string> subdirectories; /// A list of all subfolders of the save game directory, in the format /name1/child1/grandchild 71 std::string folder; /// The directory whose previews are being listed now 72 std::vector<FullPreview> previews; /// The previews of the saves in this folder 73 private: 74 friend class boost::serialization::access; 75 template <typename Archive> 76 void serialize(Archive& ar, const unsigned int version); 77 }; 78 79 /// Attempts to load headers of a save file. 80 /// Returns true on success, false if header data could not be loaded 81 /// @param path Filename to load headers of 82 FO_COMMON_API bool SaveFileWithValidHeader(const boost::filesystem::path& path); 83 84 /// Get the value of column name in this preview 85 /// @param full FullPreview to match for column @p name 86 /// \param name The name of the column 87 /// \param thin If true, tries to make the value less wide 88 FO_COMMON_API std::string ColumnInPreview(const FullPreview& full, const std::string& name, bool thin = true); 89 90 /// Load previews from files 91 /// \param path Directory where to look for files 92 /// \param extension File name extension to filter by 93 /// \param [out] previews The previews will be put here 94 FO_COMMON_API void LoadSaveGamePreviews(const boost::filesystem::path& path, const std::string& extension, 95 std::vector<FullPreview>& previews); 96 #endif // SAVEGAMEPREVIEW_H 97