| 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; |
nothing calls this directly
no test coverage detected