2014-02-04 19:41:29 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2014-11-02 12:12:05 +00:00
|
|
|
* Copyright (C) 2014 Synergy Si Ltd.
|
2014-02-04 19:41:29 +00:00
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* 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:36:45 +00:00
|
|
|
#include "synergy/ToolApp.h"
|
2014-10-27 16:39:18 +00:00
|
|
|
|
|
|
|
#include "synergy/ArgParser.h"
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "arch/Arch.h"
|
2014-10-27 16:39:18 +00:00
|
|
|
#include "base/Log.h"
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "base/String.h"
|
2014-02-04 19:41:29 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2014-10-27 16:39:18 +00:00
|
|
|
|
|
|
|
#if SYSAPI_WIN32
|
|
|
|
#include "platform/MSWindowsSession.h"
|
|
|
|
#endif
|
2014-02-04 19:41:29 +00:00
|
|
|
|
2014-03-20 10:33:33 +00:00
|
|
|
enum {
|
|
|
|
kErrorOk,
|
|
|
|
kErrorArgs,
|
|
|
|
kErrorException,
|
|
|
|
kErrorUnknown
|
|
|
|
};
|
|
|
|
|
|
|
|
UInt32
|
2014-11-11 13:51:47 +00:00
|
|
|
ToolApp::run(int argc, char** argv)
|
2014-02-04 19:41:29 +00:00
|
|
|
{
|
|
|
|
if (argc <= 1) {
|
|
|
|
std::cerr << "no args" << std::endl;
|
2014-03-20 10:33:33 +00:00
|
|
|
return kErrorArgs;
|
2014-02-04 19:41:29 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 10:33:33 +00:00
|
|
|
try {
|
2014-10-27 16:39:18 +00:00
|
|
|
CArgParser argParser(this);
|
|
|
|
bool result = argParser.parseToolArgs(m_args, argc, argv);
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
m_bye(kExitArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_args.m_printActiveDesktopName) {
|
|
|
|
#if SYSAPI_WIN32
|
|
|
|
CMSWindowsSession session;
|
|
|
|
CString name = session.getActiveDesktopName();
|
|
|
|
if (name.empty()) {
|
|
|
|
LOG((CLOG_CRIT "failed to get active desktop name"));
|
|
|
|
return kExitFailed;
|
2014-03-20 10:33:33 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-10-27 16:39:18 +00:00
|
|
|
std::cout << "activeDesktop:" << name.c_str() << std::endl;
|
2014-03-20 10:33:33 +00:00
|
|
|
}
|
2014-10-27 16:39:18 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw XSynergy("Nothing to do");
|
2014-02-04 19:41:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-20 10:33:33 +00:00
|
|
|
catch (std::exception& e) {
|
2014-10-27 16:39:18 +00:00
|
|
|
LOG((CLOG_CRIT "An error occurred: %s\n", e.what()));
|
|
|
|
return kExitFailed;
|
2014-03-20 10:33:33 +00:00
|
|
|
}
|
|
|
|
catch (...) {
|
2014-10-27 16:39:18 +00:00
|
|
|
LOG((CLOG_CRIT "An unknown error occurred.\n"));
|
|
|
|
return kExitFailed;
|
2014-03-20 10:33:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return kErrorOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-27 16:39:18 +00:00
|
|
|
CToolApp::help()
|
2014-03-20 10:33:33 +00:00
|
|
|
{
|
2014-02-04 19:41:29 +00:00
|
|
|
}
|