Horizon Official Technical Documentation
Horizon::Tools::MapCache Class Reference

#include <MapCache.hpp>

+ Collaboration diagram for Horizon::Tools::MapCache:

Public Member Functions

 MapCache ()
 
 ~MapCache ()
 
void parse_exec_args (int argc, const char *argv[])
 
bool ParseInitializeResult (mcache_error_type type)
 
bool ParseGRFLoadResult (std::pair< uint8_t, grf_load_result_type > result)
 
bool ParseMapCacheImportResult (mcache_import_error_type type)
 
Horizon::Libraries::MapCachegetLibrary ()
 

Private Attributes

Horizon::Libraries::MapCache _cache
 

Constructor & Destructor Documentation

◆ MapCache()

Horizon::Tools::MapCache::MapCache ( )
36{
37
38}

◆ ~MapCache()

Horizon::Tools::MapCache::~MapCache ( )
41{
42
43}

Member Function Documentation

◆ getLibrary()

Horizon::Libraries::MapCache & Horizon::Tools::MapCache::getLibrary ( )
inline
59{ return _cache; }
Horizon::Libraries::MapCache _cache
Definition: MapCache.hpp:61

References _cache.

Referenced by main().

+ Here is the caller graph for this function:

◆ parse_exec_args()

void Horizon::Tools::MapCache::parse_exec_args ( int  argc,
const char *  argv[] 
)
46{
47 for (int i = 1; i < argc; ++i) {
48 std::string arg(argv[i]);
49 std::vector<std::string> separated_args;
50 boost::split(separated_args, arg, boost::is_any_of("="));
51
52 if (separated_args.at(0).compare("--grf-config") == 0) {
53 getLibrary().setGRFListPath(separated_args.at(1));
54 } else if (separated_args.at(0).compare("--config") == 0) {
55 getLibrary().setMapListPath(separated_args.at(1));
56 } else if (separated_args.at(0).compare("--compression-level") == 0) {
57 int level = atoi(separated_args.at(1).c_str());
58 if (level > 9 || level < 1) {
59 printf("Error: Invalid compression level set, defaulting to 6.");
60 } else {
62 }
63 } else if (separated_args.at(0).compare("--verbose") == 0) {
65 } else if (separated_args.at(0).compare("--output") == 0) {
66 getLibrary().setMapCachePath(separated_args.at(1));
67 } else {
68 printf("Unrecognised argument '%s'\n", separated_args.at(0).c_str());
69 }
70 }
71}
void setVerbose()
Definition: MapCache.hpp:225
void setMapListPath(std::string const &path)
Definition: MapCache.hpp:207
void setMapCachePath(std::string const &file)
Definition: MapCache.hpp:199
void setCompressionLevel(int level)
Definition: MapCache.hpp:203
void setGRFListPath(std::string const &path)
Definition: MapCache.hpp:211
Horizon::Libraries::MapCache & getLibrary()
Definition: MapCache.hpp:59

Referenced by main().

+ Here is the caller graph for this function:

◆ ParseGRFLoadResult()

bool Horizon::Tools::MapCache::ParseGRFLoadResult ( std::pair< uint8_t, grf_load_result_type result)
99{
100 if (result.second != GRF_LOAD_OK) {
101 GRF &problematic_grf = getLibrary().getGRF(result.first);
102
103 switch (result.second)
104 {
106 printf("GRF: Error reading grf header. aborting...\n");
107 return true;
109 printf("GRF: Invalid or unknown grf header format. aborting...\n");
110 printf("GRF: Possible over 2GB in size...\n");
111 return true;
113 printf("GRF: Invalid grf version %x. aborting...\n", problematic_grf.getGRFVersion());
114 return true;
116 printf("GRF: Read error while loading the grf. Aborting...\n");
117 return true;
119 printf("GRF: Magic header was not 'Master of Magic'! Aborting...\n");
120 return true;
122 printf("GRF: Incorrect path '%s' given for grf. Aborting...\n", problematic_grf.getGRFPath().c_str());
123 return true;
125 printf("GRF: Error reading header of the given grf '%s'. Aborting...\n", problematic_grf.getGRFPath().c_str());
126 return true;
128 printf("GRF: Illegal data format, compressed size is greater than expected.\n");
129 return true;
130 case GRF_LOAD_OK:
131 default:
132 break;
133 }
134 }
135
136 for (auto &grf : getLibrary().getGRFs()) {
137 int size = grf.second.getGRFSize();
138 float kb_size = size / 1024;
139 float mb_size = kb_size / 1024;
140 float gb_size = mb_size / 1024;
141
142 printf("Info: GRF Loaded from '%s'.\n", grf.second.getGRFPath().string().c_str());
143 printf("Info: Total GRF Size - %d B (%0.2f KB or %0.2f MB or %0.2f GB).\n", size, kb_size, mb_size, gb_size);
144 printf("Info: GRF has '%d' Total Compressed Files.\n", grf.second.getTotalFiles());
145 printf("Info: GRF Version %x\n", grf.second.getGRFVersion());
146 printf("Info: GRF file path: '%s'\n", grf.second.getGRFPath().c_str());
147 }
148
149 return false;
150}
@ GRF_LOAD_INCOMPLETE_HEADER
Definition: GRF.hpp:50
@ GRF_LOAD_ILLEGAL_DATA_FORMAT
Definition: GRF.hpp:55
@ GRF_LOAD_OK
Definition: GRF.hpp:48
@ GRF_LOAD_MAGIC_ERROR
Definition: GRF.hpp:51
@ GRF_LOAD_FORMAT_ERROR
Definition: GRF.hpp:52
@ GRF_LOAD_READ_ERROR
Definition: GRF.hpp:56
@ GRF_LOAD_PATH_ERROR
Definition: GRF.hpp:49
@ GRF_LOAD_INVALID_VERSION
Definition: GRF.hpp:53
@ GRF_LOAD_HEADER_READ_ERROR
Definition: GRF.hpp:54
Definition: GRF.hpp:86
const boost::filesystem::path & getGRFPath() const
Definition: GRF.hpp:105
int getGRFVersion() const
Definition: GRF.hpp:111
GRF & getGRF(uint8_t id)
Definition: MapCache.hpp:194

References GRF::getGRFPath(), GRF::getGRFVersion(), GRF_LOAD_FORMAT_ERROR, GRF_LOAD_HEADER_READ_ERROR, GRF_LOAD_ILLEGAL_DATA_FORMAT, GRF_LOAD_INCOMPLETE_HEADER, GRF_LOAD_INVALID_VERSION, GRF_LOAD_MAGIC_ERROR, GRF_LOAD_OK, GRF_LOAD_PATH_ERROR, and GRF_LOAD_READ_ERROR.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseInitializeResult()

bool Horizon::Tools::MapCache::ParseInitializeResult ( mcache_error_type  type)
74{
75 switch (type)
76 {
78 printf("Invalid GRF config path '%s' provided.\n", getLibrary().getGRFListPath().c_str());
79 return false;
81 printf("Invalid config path '%s' provided.\n", getLibrary().getMapListPath().c_str());
82 return false;
84 printf("Invalid output path '%s' provided.\n", getLibrary().getMapCachePath().c_str());
85 return false;
87 printf("There was an error reading the configuration.\n");
88 return false;
90 printf("There was an error loading the GRF.\n");
91 return false;
92 default:
93 break;
94 }
95 return true;
96}
@ MCACHE_INVALID_OUTPUT_PATH
Definition: MapCache.hpp:120
@ MCACHE_INVALID_GRF_PATH
Definition: MapCache.hpp:118
@ MCACHE_CONFIG_READ_ERROR
Definition: MapCache.hpp:121
@ MCACHE_INVALID_CONFIG_PATH
Definition: MapCache.hpp:119
@ MCACHE_GRF_LOAD_ERROR
Definition: MapCache.hpp:123

References MCACHE_CONFIG_READ_ERROR, MCACHE_GRF_LOAD_ERROR, MCACHE_INVALID_CONFIG_PATH, MCACHE_INVALID_GRF_PATH, and MCACHE_INVALID_OUTPUT_PATH.

Referenced by main().

+ Here is the caller graph for this function:

◆ ParseMapCacheImportResult()

bool Horizon::Tools::MapCache::ParseMapCacheImportResult ( mcache_import_error_type  type)
153{
154 switch (type)
155 {
156 default:
157 printf("Info: Import of %lu maps was successful.\n", getLibrary().getMCache()->maps.size());
158 break;
160 printf("Error: Could not open file '%s'.\n", getLibrary().getMapCachePath().c_str());
161 return false;
163 printf("Error: Could not read file '%s', rebuilding...\n", getLibrary().getMapCachePath().c_str());
164 return false;
166 printf("Error: File cache file '%s' is corrupted (invalid checksum), rebuilding...\n", getLibrary().getMapCachePath().c_str());
167 return false;
169 printf("Error: File cache file '%s' could not be decompressed, rebuilding...\n", getLibrary().getMapCachePath().c_str());
170 return false;
172 printf("Error: Could not read map information for a map while importing file '%s', rebuilding...\n", getLibrary().getMapCachePath().c_str());
173 return false;
175 printf("Error: Could not read cell information for a map while importing file '%s', rebuilding...\n", getLibrary().getMapCachePath().c_str());
176 return false;
177 }
178
179 return true;
180}
@ MCACHE_IMPORT_INVALID_CHECKSUM
Definition: MapCache.hpp:146
@ MCACHE_IMPORT_NONEXISTENT_FILE
Definition: MapCache.hpp:144
@ MCACHE_IMPORT_READ_ERROR
Definition: MapCache.hpp:145
@ MCACHE_IMPORT_DECOMPRESS_ERROR
Definition: MapCache.hpp:147
@ MCACHE_IMPORT_MAPINFO_ERROR
Definition: MapCache.hpp:148
@ MCACHE_IMPORT_CELLINFO_ERROR
Definition: MapCache.hpp:149

References MCACHE_IMPORT_CELLINFO_ERROR, MCACHE_IMPORT_DECOMPRESS_ERROR, MCACHE_IMPORT_INVALID_CHECKSUM, MCACHE_IMPORT_MAPINFO_ERROR, MCACHE_IMPORT_NONEXISTENT_FILE, and MCACHE_IMPORT_READ_ERROR.

Referenced by main().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _cache

Horizon::Libraries::MapCache Horizon::Tools::MapCache::_cache
private

Referenced by getLibrary().


The documentation for this class was generated from the following files: