Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for get_folder_path #9562

Merged
merged 13 commits into from
Aug 17, 2021
26 changes: 11 additions & 15 deletions common/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#endif

#include <GLFW/glfw3.h>
#include "win/win-helpers.h"

namespace rs2
{
Expand Down Expand Up @@ -248,6 +249,8 @@ Some auxillary functionalities might be affected. Please report this message if
{
std::string res;
#ifdef _WIN32
using namespace librealsense::platform;
maloel marked this conversation as resolved.
Show resolved Hide resolved

if (f == temp_folder)
{
TCHAR buf[MAX_PATH];
Expand All @@ -267,21 +270,14 @@ Some auxillary functionalities might be affected. Please report this message if
case user_desktop: folder = FOLDERID_Desktop;
break;
case user_documents: folder = FOLDERID_Documents;
// Use for documents with SHGetFolderPath instead of SHGetKnownFolderPath because SHGetKnownFolderPath
// Doesn't give the path to intel one drive documents folder but to the local documents folder
TCHAR path[MAX_PATH];
hr = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, path);
if (SUCCEEDED(hr))
{
std::wstring wstring_path(&path[0]);
std::string string_path(wstring_path.begin(), wstring_path.end());
res = string_path;
res += "\\";
}
else
{
throw std::runtime_error("Failed to get requested special folder");
}
// The user's Documents folder location may get overridden, as we know OneDrive does in certain circumstances.
// In such cases, the new function, SHGetKnownFolderPath, does not always return the new path, while the deprecated
// function does.
CHAR path[MAX_PATH];
CHECK_HR(SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, 0, path));

res = path;
res += "\\";
return res;
case user_pictures: folder = FOLDERID_Pictures;
break;
Expand Down