diff --git a/src/of_path.cpp b/src/of_path.cpp index da47dde..c25a969 100644 --- a/src/of_path.cpp +++ b/src/of_path.cpp @@ -81,9 +81,12 @@ ofString COfPath::get_home() std::size_t len = 0; // _dupenv_s() 在 Visual Studio 2008 的 CRT (msvcr90) 中引入的,似乎没有进入系统 CRT (msvcrt)。 // mingw-w64 GCC 通常默认只链接到系统 CRT,所以所以找不到这个符号。 - #if defined(__MINGW32__) || defined(__MINGW64__) +#ifdef UNICODE_OFSTR + ofChar* homedir = _wgetenv(ofT("USERPROFILE")); +#else ofChar* homedir = getenv("USERPROFILE"); +#endif if (homedir) { return ofString(homedir); } @@ -147,12 +150,17 @@ bool COfPath::exist(const ofString& path) bool COfPath::write(const ofString& path, const char* data, int len) { - std::ofstream file(path, std::ios::binary); - if (!file.is_open()) { + FILE* f = nullptr; +#ifdef UNICODE_OFSTR + f = _wfopen(path.c_str(), ofT("wb")); +#else + f = fopen(path.c_str(), ofT("wb")); +#endif + if (!f) { return false; } - file.write(data, len); - file.close(); + fwrite(data, 1, len, f); + fclose(f); return true; }