diff --git a/common/device-model.cpp b/common/device-model.cpp index 277e8009b8..55f4178d92 100644 --- a/common/device-model.cpp +++ b/common/device-model.cpp @@ -13,6 +13,7 @@ #include "imgui-fonts-fontawesome.hpp" #include "imgui-fonts-monofont.hpp" +#include #include "os.h" #include #include "viewer.h" @@ -416,7 +417,7 @@ namespace rs2 refresh_notifications(viewer); - auto path = get_folder_path( special_folder::user_documents ); + auto path = rsutils::os::get_special_folder( rsutils::os::special_folder::user_documents ); path += "librealsense2/presets/"; try { diff --git a/common/fw-update-helper.cpp b/common/fw-update-helper.cpp index ff635df36a..9ed024f339 100644 --- a/common/fw-update-helper.cpp +++ b/common/fw-update-helper.cpp @@ -6,6 +6,7 @@ #include "viewer.h" #include "ux-window.h" +#include #include "os.h" #include @@ -234,7 +235,7 @@ namespace rs2 // Not all cameras supports this feature if( !flash.empty() ) { - auto temp = get_folder_path( special_folder::app_data ); + auto temp = rsutils::os::get_special_folder( rsutils::os::special_folder::app_data ); temp += serial + "." + get_timestamped_file_name() + ".bin"; { diff --git a/common/os.cpp b/common/os.cpp index f052185a59..6e2b029360 100644 --- a/common/os.cpp +++ b/common/os.cpp @@ -255,105 +255,6 @@ Some auxillary functionalities might be affected. Please report this message if return buffer; } - std::string get_folder_path(special_folder f) - { - std::string res; -#ifdef _WIN32 - - if (f == temp_folder) - { - TCHAR buf[MAX_PATH]; - if (GetTempPath(MAX_PATH, buf) != 0) - { - char str[1024]; - wcstombs(str, buf, 1023); - res = str; - } - } - else - { - GUID folder; - HRESULT hr; - switch (f) - { - case user_desktop: folder = FOLDERID_Desktop; - break; - case user_documents: folder = FOLDERID_Documents; - // 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; - case user_videos: folder = FOLDERID_Videos; - break; - case app_data: folder = FOLDERID_RoamingAppData; - break; - default: - throw std::invalid_argument( - std::string("Value of f (") + std::to_string(f) + std::string(") is not supported")); - } - - PWSTR folder_path = NULL; - hr = SHGetKnownFolderPath(folder, KF_FLAG_DEFAULT_PATH, NULL, &folder_path); - if (SUCCEEDED(hr)) - { - char str[1024]; - wcstombs(str, folder_path, 1023); - CoTaskMemFree(folder_path); - res = str; - res += "\\"; - } - else - { - throw std::runtime_error("Failed to get requested special folder"); - } - } -#endif //_WIN32 -#if defined __linux__ || defined __APPLE__ - if (f == special_folder::temp_folder) - { - const char* tmp_dir = getenv("TMPDIR"); - res = tmp_dir ? tmp_dir : "/tmp/"; - } - else - { - const char* home_dir = getenv("HOME"); - if (!home_dir) - { - struct passwd* pw = getpwuid(getuid()); - home_dir = (pw && pw->pw_dir) ? pw->pw_dir : ""; - } - if (home_dir) - { - res = home_dir; - switch (f) - { - case user_desktop: res += "/Desktop/"; - break; - case user_documents: res += "/Documents/"; - break; - case user_pictures: res += "/Pictures/"; - break; - case user_videos: res += "/Videos/"; - break; - case app_data: res += "/."; - break; - default: - throw std::invalid_argument( - std::string("Value of f (") + std::to_string(f) + std::string(") is not supported")); - } - } - } -#endif // defined __linux__ || defined __APPLE__ - return res; - } - bool ends_with(const std::string& s, const std::string& suffix) { auto i = s.rbegin(), j = suffix.rbegin(); diff --git a/common/os.h b/common/os.h index de21ee4b81..7fdc7edc00 100644 --- a/common/os.h +++ b/common/os.h @@ -50,18 +50,7 @@ namespace rs2 size_t pixel_width, size_t pixels_height, size_t bytes_per_pixel, const void* raster_data, size_t stride_bytes); - enum special_folder - { - user_desktop, - user_documents, - user_pictures, - user_videos, - temp_folder, - app_data - }; - std::string get_timestamped_file_name(); - std::string get_folder_path(special_folder f); std::string url_encode(const std::string &value); diff --git a/common/rs-config.cpp b/common/rs-config.cpp index 2aa7597dda..4005208326 100644 --- a/common/rs-config.cpp +++ b/common/rs-config.cpp @@ -3,6 +3,7 @@ #include "rs-config.h" +#include #include #include "model-views.h" @@ -88,8 +89,8 @@ void config_file::save(const char* filename) config_file& config_file::instance() { - static config_file inst(get_folder_path(rs2::special_folder::app_data) - + std::string("realsense-config.json")); + static config_file inst( rsutils::os::get_special_folder( rsutils::os::special_folder::app_data ) + + "realsense-config.json" ); return inst; } diff --git a/common/ux-window.cpp b/common/ux-window.cpp index 7fe0fbae88..51e86e4747 100644 --- a/common/ux-window.cpp +++ b/common/ux-window.cpp @@ -12,6 +12,8 @@ #include #include "device-model.h" + +#include #include "os.h" // We use STB image to load the splash-screen from memory @@ -86,7 +88,7 @@ namespace rs2 std::string path; try { - path = get_folder_path(special_folder::user_documents); + path = rsutils::os::get_special_folder( rsutils::os::special_folder::user_documents ); } catch (const std::exception&) { diff --git a/common/viewer.cpp b/common/viewer.cpp index 96885155a4..ff94a9b2e2 100644 --- a/common/viewer.cpp +++ b/common/viewer.cpp @@ -7,8 +7,6 @@ #endif #endif -#include - #include "viewer.h" #include "os.h" @@ -19,9 +17,13 @@ #include #define ARCBALL_CAMERA_IMPLEMENTATION -#include +#include + +#include #include -#include "../common/utilities/imgui/wrap.h" +#include + +#include namespace rs2 { @@ -764,7 +766,9 @@ namespace rs2 if (create_file) { - std::string tmp_filename = rsutils::string::from() << get_folder_path(special_folder::app_data) << "/.99-realsense-libusb.rules"; + std::string tmp_filename + = rsutils::os::get_special_folder( rsutils::os::special_folder::app_data ) // ~/. + + "99-realsense-libusb.rules"; std::ofstream out(tmp_filename.c_str()); out << realsense_udev_rules;