MCPcopy Create free account
hub / github.com/bwapi/bwapi / calculateMapHash

Method calculateMapHash

bwapi/BWAPI/Source/BWAPI/Map.cpp:167–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165 std::string Map::savedMapHash;
166
167 std::string Map::calculateMapHash()
168 {
169 unsigned char hash[20];
170 char hexstring[sizeof(hash)*2 + 1];
171 std::string filename = Map::getPathName();
172
173 // Open File
174 Storm::CFile file;
175 if ( !file.open(filename, SFILE_FROM_ABSOLUTE) )
176 {
177 filename += "\\staredit\\scenario.chk";
178 if ( !file.open(filename, SFILE_FROM_MPQ) )
179 return Map::savedMapHash = "Error_map_cannot_be_opened";
180 }
181
182 size_t fileSize = file.size();
183 std::vector<char> data(fileSize);
184
185 // Read file
186 if ( !file.read(data.data(), fileSize) )
187 return Map::savedMapHash = "Error_unable_to_read_file";
188
189 // Calculate hash
190 sha1::calc(data.data(), fileSize, hash);
191 sha1::toHexString(hash, hexstring);
192
193 return Map::savedMapHash = hexstring;
194 }
195 std::string Map::getMapHash()
196 {
197 return Map::savedMapHash;

Callers

nothing calls this directly

Calls 5

calcFunction · 0.85
toHexStringFunction · 0.85
openMethod · 0.45
sizeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected