| 899 | } |
| 900 | |
| 901 | bool CDemoPlayer::ExtractMap(class IStorage *pStorage) |
| 902 | { |
| 903 | unsigned char *pMapData = GetMapData(pStorage); |
| 904 | if(!pMapData) |
| 905 | return false; |
| 906 | |
| 907 | // handle sha256 |
| 908 | std::optional<SHA256_DIGEST> Sha256; |
| 909 | if(m_Info.m_Header.m_Version >= gs_Sha256Version) |
| 910 | { |
| 911 | Sha256 = m_MapInfo.m_Sha256; |
| 912 | dbg_assert(Sha256.has_value(), "SHA256 missing for version %d demo", m_Info.m_Header.m_Version); |
| 913 | } |
| 914 | else |
| 915 | { |
| 916 | Sha256 = sha256(pMapData, m_MapInfo.m_Size); |
| 917 | m_MapInfo.m_Sha256 = Sha256; |
| 918 | } |
| 919 | |
| 920 | // construct name |
| 921 | char aSha[SHA256_MAXSTRSIZE], aMapFilename[IO_MAX_PATH_LENGTH]; |
| 922 | sha256_str(Sha256.value(), aSha, sizeof(aSha)); |
| 923 | str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%s.map", m_Info.m_Header.m_aMapName, aSha); |
| 924 | |
| 925 | // save map |
| 926 | IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE); |
| 927 | if(!MapFile) |
| 928 | { |
| 929 | free(pMapData); |
| 930 | return false; |
| 931 | } |
| 932 | |
| 933 | io_write(MapFile, pMapData, m_MapInfo.m_Size); |
| 934 | io_close(MapFile); |
| 935 | |
| 936 | // free data |
| 937 | free(pMapData); |
| 938 | return true; |
| 939 | } |
| 940 | |
| 941 | int64_t CDemoPlayer::Time() |
| 942 | { |
no test coverage detected