diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index b5b0ce11..b991d2a6 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -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()); +} diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index c57fa1cd..b82984cf 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -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; diff --git a/src/lib/arch/IArchFile.h b/src/lib/arch/IArchFile.h index 7790487e..d8f96a0b 100644 --- a/src/lib/arch/IArchFile.h +++ b/src/lib/arch/IArchFile.h @@ -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; }; diff --git a/src/lib/arch/unix/ArchFileUnix.cpp b/src/lib/arch/unix/ArchFileUnix.cpp index 39b3b912..ac9f7985 100644 --- a/src/lib/arch/unix/ArchFileUnix.cpp +++ b/src/lib/arch/unix/ArchFileUnix.cpp @@ -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; +} diff --git a/src/lib/arch/unix/ArchFileUnix.h b/src/lib/arch/unix/ArchFileUnix.h index 0428b75e..7cb90a1c 100644 --- a/src/lib/arch/unix/ArchFileUnix.h +++ b/src/lib/arch/unix/ArchFileUnix.h @@ -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; }; diff --git a/src/lib/arch/win32/ArchFileWindows.cpp b/src/lib/arch/win32/ArchFileWindows.cpp index 278a18f9..d819d6e9 100644 --- a/src/lib/arch/win32/ArchFileWindows.cpp +++ b/src/lib/arch/win32/ArchFileWindows.cpp @@ -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; +} diff --git a/src/lib/arch/win32/ArchFileWindows.h b/src/lib/arch/win32/ArchFileWindows.h index aa99b7fd..596162b6 100644 --- a/src/lib/arch/win32/ArchFileWindows.h +++ b/src/lib/arch/win32/ArchFileWindows.h @@ -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; }; diff --git a/src/lib/synergy/App.cpp b/src/lib/synergy/App.cpp index b70ca9e9..1c89b83f 100644 --- a/src/lib/synergy/App.cpp +++ b/src/lib/synergy/App.cpp @@ -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)) { diff --git a/src/lib/synergy/ArgParser.cpp b/src/lib/synergy/ArgParser.cpp index c5830d54..fef32228 100644 --- a/src/lib/synergy/ArgParser.cpp +++ b/src/lib/synergy/ArgParser.cpp @@ -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; diff --git a/src/lib/synergy/ArgsBase.cpp b/src/lib/synergy/ArgsBase.cpp index 8dcfb2f9..fe581034 100644 --- a/src/lib/synergy/ArgsBase.cpp +++ b/src/lib/synergy/ArgsBase.cpp @@ -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("") { } diff --git a/src/lib/synergy/ArgsBase.h b/src/lib/synergy/ArgsBase.h index a2333a48..125f9b51 100644 --- a/src/lib/synergy/ArgsBase.h +++ b/src/lib/synergy/ArgsBase.h @@ -47,4 +47,6 @@ public: bool m_shouldExit; String m_synergyAddress; bool m_enableCrypto; + String m_profileDirectory; + String m_pluginDirectory; };