Fixed UTF-8 encoding of APPDATA and CWD on Windows.

This commit is contained in:
rude
2009-11-22 22:19:00 +01:00
parent df6389a170
commit a3f6a55593
6 changed files with 201 additions and 19 deletions
+40 -17
View File
@@ -18,10 +18,11 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "Filesystem.h"
#include <common/config.h>
// Physfs
//#include <physfs.h> // this gets included by virtue of Filesystem.h including File.h
#include <common/utf8.h>
#include "Filesystem.h"
namespace love
{
@@ -153,14 +154,26 @@ namespace physfs
const char * Filesystem::getWorkingDirectory()
{
#ifdef LOVE_WINDOWS
_getcwd(cwdbuffer, LOVE_MAX_PATH);
#else
char * temp = getcwd(cwdbuffer, LOVE_MAX_PATH);
if(temp == 0)
return 0;
#endif
return cwdbuffer;
if(cwd.empty())
{
#ifdef LOVE_WINDOWS
WCHAR w_cwd[LOVE_MAX_PATH];
_wgetcwd(w_cwd, LOVE_MAX_PATH);
cwd = to_utf8(w_cwd);
replace_char(cwd, '\\', '/');
#else
cwd = new char[LOVE_MAX_PATH];
if(!getcwd(cwd, LOVE_MAX_PATH))
{
delete [] cwd;
cwd = 0;
}
#endif
}
return cwd.c_str();
}
const char * Filesystem::getUserDirectory()
@@ -170,12 +183,22 @@ namespace physfs
const char * Filesystem::getAppdataDirectory()
{
#ifdef WINDOWS
return getenv("APPDATA");
#elif defined(LOVE_MACOSX)
std::string udir = getUserDirectory();
udir.append("/Library/Application Support");
return udir.c_str();
#ifdef LOVE_WINDOWS
if(appdata.empty())
{
wchar_t * w_appdata = _wgetenv(TEXT("APPDATA"));
appdata = to_utf8(w_appdata);
replace_char(appdata, '\\', '/');
}
return appdata.c_str();
#elif defined(LOVE_MACOSX
if(appdata.empty())
{
std::string udir = getUserDirectory();
udir.append("/Library/Application Support");
appdata = udir;
}
return appdata.c_str();
#else
return getUserDirectory();
#endif