From c16fd089f6c620f142b09d20b8edc833afbb776c Mon Sep 17 00:00:00 2001 From: walker0643 <> Date: Thu, 29 Mar 2018 16:12:45 -0400 Subject: [PATCH] old personal and profile directory functions now wrap the new implementations --- src/lib/arch/unix/ArchFileUnix.cpp | 41 ++--------------- src/lib/arch/unix/ArchFileUnix.h | 1 - src/lib/arch/win32/ArchFileWindows.cpp | 62 ++------------------------ src/lib/arch/win32/ArchFileWindows.h | 1 - src/lib/platform/MSWindowsHook.cpp | 3 +- 5 files changed, 10 insertions(+), 98 deletions(-) diff --git a/src/lib/arch/unix/ArchFileUnix.cpp b/src/lib/arch/unix/ArchFileUnix.cpp index d9ae8b21..a687f5a5 100644 --- a/src/lib/arch/unix/ArchFileUnix.cpp +++ b/src/lib/arch/unix/ArchFileUnix.cpp @@ -17,6 +17,7 @@ */ #include "arch/unix/ArchFileUnix.h" +#include "common/DataDirectories.h" #include #include @@ -57,29 +58,7 @@ ArchFileUnix::getBasename(const char* pathname) std::string ArchFileUnix::getUserDirectory() { - char* buffer = NULL; - std::string dir; -#if HAVE_GETPWUID_R - struct passwd pwent; - struct passwd* pwentp; -#if defined(_SC_GETPW_R_SIZE_MAX) - long size = sysconf(_SC_GETPW_R_SIZE_MAX); - if (size == -1) { - size = BUFSIZ; - } -#else - long size = BUFSIZ; -#endif - buffer = new char[size]; - getpwuid_r(getuid(), &pwent, buffer, size, &pwentp); -#else - struct passwd* pwentp = getpwuid(getuid()); -#endif - if (pwentp != NULL && pwentp->pw_dir != NULL) { - dir = pwentp->pw_dir; - } - delete[] buffer; - return dir; + return DataDirectories::personal(); } std::string @@ -121,19 +100,7 @@ ArchFileUnix::getPluginDirectory() std::string ArchFileUnix::getProfileDirectory() { - String dir; - if (!m_profileDirectory.empty()) { - dir = m_profileDirectory; - } - else { -#if WINAPI_XWINDOWS - dir = getUserDirectory().append("/.barrier"); -#else - dir = getUserDirectory().append("/Library/Application Support/Barrier"); -#endif - } - return dir; - + return DataDirectories::profile(); } std::string @@ -153,7 +120,7 @@ ArchFileUnix::concatPath(const std::string& prefix, void ArchFileUnix::setProfileDirectory(const String& s) { - m_profileDirectory = s; + DataDirectories::profile(s); } void diff --git a/src/lib/arch/unix/ArchFileUnix.h b/src/lib/arch/unix/ArchFileUnix.h index 86dea0c9..a59e6015 100644 --- a/src/lib/arch/unix/ArchFileUnix.h +++ b/src/lib/arch/unix/ArchFileUnix.h @@ -42,6 +42,5 @@ public: virtual void setPluginDirectory(const String& s); private: - String m_profileDirectory; String m_pluginDirectory; }; diff --git a/src/lib/arch/win32/ArchFileWindows.cpp b/src/lib/arch/win32/ArchFileWindows.cpp index 53b4b594..190fa9ce 100644 --- a/src/lib/arch/win32/ArchFileWindows.cpp +++ b/src/lib/arch/win32/ArchFileWindows.cpp @@ -17,6 +17,7 @@ */ #include "arch/win32/ArchFileWindows.h" +#include "common/DataDirectories.h" #define WIN32_LEAN_AND_MEAN #include @@ -66,45 +67,7 @@ ArchFileWindows::getBasename(const char* pathname) std::string ArchFileWindows::getUserDirectory() { - // try %HOMEPATH% - TCHAR dir[MAX_PATH]; - DWORD size = sizeof(dir) / sizeof(TCHAR); - DWORD result = GetEnvironmentVariable(_T("HOMEPATH"), dir, size); - if (result != 0 && result <= size) { - // sanity check -- if dir doesn't appear to start with a - // drive letter and isn't a UNC name then don't use it - // FIXME -- allow UNC names - if (dir[0] != '\0' && (dir[1] == ':' || - ((dir[0] == '\\' || dir[0] == '/') && - (dir[1] == '\\' || dir[1] == '/')))) { - return dir; - } - } - - // get the location of the personal files. that's as close to - // a home directory as we're likely to find. - ITEMIDLIST* idl; - if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &idl))) { - TCHAR* path = NULL; - if (SHGetPathFromIDList(idl, dir)) { - DWORD attr = GetFileAttributes(dir); - if (attr != 0xffffffff && (attr & FILE_ATTRIBUTE_DIRECTORY) != 0) - path = dir; - } - - IMalloc* shalloc; - if (SUCCEEDED(SHGetMalloc(&shalloc))) { - shalloc->Free(idl); - shalloc->Release(); - } - - if (path != NULL) { - return path; - } - } - - // use root of C drive as a default - return "C:"; + return DataDirectories::personal(); } std::string @@ -154,24 +117,7 @@ ArchFileWindows::getPluginDirectory() std::string ArchFileWindows::getProfileDirectory() { - String dir; - if (!m_profileDirectory.empty()) { - dir = m_profileDirectory; - } - else { - TCHAR result[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, result))) { - dir = result; - } - else { - dir = getUserDirectory(); - } - } - - // HACK: append program name, this seems wrong. - dir.append("\\Barrier"); - - return dir; + return DataDirectories::profile(); } std::string @@ -193,7 +139,7 @@ ArchFileWindows::concatPath(const std::string& prefix, void ArchFileWindows::setProfileDirectory(const String& s) { - m_profileDirectory = s; + DataDirectories::profile(s); } void diff --git a/src/lib/arch/win32/ArchFileWindows.h b/src/lib/arch/win32/ArchFileWindows.h index 4747b9c8..453aa61a 100644 --- a/src/lib/arch/win32/ArchFileWindows.h +++ b/src/lib/arch/win32/ArchFileWindows.h @@ -42,6 +42,5 @@ public: virtual void setPluginDirectory(const String& s); private: - String m_profileDirectory; String m_pluginDirectory; }; diff --git a/src/lib/platform/MSWindowsHook.cpp b/src/lib/platform/MSWindowsHook.cpp index 929888e4..2d7845a0 100644 --- a/src/lib/platform/MSWindowsHook.cpp +++ b/src/lib/platform/MSWindowsHook.cpp @@ -22,6 +22,7 @@ #include "platform/ImmuneKeysReader.h" #include "barrier/protocol_types.h" #include "barrier/XScreen.h" +#include "common/DataDirectories.h" #include "base/Log.h" // @@ -52,7 +53,7 @@ static BYTE g_keyState[256] = { 0 }; static bool g_fakeServerInput = false; static std::vector g_immuneKeys; -static const std::string ImmuneKeysPath = ArchFileWindows().getProfileDirectory() + "\\ImmuneKeys.txt"; +static const std::string ImmuneKeysPath = DataDirectories::profile() + "\\ImmuneKeys.txt"; static std::vector immune_keys_list() {