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; 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 path components
/*! /*!
Concatenate pathname components with a directory separator 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 std::string
ArchFileUnix::concatPath(const std::string& prefix, ArchFileUnix::concatPath(const std::string& prefix,
const std::string& suffix) const std::string& suffix)

View File

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

View File

@ -54,20 +54,6 @@ ArchFileWindows::getBasename(const char* pathname)
return basename; 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 std::string
ArchFileWindows::concatPath(const std::string& prefix, ArchFileWindows::concatPath(const std::string& prefix,
const std::string& suffix) const std::string& suffix)

View File

@ -27,7 +27,6 @@ class ArchFileWindows : public IArchFile {
public: public:
// IArchFile overrides // IArchFile overrides
virtual const char* getBasename(const char* pathname); virtual const char* getBasename(const char* pathname);
virtual std::string getSystemDirectory();
virtual std::string concatPath(const std::string& prefix, virtual std::string concatPath(const std::string& prefix,
const std::string& suffix); 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 << "If no configuration file pathname is provided then the first of the" << std::endl
<< "following to load successfully sets the configuration:" << std::endl << "following to load successfully sets the configuration:" << std::endl
<< " $HOME/" << USR_CONFIG_NAME << 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())); LOG((CLOG_PRINT "%s", buffer.str().c_str()));
} }
@ -195,7 +195,7 @@ ServerApp::loadConfig()
} }
if (!loaded) { if (!loaded) {
// try the system-wide config file // try the system-wide config file
path = ARCH->getSystemDirectory(); path = DataDirectories::systemconfig();
if (!path.empty()) { if (!path.empty()) {
path = ARCH->concatPath(path, SYS_CONFIG_NAME); path = ARCH->concatPath(path, SYS_CONFIG_NAME);
if (loadConfig(path)) { if (loadConfig(path)) {

View File

@ -14,6 +14,9 @@ public:
static const std::string& global(); static const std::string& global();
static const std::string& global(const std::string& path); static const std::string& global(const std::string& path);
static const std::string& systemconfig();
static const std::string& systemconfig(const std::string& path);
private: private:
// static class // static class
DataDirectories() {} DataDirectories() {}
@ -21,5 +24,6 @@ private:
static std::string _personal; static std::string _personal;
static std::string _profile; static std::string _profile;
static std::string _global; 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"; const std::string ProfileSubdir = "/Library/Application Support/Barrier";
#endif #endif
// static members
std::string DataDirectories::_personal;
std::string DataDirectories::_profile;
std::string DataDirectories::_global;
static std::string pw_dir(struct passwd* pwentp) static std::string pw_dir(struct passwd* pwentp)
{ {
if (pwentp != NULL && pwentp->pw_dir != NULL) if (pwentp != NULL && pwentp->pw_dir != NULL)
@ -87,3 +82,15 @@ const std::string& DataDirectories::global(const std::string& path)
return _global; 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> #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) std::string unicode_to_mb(const WCHAR* utfStr)
{ {
int utfLength = lstrlenW(utfStr); int utfLength = lstrlenW(utfStr);
@ -63,3 +58,19 @@ const std::string& DataDirectories::global(const std::string& path)
_global = path; _global = path;
return _global; 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;
}