Commit c23c19fa authored by nanahira's avatar nanahira

merge subdir in server

parents d0417aae de3fe3f2
......@@ -71,7 +71,13 @@ bool DataManager::LoadDB(const char* file) {
return true;
}
bool DataManager::LoadStrings(const char* file) {
#ifdef _WIN32
wchar_t fname[1024];
BufferIO::DecodeUTF8(file, fname);
FILE* fp = _wfopen(fname, L"r");
#else
FILE* fp = fopen(file, "r");
#endif // _WIN32
if(!fp)
return false;
char linebuf[256];
......
......@@ -13,7 +13,13 @@ DeckManager deckManager;
void DeckManager::LoadLFListSingle(const char* path) {
LFList* cur = NULL;
#ifdef _WIN32
wchar_t fname[1024];
BufferIO::DecodeUTF8(path, fname);
FILE* fp = _wfopen(fname, L"r");
#else
FILE* fp = fopen(path, "r");
#endif // _WIN32
char linebuf[256];
wchar_t strBuffer[256];
if(fp) {
......@@ -52,42 +58,15 @@ void DeckManager::LoadLFListSingle(const char* path) {
fclose(fp);
}
}
void DeckManager::LoadLFListDirectry(const char* path) {
char fpath[1000];
sprintf(fpath, "%s/lflist.conf", path);
LoadLFListSingle(fpath);
}
void DeckManager::LoadLFList() {
LoadLFListSingle("expansions/lflist.conf");
#ifdef _WIN32
char fpath[1000];
WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(L"./expansions/*", &fdataw);
if(fh != INVALID_HANDLE_VALUE) {
do {
if(wcscmp(L".",fdataw.cFileName) != 0 && wcscmp(L"..",fdataw.cFileName) != 0 && fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
char fname[780];
BufferIO::EncodeUTF8(fdataw.cFileName, fname);
sprintf(fpath, "./expansions/%s", fname);
LoadLFListDirectry(fpath);
}
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
}
#else
DIR * dir;
struct dirent * dirp;
if((dir = opendir("./expansions/")) != NULL) {
while((dirp = readdir(dir)) != NULL) {
if (strcmp(".", dirp->d_name) == 0 || strcmp("..", dirp->d_name) == 0 || dirp->d_type != DT_DIR)
continue;
char filepath[1000];
sprintf(filepath, "./expansions/%s", dirp->d_name);
LoadLFListDirectry(filepath);
FileSystem::TraversalDir("./expansions", [this](const char* name, bool isdir) {
if(isdir && strcmp(name, ".") && strcmp(name, "..")) {
char fpath[1024];
sprintf(fpath, "./expansions/%s/lflist.conf", name);
LoadLFListSingle(fpath);
}
closedir(dir);
}
#endif
});
LoadLFListSingle("lflist.conf");
LFList nolimit;
myswprintf(nolimit.listName, L"N/A");
......
......@@ -36,7 +36,6 @@ public:
std::vector<LFList> _lfList;
void LoadLFListSingle(const char* path);
void LoadLFListDirectry(const char* path);
void LoadLFList();
wchar_t* GetLFListName(int lfhash);
int CheckDeck(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg);
......
......@@ -1045,107 +1045,33 @@ void Game::SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gu
#endif //YGOPRO_SERVER_MODE
void Game::LoadExpansionDB() {
LoadExpansionDBDirectry("./expansions");
#ifdef _WIN32
char fpath[1000];
WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(L"./expansions/*", &fdataw);
if(fh != INVALID_HANDLE_VALUE) {
do {
if(wcscmp(L".",fdataw.cFileName) != 0 && wcscmp(L"..",fdataw.cFileName) != 0 && fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
char fname[780];
BufferIO::EncodeUTF8(fdataw.cFileName, fname);
sprintf(fpath, "./expansions/%s", fname);
LoadExpansionDBDirectry(fpath);
}
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
}
#else
DIR * dir;
struct dirent * dirp;
if((dir = opendir("./expansions/")) != NULL) {
while((dirp = readdir(dir)) != NULL) {
if (strcmp(".", dirp->d_name) == 0 || strcmp("..", dirp->d_name) == 0 || dirp->d_type != DT_DIR)
continue;
char filepath[1000];
sprintf(filepath, "./expansions/%s/", dirp->d_name);
LoadExpansionDBDirectry(filepath);
FileSystem::TraversalDir("./expansions", [this](const char* name, bool isdir) {
if(isdir && strcmp(name, ".") && strcmp(name, "..")) {
char subdir[1024];
sprintf(subdir, "./expansions/%s", name);
LoadExpansionDBDirectry(subdir);
}
closedir(dir);
}
#endif
});
}
void Game::LoadExpansionDBDirectry(const char* path) {
#ifdef _WIN32
char fpath[1000];
wchar_t wpath1[1000];
wchar_t wpath2[1000];
BufferIO::DecodeUTF8(path, wpath1);
myswprintf(wpath2, L"%ls/*.cdb", wpath1);
WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(wpath2, &fdataw);
if(fh != INVALID_HANDLE_VALUE) {
do {
if(!(fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
char fname[780];
BufferIO::EncodeUTF8(fdataw.cFileName, fname);
sprintf(fpath, "%s/%s", path, fname);
dataManager.LoadDB(fpath);
}
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
}
#else
DIR * dir;
struct dirent * dirp;
if((dir = opendir(path)) != NULL) {
while((dirp = readdir(dir)) != NULL) {
size_t len = strlen(dirp->d_name);
if(len < 5 || strcasecmp(dirp->d_name + len - 4, ".cdb") != 0)
continue;
char filepath[1000];
sprintf(filepath, "%s/%s", path, dirp->d_name);
dataManager.LoadDB(filepath);
FileSystem::TraversalDir(path, [path](const char* name, bool isdir) {
if(!isdir && strrchr(name, '.') && !mystrncasecmp(strrchr(name, '.'), ".cdb", 4)) {
char fpath[1024];
sprintf(fpath, "%s/%s", path, name);
dataManager.LoadDB(fpath);
}
});
}
#ifndef YGOPRO_SERVER_MODE
void Game::LoadExpansionStrings() {
LoadExpansionStringsDirectry("./expansions");
#ifdef _WIN32
char fpath[1000];
WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(L"./expansions/*", &fdataw);
if(fh != INVALID_HANDLE_VALUE) {
do {
if(wcscmp(L".",fdataw.cFileName) != 0 && wcscmp(L"..",fdataw.cFileName) != 0 && fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
char fname[780];
BufferIO::EncodeUTF8(fdataw.cFileName, fname);
sprintf(fpath, "./expansions/%s", fname);
LoadExpansionStringsDirectry(fpath);
}
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
}
#else
DIR * dir;
struct dirent * dirp;
if((dir = opendir("./expansions/")) != NULL) {
while((dirp = readdir(dir)) != NULL) {
if (strcmp(".", dirp->d_name) == 0 || strcmp("..", dirp->d_name) == 0 || dirp->d_type != DT_DIR)
continue;
char filepath[1000];
sprintf(filepath, "./expansions/%s/", dirp->d_name);
LoadExpansionStringsDirectry(filepath);
dataManager.LoadStrings("./expansions/strings.conf");
FileSystem::TraversalDir("./expansions", [](const char* name, bool isdir) {
if(isdir && strcmp(name, ".") && strcmp(name, "..")) {
char fpath[1024];
sprintf(fpath, "./expansions/%s/strings.conf", name);
dataManager.LoadStrings(fpath);
}
closedir(dir);
}
#endif
}
void Game::LoadExpansionStringsDirectry(const char* path) {
char fpath[1000];
sprintf(fpath, "%s/strings.conf", path);
dataManager.LoadStrings(fpath);
});
}
void Game::RefreshDeck(irr::gui::IGUIComboBox* cbDeck) {
cbDeck->clear();
......
......@@ -144,7 +144,6 @@ public:
void LoadExpansionDB();
void LoadExpansionDBDirectry(const char* path);
void LoadExpansionStrings();
void LoadExpansionStringsDirectry(const char* path);
void RefreshDeck(irr::gui::IGUIComboBox* cbDeck);
void RefreshReplay();
void RefreshSingleplay();
......
......@@ -271,23 +271,30 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
}
}
irr::video::ITexture* ImageManager::GetTextureFromFile(char* file, s32 width, s32 height) {
#ifdef _WIN32
wchar_t name[1024];
BufferIO::DecodeUTF8(file, name);
#else
char* name = file;
#endif // _WIN32
if(mainGame->gameConf.use_image_scale) {
irr::video::ITexture* texture;
irr::video::IImage* srcimg = driver->createImageFromFile(file);
irr::video::IImage* srcimg = driver->createImageFromFile(name);
if(srcimg == NULL)
return NULL;
if(srcimg->getDimension() == irr::core::dimension2d<u32>(width, height)) {
texture = driver->addTexture(file, srcimg);
texture = driver->addTexture(name, srcimg);
} else {
video::IImage *destimg = driver->createImage(srcimg->getColorFormat(), irr::core::dimension2d<u32>(width, height));
imageScaleNNAA(srcimg, destimg);
texture = driver->addTexture(file, destimg);
texture = driver->addTexture(name, destimg);
destimg->drop();
}
srcimg->drop();
return texture;
} else {
return driver->getTexture(file);
return driver->getTexture(name);
}
}
irr::video::ITexture* ImageManager::GetTextureUnknown(s32 width, s32 height, int index) {
......@@ -299,39 +306,18 @@ irr::video::ITexture* ImageManager::GetTextureExpansions(char* file, s32 width,
irr::video::ITexture* img = GetTextureExpansionsDirectry("./expansions", file, width, height);
if(img != NULL)
return img;
#ifdef _WIN32
char fpath[1000];
WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(L"./expansions/*", &fdataw);
if(fh != INVALID_HANDLE_VALUE) {
do {
if(wcscmp(L".",fdataw.cFileName) != 0 && wcscmp(L"..",fdataw.cFileName) != 0 && fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
char fname[780];
BufferIO::EncodeUTF8(fdataw.cFileName, fname);
sprintf(fpath, "./expansions/%s", fname);
img = GetTextureExpansionsDirectry(fpath, file, width, height);
if(img != NULL)
return img;
}
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
}
#else
DIR * dir;
struct dirent * dirp;
if((dir = opendir("./expansions/")) != NULL) {
while((dirp = readdir(dir)) != NULL) {
if (strcmp(".", dirp->d_name) == 0 || strcmp("..", dirp->d_name) == 0 || dirp->d_type != DT_DIR)
continue;
char filepath[1000];
sprintf(filepath, "./expansions/%s/", dirp->d_name);
img = GetTextureExpansionsDirectry(filepath, file, width, height);
if(img != NULL)
return img;
bool find = false;
FileSystem::TraversalDir("./expansions", [this, file, width, height, &img, &find](const char* name, bool isdir) {
if(!find && isdir && strcmp(name, ".") && strcmp(name, "..")) {
char subdir[1024];
sprintf(subdir, "./expansions/%s", name);
img = GetTextureExpansionsDirectry(subdir, file, width, height);
if(img)
find = true;
}
closedir(dir);
}
#endif
});
if(find)
return img;
return img;
}
irr::video::ITexture* ImageManager::GetTextureExpansionsDirectry(const char* path, char* file, s32 width, s32 height) {
......
......@@ -952,39 +952,18 @@ byte* ReplayMode::ScriptReaderEx(const char* script_name, int* slen) {
buffer = ScriptReaderExDirectry("./beta", script_name, slen);
if(buffer)
return buffer;
#ifdef _WIN32
char fpath[1000];
WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(L"./expansions/*", &fdataw);
if(fh != INVALID_HANDLE_VALUE) {
do {
if(wcscmp(L".",fdataw.cFileName) != 0 && wcscmp(L"..",fdataw.cFileName) != 0 && fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
char fname[780];
BufferIO::EncodeUTF8(fdataw.cFileName, fname);
sprintf(fpath, "./expansions/%s", fname);
buffer = ScriptReaderExDirectry(fpath, script_name, slen);
if(buffer)
return buffer;
}
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
}
#else
DIR * dir;
struct dirent * dirp;
if((dir = opendir("./expansions/")) != NULL) {
while((dirp = readdir(dir)) != NULL) {
if (strcmp(".", dirp->d_name) == 0 || strcmp("..", dirp->d_name) == 0 || dirp->d_type != DT_DIR)
continue;
char filepath[1000];
sprintf(filepath, "./expansions/%s/", dirp->d_name);
buffer = ScriptReaderExDirectry(filepath, script_name, slen);
bool find = false;
FileSystem::TraversalDir("./expansions", [script_name, slen, &buffer, &find](const char* name, bool isdir) {
if(!find && isdir && strcmp(name, ".") && strcmp(name, "..")) {
char subdir[1024];
sprintf(subdir, "./expansions/%s", name);
buffer = ScriptReaderExDirectry(subdir, script_name, slen);
if(buffer)
return buffer;
find = true;
}
closedir(dir);
}
#endif
});
if(find)
return buffer;
return default_script_reader(script_name, slen);
}
byte* ReplayMode::ScriptReaderExDirectry(const char* path, const char* script_name, int* slen, int pre_len) {
......
......@@ -2135,39 +2135,18 @@ byte* SingleDuel::ScriptReaderEx(const char* script_name, int* slen) {
buffer = ScriptReaderExDirectry("./beta", script_name, slen);
if(buffer)
return buffer;
#ifdef _WIN32
char fpath[1000];
WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(L"./expansions/*", &fdataw);
if(fh != INVALID_HANDLE_VALUE) {
do {
if(wcscmp(L".",fdataw.cFileName) != 0 && wcscmp(L"..",fdataw.cFileName) != 0 && fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
char fname[780];
BufferIO::EncodeUTF8(fdataw.cFileName, fname);
sprintf(fpath, "./expansions/%s", fname);
buffer = ScriptReaderExDirectry(fpath, script_name, slen);
if(buffer)
return buffer;
}
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
}
#else
DIR * dir;
struct dirent * dirp;
if((dir = opendir("./expansions/")) != NULL) {
while((dirp = readdir(dir)) != NULL) {
if (strcmp(".", dirp->d_name) == 0 || strcmp("..", dirp->d_name) == 0 || dirp->d_type != DT_DIR)
continue;
char filepath[1000];
sprintf(filepath, "./expansions/%s/", dirp->d_name);
buffer = ScriptReaderExDirectry(filepath, script_name, slen);
bool find = false;
FileSystem::TraversalDir("./expansions", [script_name, slen, &buffer, &find](const char* name, bool isdir) {
if(!find && isdir && strcmp(name, ".") && strcmp(name, "..")) {
char subdir[1024];
sprintf(subdir, "./expansions/%s", name);
buffer = ScriptReaderExDirectry(subdir, script_name, slen);
if(buffer)
return buffer;
find = true;
}
closedir(dir);
}
#endif
});
if(find)
return buffer;
return default_script_reader(script_name, slen);
}
byte* SingleDuel::ScriptReaderExDirectry(const char* path, const char* script_name, int* slen, int pre_len) {
......
......@@ -872,45 +872,23 @@ byte* SingleMode::ScriptReaderEx(const char* script_name, int* slen) {
buffer = ScriptReaderExDirectry("./beta", script_name, slen);
if(buffer)
return buffer;
#ifdef _WIN32
char fpath[1000];
WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(L"./expansions/*", &fdataw);
if(fh != INVALID_HANDLE_VALUE) {
do {
if(wcscmp(L".",fdataw.cFileName) != 0 && wcscmp(L"..",fdataw.cFileName) != 0 && fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
char fname[780];
BufferIO::EncodeUTF8(fdataw.cFileName, fname);
sprintf(fpath, "./expansions/%s", fname);
buffer = ScriptReaderExDirectry(fpath, script_name, slen);
if(buffer)
return buffer;
}
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
}
#else
DIR * dir;
struct dirent * dirp;
if((dir = opendir("./expansions/")) != NULL) {
while((dirp = readdir(dir)) != NULL) {
if (strcmp(".", dirp->d_name) == 0 || strcmp("..", dirp->d_name) == 0 || dirp->d_type != DT_DIR)
continue;
char filepath[1000];
sprintf(filepath, "./expansions/%s/", dirp->d_name);
buffer = ScriptReaderExDirectry(filepath, script_name, slen);
bool find = false;
FileSystem::TraversalDir("./expansions", [script_name, slen, &buffer, &find](const char* name, bool isdir) {
if(!find && isdir && strcmp(name, ".") && strcmp(name, "..")) {
char subdir[1024];
sprintf(subdir, "./expansions/%s", name);
buffer = ScriptReaderExDirectry(subdir, script_name, slen);
if(buffer)
return buffer;
find = true;
}
closedir(dir);
}
#endif
});
if(find)
return buffer;
return ScriptReader(script_name, slen);
}
byte* SingleMode::ScriptReaderExDirectry(const char* path, const char* script_name, int* slen, int pre_len) {
char sname[256];
strcpy(sname, path);
strcat(sname, script_name + pre_len);//default script name: ./script/c%d.lua
sprintf(sname, "%s%s", path, script_name + pre_len); //default script name: ./script/c%d.lua
return ScriptReader(sname, slen);
}
byte* SingleMode::ScriptReader(const char* script_name, int* slen) {
......
......@@ -2295,39 +2295,18 @@ byte* TagDuel::ScriptReaderEx(const char* script_name, int* slen) {
buffer = ScriptReaderExDirectry("./beta", script_name, slen);
if(buffer)
return buffer;
#ifdef _WIN32
char fpath[1000];
WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(L"./expansions/*", &fdataw);
if(fh != INVALID_HANDLE_VALUE) {
do {
if(wcscmp(L".",fdataw.cFileName) != 0 && wcscmp(L"..",fdataw.cFileName) != 0 && fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
char fname[780];
BufferIO::EncodeUTF8(fdataw.cFileName, fname);
sprintf(fpath, "./expansions/%s", fname);
buffer = ScriptReaderExDirectry(fpath, script_name, slen);
if(buffer)
return buffer;
}
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
}
#else
DIR * dir;
struct dirent * dirp;
if((dir = opendir("./expansions/")) != NULL) {
while((dirp = readdir(dir)) != NULL) {
if (strcmp(".", dirp->d_name) == 0 || strcmp("..", dirp->d_name) == 0 || dirp->d_type != DT_DIR)
continue;
char filepath[1000];
sprintf(filepath, "./expansions/%s/", dirp->d_name);
buffer = ScriptReaderExDirectry(filepath, script_name, slen);
bool find = false;
FileSystem::TraversalDir("./expansions", [script_name, slen, &buffer, &find](const char* name, bool isdir) {
if(!find && isdir && strcmp(name, ".") && strcmp(name, "..")) {
char subdir[1024];
sprintf(subdir, "./expansions/%s", name);
buffer = ScriptReaderExDirectry(subdir, script_name, slen);
if(buffer)
return buffer;
find = true;
}
closedir(dir);
}
#endif
});
if(find)
return buffer;
return default_script_reader(script_name, slen);
}
byte* TagDuel::ScriptReaderExDirectry(const char* path, const char* script_name, int* slen, int pre_len) {
......
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