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:14:17 +08:00
|
|
|
StatusParagraph::StatusParagraph() : want(want_t::error), state(InstallState::error)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& os, const StatusParagraph& p)
|
|
|
|
{
|
|
|
|
os << p.package;
|
|
|
|
os << "Status: " << to_string(p.want) << " ok " << to_string(p.state) << "\n";
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
return want_t::unknown;
|
|
|
|
if (text == "install")
|
|
|
|
return want_t::install;
|
|
|
|
if (text == "hold")
|
|
|
|
return want_t::hold;
|
|
|
|
if (text == "deinstall")
|
|
|
|
return want_t::deinstall;
|
|
|
|
if (text == "purge")
|
|
|
|
return want_t::purge;
|
|
|
|
return want_t::error;
|
|
|
|
}(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:14:17 +08:00
|
|
|
return InstallState::not_installed;
|
2016-09-19 11:50:08 +08:00
|
|
|
if (text == "installed")
|
2017-04-04 06:14:17 +08:00
|
|
|
return InstallState::installed;
|
2016-09-19 11:50:08 +08:00
|
|
|
if (text == "half-installed")
|
2017-04-04 06:14:17 +08:00
|
|
|
return InstallState::half_installed;
|
|
|
|
return InstallState::error;
|
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:14:17 +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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string to_string(want_t f)
|
|
|
|
{
|
|
|
|
switch (f)
|
|
|
|
{
|
|
|
|
case want_t::deinstall: return "deinstall";
|
|
|
|
case want_t::hold: return "hold";
|
|
|
|
case want_t::install: return "install";
|
|
|
|
case want_t::purge: return "purge";
|
|
|
|
case want_t::unknown: return "unknown";
|
|
|
|
default: return "error";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|