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
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2020-10-26 03:54:36 -07:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PCM_DATA_H_
|
|
|
|
#define PCM_DATA_H_
|
|
|
|
|
|
|
|
#include "core/wx_stl_compat.h"
|
|
|
|
|
|
|
|
#include <map>
|
2024-03-13 22:49:01 -04:00
|
|
|
#include <json_common.h>
|
2023-09-06 14:55:09 +03:00
|
|
|
#include <core/json_serializers.h>
|
2022-08-28 04:40:06 -07:00
|
|
|
#include <optional>
|
2020-10-26 03:54:36 -07:00
|
|
|
#include <string>
|
|
|
|
#include <tuple>
|
|
|
|
#include <vector>
|
|
|
|
#include <wx/string.h>
|
|
|
|
|
|
|
|
|
|
|
|
using STRING_MAP = std::map<std::string, wxString>;
|
|
|
|
using nlohmann::json;
|
|
|
|
|
|
|
|
|
|
|
|
///< Supported package types
|
|
|
|
enum PCM_PACKAGE_TYPE
|
|
|
|
{
|
|
|
|
PT_INVALID,
|
|
|
|
PT_PLUGIN,
|
2024-12-09 16:30:15 -08:00
|
|
|
PT_FAB,
|
2020-10-26 03:54:36 -07:00
|
|
|
PT_LIBRARY,
|
2021-07-10 23:24:30 -07:00
|
|
|
PT_COLORTHEME,
|
2020-10-26 03:54:36 -07:00
|
|
|
};
|
|
|
|
|
2024-12-09 16:30:15 -08:00
|
|
|
///< Plugin categories
|
|
|
|
enum PCM_PLUGIN_CATEGORY
|
|
|
|
{
|
|
|
|
PC_INVALID,
|
|
|
|
PC_GENERAL,
|
|
|
|
PC_FAB,
|
|
|
|
};
|
|
|
|
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
///< Status of specific package version
|
|
|
|
enum PCM_PACKAGE_VERSION_STATUS
|
|
|
|
{
|
|
|
|
PVS_INVALID,
|
|
|
|
PVS_STABLE,
|
|
|
|
PVS_TESTING,
|
|
|
|
PVS_DEVELOPMENT,
|
|
|
|
PVS_DEPRECATED
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///< Describes a person's name and contact information
|
|
|
|
struct PCM_CONTACT
|
|
|
|
{
|
|
|
|
wxString name;
|
|
|
|
STRING_MAP contact;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// MSVC, wxWidgets and nlohmann_json don't play nice together and
|
|
|
|
// create linker errors about redefinition of some vector members
|
|
|
|
// if an attempt to use vector<wxString> in json is made.
|
|
|
|
|
|
|
|
///< Package version metadata
|
|
|
|
struct PACKAGE_VERSION
|
|
|
|
{
|
|
|
|
wxString version;
|
2022-08-25 15:50:47 -07:00
|
|
|
std::optional<int> version_epoch;
|
|
|
|
std::optional<wxString> download_url;
|
|
|
|
std::optional<wxString> download_sha256;
|
|
|
|
std::optional<uint64_t> download_size;
|
|
|
|
std::optional<uint64_t> install_size;
|
2020-10-26 03:54:36 -07:00
|
|
|
PCM_PACKAGE_VERSION_STATUS status;
|
|
|
|
std::vector<std::string> platforms;
|
|
|
|
wxString kicad_version;
|
2022-08-25 15:50:47 -07:00
|
|
|
std::optional<wxString> kicad_version_max;
|
2022-06-30 21:09:25 -07:00
|
|
|
std::vector<std::string> keep_on_update;
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
// Not serialized fields
|
|
|
|
std::tuple<int, int, int, int> parsed_version; // Full version tuple for sorting
|
2022-08-19 10:42:47 +02:00
|
|
|
bool compatible = true;
|
2020-10-26 03:54:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///< Package metadata
|
|
|
|
struct PCM_PACKAGE
|
|
|
|
{
|
2024-12-09 16:30:15 -08:00
|
|
|
wxString name;
|
|
|
|
wxString description;
|
|
|
|
wxString description_full;
|
|
|
|
wxString identifier;
|
|
|
|
PCM_PACKAGE_TYPE type;
|
|
|
|
std::optional<PCM_PLUGIN_CATEGORY> category;
|
|
|
|
PCM_CONTACT author;
|
|
|
|
std::optional<PCM_CONTACT> maintainer;
|
|
|
|
wxString license;
|
|
|
|
STRING_MAP resources;
|
|
|
|
std::vector<std::string> tags;
|
|
|
|
std::vector<std::string> keep_on_update;
|
|
|
|
std::vector<PACKAGE_VERSION> versions;
|
2020-10-26 03:54:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///< Repository reference to a resource
|
|
|
|
struct PCM_RESOURCE_REFERENCE
|
|
|
|
{
|
2022-08-25 15:50:47 -07:00
|
|
|
wxString url;
|
|
|
|
std::optional<wxString> sha256;
|
|
|
|
uint64_t update_timestamp;
|
2020-10-26 03:54:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///< Repository metadata
|
|
|
|
struct PCM_REPOSITORY
|
|
|
|
{
|
2022-08-25 15:50:47 -07:00
|
|
|
wxString name;
|
|
|
|
PCM_RESOURCE_REFERENCE packages;
|
|
|
|
std::optional<PCM_RESOURCE_REFERENCE> resources;
|
|
|
|
std::optional<PCM_RESOURCE_REFERENCE> manifests;
|
|
|
|
std::optional<PCM_CONTACT> maintainer;
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
// Not serialized fields
|
|
|
|
std::vector<PCM_PACKAGE> package_list;
|
2022-08-18 20:41:43 +00:00
|
|
|
// pkg id to index of package from package_list for quick lookup
|
|
|
|
std::unordered_map<wxString, size_t> package_map;
|
2020-10-26 03:54:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///< Package installation entry
|
|
|
|
struct PCM_INSTALLATION_ENTRY
|
|
|
|
{
|
|
|
|
PCM_PACKAGE package;
|
|
|
|
wxString current_version;
|
|
|
|
wxString repository_id;
|
|
|
|
wxString repository_name;
|
|
|
|
uint64_t install_timestamp;
|
2022-08-28 04:40:06 -07:00
|
|
|
bool pinned;
|
2022-08-18 20:41:43 +00:00
|
|
|
|
|
|
|
// Not serialized fields
|
|
|
|
bool update_available;
|
2020-10-26 03:54:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
NLOHMANN_JSON_SERIALIZE_ENUM( PCM_PACKAGE_TYPE, {
|
|
|
|
{ PT_INVALID, "invalid" },
|
|
|
|
{ PT_PLUGIN, "plugin" },
|
2024-12-09 16:30:15 -08:00
|
|
|
{ PT_FAB, "fab" },
|
2020-10-26 03:54:36 -07:00
|
|
|
{ PT_LIBRARY, "library" },
|
2021-07-10 23:24:30 -07:00
|
|
|
{ PT_COLORTHEME, "colortheme" },
|
2020-10-26 03:54:36 -07:00
|
|
|
} )
|
|
|
|
|
2024-12-09 16:30:15 -08:00
|
|
|
NLOHMANN_JSON_SERIALIZE_ENUM( PCM_PLUGIN_CATEGORY, {
|
|
|
|
{ PC_INVALID, "invalid" },
|
|
|
|
{ PC_GENERAL, "general" },
|
|
|
|
{ PC_FAB, "fab" },
|
|
|
|
} )
|
|
|
|
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
NLOHMANN_JSON_SERIALIZE_ENUM( PCM_PACKAGE_VERSION_STATUS,
|
|
|
|
{
|
|
|
|
{ PVS_INVALID, "invalid" },
|
|
|
|
{ PVS_STABLE, "stable" },
|
|
|
|
{ PVS_TESTING, "testing" },
|
|
|
|
{ PVS_DEVELOPMENT, "development" },
|
|
|
|
{ PVS_DEPRECATED, "deprecated" },
|
|
|
|
} )
|
|
|
|
|
|
|
|
|
|
|
|
// Following are templates and definitions for en/decoding above structs
|
|
|
|
// to/from json
|
|
|
|
|
|
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( PCM_CONTACT, name, contact )
|
|
|
|
|
|
|
|
|
|
|
|
void to_json( json& j, const PACKAGE_VERSION& v );
|
|
|
|
void from_json( const json& j, PACKAGE_VERSION& v );
|
|
|
|
|
|
|
|
|
|
|
|
void to_json( json& j, const PCM_PACKAGE& p );
|
|
|
|
void from_json( const json& j, PCM_PACKAGE& p );
|
|
|
|
|
|
|
|
|
|
|
|
void to_json( json& j, const PCM_RESOURCE_REFERENCE& r );
|
|
|
|
void from_json( const json& j, PCM_RESOURCE_REFERENCE& r );
|
|
|
|
|
|
|
|
|
|
|
|
void to_json( json& j, const PCM_REPOSITORY& r );
|
|
|
|
void from_json( const json& j, PCM_REPOSITORY& r );
|
|
|
|
|
|
|
|
|
2022-08-28 04:40:06 -07:00
|
|
|
void to_json( json& j, const PCM_INSTALLATION_ENTRY& e );
|
|
|
|
void from_json( const json& j, PCM_INSTALLATION_ENTRY& e );
|
2020-10-26 03:54:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
#endif // PCM_DATA_H_
|