Commit 41e1c2a8 authored by nanahira's avatar nanahira

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

parents 70108fa0 447e38c7
Pipeline #36856 passed with stages
in 5 minutes and 43 seconds
......@@ -1351,7 +1351,7 @@ void Game::RefreshDeck(const wchar_t* deckpath, const std::function<void(const w
void Game::RefreshReplay() {
lstReplayList->clear();
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);
});
}
......
......@@ -513,10 +513,13 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
case LISTBOX_REPLAY_LIST: {
int sel = mainGame->lstReplayList->getSelected();
if(sel == -1)
if(sel < 0)
break;
auto filename = mainGame->lstReplayList->getListItem(sel);
if (!filename)
break;
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)) {
mainGame->stReplayInfo->setText(L"Error");
break;
......@@ -526,8 +529,13 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
time_t curtime;
if(temp_replay.pheader.flag & REPLAY_UNIFORM)
curtime = temp_replay.pheader.start_time;
else
else{
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));
repinfo.append(infobuf);
if (temp_replay.pheader.flag & REPLAY_SINGLE_MODE) {
......
......@@ -111,7 +111,16 @@ bool Replay::OpenReplay(const wchar_t* name) {
return false;
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);
return false;
}
......@@ -142,17 +151,6 @@ bool Replay::OpenReplay(const wchar_t* name) {
data_position = 0;
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) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
......
......@@ -53,7 +53,6 @@ public:
void SaveReplay(const wchar_t* name);
// play
static bool CheckReplay(const wchar_t* name);
static bool DeleteReplay(const wchar_t* name);
static bool RenameReplay(const wchar_t* oldname, const wchar_t* newname);
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