remove some stale code and put windows service logfile in a better spot

This commit is contained in:
walker0643 2018-03-29 21:41:30 -04:00
parent 1be86a9248
commit d81054ab6e
12 changed files with 55 additions and 128 deletions

View File

@ -51,25 +51,6 @@ public:
*/
virtual std::string getSystemDirectory() = 0;
//! Get installed directory
/*!
Returns the directory in which Barrier is installed.
*/
virtual std::string getInstalledDirectory() = 0;
//! Get log directory
/*!
Returns the log file directory.
*/
virtual std::string getLogDirectory() = 0;
//! Get plugins directory
/*!
Returns the plugin files directory. If no plugin directory is set,
this will return the plugin folder within the user's profile.
*/
virtual std::string getPluginDirectory() = 0;
//! Get user's profile directory
/*!
Returns the user's profile directory. If no profile directory is set,
@ -95,11 +76,4 @@ public:
Returns the user's profile directory.
*/
virtual void setProfileDirectory(const String& s) = 0;
//@}
//! Set the user's plugin directory
/*
Returns the user's plugin directory.
*/
virtual void setPluginDirectory(const String& s) = 0;
};

View File

@ -67,36 +67,6 @@ ArchFileUnix::getSystemDirectory()
return "/etc";
}
std::string
ArchFileUnix::getInstalledDirectory()
{
#if WINAPI_XWINDOWS
return "/usr/bin";
#else
return "/Applications/Barrier.app/Contents/MacOS";
#endif
}
std::string
ArchFileUnix::getLogDirectory()
{
return "/var/log";
}
std::string
ArchFileUnix::getPluginDirectory()
{
if (!m_pluginDirectory.empty()) {
return m_pluginDirectory;
}
#if WINAPI_XWINDOWS
return getProfileDirectory().append("/plugins");
#else
return getProfileDirectory().append("/Plugins");
#endif
}
std::string
ArchFileUnix::getProfileDirectory()
{

View File

@ -32,9 +32,6 @@ public:
virtual const char* getBasename(const char* pathname);
virtual std::string getUserDirectory();
virtual std::string getSystemDirectory();
virtual std::string getInstalledDirectory();
virtual std::string getLogDirectory();
virtual std::string getPluginDirectory();
virtual std::string getProfileDirectory();
virtual std::string concatPath(const std::string& prefix,
const std::string& suffix);

View File

@ -29,16 +29,6 @@
// ArchFileWindows
//
ArchFileWindows::ArchFileWindows()
{
// do nothing
}
ArchFileWindows::~ArchFileWindows()
{
// do nothing
}
const char*
ArchFileWindows::getBasename(const char* pathname)
{
@ -84,36 +74,6 @@ ArchFileWindows::getSystemDirectory()
}
}
std::string
ArchFileWindows::getInstalledDirectory()
{
char fileNameBuffer[MAX_PATH];
GetModuleFileName(NULL, fileNameBuffer, MAX_PATH);
std::string fileName(fileNameBuffer);
size_t lastSlash = fileName.find_last_of("\\");
fileName = fileName.substr(0, lastSlash);
return fileName;
}
std::string
ArchFileWindows::getLogDirectory()
{
return getInstalledDirectory();
}
std::string
ArchFileWindows::getPluginDirectory()
{
if (!m_pluginDirectory.empty()) {
return m_pluginDirectory;
}
std::string dir = getProfileDirectory();
dir.append("\\Plugins");
return dir;
}
std::string
ArchFileWindows::getProfileDirectory()
{
@ -141,9 +101,3 @@ ArchFileWindows::setProfileDirectory(const String& s)
{
DataDirectories::profile(s);
}
void
ArchFileWindows::setPluginDirectory(const String& s)
{
m_pluginDirectory = s;
}

View File

@ -25,22 +25,12 @@
//! Win32 implementation of IArchFile
class ArchFileWindows : public IArchFile {
public:
ArchFileWindows();
virtual ~ArchFileWindows();
// IArchFile overrides
virtual const char* getBasename(const char* pathname);
virtual std::string getUserDirectory();
virtual std::string getSystemDirectory();
virtual std::string getInstalledDirectory();
virtual std::string getLogDirectory();
virtual std::string getPluginDirectory();
virtual std::string getProfileDirectory();
virtual std::string concatPath(const std::string& prefix,
const std::string& suffix);
virtual void setProfileDirectory(const String& s);
virtual void setPluginDirectory(const String& s);
private:
String m_pluginDirectory;
};

View File

@ -176,7 +176,6 @@ App::initApp(int argc, const char** argv)
parseArgs(argc, argv);
ARCH->setProfileDirectory(argsBase().m_profileDirectory);
ARCH->setPluginDirectory(argsBase().m_pluginDirectory);
// set log filter
if (!CLOG->setFilter(argsBase().m_logFilter)) {

View File

@ -33,6 +33,7 @@
#include "base/EventQueue.h"
#include "base/log_outputters.h"
#include "base/Log.h"
#include "common/DataDirectories.h"
#include "arch/win32/ArchMiscWindows.h"
#include "arch/win32/XArchWindows.h"
@ -41,6 +42,7 @@
#include "platform/MSWindowsDebugOutputter.h"
#include "platform/MSWindowsWatchdog.h"
#include "platform/MSWindowsEventQueueBuffer.h"
#include "platform/MSWindowsUtil.h"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
@ -241,14 +243,10 @@ DaemonApp::foregroundError(const char* message)
std::string
DaemonApp::logFilename()
{
string logFilename;
logFilename = ARCH->setting("LogFilename");
if (logFilename.empty()) {
logFilename = ARCH->getLogDirectory();
logFilename.append("/");
logFilename.append(LOG_FILENAME);
}
string logFilename = ARCH->setting("LogFilename");
if (logFilename.empty())
logFilename = DataDirectories::global() + "\\" + LOG_FILENAME;
MSWindowsUtil::createDirectory(logFilename, true);
return logFilename;
}

View File

@ -11,11 +11,15 @@ public:
static const std::string& profile();
static const std::string& profile(const std::string& path);
static const std::string& global();
static const std::string& global(const std::string& path);
private:
// static class
DataDirectories() {}
static std::string _personal;
static std::string _profile;
static std::string _global;
};

View File

@ -13,6 +13,7 @@ const std::string ProfileSubdir = "/Library/Application Support/Barrier";
// static members
std::string DataDirectories::_personal;
std::string DataDirectories::_profile;
std::string DataDirectories::_global;
static std::string pw_dir(struct passwd* pwentp)
{
@ -54,7 +55,6 @@ const std::string& DataDirectories::personal()
_personal = unix_home();
return _personal;
}
const std::string& DataDirectories::personal(const std::string& path)
{
_personal = path;
@ -67,10 +67,23 @@ const std::string& DataDirectories::profile()
_profile = personal() + ProfileSubdir;
return _profile;
}
const std::string& DataDirectories::profile(const std::string& path)
{
_profile = path;
return _profile;
}
const std::string& DataDirectories::global()
{
if (_global.empty())
// TODO: where on a unix system should public/global shared data go?
// as of march 2018 global() is not used for unix
_global = "/tmp";
return _global;
}
const std::string& DataDirectories::global(const std::string& path)
{
_global = path;
return _global;
}

View File

@ -5,6 +5,7 @@
// static member
std::string DataDirectories::_personal;
std::string DataDirectories::_profile;
std::string DataDirectories::_global;
std::string unicode_to_mb(const WCHAR* utfStr)
{
@ -33,7 +34,6 @@ const std::string& DataDirectories::personal()
_personal = known_folder_path(FOLDERID_Documents);
return _personal;
}
const std::string& DataDirectories::personal(const std::string& path)
{
_personal = path;
@ -46,10 +46,20 @@ const std::string& DataDirectories::profile()
_profile = known_folder_path(FOLDERID_LocalAppData) + "\\Barrier";
return _profile;
}
const std::string& DataDirectories::profile(const std::string& path)
{
_profile = path;
return _profile;
}
const std::string& DataDirectories::global()
{
if (_global.empty())
_global = known_folder_path(FOLDERID_ProgramData) + "\\Barrier";
return _global;
}
const std::string& DataDirectories::global(const std::string& path)
{
_global = path;
return _global;
}

View File

@ -62,3 +62,14 @@ MSWindowsUtil::getErrorString(HINSTANCE hinstance, DWORD error, DWORD id)
return result;
}
}
void
MSWindowsUtil::createDirectory(const std::string& path, bool stripLast)
{
// create parent directories
for (auto pos = path.find_first_of('\\'); pos != std::string::npos; pos = path.find_first_of('\\', pos + 1))
CreateDirectory(path.substr(0, pos).c_str(), NULL);
if (!stripLast)
// create innermost directory
CreateDirectory(path.c_str(), NULL);
}

View File

@ -37,4 +37,11 @@ public:
found return the string for \p id, replacing ${1} with \p error.
*/
static String getErrorString(HINSTANCE, DWORD error, DWORD id);
//! Create directory
/*!
Create directory \p recursively optionally stripping the last component
(presumably the filename) if \p is set.
*/
static void createDirectory(const std::string& path, bool stripLast = false);
};