Commit 051949fb authored by Chen Bill's avatar Chen Bill Committed by GitHub

use reference to array in IsExtension (#2808)

* simplify

* use reference to array in IsExtension
parent 5ec2549a
......@@ -50,22 +50,6 @@ void DuelInfo::Clear() {
time_left[1] = 0;
}
bool IsExtension(const wchar_t* filename, const wchar_t* extension) {
auto flen = std::wcslen(filename);
auto elen = std::wcslen(extension);
if (!elen || flen < elen)
return false;
return !mywcsncasecmp(filename + (flen - elen), extension, elen);
}
bool IsExtension(const char* filename, const char* extension) {
auto flen = std::strlen(filename);
auto elen = std::strlen(extension);
if (!elen || flen < elen)
return false;
return !mystrncasecmp(filename + (flen - elen), extension, elen);
}
bool Game::Initialize() {
LoadConfig();
irr::SIrrlichtCreationParameters params{};
......@@ -1141,19 +1125,21 @@ std::wstring Game::SetStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cW
}
void Game::LoadExpansions() {
FileSystem::TraversalDir(L"./expansions", [](const wchar_t* name, bool isdir) {
if (isdir)
return;
wchar_t fpath[1024];
myswprintf(fpath, L"./expansions/%ls", name);
if (!isdir && IsExtension(name, L".cdb")) {
if (IsExtension(name, L".cdb")) {
dataManager.LoadDB(fpath);
return;
}
if (!isdir && IsExtension(name, L".conf")) {
if (IsExtension(name, L".conf")) {
char upath[1024];
BufferIO::EncodeUTF8(fpath, upath);
dataManager.LoadStrings(upath);
return;
}
if (!isdir && (IsExtension(name, L".zip") || IsExtension(name, L".ypk"))) {
if (IsExtension(name, L".zip") || IsExtension(name, L".ypk")) {
#ifdef _WIN32
DataManager::FileSystem->addFileArchive(fpath, true, false, irr::io::EFAT_ZIP);
#else
......
......@@ -28,8 +28,23 @@ constexpr int TEXT_LINE_SIZE = 256;
namespace ygo {
bool IsExtension(const wchar_t* filename, const wchar_t* extension);
bool IsExtension(const char* filename, const char* extension);
template<size_t N>
bool IsExtension(const wchar_t* filename, const wchar_t(&extension)[N]) {
auto flen = std::wcslen(filename);
constexpr size_t elen = N - 1;
if (!elen || flen < elen)
return false;
return !mywcsncasecmp(filename + (flen - elen), extension, elen);
}
template<size_t N>
bool IsExtension(const char* filename, const char(&extension)[N]) {
auto flen = std::strlen(filename);
constexpr size_t elen = N - 1;
if (!elen || flen < elen)
return false;
return !mystrncasecmp(filename + (flen - elen), extension, elen);
}
struct Config {
bool use_d3d{ false };
......
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