chore: make yuzu REUSE compliant
[REUSE] is a specification that aims at making file copyright
information consistent, so that it can be both human and machine
readable. It basically requires that all files have a header containing
copyright and licensing information. When this isn't possible, like
when dealing with binary assets, generated files or embedded third-party
dependencies, it is permitted to insert copyright information in the
`.reuse/dep5` file.
Oh, and it also requires that all the licenses used in the project are
present in the `LICENSES` folder, that's why the diff is so huge.
This can be done automatically with `reuse download --all`.
The `reuse` tool also contains a handy subcommand that analyzes the
project and tells whether or not the project is (still) compliant,
`reuse lint`.
Following REUSE has a few advantages over the current approach:
- Copyright information is easy to access for users / downstream
- Files like `dist/license.md` do not need to exist anymore, as
`.reuse/dep5` is used instead
- `reuse lint` makes it easy to ensure that copyright information of
files like binary assets / images is always accurate and up to date
To add copyright information of files that didn't have it I looked up
who committed what and when, for each file. As yuzu contributors do not
have to sign a CLA or similar I couldn't assume that copyright ownership
was of the "yuzu Emulator Project", so I used the name and/or email of
the commit author instead.
[REUSE]: https://reuse.software
Follow-up to 01cf05bc75b1e47beb08937439f3ed9339e7b254
2022-05-15 03:06:02 +03:00
|
|
|
// SPDX-FileCopyrightText: 2017 Citra Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-01-20 22:30:11 +03:00
|
|
|
|
|
|
|
#include <array>
|
2021-10-01 03:59:49 +03:00
|
|
|
#include <stdexcept>
|
2018-07-21 00:17:26 +03:00
|
|
|
#include <utility>
|
2017-01-20 22:30:11 +03:00
|
|
|
#include <vector>
|
2018-07-21 00:17:26 +03:00
|
|
|
|
2017-01-20 22:30:11 +03:00
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "common/param_package.h"
|
|
|
|
#include "common/string_util.h"
|
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
constexpr char KEY_VALUE_SEPARATOR = ':';
|
|
|
|
constexpr char PARAM_SEPARATOR = ',';
|
2018-07-21 00:05:46 +03:00
|
|
|
|
2017-01-20 22:30:11 +03:00
|
|
|
constexpr char ESCAPE_CHARACTER = '$';
|
2018-07-21 00:05:46 +03:00
|
|
|
constexpr char KEY_VALUE_SEPARATOR_ESCAPE[] = "$0";
|
|
|
|
constexpr char PARAM_SEPARATOR_ESCAPE[] = "$1";
|
|
|
|
constexpr char ESCAPE_CHARACTER_ESCAPE[] = "$2";
|
2017-01-20 22:30:11 +03:00
|
|
|
|
2018-08-26 11:23:12 +03:00
|
|
|
/// A placeholder for empty param packages to avoid empty strings
|
|
|
|
/// (they may be recognized as "not set" by some frontend libraries like qt)
|
|
|
|
constexpr char EMPTY_PLACEHOLDER[] = "[empty]";
|
|
|
|
|
2017-01-20 22:30:11 +03:00
|
|
|
ParamPackage::ParamPackage(const std::string& serialized) {
|
2018-08-26 11:23:12 +03:00
|
|
|
if (serialized == EMPTY_PLACEHOLDER) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-20 22:30:11 +03:00
|
|
|
std::vector<std::string> pairs;
|
|
|
|
Common::SplitString(serialized, PARAM_SEPARATOR, pairs);
|
|
|
|
|
|
|
|
for (const std::string& pair : pairs) {
|
|
|
|
std::vector<std::string> key_value;
|
|
|
|
Common::SplitString(pair, KEY_VALUE_SEPARATOR, key_value);
|
|
|
|
if (key_value.size() != 2) {
|
2018-07-02 19:13:26 +03:00
|
|
|
LOG_ERROR(Common, "invalid key pair {}", pair);
|
2017-01-20 22:30:11 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (std::string& part : key_value) {
|
|
|
|
part = Common::ReplaceAll(part, KEY_VALUE_SEPARATOR_ESCAPE, {KEY_VALUE_SEPARATOR});
|
|
|
|
part = Common::ReplaceAll(part, PARAM_SEPARATOR_ESCAPE, {PARAM_SEPARATOR});
|
|
|
|
part = Common::ReplaceAll(part, ESCAPE_CHARACTER_ESCAPE, {ESCAPE_CHARACTER});
|
|
|
|
}
|
|
|
|
|
2018-07-21 00:17:26 +03:00
|
|
|
Set(key_value[0], std::move(key_value[1]));
|
2017-01-20 22:30:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ParamPackage::ParamPackage(std::initializer_list<DataType::value_type> list) : data(list) {}
|
|
|
|
|
|
|
|
std::string ParamPackage::Serialize() const {
|
|
|
|
if (data.empty())
|
2018-08-26 11:23:12 +03:00
|
|
|
return EMPTY_PLACEHOLDER;
|
2017-01-20 22:30:11 +03:00
|
|
|
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
for (const auto& pair : data) {
|
|
|
|
std::array<std::string, 2> key_value{{pair.first, pair.second}};
|
|
|
|
for (std::string& part : key_value) {
|
|
|
|
part = Common::ReplaceAll(part, {ESCAPE_CHARACTER}, ESCAPE_CHARACTER_ESCAPE);
|
|
|
|
part = Common::ReplaceAll(part, {PARAM_SEPARATOR}, PARAM_SEPARATOR_ESCAPE);
|
|
|
|
part = Common::ReplaceAll(part, {KEY_VALUE_SEPARATOR}, KEY_VALUE_SEPARATOR_ESCAPE);
|
|
|
|
}
|
|
|
|
result += key_value[0] + KEY_VALUE_SEPARATOR + key_value[1] + PARAM_SEPARATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.pop_back(); // discard the trailing PARAM_SEPARATOR
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParamPackage::Get(const std::string& key, const std::string& default_value) const {
|
|
|
|
auto pair = data.find(key);
|
|
|
|
if (pair == data.end()) {
|
2022-06-16 18:26:30 +03:00
|
|
|
LOG_TRACE(Common, "key '{}' not found", key);
|
2017-01-20 22:30:11 +03:00
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pair->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ParamPackage::Get(const std::string& key, int default_value) const {
|
|
|
|
auto pair = data.find(key);
|
|
|
|
if (pair == data.end()) {
|
2022-06-16 18:26:30 +03:00
|
|
|
LOG_TRACE(Common, "key '{}' not found", key);
|
2017-01-20 22:30:11 +03:00
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
return std::stoi(pair->second);
|
|
|
|
} catch (const std::logic_error&) {
|
2018-07-02 19:13:26 +03:00
|
|
|
LOG_ERROR(Common, "failed to convert {} to int", pair->second);
|
2017-01-20 22:30:11 +03:00
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float ParamPackage::Get(const std::string& key, float default_value) const {
|
|
|
|
auto pair = data.find(key);
|
|
|
|
if (pair == data.end()) {
|
2022-06-16 18:26:30 +03:00
|
|
|
LOG_TRACE(Common, "key {} not found", key);
|
2017-01-20 22:30:11 +03:00
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
return std::stof(pair->second);
|
|
|
|
} catch (const std::logic_error&) {
|
2018-07-02 19:13:26 +03:00
|
|
|
LOG_ERROR(Common, "failed to convert {} to float", pair->second);
|
2017-01-20 22:30:11 +03:00
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-21 00:17:26 +03:00
|
|
|
void ParamPackage::Set(const std::string& key, std::string value) {
|
|
|
|
data.insert_or_assign(key, std::move(value));
|
2017-01-20 22:30:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParamPackage::Set(const std::string& key, int value) {
|
2018-07-21 00:12:24 +03:00
|
|
|
data.insert_or_assign(key, std::to_string(value));
|
2017-01-20 22:30:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParamPackage::Set(const std::string& key, float value) {
|
2018-07-21 00:12:24 +03:00
|
|
|
data.insert_or_assign(key, std::to_string(value));
|
2017-01-20 22:30:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ParamPackage::Has(const std::string& key) const {
|
|
|
|
return data.find(key) != data.end();
|
|
|
|
}
|
|
|
|
|
2018-08-26 11:23:12 +03:00
|
|
|
void ParamPackage::Erase(const std::string& key) {
|
|
|
|
data.erase(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParamPackage::Clear() {
|
|
|
|
data.clear();
|
|
|
|
}
|
|
|
|
|
2017-01-20 22:30:11 +03:00
|
|
|
} // namespace Common
|