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