2020-04-09 10:07:19 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Luciano Iam <lucianito@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the/GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2020-04-11 03:31:06 -04:00
|
|
|
|
|
|
|
#include <glibmm/fileutils.h>
|
2020-04-09 10:07:19 -04:00
|
|
|
#include <glibmm/miscutils.h>
|
|
|
|
|
|
|
|
#include "pbd/xml++.h"
|
|
|
|
|
|
|
|
#include "manifest.h"
|
|
|
|
|
2020-04-11 03:31:06 -04:00
|
|
|
static const char* const manifest_filename = "manifest.xml";
|
|
|
|
|
|
|
|
SurfaceManifest::SurfaceManifest (std::string path)
|
|
|
|
: _path (path)
|
2020-04-09 10:07:19 -04:00
|
|
|
{
|
|
|
|
XMLTree tree;
|
2020-04-11 03:31:06 -04:00
|
|
|
std::string xml_path = Glib::build_filename (_path, manifest_filename);
|
2020-04-09 10:07:19 -04:00
|
|
|
|
|
|
|
if (!tree.read (xml_path.c_str())) {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
std::cerr << "SurfaceManifest: could not parse " << xml_path << std::endl;
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNodeList nlist = tree.root ()->children ();
|
|
|
|
|
|
|
|
for (XMLNodeConstIterator niter = nlist.begin(); niter != nlist.end(); ++niter) {
|
|
|
|
XMLNode* node = *niter;
|
|
|
|
std::string name = node->name ();
|
|
|
|
std::string value;
|
|
|
|
|
|
|
|
node->get_property ("value", value);
|
|
|
|
|
2020-04-11 03:31:06 -04:00
|
|
|
if (name == "Name") {
|
2020-04-09 10:07:19 -04:00
|
|
|
_name = value;
|
|
|
|
} else if (name == "Description") {
|
|
|
|
_description = value;
|
2020-04-12 04:02:07 -04:00
|
|
|
} else if (name == "Version") {
|
|
|
|
_version = value;
|
2020-04-09 10:07:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-12 04:02:07 -04:00
|
|
|
if (_name.empty () || _description.empty () || _version.empty ()) {
|
2020-04-11 03:31:06 -04:00
|
|
|
#ifndef NDEBUG
|
2020-04-09 10:07:19 -04:00
|
|
|
std::cerr << "SurfaceManifest: missing properties in " << xml_path << std::endl;
|
|
|
|
#endif
|
2020-04-11 03:31:06 -04:00
|
|
|
return;
|
2020-04-09 10:07:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_valid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
SurfaceManifest::to_json ()
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
ss << "{"
|
2020-04-11 03:58:42 -04:00
|
|
|
<< "\"path\":\"" << Glib::path_get_basename (_path) << "\""
|
2020-04-09 10:07:19 -04:00
|
|
|
<< ",\"name\":\"" << _name << "\""
|
|
|
|
<< ",\"description\":\"" << _description << "\""
|
2020-04-12 04:02:07 -04:00
|
|
|
<< ",\"version\":\"" << _version << "\""
|
2020-04-09 10:07:19 -04:00
|
|
|
<< "}";
|
|
|
|
|
|
|
|
return ss.str ();
|
|
|
|
}
|
2020-04-11 03:31:06 -04:00
|
|
|
|
|
|
|
bool
|
|
|
|
SurfaceManifest::exists_at_path (std::string path)
|
|
|
|
{
|
|
|
|
std::string xml_path = Glib::build_filename (path, manifest_filename);
|
|
|
|
return Glib::file_test (xml_path, Glib::FILE_TEST_EXISTS);
|
|
|
|
}
|