2020-10-26 03:54:36 -07:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 Andrew Lutsenko, anlutsenko at gmail dot com
|
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pcm_data.h"
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-08-25 15:50:47 -07:00
|
|
|
void to_optional( const json& j, const char* key, std::optional<T>& dest )
|
2020-10-26 03:54:36 -07:00
|
|
|
{
|
|
|
|
if( j.contains( key ) )
|
|
|
|
{
|
|
|
|
T tmp;
|
|
|
|
j.at( key ).get_to( tmp );
|
|
|
|
dest.emplace( tmp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void to_json( json& j, const PACKAGE_VERSION& v )
|
|
|
|
{
|
|
|
|
j = json{ { "version", v.version },
|
|
|
|
{ "status", v.status },
|
|
|
|
{ "kicad_version", v.kicad_version } };
|
|
|
|
|
|
|
|
if( v.version_epoch )
|
2022-08-30 13:58:43 -07:00
|
|
|
j["version_epoch"] = *v.version_epoch;
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
if( v.download_url )
|
2022-08-30 13:58:43 -07:00
|
|
|
j["download_url"] = *v.download_url;
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
if( v.download_sha256 )
|
2022-08-30 13:58:43 -07:00
|
|
|
j["download_sha256"] = *v.download_sha256;
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
if( v.download_size )
|
2022-08-30 13:58:43 -07:00
|
|
|
j["download_size"] = *v.download_size;
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
if( v.install_size )
|
2022-08-30 13:58:43 -07:00
|
|
|
j["install_size"] = *v.install_size;
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
if( v.platforms.size() > 0 )
|
|
|
|
nlohmann::to_json( j["platforms"], v.platforms );
|
|
|
|
|
|
|
|
if( v.kicad_version_max )
|
2022-08-30 13:58:43 -07:00
|
|
|
j["kicad_version_max"] = *v.kicad_version_max;
|
2022-06-30 21:09:25 -07:00
|
|
|
|
|
|
|
if( v.keep_on_update.size() > 0 )
|
|
|
|
nlohmann::to_json( j["keep_on_update"], v.keep_on_update );
|
2020-10-26 03:54:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void from_json( const json& j, PACKAGE_VERSION& v )
|
|
|
|
{
|
|
|
|
j.at( "version" ).get_to( v.version );
|
|
|
|
j.at( "status" ).get_to( v.status );
|
|
|
|
j.at( "kicad_version" ).get_to( v.kicad_version );
|
|
|
|
|
|
|
|
to_optional( j, "version_epoch", v.version_epoch );
|
|
|
|
to_optional( j, "download_url", v.download_url );
|
|
|
|
to_optional( j, "download_sha256", v.download_sha256 );
|
|
|
|
to_optional( j, "download_size", v.download_size );
|
|
|
|
to_optional( j, "install_size", v.install_size );
|
|
|
|
to_optional( j, "kicad_version_max", v.kicad_version_max );
|
|
|
|
|
|
|
|
if( j.contains( "platforms" ) )
|
|
|
|
j.at( "platforms" ).get_to( v.platforms );
|
2022-06-30 21:09:25 -07:00
|
|
|
|
|
|
|
if( j.contains( "keep_on_update" ) )
|
|
|
|
j.at( "keep_on_update" ).get_to( v.keep_on_update );
|
2020-10-26 03:54:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void to_json( json& j, const PCM_PACKAGE& p )
|
|
|
|
{
|
|
|
|
j = json{ { "name", p.name },
|
|
|
|
{ "description", p.description },
|
|
|
|
{ "description_full", p.description_full },
|
|
|
|
{ "identifier", p.identifier },
|
|
|
|
{ "type", p.type },
|
|
|
|
{ "author", p.author },
|
|
|
|
{ "license", p.license },
|
|
|
|
{ "resources", p.resources },
|
|
|
|
{ "versions", p.versions } };
|
|
|
|
|
|
|
|
if( p.maintainer )
|
2022-08-30 13:58:43 -07:00
|
|
|
j["maintainer"] = *p.maintainer;
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
if( p.tags.size() > 0 )
|
|
|
|
j["tags"] = p.tags;
|
2022-06-30 21:09:25 -07:00
|
|
|
|
|
|
|
if( p.keep_on_update.size() > 0 )
|
|
|
|
j["keep_on_update"] = p.keep_on_update;
|
2020-10-26 03:54:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void from_json( const json& j, PCM_PACKAGE& p )
|
|
|
|
{
|
|
|
|
j.at( "name" ).get_to( p.name );
|
|
|
|
j.at( "description" ).get_to( p.description );
|
|
|
|
j.at( "description_full" ).get_to( p.description_full );
|
|
|
|
j.at( "identifier" ).get_to( p.identifier );
|
|
|
|
j.at( "type" ).get_to( p.type );
|
|
|
|
j.at( "author" ).get_to( p.author );
|
|
|
|
j.at( "license" ).get_to( p.license );
|
|
|
|
j.at( "resources" ).get_to( p.resources );
|
|
|
|
j.at( "versions" ).get_to( p.versions );
|
|
|
|
|
|
|
|
to_optional( j, "maintainer", p.maintainer );
|
2024-12-09 16:30:15 -08:00
|
|
|
to_optional( j, "category", p.category );
|
|
|
|
|
|
|
|
if( p.type == PT_PLUGIN && p.category && p.category.value() == PC_FAB )
|
|
|
|
p.type = PT_FAB;
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
if( j.contains( "tags" ) )
|
|
|
|
j.at( "tags" ).get_to( p.tags );
|
2022-06-30 21:09:25 -07:00
|
|
|
|
|
|
|
if( j.contains( "keep_on_update" ) )
|
|
|
|
j.at( "keep_on_update" ).get_to( p.keep_on_update );
|
2020-10-26 03:54:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void to_json( json& j, const PCM_RESOURCE_REFERENCE& r )
|
|
|
|
{
|
|
|
|
j = json{ { "url", r.url }, { "update_timestamp", r.update_timestamp } };
|
|
|
|
|
|
|
|
if( r.sha256 )
|
2022-08-30 13:58:43 -07:00
|
|
|
j["sha256"] = *r.sha256;
|
2020-10-26 03:54:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void from_json( const json& j, PCM_RESOURCE_REFERENCE& r )
|
|
|
|
{
|
|
|
|
j.at( "url" ).get_to( r.url );
|
|
|
|
j.at( "update_timestamp" ).get_to( r.update_timestamp );
|
|
|
|
|
2022-06-30 21:09:25 -07:00
|
|
|
to_optional( j, "sha256", r.sha256 );
|
2020-10-26 03:54:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void to_json( json& j, const PCM_REPOSITORY& r )
|
|
|
|
{
|
|
|
|
j = json{ { "name", r.name }, { "packages", r.packages } };
|
|
|
|
|
|
|
|
if( r.resources )
|
2022-08-30 13:58:43 -07:00
|
|
|
j["resources"] = *r.resources;
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
if( r.manifests )
|
2022-08-30 13:58:43 -07:00
|
|
|
j["manifests"] = *r.manifests;
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
if( r.maintainer )
|
2022-08-30 13:58:43 -07:00
|
|
|
j["maintainer"] = *r.maintainer;
|
2020-10-26 03:54:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void from_json( const json& j, PCM_REPOSITORY& r )
|
|
|
|
{
|
|
|
|
j.at( "name" ).get_to( r.name );
|
|
|
|
j.at( "packages" ).get_to( r.packages );
|
|
|
|
|
2022-06-30 21:09:25 -07:00
|
|
|
to_optional( j, "resources", r.resources );
|
|
|
|
to_optional( j, "manifests", r.manifests );
|
|
|
|
to_optional( j, "maintainer", r.maintainer );
|
2020-10-26 03:54:36 -07:00
|
|
|
}
|
2022-08-28 04:40:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
void to_json( json& j, const PCM_INSTALLATION_ENTRY& e )
|
|
|
|
{
|
|
|
|
j = json{ { "package", e.package },
|
|
|
|
{ "current_version", e.current_version },
|
|
|
|
{ "repository_id", e.repository_id },
|
|
|
|
{ "repository_name", e.repository_name },
|
|
|
|
{ "install_timestamp", e.install_timestamp },
|
|
|
|
{ "pinned", e.pinned } };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void from_json( const json& j, PCM_INSTALLATION_ENTRY& e )
|
|
|
|
{
|
|
|
|
j.at( "package" ).get_to( e.package );
|
|
|
|
j.at( "current_version" ).get_to( e.current_version );
|
|
|
|
j.at( "repository_id" ).get_to( e.repository_id );
|
|
|
|
j.at( "repository_name" ).get_to( e.repository_name );
|
|
|
|
j.at( "install_timestamp" ).get_to( e.install_timestamp );
|
|
|
|
|
|
|
|
e.pinned = false;
|
|
|
|
if( j.contains( "pinned" ) )
|
|
|
|
j.at( "pinned" ).get_to( e.pinned );
|
|
|
|
}
|