Commit 113e0e8b authored by mercury233's avatar mercury233

use reader in DeckManager::LoadDeck

parent 21a27fc4
......@@ -5,6 +5,7 @@
namespace ygo {
char DeckManager::deckBuffer[0x10000];
DeckManager deckManager;
void DeckManager::LoadLFListSingle(const char* path) {
......@@ -254,20 +255,38 @@ FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
#endif
return fp;
}
IReadFile* DeckManager::OpenDeckReader(const wchar_t* file) {
#ifdef WIN32
IReadFile* reader = dataManager.FileSystem->createAndOpenFile(file);
#else
char file2[256];
BufferIO::EncodeUTF8(file, file2);
IReadFile* reader = dataManager.FileSystem->createAndOpenFile(file2);
#endif
return reader;
}
bool DeckManager::LoadDeck(const wchar_t* file, bool is_packlist) {
int sp = 0, ct = 0, mainc = 0, sidec = 0, code;
FILE* fp = OpenDeckFile(file, "r");
if(!fp) {
IReadFile* reader = OpenDeckReader(file);
if(!reader) {
wchar_t localfile[64];
myswprintf(localfile, L"./deck/%ls.ydk", file);
fp = OpenDeckFile(localfile, "r");
reader = OpenDeckReader(localfile);
}
if(!fp)
if(!reader)
return false;
size_t size = reader->getSize();
if(size >= 0x20000) {
reader->drop();
return false;
}
reader->read(deckBuffer, size);
reader->drop();
std::istringstream deckStream(deckBuffer);
int sp = 0, ct = 0, mainc = 0, sidec = 0, code;
int cardlist[300];
bool is_side = false;
char linebuf[256];
while(fgets(linebuf, 256, fp) && ct < 300) {
std::string linebuf;
while(std::getline(deckStream, linebuf) && ct < 300) {
if(linebuf[0] == '!') {
is_side = true;
continue;
......@@ -277,12 +296,11 @@ bool DeckManager::LoadDeck(const wchar_t* file, bool is_packlist) {
sp = 0;
while(linebuf[sp] >= '0' && linebuf[sp] <= '9') sp++;
linebuf[sp] = 0;
code = atoi(linebuf);
code = atoi(linebuf.c_str());
cardlist[ct++] = code;
if(is_side) sidec++;
else mainc++;
}
fclose(fp);
LoadDeck(current_deck, cardlist, mainc, sidec, is_packlist);
return true;
}
......
......@@ -5,6 +5,7 @@
#include "client_card.h"
#include <unordered_map>
#include <vector>
#include <sstream>
namespace ygo {
......@@ -35,6 +36,8 @@ public:
Deck current_deck;
std::vector<LFList> _lfList;
static char deckBuffer[0x10000];
void LoadLFListSingle(const char* path);
void LoadLFList();
const wchar_t* GetLFListName(int lfhash);
......@@ -45,7 +48,8 @@ public:
void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text);
void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
bool LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
FILE* OpenDeckFile(const wchar_t * file, const char * mode);
FILE* OpenDeckFile(const wchar_t* file, const char* mode);
IReadFile* OpenDeckReader(const wchar_t* file);
bool LoadDeck(const wchar_t* file, bool is_packlist = false);
bool SaveDeck(Deck& deck, const wchar_t* file);
bool DeleteDeck(const wchar_t* file);
......
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