diff options
author | Don Bright <hugh.m.bright@gmail.com> | 2013-05-27 03:55:14 (GMT) |
---|---|---|
committer | Don Bright <hugh.m.bright@gmail.com> | 2013-05-27 03:55:14 (GMT) |
commit | 6742ad55f4cf335fc767ab65784aab81e06b61d0 (patch) | |
tree | 53bf1b3661a8d0d894487d20906b26e498158649 | |
parent | 53e778af703e40e91c2021d4ab12f8d30e14bd60 (diff) |
fix buggy string init. remove debug string
-rw-r--r-- | src/PlatformUtils-win.cc | 16 | ||||
-rw-r--r-- | src/PlatformUtils.cc | 9 |
2 files changed, 18 insertions, 7 deletions
diff --git a/src/PlatformUtils-win.cc b/src/PlatformUtils-win.cc index a314ebe..a58a346 100644 --- a/src/PlatformUtils-win.cc +++ b/src/PlatformUtils-win.cc @@ -9,8 +9,6 @@ // convert from windows api w_char strings (usually utf16) to utf8 std::string std::string winapi_wstr_to_utf8( std::wstring wstr ) { - std::string utf8_str(""); - UINT CodePage = CP_UTF8; DWORD dwFlags = 0; LPCWSTR lpWideCharStr = &wstr[0]; @@ -23,6 +21,9 @@ std::string winapi_wstr_to_utf8( std::wstring wstr ) int numbytes = WideCharToMultiByte( CodePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar ); + //PRINTB("utf16 to utf8 conversion: numbytes %i",numbytes); + + std::string utf8_str(numbytes,0); lpMultiByteStr = &utf8_str[0]; cbMultiByte = numbytes; @@ -48,12 +49,19 @@ std::string PlatformUtils::documentsPath() std::string retval; std::wstring path(MAX_PATH,0); - HRESULT result = SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, - SHGFP_TYPE_CURRENT, &path[0]); + HWND hwndOwner = 0; + int nFolder = CSIDL_PERSONAL; + HANDLE hToken = NULL; + DWORD dwFlags = SHGFP_TYPE_CURRENT; + LPTSTR pszPath = &path[0]; + + int result = SHGetFolderPathW( hwndOwner, nFolder, hToken, dwFlags, pszPath ); if (result == S_OK) { path = std::wstring( path.c_str() ); // stip extra NULLs + //std::wcerr << "wchar path:" << "\n"; retval = winapi_wstr_to_utf8( path ); + //PRINTB("Path found: %s",retval); } else { PRINT("ERROR: Could not find My Documents location"); retval = ""; diff --git a/src/PlatformUtils.cc b/src/PlatformUtils.cc index 47569b0..5dd007d 100644 --- a/src/PlatformUtils.cc +++ b/src/PlatformUtils.cc @@ -7,7 +7,7 @@ bool PlatformUtils::createLibraryPath() bool OK = false; try { if (!fs::exists(fs::path(path))) { - PRINTB("Creating library folder %s", path ); + //PRINTB("Creating library folder %s", path ); OK = fs::create_directories( path ); } if (!OK) { @@ -23,11 +23,14 @@ std::string PlatformUtils::libraryPath() { fs::path path; try { - path = boosty::canonical(fs::path(PlatformUtils::documentsPath())); + std::string pathstr = PlatformUtils::documentsPath(); + if (pathstr=="") return ""; + path = boosty::canonical(fs::path( pathstr )); + //PRINTB("path size %i",boosty::stringy(path).size()); + //PRINTB("lib path found: [%s]", path ); if (path.empty()) return ""; path /= "OpenSCAD"; path /= "libraries"; - //PRINTB("path size %i",boosty::stringy(path).size()); //PRINTB("Appended path %s", path ); //PRINTB("Exists: %i", fs::exists(path) ); } catch (const fs::filesystem_error& ex) { |