Commit b5001317 authored by nanahira's avatar nanahira

Merge branch 'patch-check' of github.com:salix5/ygopro into develop

parents b262c5da 447e38c7
...@@ -1265,7 +1265,7 @@ void Game::RefreshDeck(const wchar_t* deckpath, const std::function<void(const w ...@@ -1265,7 +1265,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);
}); });
} }
......
...@@ -523,10 +523,13 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -523,10 +523,13 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
} }
case LISTBOX_REPLAY_LIST: { case LISTBOX_REPLAY_LIST: {
int sel = mainGame->lstReplayList->getSelected(); int sel = mainGame->lstReplayList->getSelected();
if(sel == -1) if(sel < 0)
break;
auto filename = mainGame->lstReplayList->getListItem(sel);
if (!filename)
break; break;
wchar_t replay_path[256]{}; wchar_t replay_path[256]{};
myswprintf(replay_path, L"./replay/%ls", mainGame->lstReplayList->getListItem(sel)); myswprintf(replay_path, L"./replay/%ls", filename);
if (!temp_replay.OpenReplay(replay_path)) { if (!temp_replay.OpenReplay(replay_path)) {
mainGame->stReplayInfo->setText(L"Error"); mainGame->stReplayInfo->setText(L"Error");
break; break;
...@@ -536,8 +539,13 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -536,8 +539,13 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
time_t curtime; time_t curtime;
if(temp_replay.pheader.flag & REPLAY_UNIFORM) if(temp_replay.pheader.flag & REPLAY_UNIFORM)
curtime = temp_replay.pheader.start_time; curtime = temp_replay.pheader.start_time;
else else{
curtime = temp_replay.pheader.seed; curtime = temp_replay.pheader.seed;
wchar_t version_info[256]{};
myswprintf(version_info, L"version 0x%X", temp_replay.pheader.version);
repinfo.append(version_info);
repinfo.append(L"\n");
}
std::wcsftime(infobuf, sizeof infobuf / sizeof infobuf[0], L"%Y/%m/%d %H:%M:%S\n", std::localtime(&curtime)); std::wcsftime(infobuf, sizeof infobuf / sizeof infobuf[0], L"%Y/%m/%d %H:%M:%S\n", std::localtime(&curtime));
repinfo.append(infobuf); repinfo.append(infobuf);
if (temp_replay.pheader.flag & REPLAY_SINGLE_MODE) { if (temp_replay.pheader.flag & REPLAY_SINGLE_MODE) {
......
...@@ -111,7 +111,16 @@ bool Replay::OpenReplay(const wchar_t* name) { ...@@ -111,7 +111,16 @@ bool Replay::OpenReplay(const wchar_t* name) {
return false; return false;
Reset(); Reset();
if(std::fread(&pheader, sizeof pheader, 1, rfp) < 1) { bool correct_header = true;
if (std::fread(&pheader, sizeof pheader, 1, rfp) < 1)
correct_header = false;
else if (pheader.id != 0x31707279)
correct_header = false;
else if (pheader.version < 0x12d0u)
correct_header = false;
else if (pheader.version >= 0x1353u && !(pheader.flag & REPLAY_UNIFORM))
correct_header = false;
if (!correct_header) {
std::fclose(rfp); std::fclose(rfp);
return false; return false;
} }
...@@ -142,17 +151,6 @@ bool Replay::OpenReplay(const wchar_t* name) { ...@@ -142,17 +151,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