mirror of
https://github.com/etlegacy/Update-Installer.git
synced 2024-12-02 08:31:58 +00:00
adba463f61
Following the change to FileOps::removeFile() to support 'removal' of files that are in use in Windows, the cleanup of the updater's temporary directory can be performed from the non-elevated updater setup process once the main install process has returned. This removes the --mode cleanup run mode in the updater.
126 lines
2.3 KiB
C++
126 lines
2.3 KiB
C++
#include "UpdaterOptions.h"
|
|
|
|
#include "Log.h"
|
|
#include "AnyOption/anyoption.h"
|
|
#include "Platform.h"
|
|
#include "StringUtils.h"
|
|
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
long long atoll(const char* string)
|
|
{
|
|
return _atoi64(string);
|
|
}
|
|
#endif
|
|
|
|
UpdaterOptions::UpdaterOptions()
|
|
: mode(UpdateInstaller::Setup)
|
|
, waitPid(0)
|
|
{
|
|
}
|
|
|
|
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::parseOldFormatArg(const std::string& arg, std::string* key, std::string* value)
|
|
{
|
|
size_t pos = arg.find('=');
|
|
if (pos != std::string::npos)
|
|
{
|
|
*key = arg.substr(0,pos);
|
|
*value = arg.substr(pos+1);
|
|
}
|
|
}
|
|
|
|
void UpdaterOptions::parseOldFormatArgs(int argc, char** argv)
|
|
{
|
|
for (int i=0; i < argc; i++)
|
|
{
|
|
std::string key;
|
|
std::string value;
|
|
|
|
parseOldFormatArg(argv[i],&key,&value);
|
|
|
|
if (key == "CurrentDir")
|
|
{
|
|
installDir = value;
|
|
}
|
|
else if (key == "TempDir")
|
|
{
|
|
packageDir = value;
|
|
}
|
|
else if (key == "UpdateScriptFileName")
|
|
{
|
|
scriptPath = value;
|
|
}
|
|
else if (key == "AppFileName")
|
|
{
|
|
// TODO - Store app file name
|
|
}
|
|
else if (key == "PID")
|
|
{
|
|
waitPid = static_cast<PLATFORM_PID>(atoll(value.c_str()));
|
|
}
|
|
else if (key == "--main")
|
|
{
|
|
mode = UpdateInstaller::Main;
|
|
}
|
|
}
|
|
}
|
|
|
|
void UpdaterOptions::parse(int argc, char** argv)
|
|
{
|
|
AnyOption parser;
|
|
parser.setOption("install-dir");
|
|
parser.setOption("package-dir");
|
|
parser.setOption("script");
|
|
parser.setOption("wait");
|
|
parser.setOption("mode");
|
|
|
|
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")));
|
|
}
|
|
|
|
if (installDir.empty())
|
|
{
|
|
// if no --install-dir argument is present, try parsing
|
|
// the command-line arguments in the old format (which uses
|
|
// a list of 'Key=Value' args)
|
|
parseOldFormatArgs(argc,argv);
|
|
}
|
|
}
|
|
|