Commit 83e21402 authored by Chen Bill's avatar Chen Bill Committed by GitHub

fix set working directory (#2706)

parent 9d913e88
......@@ -58,6 +58,14 @@ bool IsExtension(const wchar_t* filename, const wchar_t* extension) {
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 = irr::SIrrlichtCreationParameters();
......
......@@ -29,6 +29,7 @@ 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);
struct Config {
bool use_d3d{ false };
......
......@@ -36,17 +36,15 @@ int main(int argc, char* argv[]) {
CFRelease(path);
#endif //__APPLE__
#ifdef _WIN32
#ifndef _DEBUG
char* pstrext;
if(argc == 2 && (pstrext = std::strrchr(argv[1], '.'))
&& (!mystrncasecmp(pstrext, ".ydk", 4) || !mystrncasecmp(pstrext, ".yrp", 4))) {
if (argc == 2 && (ygo::IsExtension(argv[1], ".ydk") || ygo::IsExtension(argv[1], ".yrp"))) { // open file from explorer
wchar_t exepath[MAX_PATH];
GetModuleFileNameW(nullptr, exepath, MAX_PATH);
wchar_t* p = std::wcsrchr(exepath, '\\');
*p = '\0';
SetCurrentDirectoryW(exepath);
wchar_t* p = std::wcsrchr(exepath, L'\\');
if (p) {
*p = 0;
SetCurrentDirectoryW(exepath);
}
}
#endif //_DEBUG
#endif //_WIN32
#ifdef _WIN32
WORD wVersionRequested;
......
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