Skip to content

Commit

Permalink
Revert "When recording to a.bag file that is being installed in Progr…
Browse files Browse the repository at this point in the history
…am Files in defa…"
  • Loading branch information
maloel authored Jun 13, 2021
1 parent b933a8b commit cc0fe62
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 221 deletions.
2 changes: 0 additions & 2 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ set(COMMON_SRC
"${CMAKE_CURRENT_LIST_DIR}/opengl3.h"
"${CMAKE_CURRENT_LIST_DIR}/rs-config.h"
"${CMAKE_CURRENT_LIST_DIR}/rs-config.cpp"
"${CMAKE_CURRENT_LIST_DIR}/filesystem.h"
"${CMAKE_CURRENT_LIST_DIR}/filesystem.cpp"
"${CMAKE_CURRENT_LIST_DIR}/os.h"
"${CMAKE_CURRENT_LIST_DIR}/os.cpp"
"${CMAKE_CURRENT_LIST_DIR}/fw-update-helper.h"
Expand Down
168 changes: 0 additions & 168 deletions common/filesystem.cpp

This file was deleted.

26 changes: 0 additions & 26 deletions common/filesystem.h

This file was deleted.

123 changes: 123 additions & 0 deletions common/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ Some auxillary functionalities might be affected. Please report this message if
return (int)(floor(scale));
}
bool directory_exists(const char* dir)
{
struct stat info;
if (stat(dir, &info ) != 0)
return false;
else if (info.st_mode & S_IFDIR)
return true;
else
return false;
}
const char* file_dialog_open(file_dialog_mode flags, const char* filters,
const char* default_path, const char* default_name)
{
Expand Down Expand Up @@ -209,6 +221,117 @@ Some auxillary functionalities might be affected. Please report this message if
return stbi_write_png(filename, (int)pixel_width, (int)pixels_height, (int)bytes_per_pixel, raster_data, (int)stride_bytes);
}
std::string get_file_name(const std::string& path)
{
std::string file_name;
for (auto rit = path.rbegin(); rit != path.rend(); ++rit)
{
if (*rit == '\\' || *rit == '/')
break;
file_name += *rit;
}
std::reverse(file_name.begin(), file_name.end());
return file_name;
}
std::string get_timestamped_file_name()
{
std::time_t now = std::time(NULL);
std::tm * ptm = std::localtime(&now);
char buffer[16];
// Format: 20170529_205500
std::strftime(buffer, 16, "%Y%m%d_%H%M%S", ptm);
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;
switch (f)
{
case user_desktop: folder = FOLDERID_Desktop;
break;
case user_documents: folder = FOLDERID_Documents;
break;
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;
HRESULT 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();
Expand Down
21 changes: 18 additions & 3 deletions common/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <vector>
#include <string>
#include <rendering.h>
#include "filesystem.h"

struct GLFWmonitor;
struct GLFWwindow;
Expand All @@ -18,7 +17,9 @@ namespace rs2

std::string truncate_string(const std::string& str, size_t width);

void open_url(const char* url);
void open_url(const char* url);

bool directory_exists(const char* dir);

std::vector<std::string> split_string(std::string& input, char delim);

Expand All @@ -32,6 +33,8 @@ namespace rs2
// that most of the application is presented on
int pick_scale_factor(GLFWwindow* window);

std::string get_file_name(const std::string& path);

// Wrapper for cross-platform dialog control
enum file_dialog_mode {
open_file = (1 << 0),
Expand All @@ -44,7 +47,19 @@ namespace rs2
int save_to_png(const char* filename,
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);

Expand Down
Loading

0 comments on commit cc0fe62

Please sign in to comment.