Commit 4dad413a authored by Chen Bill's avatar Chen Bill

check header in OpenReplay

parent c3e25993
...@@ -1256,7 +1256,7 @@ void Game::RefreshDeck(const wchar_t* deckpath, const std::function<void(const w ...@@ -1256,7 +1256,7 @@ void Game::RefreshDeck(const wchar_t* deckpath, const std::function<void(const w
void Game::RefreshReplay() { void Game::RefreshReplay() {
lstReplayList->clear(); lstReplayList->clear();
FileSystem::TraversalDir(L"./replay", [this](const wchar_t* name, bool isdir) { FileSystem::TraversalDir(L"./replay", [this](const wchar_t* name, bool isdir) {
if (!isdir && IsExtension(name, L".yrp") && Replay::CheckReplay(name)) if (!isdir && IsExtension(name, L".yrp"))
lstReplayList->addItem(name); lstReplayList->addItem(name);
}); });
} }
......
...@@ -115,6 +115,14 @@ bool Replay::OpenReplay(const wchar_t* name) { ...@@ -115,6 +115,14 @@ bool Replay::OpenReplay(const wchar_t* name) {
std::fclose(rfp); std::fclose(rfp);
return false; return false;
} }
if(pheader.id != 0x31707279 || pheader.version < 0x12d0u) {
std::fclose(rfp);
return false;
}
if (pheader.version >= 0x1353u && !(pheader.flag & REPLAY_UNIFORM)) {
std::fclose(rfp);
return false;
}
if(pheader.flag & REPLAY_COMPRESSED) { if(pheader.flag & REPLAY_COMPRESSED) {
comp_size = std::fread(comp_data, 1, MAX_COMP_SIZE, rfp); comp_size = std::fread(comp_data, 1, MAX_COMP_SIZE, rfp);
std::fclose(rfp); std::fclose(rfp);
...@@ -142,17 +150,6 @@ bool Replay::OpenReplay(const wchar_t* name) { ...@@ -142,17 +150,6 @@ bool Replay::OpenReplay(const wchar_t* name) {
data_position = 0; data_position = 0;
return true; return true;
} }
bool Replay::CheckReplay(const wchar_t* name) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
FILE* rfp = mywfopen(fname, "rb");
if(!rfp)
return false;
ReplayHeader rheader;
size_t count = std::fread(&rheader, sizeof rheader, 1, rfp);
std::fclose(rfp);
return count == 1 && rheader.id == 0x31707279 && rheader.version >= 0x12d0u && (rheader.version < 0x1353u || (rheader.flag & REPLAY_UNIFORM));
}
bool Replay::DeleteReplay(const wchar_t* name) { bool Replay::DeleteReplay(const wchar_t* name) {
wchar_t fname[256]; wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name); myswprintf(fname, L"./replay/%ls", name);
......
...@@ -53,7 +53,6 @@ public: ...@@ -53,7 +53,6 @@ public:
void SaveReplay(const wchar_t* name); void SaveReplay(const wchar_t* name);
// play // play
static bool CheckReplay(const wchar_t* name);
static bool DeleteReplay(const wchar_t* name); static bool DeleteReplay(const wchar_t* name);
static bool RenameReplay(const wchar_t* oldname, const wchar_t* newname); static bool RenameReplay(const wchar_t* oldname, const wchar_t* newname);
static size_t GetDeckPlayer(size_t deck_index) { static size_t GetDeckPlayer(size_t deck_index) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment