Fixed: Plugins dir may change depending on user #4168

This commit is contained in:
Nick Bolton 2015-03-04 11:15:07 +00:00
parent c5ed03a8a0
commit cfd21216cd
11 changed files with 132 additions and 12 deletions

View File

@ -450,6 +450,8 @@ void MainWindow::startSynergy()
args << "--enable-crypto";
}
args << "--profile-dir" << getProfileDirectoryForArg();
if ((synergyType() == synergyClient && !clientArgs(args, app))
|| (synergyType() == synergyServer && !serverArgs(args, app)))
{
@ -473,6 +475,8 @@ void MainWindow::startSynergy()
appendLogNote("starting " + QString(synergyType() == synergyServer ? "server" : "client"));
qDebug() << args;
// show command if debug log level...
if (appConfig().logLevel() >= 4) {
appendLogNote(QString("command: %1 %2").arg(app, args.join(" ")));
@ -1216,3 +1220,29 @@ void MainWindow::bonjourInstallFinished()
m_pCheckBoxAutoConfig->setChecked(true);
}
QString MainWindow::getProfileDirectory()
{
#if defined(Q_OS_WIN)
QString qtDataDir = QDesktopServices::storageLocation(
QDesktopServices::DataLocation);
// HACK: core wants the base app data dir, this seems like a very hacky
// way to get it (maybe consider using %LOCALAPPDATA% instead?)
return qtDataDir.replace("\\Synergy\\Synergy", "");
#else
// HACK: this seems hacky, since we're using a hidden folder inside the
// user's home dir to store plugins, etc... but we call it profile dir?
return QDesktopServices::storageLocation(
QDesktopServices::HomeLocation);
#endif
}
QString MainWindow::getProfileDirectoryForArg()
{
return QString("\"%1\"").arg(getProfileDirectory());
}

View File

@ -165,6 +165,8 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
void downloadBonjour();
void promptAutoConfig();
void updateEdition();
QString getProfileDirectory();
QString getProfileDirectoryForArg();
private:
QSettings& m_Settings;

View File

@ -20,6 +20,7 @@
#include "common/IInterface.h"
#include "common/stdstring.h"
#include "base/String.h"
//! Interface for architecture dependent file system operations
/*!
@ -64,13 +65,16 @@ public:
//! Get plugins directory
/*!
Returns the plugin files 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 local profile directory
//! Get user's profile directory
/*!
Returns the local profile directory.
Returns the user's profile directory. If no profile directory is set,
this will return the user's profile according to the operating system,
which will depend on which user launched the program.
*/
virtual std::string getProfileDirectory() = 0;
@ -84,6 +88,18 @@ public:
virtual std::string concatPath(
const std::string& prefix,
const std::string& suffix) = 0;
//@}
//! Set the user's profile directory
/*
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

@ -107,6 +107,10 @@ ArchFileUnix::getLogDirectory()
std::string
ArchFileUnix::getPluginDirectory()
{
if (!m_pluginDirectory.empty()) {
return m_pluginDirectory;
}
#if WINAPI_XWINDOWS
return getProfileDirectory().append("/plugins");
#else
@ -117,11 +121,19 @@ ArchFileUnix::getPluginDirectory()
std::string
ArchFileUnix::getProfileDirectory()
{
String dir;
if (!m_profileDirectory.empty()) {
dir = m_profileDirectory;
}
else {
#if WINAPI_XWINDOWS
return getUserDirectory().append("/.synergy");
dir = getUserDirectory().append("/.synergy");
#else
return getUserDirectory().append("/Library/Synergy");
dir = getUserDirectory().append("/Library/Synergy");
#endif
}
return dir;
}
std::string
@ -137,3 +149,15 @@ ArchFileUnix::concatPath(const std::string& prefix,
path += suffix;
return path;
}
void
ArchFileUnix::setProfileDirectory(const String& s)
{
m_profileDirectory = s;
}
void
ArchFileUnix::setPluginDirectory(const String& s)
{
m_pluginDirectory = s;
}

View File

@ -38,4 +38,10 @@ public:
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_profileDirectory;
String m_pluginDirectory;
};

View File

@ -142,6 +142,10 @@ ArchFileWindows::getLogDirectory()
std::string
ArchFileWindows::getPluginDirectory()
{
if (!m_pluginDirectory.empty()) {
return m_pluginDirectory;
}
std::string dir = getProfileDirectory();
dir.append("\\Plugins");
return dir;
@ -150,16 +154,23 @@ ArchFileWindows::getPluginDirectory()
std::string
ArchFileWindows::getProfileDirectory()
{
TCHAR result[MAX_PATH];
std::string dir;
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, result))) {
dir = result;
String dir;
if (!m_profileDirectory.empty()) {
dir = m_profileDirectory;
}
else {
dir = getUserDirectory();
TCHAR result[MAX_PATH];
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, result))) {
dir = result;
}
else {
dir = getUserDirectory();
}
}
// HACK: append program name, this seems wrong.
dir.append("\\Synergy");
return dir;
}
@ -178,3 +189,15 @@ ArchFileWindows::concatPath(const std::string& prefix,
path += suffix;
return path;
}
void
ArchFileWindows::setProfileDirectory(const String& s)
{
m_profileDirectory = s;
}
void
ArchFileWindows::setPluginDirectory(const String& s)
{
m_pluginDirectory = s;
}

View File

@ -38,4 +38,10 @@ public:
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_profileDirectory;
String m_pluginDirectory;
};

View File

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

View File

@ -253,7 +253,7 @@ ArgParser::parseGenericArgs(int argc, const char* const* argv, int& i)
else if (isArg(i, argc, argv, NULL, "--client")) {
// HACK: stop error happening when using portable (synergyp)
}
else if (isArg(i, argc, argv, NULL, "--enable-drag-drop")) {
else if (isArg(i, argc, argv, NULL, "--enable-drag-drop", 1)) {
bool useDragDrop = true;
#ifdef WINAPI_XWINDOWS
@ -283,6 +283,12 @@ ArgParser::parseGenericArgs(int argc, const char* const* argv, int& i)
else if (isArg(i, argc, argv, NULL, "--enable-crypto")) {
argsBase().m_enableCrypto = true;
}
else if (isArg(i, argc, argv, NULL, "--profile-dir", 1)) {
argsBase().m_profileDirectory = argv[++i];
}
else if (isArg(i, argc, argv, NULL, "--plugin-dir", 1)) {
argsBase().m_pluginDirectory = argv[++i];
}
else {
// option not supported here
return false;

View File

@ -42,7 +42,9 @@ m_enableIpc(false),
m_enableDragDrop(false),
m_shouldExit(false),
m_synergyAddress(),
m_enableCrypto(false)
m_enableCrypto(false),
m_profileDirectory(""),
m_pluginDirectory("")
{
}

View File

@ -47,4 +47,6 @@ public:
bool m_shouldExit;
String m_synergyAddress;
bool m_enableCrypto;
String m_profileDirectory;
String m_pluginDirectory;
};