Add subscription functionalities in syntool #4715

This commit is contained in:
Jerry (Xinyu Hou) 2015-10-21 16:35:22 -07:00
parent 8f941f5713
commit 18e7004213
6 changed files with 62 additions and 8 deletions

View File

@ -147,9 +147,10 @@
#include <string.h>
enum {
kExitSuccess = 0, // successful completion
kExitFailed = 1, // general failure
kExitTerminated = 2, // killed by signal
kExitArgs = 3, // bad arguments
kExitConfig = 4 // cannot read configuration
kExitSuccess = 0, // successful completion
kExitFailed = 1, // general failure
kExitTerminated = 2, // killed by signal
kExitArgs = 3, // bad arguments
kExitConfig = 4, // cannot read configuration
kExitSubscription = 5 // subscription error
};

View File

@ -163,7 +163,6 @@ ArgParser::parsePlatformArg(ArgsBase& argsBase, const int& argc, const char* con
#endif
}
bool
ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv)
{
@ -196,6 +195,22 @@ ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv)
args.m_getArch = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--subscription-serial", 1)) {
args.m_subscriptionSerial = argv[++i];
if (args.m_subscriptionSerial.empty()) {
LOG((CLOG_CRIT "subscription error: serial was not provided"));
return false;
}
return true;
}
else if (isArg(i, argc, argv, NULL, "--get-subscription-filename", 0)) {
args.m_printSubscriptionFilename = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--check-subscription", 0)) {
args.m_checkSubscription = true;
return true;
}
else {
return false;
}

View File

@ -194,7 +194,7 @@ SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey&
String
SubscriptionManager::getFilename()
{
String path = ARCH->getUserDirectory();
String path = ARCH->getProfileDirectory();
path = ARCH->concatPath(path, kFile);
if (path.empty()) {
throw XSubscription("Could not get filename.");

View File

@ -18,6 +18,7 @@
#include "synergy/ToolApp.h"
#include "synergy/ArgParser.h"
#include "synergy/SubscriptionManager.h"
#include "arch/Arch.h"
#include "base/Log.h"
#include "base/String.h"
@ -86,6 +87,36 @@ ToolApp::run(int argc, char** argv)
else if (m_args.m_getArch) {
std::cout << ARCH->getPlatformName() << std::endl;
}
else if (!m_args.m_subscriptionSerial.empty()) {
try {
SubscriptionManager subscriptionManager;
subscriptionManager.activate(m_args.m_subscriptionSerial);
}
catch (XSubscription& e) {
LOG((CLOG_CRIT "subscription error: %s", e.what()));
return kExitSubscription;
}
}
else if (m_args.m_printSubscriptionFilename) {
try {
SubscriptionManager subscriptionManager;
subscriptionManager.printFilename();
}
catch (XSubscription& e) {
LOG((CLOG_CRIT "subscription error: %s", e.what()));
return kExitSubscription;
}
}
else if (m_args.m_checkSubscription) {
try {
SubscriptionManager subscriptionManager;
subscriptionManager.checkFile("");
}
catch (XSubscription& e) {
LOG((CLOG_CRIT "subscription error: %s", e.what()));
return kExitSubscription;
}
}
else {
throw XSynergy("Nothing to do");
}

View File

@ -23,6 +23,10 @@ ToolArgs::ToolArgs() :
m_getPluginList(false),
m_getPluginDir(false),
m_getInstalledDir(false),
m_getProfileDir(false)
m_getProfileDir(false),
m_getArch(false),
m_printSubscriptionFilename(false),
m_checkSubscription(false),
m_subscriptionSerial()
{
}

View File

@ -31,4 +31,7 @@ public:
bool m_getInstalledDir;
bool m_getProfileDir;
bool m_getArch;
bool m_printSubscriptionFilename;
bool m_checkSubscription;
String m_subscriptionSerial;
};