10#ifndef BASE_MEDIA_BASE_H
11#define BASE_MEDIA_BASE_H
16#include "3rdparty/md5/md5.h"
17#include <unordered_map>
51 typedef std::unordered_map<std::string, std::string, StringHash, std::equal_to<>> TranslatedStrings;
69 std::array<MD5File, BaseSet<T>::NUM_FILES>
files{};
100 void LogError(std::string_view full_filename, std::string_view detail,
int level = 0)
const;
103 bool FillSetDetails(
const IniFile &ini,
const std::string &path,
const std::string &full_filename,
bool allow_empty_filename =
true);
104 void CopyCompatibleConfig([[maybe_unused]]
const T &src) {}
116 if (!isocode.empty()) {
118 auto desc = this->description.find(isocode);
119 if (desc != this->description.end())
return desc->second;
122 desc = this->description.find(isocode.substr(0, 2));
123 if (desc != this->description.end())
return desc->second;
126 return this->description.at(std::string{});
140 return file->
CheckMD5(subdir, SIZE_MAX);
150 for (
const auto &file : this->
files) {
152 if (textfile.has_value()) {
170template <
class Tbase_set>
177 bool AddFile(
const std::string &filename,
size_t basepath_length,
const std::string &tar_filename)
override;
203 static bool SetSet(
const Tbase_set *set);
206 static void GetSetsList(std::back_insert_iterator<std::string> &output_iterator);
209 static const Tbase_set *
GetSet(
int index);
228template <
class Tbase_set>
Helper for scanning for files with a given name.
uint Scan(std::string_view extension, Subdirectory sd, bool tars=true, bool recursive=true)
Scan for files with the given extension in the given search path.
Functions for Standard In/Out file operations.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
@ OLD_DATA_DIR
Old subdirectory for the data.
@ OLD_GM_DIR
Old subdirectory for the music.
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
Defines the traits of a BaseSet type.
Information about a single base set.
uint found_files
Number of the files that could be found.
std::array< MD5File, BaseSet< T >::NUM_FILES > files
All files part of this set.
uint valid_files
Number of the files that could be found and are valid.
void LogError(std::string_view full_filename, std::string_view detail, int level=0) const
Log error from reading basesets.
const IniItem * GetMandatoryItem(std::string_view full_filename, const IniGroup &group, std::string_view name) const
Try to read a single piece of metadata and return nullptr if it doesn't exist.
std::string url
URL for information about the base set.
~BaseSet()
Free everything we allocated.
TranslatedStrings description
Description of the base set.
static constexpr size_t NUM_FILES
Number of files in this set.
std::optional< std::string > GetTextfile(TextfileType type) const
Search a textfile file next to this base media.
static constexpr bool SEARCH_IN_TARS
Whether to search in the tars or not.
static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir)
Calculate and check the MD5 hash of the supplied file.
static std::span< const std::string_view > GetFilenames()
Get the internal names of the files in this set.
static constexpr std::string_view SET_TYPE
BaseSet type name.
std::string name
The name of the base set.
bool fallback
This set is a fallback set, i.e. it should be used only as last resort.
bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename, bool allow_empty_filename=true)
Read the set information from a loaded ini.
T * next
The next base set in this list.
int GetNumMissing() const
Get the number of missing files.
std::vector< uint32_t > version
The version of this base set.
uint32_t shortname
Four letter short variant of the name.
int GetNumInvalid() const
Get the number of invalid files.
const std::string & GetDescription(std::string_view isocode) const
Get the description for the given ISO code.
Container for all important information about a piece of content.
Ini file that supports both loading and saving.
A group within an ini file.
A single "line" in an ini file.
Structure holding filename and MD5 information about a single file.
std::string missing_warning
warning when this file is missing
ChecksumResult check_result
cached result of md5 check
ChecksumResult CheckMD5(Subdirectory subdir, size_t max_size) const
Calculate and check the MD5 hash of the supplied filename.
ChecksumResult
The result of a checksum check.
@ CR_MATCH
The file did exist and the md5 checksum did match.
@ CR_MISMATCH
The file did exist, just the md5 checksum did not match.
@ CR_NO_FILE
The file did not exist.
@ CR_UNKNOWN
The file has not been checked yet.
MD5Hash hash
md5 sum of the file
std::string filename
filename
GUI functions related to textfiles.
Types related to textfiles.
TextfileType
Additional text files accompanying Tar archives.