2013-12-02 05:25:24 +05:30
|
|
|
#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 08:02:12 +05:30
|
|
|
parser.setOption("finish-cmd");
|
2014-01-05 21:17:12 +05:30
|
|
|
parser.setOption("finish-dir");
|
2013-12-02 05:25:24 +05:30
|
|
|
parser.setOption("script");
|
|
|
|
parser.setOption("wait");
|
|
|
|
parser.setOption("mode");
|
|
|
|
parser.setFlag("version");
|
|
|
|
parser.setFlag("force-elevated");
|
2014-01-05 04:36:55 +05:30
|
|
|
parser.setFlag("dry-run");
|
2013-12-02 05:25:24 +05:30
|
|
|
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 08:02:12 +05:30
|
|
|
if (parser.getValue("finish-cmd"))
|
|
|
|
{
|
|
|
|
finishCmd = parser.getValue("finish-cmd");
|
|
|
|
}
|
2014-01-05 21:17:12 +05:30
|
|
|
if (parser.getValue("finish-dir"))
|
|
|
|
{
|
|
|
|
finishDir = parser.getValue("finish-dir");
|
|
|
|
}
|
2013-12-02 05:25:24 +05:30
|
|
|
|
|
|
|
showVersion = parser.getFlag("version");
|
|
|
|
forceElevated = parser.getFlag("force-elevated");
|
2014-01-05 04:36:55 +05:30
|
|
|
dryRun = parser.getFlag("dry-run");
|
2013-12-02 05:25:24 +05:30
|
|
|
autoClose = parser.getFlag("auto-close");
|
|
|
|
}
|