2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2012-2016 Symless Ltd.
|
2012-09-04 02:09:56 +00:00
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
2012-06-10 16:50:54 +00:00
|
|
|
*
|
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2012-06-10 16:50:54 +00:00
|
|
|
*
|
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-02-28 12:55:14 +00:00
|
|
|
#include "arch/unix/ArchFileUnix.h"
|
2014-02-28 12:36:45 +00:00
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <pwd.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// ArchFileUnix
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
ArchFileUnix::ArchFileUnix()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
// do nothing
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
ArchFileUnix::~ArchFileUnix()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
// do nothing
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char*
|
2014-11-11 13:51:47 +00:00
|
|
|
ArchFileUnix::getBasename(const char* pathname)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
if (pathname == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* basename = strrchr(pathname, '/');
|
|
|
|
|
if (basename != NULL) {
|
|
|
|
|
return basename + 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return pathname;
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string
|
2014-11-11 13:51:47 +00:00
|
|
|
ArchFileUnix::getUserDirectory()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
char* buffer = NULL;
|
|
|
|
|
std::string dir;
|
2012-06-10 16:50:54 +00:00
|
|
|
#if HAVE_GETPWUID_R
|
2016-12-28 11:50:32 +00:00
|
|
|
struct passwd pwent;
|
|
|
|
|
struct passwd* pwentp;
|
2012-06-10 16:50:54 +00:00
|
|
|
#if defined(_SC_GETPW_R_SIZE_MAX)
|
2016-12-28 11:50:32 +00:00
|
|
|
long size = sysconf(_SC_GETPW_R_SIZE_MAX);
|
|
|
|
|
if (size == -1) {
|
|
|
|
|
size = BUFSIZ;
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
#else
|
2016-12-28 11:50:32 +00:00
|
|
|
long size = BUFSIZ;
|
2012-06-10 16:50:54 +00:00
|
|
|
#endif
|
2016-12-28 11:50:32 +00:00
|
|
|
buffer = new char[size];
|
|
|
|
|
getpwuid_r(getuid(), &pwent, buffer, size, &pwentp);
|
2012-06-10 16:50:54 +00:00
|
|
|
#else
|
2016-12-28 11:50:32 +00:00
|
|
|
struct passwd* pwentp = getpwuid(getuid());
|
2012-06-10 16:50:54 +00:00
|
|
|
#endif
|
2016-12-28 11:50:32 +00:00
|
|
|
if (pwentp != NULL && pwentp->pw_dir != NULL) {
|
|
|
|
|
dir = pwentp->pw_dir;
|
|
|
|
|
}
|
|
|
|
|
delete[] buffer;
|
|
|
|
|
return dir;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string
|
2014-11-11 13:51:47 +00:00
|
|
|
ArchFileUnix::getSystemDirectory()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
return "/etc";
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 14:58:30 +00:00
|
|
|
std::string
|
2014-11-11 13:51:47 +00:00
|
|
|
ArchFileUnix::getInstalledDirectory()
|
2014-10-27 14:11:43 +00:00
|
|
|
{
|
|
|
|
|
#if WINAPI_XWINDOWS
|
2016-12-28 11:50:32 +00:00
|
|
|
return "/usr/bin";
|
2014-10-27 14:11:43 +00:00
|
|
|
#else
|
2016-12-28 11:50:32 +00:00
|
|
|
return "/Applications/Synergy.app/Contents/MacOS";
|
2014-10-27 14:11:43 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string
|
2014-11-11 13:51:47 +00:00
|
|
|
ArchFileUnix::getLogDirectory()
|
2014-10-27 14:11:43 +00:00
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
return "/var/log";
|
2014-10-27 14:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-09 15:37:47 +00:00
|
|
|
std::string
|
|
|
|
|
ArchFileUnix::getPluginDirectory()
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
if (!m_pluginDirectory.empty()) {
|
|
|
|
|
return m_pluginDirectory;
|
|
|
|
|
}
|
2015-03-04 11:15:07 +00:00
|
|
|
|
2015-02-09 15:37:47 +00:00
|
|
|
#if WINAPI_XWINDOWS
|
2016-12-28 11:50:32 +00:00
|
|
|
return getProfileDirectory().append("/plugins");
|
2015-02-09 15:37:47 +00:00
|
|
|
#else
|
2016-12-28 11:50:32 +00:00
|
|
|
return getProfileDirectory().append("/Plugins");
|
2015-02-11 17:28:56 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string
|
|
|
|
|
ArchFileUnix::getProfileDirectory()
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
String dir;
|
|
|
|
|
if (!m_profileDirectory.empty()) {
|
|
|
|
|
dir = m_profileDirectory;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-02-11 17:28:56 +00:00
|
|
|
#if WINAPI_XWINDOWS
|
2016-12-28 11:50:32 +00:00
|
|
|
dir = getUserDirectory().append("/.synergy");
|
2015-02-11 17:28:56 +00:00
|
|
|
#else
|
2016-12-28 11:50:32 +00:00
|
|
|
dir = getUserDirectory().append("/Library/Synergy");
|
2015-02-09 15:37:47 +00:00
|
|
|
#endif
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
|
|
|
|
return dir;
|
2015-03-04 11:15:07 +00:00
|
|
|
|
2015-02-09 15:37:47 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
std::string
|
2014-11-11 13:51:47 +00:00
|
|
|
ArchFileUnix::concatPath(const std::string& prefix,
|
2016-12-28 11:50:32 +00:00
|
|
|
const std::string& suffix)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
std::string path;
|
|
|
|
|
path.reserve(prefix.size() + 1 + suffix.size());
|
|
|
|
|
path += prefix;
|
|
|
|
|
if (path.size() == 0 || path[path.size() - 1] != '/') {
|
|
|
|
|
path += '/';
|
|
|
|
|
}
|
|
|
|
|
path += suffix;
|
|
|
|
|
return path;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
2015-03-04 11:15:07 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ArchFileUnix::setProfileDirectory(const String& s)
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
m_profileDirectory = s;
|
2015-03-04 11:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ArchFileUnix::setPluginDirectory(const String& s)
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
m_pluginDirectory = s;
|
2015-03-04 11:15:07 +00:00
|
|
|
}
|