diff --git a/inc/osvr/Util/Directories.h b/inc/osvr/Util/Directories.h new file mode 100644 index 000000000..f36a06fca --- /dev/null +++ b/inc/osvr/Util/Directories.h @@ -0,0 +1,75 @@ +/** @file + @brief Helper functions for determine where to load or store configuration files, log files, etc. + + @date 2016 + + @author + Sensics, Inc. + + +*/ + +// Copyright 2016 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INCLUDED_Directories_h_GUID_924A614D_303C_470D_9AC4_01BCBE8F1104 +#define INCLUDED_Directories_h_GUID_924A614D_303C_470D_9AC4_01BCBE8F1104 + +// Internal Includes +#include + +// Library/third-party includes +// - none + +// Standard includes +#include +#include + +namespace osvr { +namespace util { + +enum OSVR_UTIL_EXPORT DirectoryType { + USER_DIRECTORY_DATA, ///< user-specific data files + USER_DIRECTORY_CONFIG, ///< user-specific configuration files + USER_DIRECTORY_CACHE, ///< user-specific non-essential data files + USER_DIRECTORY_STATE, ///< user-specific state files + USER_DIRECTORY_LOG, ///< user-specific log files + SITE_DIRECTORY_DATA, ///< system-wide data files + SITE_DIRECTORY_CONFIG, ///< system-wide configuration files + USER_DIRECTORY_DESKTOP, ///< the user's Desktop directory + USER_DIRECTORY_DOCUMENTS, ///< the user's Documents directory + USER_DIRECTORY_DOWNLOAD, ///< the user's Downloads directory + USER_DIRECTORY_MUSIC, ///< the user's Music directory + USER_DIRECTORY_PICTURES, ///< the user's Pictures directory + USER_DIRECTORY_PUBLIC_SHARE, ///< the user's shared directory + USER_DIRECTORY_TEMPLATES, ///< the user's Templates directory + USER_DIRECTORY_VIDEOS ///< the user's Movies directory +}; + +OSVR_UTIL_EXPORT std::vector getDirectories(DirectoryType dirtype, const std::string& appname = "OSVR", const std::string& author = "", const std::string& version = ""); + +/** + * @brief Return full path to the requested directory type. + * + * @param dirtype The requested directory to return. + */ +OSVR_UTIL_EXPORT std::string getDirectory(const DirectoryType dirtype, const std::string& appname = "OSVR", const std::string& author = "", const std::string& version = ""); + +OSVR_UTIL_EXPORT std::string getUserDataDir(const std::string& appname = "OSVR", const std::string& author = "", const std::string& version = ""); + +} // end namespace util +} // end namespace osvr + +#endif // INCLUDED_Directories_h_GUID_924A614D_303C_470D_9AC4_01BCBE8F1104 + diff --git a/inc/osvr/Util/GetEnvironmentVariable.h b/inc/osvr/Util/GetEnvironmentVariable.h index 722b5f355..27b5d1b5e 100644 --- a/inc/osvr/Util/GetEnvironmentVariable.h +++ b/inc/osvr/Util/GetEnvironmentVariable.h @@ -44,8 +44,12 @@ namespace util { OSVR_UTIL_EXPORT boost::optional getEnvironmentVariable(std::string const &var); + /// @brief Gets an environment variable's value. If the environment + /// variable is not set or is empty, the fallback value will be returned. + OSVR_UTIL_EXPORT std::string + getEnvironmentVariable(std::string const &var, std::string const &fallback); + } // namespace util } // namespace osvr #endif // INCLUDED_GetEnvironmentVariable_h_GUID_500031B7_31FB_45A1_B1E9_8E61905A4E0F - diff --git a/src/osvr/Util/CMakeLists.txt b/src/osvr/Util/CMakeLists.txt index e7f5b7d2f..86d58752d 100644 --- a/src/osvr/Util/CMakeLists.txt +++ b/src/osvr/Util/CMakeLists.txt @@ -63,6 +63,7 @@ set(API "${HEADER_LOCATION}/DefaultPort.h" "${HEADER_LOCATION}/Deletable.h" "${HEADER_LOCATION}/DeviceCallbackTypesC.h" + "${HEADER_LOCATION}/Directories.h" "${HEADER_LOCATION}/EigenCoreGeometry.h" "${HEADER_LOCATION}/EigenExtras.h" "${HEADER_LOCATION}/EigenFilters.h" @@ -146,6 +147,7 @@ set(SOURCE AnyMap.cpp BinaryLocation.cpp Deletable.cpp + Directories.cpp GetEnvironmentVariable.cpp GuardInterface.cpp TimeValueC.cpp @@ -196,6 +198,7 @@ target_link_libraries(${LIBNAME_FULL} eigen-headers spdlog boost_filesystem + ${Boost_SYSTEM_LIBRARY} osvrTypePack) if(ANDROID) diff --git a/src/osvr/Util/Directories.cpp b/src/osvr/Util/Directories.cpp new file mode 100644 index 000000000..b0a18bf91 --- /dev/null +++ b/src/osvr/Util/Directories.cpp @@ -0,0 +1,618 @@ +/** @file + @brief Helper functions for determine where to load or store configuration files, log files, etc. + + @date 2016 + + @author + Sensics, Inc. + + +*/ + +// Copyright 2016 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Internal Includes +#include +#include +#include + +// Library/third-party includes +#include + +// Standard includes +#include +#include + +// Platform-specific includes +#if defined(OSVR_WINDOWS) +#include // for SHGetKnownFolderPath() +#include +#include +#include +#elif defined(OSVR_LINUX) +#include // for boost::split() +#endif + +namespace osvr { +namespace util { + +// https://github.com/ActiveState/appdirs/blob/master/appdirs.py +// https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html +// http://www.filewatcher.com/m/BPFileSystem.pdf.457603-0.html +// https://support.microsoft.com/en-us/kb/310294#XSLTH3194121123120121120120 +// + +namespace { + +#if defined(OSVR_WINDOWS) +inline std::string to_string(const std::wstring& s) +{ + std::wstring_convert, wchar_t> converter; + return converter.to_bytes(s); +} + +// https://msdn.microsoft.com/en-us/library/dd378457.aspx +inline std::string getKnownFolderPath(KNOWNFOLDERID known_folder_id) +{ + LPWSTR wide_path = nullptr; + const auto result = SHGetKnownFolderPath(&known_folder_id, 0, nullptr, wide_path); + if (SUCCEEDED(result)) { + return to_string(wide_path); + } + return ""; +} +#endif // OSVR_WINDOWS + +#if defined(OSVR_LINUX) +// The following functions return paths specified by the XDG Base Directory +// Specification +// . +// These functions apply to modern Linux installations. + +enum class XDGDirectory { + XDG_CACHE_HOME, ///< user-specific non-essential data files + XDG_CONFIG_DIRS, ///< search for configuration files in addition to the XDG_CONFIG_HOME + XDG_CONFIG_HOME, ///< user-specific configuration files + XDG_DATA_DIRS, ///< search for data files in addition to the XDG_DATA_HOME + XDG_DATA_HOME, ///< user-specific data files + XDG_RUNTIME_DIR ///< user-specific non-essential runtime files (sockets, named pipes, etc.) +}; + +inline std::vector getXDGDirectoriesEnvOrDefault(const std::string& env, const std::vector& default) +{ + const auto dirs_str = getEnvironmentVariable(env); + if (!dirs_str || dirs_str->empty()) + return default; + + std::vector dirs; + boost::split(dirs, *env, boost::is_any_of(":")); + return dirs; +} + +inline std::vector getXDGDirectories(const XDGDirectory dir) +{ + if (XDG_CONFIG_DIRS == dir) { + return getXDGDirectoriesEnvOrDefault("XDG_CONFIG_DIRS", {"/usr/local/share", "/usr/share"}); + } else if (XDG_DATA_DIRS == dir) { + return getXDGDirectoriesEnvOrDefault("XDG_DATA_DIRS", {"/etc/xdg"}); + } + + return {}; +} + +inline std::string getXDGDirectoryEnvOrDefault(const std::string& env, const std::string& default) +{ + const auto dir = getEnvironmentVariable(env); + if (!dir || dir->empty()) + return default; + return *dir; +} + +inline std::string getXDGDirectory(const XDGDirectory dir) +{ + const auto home_dir = *getEnvironmentVariable("HOME"); + + if (XDG_CACHE_HOME == dir) { + return getXDGDirectoryEnvOrDefault("XDG_CACHE_HOME", home_dir + "/.cache"); + } else if (XDG_CONFIG_HOME == dir) { + return getXDGDirectoryEnvOrDefault("XDG_CONFIG_HOME", home_dir + "/.config"); + } else if (XDG_DATA_HOME == dir) { + return getXDGDirectoryEnvOrDefault("XDG_DATA_HOME", home_dir + "/.local/share"); + } else if (XDG_RUNTIME_DIR == dir) { + // FIXME (use /run/user/~ or /tmp or /var/tmp etc.) + return getXDGDirectoryEnvOrDefault("XDG_RUNTIME_DIR", "/tmo"); + } else { + // TODO + return ""; + } +} + +// https://freedesktop.org/wiki/Software/xdg-user-dirs/ +inline std::string getXDGUserDirectory(const std::string& type, const std::string& fallback) +{ + FILE *file; + char *home_dir, *config_home, *config_file; + char buffer[512]; + char *user_dir; + char *p, *d; + int len; + int relative; + + const auto home_dir = getEnvironmentVariable("HOME"); + + if (!home_dir) { + return fallback; + } + + const auto config_home = getXDGDirectory(XDG_CONFIG_HOME); + const auto config_file = config_home + "/user-dirs.dirs"; + + std::ifstream input(config_file); + for (std::string line; std::getline(input, line); ) { + + if (line.find("XDG_" + type + "_DIR") != std::end(line)) { + + } + + if (relative) + { + user_dir = (char*) malloc (strlen (home_dir) + 1 + strlen (p) + 1); + if (user_dir == NULL) + goto error2; + + strcpy (user_dir, home_dir); + strcat (user_dir, "/"); + } + else + { + user_dir = (char*) malloc (strlen (p) + 1); + if (user_dir == NULL) + goto error2; + + *user_dir = 0; + } + + d = user_dir + strlen (user_dir); + while (*p && *p != '"') + { + if ((*p == '\\') && (*(p+1) != 0)) + p++; + *d++ = *p++; + } + *d = 0; + } +error2: + fclose (file); + + if (user_dir) + return user_dir; + +error: + if (fallback) + return strdup (fallback); + return NULL; +} + +/** + * xdg_user_dir_lookup: + * @type: a string specifying the type of directory + * @returns: a newly allocated absolute pathname + * + * Looks up a XDG user directory of the specified type. + * Example of types are "DESKTOP" and "DOWNLOAD". + * + * The return value is always != NULL (unless out of memory), + * and if a directory + * for the type is not specified by the user the default + * is the home directory. Except for DESKTOP which defaults + * to ~/Desktop. + * + * The return value is newly allocated and must be freed with + * free(). + **/ +static char * +xdg_user_dir_lookup (const char *type) +{ + char *dir, *home_dir, *user_dir; + + dir = xdg_user_dir_lookup_with_fallback (type, NULL); + if (dir != NULL) + return dir; + + home_dir = getenv ("HOME"); + + if (home_dir == NULL) + return strdup ("/tmp"); + + /* Special case desktop for historical compatibility */ + if (strcmp (type, "DESKTOP") == 0) + { + user_dir = (char*) malloc (strlen (home_dir) + strlen ("/Desktop") + 1); + if (user_dir == NULL) + return NULL; + + strcpy (user_dir, home_dir); + strcat (user_dir, "/Desktop"); + return user_dir; + } + + return strdup (home_dir); +} +#endif // OSVR_LINUX + +} // end anonymous namespace + +std::vector getDirectories(DirectoryType dirtype, const std::string& appname, const std::string& author, const std::string& version) +{ + std::vector dirs; + // TODO + return dirs; +} + +std::string getUserDataDir(const std::string& appname, const std::string& author, const std::string& version) +{ + // Typical user data directories are: + // Mac OS X: ~/Library/Application Support// + // Unix: $XDG_DATA_HOME// + // Windows: C:\Users\\AppData\Local\\\ + + namespace fs = boost::filesystem; + fs::path path; + +#if defined(OSVR_MACOSX) + const auto home_dir = getEnvironmentVariable("HOME"); + if (home_dir) { + path = *home_dir; + } + path /= fs::path("Library") / "Application Support"; + if (!appname.empty()) { + path /= appname; + } +#elif defined(OSVR_WINDOWS) + path = getKnownFolderPath(FOLDERID_LocalAppData); + if (!author.empty()) { + if (author != appname) { + path /= author / appname; + } else { + path /= appname; + } + } +#elif defined(OSVR_LINUX) + path = getXDGDirectory(XDG_DATA_HOME); + if (!appname.empty()) + path /= appname; +#else +#warning "osvr::util::getUserDataDir() is not yet supported on this platform." +#endif // platform-specific code + + if (!appname.empty() && !version.empty()) { + path /= version; + } + + return path.string(); +} + +std::string getUserConfigDir(const std::string& appname, const std::string& author, const std::string& version) +{ + // Typical user config directories are: + // Mac OS X: same as user_data_dir + // Windowns: same as user_data_dir + // Unix: XDG_CONFIG_HOME + + namespace fs = boost::filesystem; + fs::path path; + +#if defined(OSVR_WINDOWS) || defined(OSVR_MACOSX) + path = getUserDataDir(appname, author, version); +#elif defined(OSVR_LINUX) + path = getXDGDirectory(XDG_CONFIG_HOME); + + if (!appname.empty()) + path /= appname; +#else +#warning "osvr::util::getUserConfigDir() is not yet supported on this platform." +#endif + + if (!appname.empty() && !version.empty()) + path /= version; + + return path.string(); +} + +std::string getUserCacheDir(const std::string& appname, const std::string& author, const std::string& version) +{ + // Typical user cache directories are: + // Mac OS X: ~/Library/Caches// + // ~/Library/Caches/ + // ~/Library/Caches + // Unix: $XDG_CACHE_HOME// + // Unix: $XDG_CACHE_HOME/ + // $XDG_CACHE_HOME + // Windows: %LocalAppData%\\\\Cache + // %LocalAppData%\\\Cache + // %LocalAppData%\\Cache + // %LocalAppData%\Cache + + namespace fs = boost::filesystem; + fs::path path; + +#if defined(OSVR_MACOSX) + path = *getEnvironmentVariable("HOME") / fs::path("Library") / "Caches"; + if (!appname.empty()) + path /= appname; + if (!appname.empty() && !version.empty()) + path /= version; +#elif defined(OSVR_WINDOWS) + path = getKnownFolderPath(FOLDERID_LocalAppData); + + if (!author.empty()) + path /= author; + + if (!appname.empty()) + path /= appname; + + if (!version.empty()) + path /= version; + + path /= "Cache"; + +#elif defined(OSVR_LINUX) + path = getXDGDirectory(XDG_CACHE_HOME); + if (!appname.empty()) + path /= appname; + if (!appname.empty() && !version.empty()) + path /= version; +#else +#warning "osvr::util::getUserCacheDir() is not yet supported on this platform." +#endif + + return path.string(); +} + +std::string getUserStateDir(const std::string& appname, const std::string& author, const std::string& version) +{ + // Typical user state directories are: + // Mac OS X: same as user_data_dir + // Windows: same as user_data_dir + // Unix: $XDG_STATE_HOME/ + + namespace fs = boost::filesystem; + fs::path path; + +#if defined(OSVR_MACOSX) || defined(OSVR_WINDOWS) + return getUserDataDir(appname, author, version); +#elif defined(OSVR_LINUX) + path = getXDGDirectory(XDG_STATE_HOME); + if (!appname.empty()) { + path /= appname; + if (!version.empty()) { + path /= version; + } + } + +#else +#warning "osvr::util::getUserStateDir() is not yet supported on this platform." +#endif + + return path.string(); +} + +std::string getUserLogDir(const std::string& appname, const std::string& author, const std::string& version) +{ + // Typical user state directories are: + // Mac OS X: ~/Library/Logs/ + // Windows: %LocalAppData%///Logs + // Unix: $XDG_CACHE_HOME//logs + + namespace fs = boost::filesystem; + fs::path log_dir; + +#if defined(OSVR_LINUX) + // There's currently no great location for storing log files in the + // XDG system. (See the STATE proposal by Debian + // .) + // So for now, we'll store our log files in the $XDG_CACHE_HOME + // directory. + // + // $XDG_CACHE_HOME defines the base directory relative to which user + // specific non-essential data files should be stored. If + // $XDG_CACHE_HOME is either not set or empty, a default equal to + // $HOME/.cache should be used. + log_dir /= getXDGDirectory(XDG_CACHE_HOME); + + if (!appname.empty()) + log_dir /= appname; + + log_dir /= "logs"; +#elif defined(OSVR_MACOSX) + auto home_dir = getEnvironmentVariable("HOME"); + if (home_dir) + log_dir = *home_dir; + + log_dir /= "Library" / fs::path("Logs"); + + if (!appname.empty()) + log_dir /= appname; +#elif defined(OSVR_WINDOWS) + log_dir = getKnownFolderPath(FOLDERID_LocalAppData); + if (!author.empty()) + log_dir /= author; + + if (!appname.empty()) + log_dir /= appname; + + log_dir /= "Logs"; +#else +#warning "osvr::util::getUserLogDir() is not yet supported on this platform." +#endif + + return log_dir.string(); +} + +std::string getSiteDataDir(const std::string& appname, const std::string& author, const std::string& version) +{ + // Typical site data directories are: + // Mac OS X: /Library/Application Support// + // /Library/Application Support/ + // Linux: $HDG_DATA_DIRS[0]// + // $HDG_DATA_DIRS[0]/ + // Windows: C:\ProgramData\\\ + // C:\ProgramData\\ + // C:\ProgramData\ + + namespace fs = boost::filesystem; + fs::path path; + +#if defined(OSVR_WINDOWS) + path = getKnownFolderPath(FOLDERID_ProgramData); + + if (!appname.empty()) { + if (!author.empty()) + path /= author; + + path /= appname; + + if (!version.empty()) + path /= version; + } +#elif defined(OSVR_MACOSX) + path = *getEnvironmentVariable("HOME"); + path /= "Library"; + path /= "Application Support"; + + if (!appname.empty()) { + path /= appname; + + if (!version.empty()) + path /= version; + } +#elif defined(OSVR_LINUX) + path = getXDGDirectories(XDG_DATA_DIRS)[0]; + + if (!appname.empty()) { + path /= appname; + + if (!version.empty()) + path /= version; + } +#else +#warning "osvr::util::getSiteDataDir() is not yet supported on this platform." +#endif + + return path.string(); +} + +std::string getSiteConfigDir(const std::string& appname, const std::string& author, const std::string& version) +{ + // Typical site data directories are: + // Mac OS X: same as getSiteDataDir() + // Linux: $HDG_CONFIG_DIRS[0]// + // $HDG_CONFIG_DIRS[0]/ + // Windows: same as getSiteDataDir() + + namespace fs = boost::filesystem; + fs::path path; + +#if defined(OSVR_WINDOWS) || defined(OSVR_MACOSX) + return getSiteDataDir(appname, author, version); +#elif defined(OSVR_LINUX) + path = getXDGDirectories(XDG_CONFIG_DIRS)[0]; + + if (!appname.empty()) { + path /= appname; + + if (!version.empty()) + path /= version; + } +#else +#warning "osvr::util::getSiteConfigDir() is not yet supported on this platform." +#endif + + return path.string(); +} + +std::string getUserDesktopDir(const std::string& appname, const std::string& author, const std::string& version) +{ + // Typical site data directories are: + // Mac OS X: same as getSiteDataDir() + // Linux: $HDG_CONFIG_DIRS[0]// + // $HDG_CONFIG_DIRS[0]/ + // Windows: same as getSiteDataDir() + + namespace fs = boost::filesystem; + fs::path path; + +#if defined(OSVR_WINDOWS) + return getKnownFolderPath(FOLDERID_Desktop); +#elif defined(OSVR_MACOSX) + // FIXME +#elif defined(OSVR_LINUX) + // FIXME +#else +#warning "osvr::util::getSiteConfigDir() is not yet supported on this platform." +#endif + + return path.string(); +} + +/** + * @brief Return full path to the requested directory type. + * + * @param dirtype The requested directory to return. + */ +std::string getDirectory(const DirectoryType dirtype, const std::string& appname, const std::string& author, const std::string& version) +{ + switch (dirtype) { + case USER_DIRECTORY_DATA: + return getUserDataDir(appname, author, version); + case USER_DIRECTORY_CONFIG: + return getUserConfigDir(appname, author, version); + case USER_DIRECTORY_CACHE: + return getUserCacheDir(appname, author, version); + case USER_DIRECTORY_STATE: + return getUserStateDir(appname, author, version); + case USER_DIRECTORY_LOG: + return getUserLogDir(appname, author, version); + case SITE_DIRECTORY_DATA: + return getSiteDataDir(appname, author, version); + case SITE_DIRECTORY_CONFIG: + return getSiteConfigDir(appname, author, version); + case USER_DIRECTORY_DESKTOP: + return getUserDesktopDir(appname, author, version); +#if 0 + case USER_DIRECTORY_DOCUMENTS: + return getUserDocumentsDir(appname, author, version); + case USER_DIRECTORY_DOWNLOAD: + return getUserDownloadsDir(appname, author, version); + case USER_DIRECTORY_MUSIC: + return getUserMusicDir(appname, author, version); + case USER_DIRECTORY_PICTURES: + return getUserPicturesDir(appname, author, version); + case USER_DIRECTORY_PUBLIC_SHARE: + return getUserPublicShareDir(appname, author, version); + case USER_DIRECTORY_TEMPLATES: + return getUserTemplatesDir(appname, author, version); + case USER_DIRECTORY_VIDEOS: + return getUserVideosDir(appname, author, version); + default: +#endif // not yet implemented + } + + return ""; +} + +} // end namespace util +} // end namespace osvr + diff --git a/src/osvr/Util/GetEnvironmentVariable.cpp b/src/osvr/Util/GetEnvironmentVariable.cpp index a1080e414..7068cd41c 100644 --- a/src/osvr/Util/GetEnvironmentVariable.cpp +++ b/src/osvr/Util/GetEnvironmentVariable.cpp @@ -68,5 +68,17 @@ namespace util { return ret; } #endif // end of if windows non-desktop + + std::string + getEnvironmentVariable(std::string const &var, std::string const &fallback) + { + const auto value = getEnvironmentVariable(var); + if (!value) + return fallback; + return *value; + } + + } // namespace util } // namespace osvr + diff --git a/tests/cplusplus/Util/CMakeLists.txt b/tests/cplusplus/Util/CMakeLists.txt index dea1917fd..649758046 100644 --- a/tests/cplusplus/Util/CMakeLists.txt +++ b/tests/cplusplus/Util/CMakeLists.txt @@ -1,4 +1,4 @@ -foreach(testname TreeNode ContainerWrapper UniqueContainer Projection QuatExpMap) +foreach(testname TreeNode ContainerWrapper UniqueContainer Projection QuatExpMap Directories ExpandEnvironmentVariables) add_executable(${testname} ${testname}.cpp) target_link_libraries(${testname} osvrUtilCpp) osvr_setup_gtest(${testname}) @@ -6,3 +6,5 @@ endforeach() target_link_libraries(Projection eigen-headers) target_link_libraries(QuatExpMap eigen-headers vendored-vrpn) +target_link_libraries(Directories boost_filesystem ${Boost_SYSTEM_LIBRARIES}) + diff --git a/tests/cplusplus/Util/Directories.cpp b/tests/cplusplus/Util/Directories.cpp new file mode 100644 index 000000000..bb566ec2d --- /dev/null +++ b/tests/cplusplus/Util/Directories.cpp @@ -0,0 +1,70 @@ +/** @file + @brief Test Implementation + + @date 2016 + + @author + Sensics, Inc. + + +*/ + +// Copyright 2016 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Internal Includes +#include +#include + +// Library/third-party includes +#include "gtest/gtest.h" + +// Standard includes +#include + +using std::string; + +#define print_dir(x) \ + std::cout << #x << " = " << osvr::util::getDirectory(x) << std::endl; + +TEST(Directories, Directories) { +#if defined(OSVR_WINDOWS) + std::cout << "Platform: Windows" << std::endl; +#elif defined(OSVR_MACOSX) + std::cout << "Platform: macOS" << std::endl; +#elif defined(OSVR_LINUX) + std::cout << "Platform: Linux" << std::endl; +#else + std::cout << " -- Unsupported platform!" << std::endl; +#endif + + using namespace osvr::util; + + print_dir(USER_DIRECTORY_DATA); + print_dir(USER_DIRECTORY_CONFIG); + print_dir(USER_DIRECTORY_CACHE); + print_dir(USER_DIRECTORY_STATE); + print_dir(USER_DIRECTORY_LOG); + print_dir(SITE_DIRECTORY_DATA); + print_dir(SITE_DIRECTORY_CONFIG); + print_dir(USER_DIRECTORY_DESKTOP); + print_dir(USER_DIRECTORY_DOCUMENTS); + print_dir(USER_DIRECTORY_DOWNLOAD); + print_dir(USER_DIRECTORY_MUSIC); + print_dir(USER_DIRECTORY_PICTURES); + print_dir(USER_DIRECTORY_PUBLIC_SHARE); + print_dir(USER_DIRECTORY_TEMPLATES); + print_dir(USER_DIRECTORY_VIDEOS); +} +