old personal and profile directory functions now wrap the new implementations

This commit is contained in:
walker0643 2018-03-29 16:12:45 -04:00
parent 96627f4f07
commit c16fd089f6
5 changed files with 10 additions and 98 deletions

View File

@ -17,6 +17,7 @@
*/
#include "arch/unix/ArchFileUnix.h"
#include "common/DataDirectories.h"
#include <stdio.h>
#include <unistd.h>
@ -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

View File

@ -42,6 +42,5 @@ public:
virtual void setPluginDirectory(const String& s);
private:
String m_profileDirectory;
String m_pluginDirectory;
};

View File

@ -17,6 +17,7 @@
*/
#include "arch/win32/ArchFileWindows.h"
#include "common/DataDirectories.h"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
@ -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

View File

@ -42,6 +42,5 @@ public:
virtual void setPluginDirectory(const String& s);
private:
String m_profileDirectory;
String m_pluginDirectory;
};

View File

@ -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<DWORD> g_immuneKeys;
static const std::string ImmuneKeysPath = ArchFileWindows().getProfileDirectory() + "\\ImmuneKeys.txt";
static const std::string ImmuneKeysPath = DataDirectories::profile() + "\\ImmuneKeys.txt";
static std::vector<DWORD> immune_keys_list()
{