2013-12-01 23:55:24 +00:00
|
|
|
#include "UpdaterOptions.h"
|
|
|
|
|
|
|
|
#include "Log.h"
|
|
|
|
#include "AnyOption/anyoption.h"
|
|
|
|
#include "FileUtils.h"
|
|
|
|
#include "Platform.h"
|
|
|
|
#include "StringUtils.h"
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
UpdaterOptions::UpdaterOptions()
|
|
|
|
: mode(UpdateInstaller::Setup)
|
|
|
|
, waitPid(0)
|
|
|
|
, showVersion(false)
|
|
|
|
, forceElevated(false)
|
|
|
|
, autoClose(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateInstaller::Mode stringToMode(const std::string& modeStr)
|
|
|
|
{
|
|
|
|
if (modeStr == "main")
|
|
|
|
{
|
|
|
|
return UpdateInstaller::Main;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!modeStr.empty())
|
|
|
|
{
|
|
|
|
LOG(Error,"Unknown mode " + modeStr);
|
|
|
|
}
|
|
|
|
return UpdateInstaller::Setup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdaterOptions::parse(int argc, char** argv)
|
|
|
|
{
|
|
|
|
AnyOption parser;
|
|
|
|
parser.setOption("install-dir");
|
|
|
|
parser.setOption("package-dir");
|
2013-12-06 02:32:12 +00:00
|
|
|
parser.setOption("finish-cmd");
|
2014-01-05 15:47:12 +00:00
|
|
|
parser.setOption("finish-dir");
|
2013-12-01 23:55:24 +00:00
|
|
|
parser.setOption("script");
|
|
|
|
parser.setOption("wait");
|
|
|
|
parser.setOption("mode");
|
|
|
|
parser.setFlag("version");
|
|
|
|
parser.setFlag("force-elevated");
|
2014-01-04 23:06:55 +00:00
|
|
|
parser.setFlag("dry-run");
|
2013-12-01 23:55:24 +00:00
|
|
|
parser.setFlag("auto-close");
|
|
|
|
|
|
|
|
parser.processCommandArgs(argc,argv);
|
|
|
|
|
|
|
|
if (parser.getValue("mode"))
|
|
|
|
{
|
|
|
|
mode = stringToMode(parser.getValue("mode"));
|
|
|
|
}
|
|
|
|
if (parser.getValue("install-dir"))
|
|
|
|
{
|
|
|
|
installDir = parser.getValue("install-dir");
|
|
|
|
}
|
|
|
|
if (parser.getValue("package-dir"))
|
|
|
|
{
|
|
|
|
packageDir = parser.getValue("package-dir");
|
|
|
|
}
|
|
|
|
if (parser.getValue("script"))
|
|
|
|
{
|
|
|
|
scriptPath = parser.getValue("script");
|
|
|
|
}
|
|
|
|
if (parser.getValue("wait"))
|
|
|
|
{
|
|
|
|
waitPid = static_cast<PLATFORM_PID>(atoll(parser.getValue("wait")));
|
|
|
|
}
|
2013-12-06 02:32:12 +00:00
|
|
|
if (parser.getValue("finish-cmd"))
|
|
|
|
{
|
|
|
|
finishCmd = parser.getValue("finish-cmd");
|
|
|
|
}
|
2014-01-05 15:47:12 +00:00
|
|
|
if (parser.getValue("finish-dir"))
|
|
|
|
{
|
|
|
|
finishDir = parser.getValue("finish-dir");
|
|
|
|
}
|
2013-12-01 23:55:24 +00:00
|
|
|
|
|
|
|
showVersion = parser.getFlag("version");
|
|
|
|
forceElevated = parser.getFlag("force-elevated");
|
2014-01-04 23:06:55 +00:00
|
|
|
dryRun = parser.getFlag("dry-run");
|
2013-12-01 23:55:24 +00:00
|
|
|
autoClose = parser.getFlag("auto-close");
|
|
|
|
}
|