reimplement ArchFile*::getSystemDirectory() as DataDirectories::systemconfig(). windows will now use ProgramData by default rather than C:\Windows

This commit is contained in:
walker0643 2018-03-30 14:39:12 -04:00
parent 6c5acdd552
commit 131a19d478
10 changed files with 41 additions and 40 deletions

View File

@ -38,12 +38,6 @@ public:
*/
virtual const char* getBasename(const char* pathname) = 0;
//! Get system directory
/*!
Returns the ussystem configuration file directory.
*/
virtual std::string getSystemDirectory() = 0;
//! Concatenate path components
/*!
Concatenate pathname components with a directory separator

View File

@ -45,12 +45,6 @@ ArchFileUnix::getBasename(const char* pathname)
}
}
std::string
ArchFileUnix::getSystemDirectory()
{
return "/etc";
}
std::string
ArchFileUnix::concatPath(const std::string& prefix,
const std::string& suffix)

View File

@ -27,7 +27,6 @@ class ArchFileUnix : public IArchFile {
public:
// IArchFile overrides
virtual const char* getBasename(const char* pathname);
virtual std::string getSystemDirectory();
virtual std::string concatPath(const std::string& prefix,
const std::string& suffix);
};

View File

@ -54,20 +54,6 @@ ArchFileWindows::getBasename(const char* pathname)
return basename;
}
std::string
ArchFileWindows::getSystemDirectory()
{
// get windows directory
char dir[MAX_PATH];
if (GetWindowsDirectory(dir, sizeof(dir)) != 0) {
return dir;
}
else {
// can't get it. use C:\ as a default.
return "C:";
}
}
std::string
ArchFileWindows::concatPath(const std::string& prefix,
const std::string& suffix)

View File

@ -27,7 +27,6 @@ class ArchFileWindows : public IArchFile {
public:
// IArchFile overrides
virtual const char* getBasename(const char* pathname);
virtual std::string getSystemDirectory();
virtual std::string concatPath(const std::string& prefix,
const std::string& suffix);
};

View File

@ -144,7 +144,7 @@ ServerApp::help()
<< "If no configuration file pathname is provided then the first of the" << std::endl
<< "following to load successfully sets the configuration:" << std::endl
<< " $HOME/" << USR_CONFIG_NAME << std::endl
<< " " << ARCH->concatPath(ARCH->getSystemDirectory(), SYS_CONFIG_NAME) << std::endl;
<< " " << ARCH->concatPath(DataDirectories::systemconfig(), SYS_CONFIG_NAME) << std::endl;
LOG((CLOG_PRINT "%s", buffer.str().c_str()));
}
@ -195,7 +195,7 @@ ServerApp::loadConfig()
}
if (!loaded) {
// try the system-wide config file
path = ARCH->getSystemDirectory();
path = DataDirectories::systemconfig();
if (!path.empty()) {
path = ARCH->concatPath(path, SYS_CONFIG_NAME);
if (loadConfig(path)) {

View File

@ -14,6 +14,9 @@ public:
static const std::string& global();
static const std::string& global(const std::string& path);
static const std::string& systemconfig();
static const std::string& systemconfig(const std::string& path);
private:
// static class
DataDirectories() {}
@ -21,5 +24,6 @@ private:
static std::string _personal;
static std::string _profile;
static std::string _global;
static std::string _systemconfig;
};

View File

@ -0,0 +1,7 @@
#include "DataDirectories.h"
// static member
std::string DataDirectories::_personal;
std::string DataDirectories::_profile;
std::string DataDirectories::_global;
std::string DataDirectories::_systemconfig;

View File

@ -10,11 +10,6 @@ const std::string ProfileSubdir = "/.barrier";
const std::string ProfileSubdir = "/Library/Application Support/Barrier";
#endif
// static members
std::string DataDirectories::_personal;
std::string DataDirectories::_profile;
std::string DataDirectories::_global;
static std::string pw_dir(struct passwd* pwentp)
{
if (pwentp != NULL && pwentp->pw_dir != NULL)
@ -87,3 +82,15 @@ const std::string& DataDirectories::global(const std::string& path)
return _global;
}
const std::string& DataDirectories::systemconfig()
{
if (_systemconfig.empty())
_systemconfig = "/etc";
return _systemconfig;
}
const std::string& DataDirectories::systemconfig(const std::string& path)
{
_systemconfig = path;
return _systemconfig;
}

View File

@ -2,11 +2,6 @@
#include <Shlobj.h>
// static member
std::string DataDirectories::_personal;
std::string DataDirectories::_profile;
std::string DataDirectories::_global;
std::string unicode_to_mb(const WCHAR* utfStr)
{
int utfLength = lstrlenW(utfStr);
@ -63,3 +58,19 @@ const std::string& DataDirectories::global(const std::string& path)
_global = path;
return _global;
}
const std::string& DataDirectories::systemconfig()
{
// systemconfig() is a special case in that it will track the current value
// of global() unless and until it is explictly set otherwise
// previously it would default to the windows folder which was horrible!
if (_systemconfig.empty())
return global();
return _systemconfig;
}
const std::string& DataDirectories::systemconfig(const std::string& path)
{
_systemconfig = path;
return _systemconfig;
}