refactor: remove unused ARCH::getUserDirectory
This commit is contained in:
parent
7fe862b715
commit
8609cbc20a
5 changed files with 0 additions and 77 deletions
|
|
@ -27,13 +27,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual const char *getBasename(const char *pathname) = 0;
|
virtual const char *getBasename(const char *pathname) = 0;
|
||||||
|
|
||||||
//! Get user's home directory
|
|
||||||
/*!
|
|
||||||
Returns the user's home directory. Returns the empty string if
|
|
||||||
this cannot be determined.
|
|
||||||
*/
|
|
||||||
virtual std::string getUserDirectory() = 0;
|
|
||||||
|
|
||||||
//! Get installed directory
|
//! Get installed directory
|
||||||
/*!
|
/*!
|
||||||
Returns the directory in which Deskflow is installed.
|
Returns the directory in which Deskflow is installed.
|
||||||
|
|
|
||||||
|
|
@ -43,33 +43,6 @@ const char *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;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ArchFileUnix::getInstalledDirectory()
|
std::string ArchFileUnix::getInstalledDirectory()
|
||||||
{
|
{
|
||||||
#if WINAPI_XWINDOWS
|
#if WINAPI_XWINDOWS
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ public:
|
||||||
|
|
||||||
// IArchFile overrides
|
// IArchFile overrides
|
||||||
virtual const char *getBasename(const char *pathname);
|
virtual const char *getBasename(const char *pathname);
|
||||||
virtual std::string getUserDirectory();
|
|
||||||
virtual std::string getInstalledDirectory();
|
virtual std::string getInstalledDirectory();
|
||||||
virtual std::string concatPath(const std::string &prefix, const std::string &suffix);
|
virtual std::string concatPath(const std::string &prefix, const std::string &suffix);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -50,47 +50,6 @@ const char *ArchFileWindows::getBasename(const char *pathname)
|
||||||
return basename;
|
return basename;
|
||||||
}
|
}
|
||||||
|
|
||||||
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:";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ArchFileWindows::getInstalledDirectory()
|
std::string ArchFileWindows::getInstalledDirectory()
|
||||||
{
|
{
|
||||||
char fileNameBuffer[MAX_PATH];
|
char fileNameBuffer[MAX_PATH];
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ public:
|
||||||
|
|
||||||
// IArchFile overrides
|
// IArchFile overrides
|
||||||
virtual const char *getBasename(const char *pathname);
|
virtual const char *getBasename(const char *pathname);
|
||||||
virtual std::string getUserDirectory();
|
|
||||||
virtual std::string getInstalledDirectory();
|
virtual std::string getInstalledDirectory();
|
||||||
virtual std::string concatPath(const std::string &prefix, const std::string &suffix);
|
virtual std::string concatPath(const std::string &prefix, const std::string &suffix);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue