Record
| 58 | |
| 59 | // Record |
| 60 | int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetVersion, const char *pMap, const SHA256_DIGEST &Sha256, unsigned Crc, const char *pType, unsigned MapSize, unsigned char *pMapData, IOHANDLE MapFile, DEMOFUNC_FILTER pfnFilter, void *pUser) |
| 61 | { |
| 62 | dbg_assert(m_File == 0, "Demo recorder already recording"); |
| 63 | |
| 64 | m_pConsole = pConsole; |
| 65 | m_pStorage = pStorage; |
| 66 | |
| 67 | if(!str_valid_filename(fs_filename(pFilename))) |
| 68 | { |
| 69 | log_error_color(DEMO_PRINT_COLOR, "demo_recorder", "The name '%s' cannot be used for demos because not all platforms support it", pFilename); |
| 70 | return -1; |
| 71 | } |
| 72 | |
| 73 | IOHANDLE DemoFile = pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE); |
| 74 | if(!DemoFile) |
| 75 | { |
| 76 | if(m_pConsole) |
| 77 | { |
| 78 | char aBuf[64 + IO_MAX_PATH_LENGTH]; |
| 79 | str_format(aBuf, sizeof(aBuf), "Unable to open '%s' for recording", pFilename); |
| 80 | m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", aBuf, gs_DemoPrintColor); |
| 81 | } |
| 82 | return -1; |
| 83 | } |
| 84 | |
| 85 | bool CloseMapFile = false; |
| 86 | |
| 87 | if(MapFile) |
| 88 | io_seek(MapFile, 0, IOSEEK_START); |
| 89 | |
| 90 | char aSha256[SHA256_MAXSTRSIZE]; |
| 91 | sha256_str(Sha256, aSha256, sizeof(aSha256)); |
| 92 | |
| 93 | if(!pMapData && !MapFile) |
| 94 | { |
| 95 | // open mapfile |
| 96 | char aMapFilename[IO_MAX_PATH_LENGTH]; |
| 97 | // try the downloaded maps |
| 98 | str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%s.map", pMap, aSha256); |
| 99 | MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ, IStorage::TYPE_ALL); |
| 100 | if(!MapFile) |
| 101 | { |
| 102 | // try the normal maps folder |
| 103 | str_format(aMapFilename, sizeof(aMapFilename), "maps/%s.map", pMap); |
| 104 | MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ, IStorage::TYPE_ALL); |
| 105 | } |
| 106 | if(!MapFile) |
| 107 | { |
| 108 | // search for the map within subfolders |
| 109 | char aBuf[IO_MAX_PATH_LENGTH]; |
| 110 | str_format(aMapFilename, sizeof(aMapFilename), "%s.map", pMap); |
| 111 | if(pStorage->FindFile(aMapFilename, "maps", IStorage::TYPE_ALL, aBuf, sizeof(aBuf))) |
| 112 | MapFile = pStorage->OpenFile(aBuf, IOFLAG_READ, IStorage::TYPE_ALL); |
| 113 | } |
| 114 | if(!MapFile) |
| 115 | { |
| 116 | if(m_pConsole) |
| 117 | { |
no test coverage detected