win32: Search resources in the executable directory by default instead of the current directory. Because new default location is much more predictable.

This commit is contained in:
Vladimir Timofeev 2015-02-06 15:12:02 +03:00 committed by Vladimir Timofeev
parent 95bb2b7b7b
commit 653bf1549d
1 changed files with 10 additions and 7 deletions

View File

@ -29,6 +29,7 @@ THE SOFTWARE.
#include "CCFileUtils-win32.h"
#include "platform/CCCommon.h"
#include <Shlobj.h>
#include <cstdlib>
using namespace std;
@ -59,14 +60,16 @@ static void _checkPath()
{
if (0 == s_resourcePath.length())
{
WCHAR utf16Path[CC_MAX_PATH] = {0};
GetCurrentDirectoryW(sizeof(utf16Path)-1, utf16Path);
char utf8Path[CC_MAX_PATH] = {0};
int nNum = WideCharToMultiByte(CP_UTF8, 0, utf16Path, -1, utf8Path, sizeof(utf8Path), nullptr, nullptr);
WCHAR *pUtf16ExePath = nullptr;
_get_wpgmptr(&pUtf16ExePath);
s_resourcePath = convertPathFormatToUnixStyle(utf8Path);
s_resourcePath.append("/");
// We need only directory part without exe
WCHAR *pUtf16DirEnd = wcsrchr(pUtf16ExePath, L'\\');
char utf8ExeDir[CC_MAX_PATH] = { 0 };
int nNum = WideCharToMultiByte(CP_UTF8, 0, pUtf16ExePath, pUtf16DirEnd-pUtf16ExePath+1, utf8ExeDir, sizeof(utf8ExeDir), nullptr, nullptr);
s_resourcePath = convertPathFormatToUnixStyle(utf8ExeDir);
}
}