2017-01-28 04:49:09 +08:00
|
|
|
#include "pch.h"
|
2016-09-19 11:50:08 +08:00
|
|
|
#include "StatusParagraph.h"
|
|
|
|
#include "vcpkglib_helpers.h"
|
|
|
|
|
|
|
|
using namespace vcpkg::details;
|
|
|
|
|
|
|
|
namespace vcpkg
|
|
|
|
{
|
2016-11-04 09:55:32 +08:00
|
|
|
//
|
|
|
|
namespace BinaryParagraphRequiredField
|
|
|
|
{
|
|
|
|
static const std::string STATUS = "Status";
|
|
|
|
}
|
|
|
|
|
2017-04-04 06:42:26 +08:00
|
|
|
StatusParagraph::StatusParagraph() : want(Want::ERROR_STATE), state(InstallState::ERROR_STATE)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-13 13:48:52 +08:00
|
|
|
void serialize(const StatusParagraph& pgh, std::string& out_str)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-13 13:48:52 +08:00
|
|
|
serialize(pgh.package, out_str);
|
|
|
|
out_str.append("Status: ").append(to_string(pgh.want)).append(" ok ").append(to_string(pgh.state)).push_back('\n');
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusParagraph::StatusParagraph(const std::unordered_map<std::string, std::string>& fields)
|
|
|
|
: package(fields)
|
|
|
|
{
|
2016-11-04 09:55:32 +08:00
|
|
|
std::string status_field = required_field(fields, BinaryParagraphRequiredField::STATUS);
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
auto b = status_field.begin();
|
|
|
|
auto mark = b;
|
|
|
|
auto e = status_field.end();
|
|
|
|
|
|
|
|
// Todo: improve error handling
|
|
|
|
while (b != e && *b != ' ')
|
|
|
|
++b;
|
|
|
|
|
|
|
|
want = [](const std::string& text)
|
|
|
|
{
|
|
|
|
if (text == "unknown")
|
2017-04-04 06:42:26 +08:00
|
|
|
return Want::UNKNOWN;
|
2016-09-19 11:50:08 +08:00
|
|
|
if (text == "install")
|
2017-04-04 06:42:26 +08:00
|
|
|
return Want::INSTALL;
|
2016-09-19 11:50:08 +08:00
|
|
|
if (text == "hold")
|
2017-04-04 06:42:26 +08:00
|
|
|
return Want::HOLD;
|
2016-09-19 11:50:08 +08:00
|
|
|
if (text == "deinstall")
|
2017-04-04 06:42:26 +08:00
|
|
|
return Want::DEINSTALL;
|
2016-09-19 11:50:08 +08:00
|
|
|
if (text == "purge")
|
2017-04-04 06:42:26 +08:00
|
|
|
return Want::PURGE;
|
|
|
|
return Want::ERROR_STATE;
|
2016-09-19 11:50:08 +08:00
|
|
|
}(std::string(mark, b));
|
|
|
|
|
|
|
|
if (std::distance(b, e) < 4)
|
|
|
|
return;
|
|
|
|
b += 4;
|
|
|
|
|
|
|
|
state = [](const std::string& text)
|
|
|
|
{
|
|
|
|
if (text == "not-installed")
|
2017-04-04 06:25:34 +08:00
|
|
|
return InstallState::NOT_INSTALLED;
|
2016-09-19 11:50:08 +08:00
|
|
|
if (text == "installed")
|
2017-04-04 06:25:34 +08:00
|
|
|
return InstallState::INSTALLED;
|
2016-09-19 11:50:08 +08:00
|
|
|
if (text == "half-installed")
|
2017-04-04 06:25:34 +08:00
|
|
|
return InstallState::HALF_INSTALLED;
|
|
|
|
return InstallState::ERROR_STATE;
|
2016-09-19 11:50:08 +08:00
|
|
|
}(std::string(b, e));
|
|
|
|
}
|
|
|
|
|
2017-04-04 06:14:17 +08:00
|
|
|
std::string to_string(InstallState f)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
switch (f)
|
|
|
|
{
|
2017-04-04 06:25:34 +08:00
|
|
|
case InstallState::HALF_INSTALLED: return "half-installed";
|
|
|
|
case InstallState::INSTALLED: return "installed";
|
|
|
|
case InstallState::NOT_INSTALLED: return "not-installed";
|
2016-09-19 11:50:08 +08:00
|
|
|
default: return "error";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-04 06:25:53 +08:00
|
|
|
std::string to_string(Want f)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
switch (f)
|
|
|
|
{
|
2017-04-04 06:42:26 +08:00
|
|
|
case Want::DEINSTALL: return "deinstall";
|
|
|
|
case Want::HOLD: return "hold";
|
|
|
|
case Want::INSTALL: return "install";
|
|
|
|
case Want::PURGE: return "purge";
|
|
|
|
case Want::UNKNOWN: return "unknown";
|
2016-09-19 11:50:08 +08:00
|
|
|
default: return "error";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|