Skip to content

Commit

Permalink
Merge pull request #5947 from BOINC/vko_msi_refactor
Browse files Browse the repository at this point in the history
Refactor boinc.json structure a little bit.
  • Loading branch information
AenBleidd authored Dec 12, 2024
2 parents 14a2a26 + 6b45a98 commit 318e591
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 133 deletions.
7 changes: 7 additions & 0 deletions installer/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Control::Control(const nlohmann::json& json,
JsonHelper::handle(json, "EventMappings", [&](const auto& eventMapping) {
eventMappings.emplace_back(eventMapping, dialog, control);
});
JsonHelper::handle(json, "RadioButtons", [&](const auto& radioButton) {
radioButtons.emplace_back(radioButton, property, installerStrings);
});
}

const std::vector<ControlCondition>& Control::get_conditions() const noexcept {
Expand All @@ -57,6 +60,10 @@ const std::vector<EventMapping>& Control::get_event_mappings() const noexcept {
return eventMappings;
}

const std::vector<RadioButton>& Control::get_radio_buttons() const noexcept {
return radioButtons;
}

MSIHANDLE Control::getRecord() const {
return MsiHelper::MsiRecordSet({ dialog, control, type, x, y, width,
height, attributes, property, text, next, help });
Expand Down
3 changes: 3 additions & 0 deletions installer/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "ControlCondition.h"
#include "ControlEvent.h"
#include "EventMapping.h"
#include "RadioButton.h"
#include "InstallerStrings.h"

class Control : public Record {
Expand All @@ -35,6 +36,7 @@ class Control : public Record {
const std::vector<ControlCondition>& get_conditions() const noexcept;
const std::vector<ControlEvent>& get_events() const noexcept;
const std::vector<EventMapping>& get_event_mappings() const noexcept;
const std::vector<RadioButton>& get_radio_buttons() const noexcept;
MSIHANDLE getRecord() const override;
private:
std::string dialog{};
Expand All @@ -52,4 +54,5 @@ class Control : public Record {
std::vector<ControlCondition> conditions{};
std::vector<ControlEvent> events{};
std::vector<EventMapping> eventMappings{};
std::vector<RadioButton> radioButtons{};
};
5 changes: 5 additions & 0 deletions installer/ControlTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ControlConditionTable.h"
#include "ControlEventTable.h"
#include "EventMappingTable.h"
#include "RadioButtonTable.h"
#include "ControlTable.h"

ControlTable::ControlTable(const std::vector<Dialog>& dialogs) noexcept :
Expand All @@ -46,6 +47,10 @@ bool ControlTable::generate(MSIHANDLE hDatabase)
std::cerr << "Failed to generate EventMappingTable" << std::endl;
return false;
}
if (!RadioButtonTable(controls).generate(hDatabase)) {
std::cerr << "Failed to generate RadioButtonTable" << std::endl;
return false;
}

std::cout << "Generating ControlTable..." << std::endl;

Expand Down
13 changes: 5 additions & 8 deletions installer/Installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ Installer::Installer(const std::filesystem::path& output_path,
}

bool Installer::load(const std::filesystem::path& json) {
if (!installer_strings.load(json.parent_path())) {
return false;
}

std::ifstream file(json);
if (!file.is_open()) {
std::cerr << "Could not open file " << json << std::endl;
Expand All @@ -77,6 +73,11 @@ bool Installer::load_from_json(const nlohmann::json& json,
const std::filesystem::path& path)
{
try {
if (JsonHelper::exists(json, "Locale")) {
if (!installer_strings.load(json["Locale"], path)) {
return false;
}
}
if (JsonHelper::exists(json, "Summary")) {
tables["Summary"] = std::make_shared<SummaryInformationTable>(
json["Summary"], installer_strings, platform);
Expand Down Expand Up @@ -150,10 +151,6 @@ bool Installer::load_from_json(const nlohmann::json& json,
tables["Property"] = std::make_shared<PropertyTable>(
json["Property"], installer_strings);
}
if (JsonHelper::exists(json, "RadioButton")) {
tables["RadioButton"] = std::make_shared<RadioButtonTable>(
json["RadioButton"], installer_strings);
}
if (JsonHelper::exists(json, "TextStyle")) {
tables["TextStyle"] = std::make_shared<TextStyleTable>(
json["TextStyle"]);
Expand Down
35 changes: 31 additions & 4 deletions installer/InstallerStrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
InstallerStrings::~InstallerStrings() {
for (const auto& key : strings) {
if (keys_used.find(key.first) == keys_used.end()) {
std::cerr << "WARNING: Key " << key.first<< " not used."
std::cerr << "WARNING: Key " << key.first << " not used."
<< std::endl;
}
}
Expand All @@ -38,16 +38,43 @@ const std::string& InstallerStrings::get(const std::string& key) {
keys_used.insert(key);
return strings.at(key);
};
bool InstallerStrings::load(const std::filesystem::path& path) {
const auto filename = path / "locale/en.json";
bool InstallerStrings::load(const nlohmann::json& json,
const std::filesystem::path& path) {
std::string en_path{};
for (const auto& item : json) {
std::string p{};
std::string language{};
std::string title{};
JsonHelper::get(item, "Path", p);
JsonHelper::get(item, "Language", language);
JsonHelper::get(item, "Title", title);

if (language == "en") {
en_path = p;
}
else {
std::cerr << "WARNING: Unsupported language " << language
<< std::endl;
}

}

if (en_path.empty()) {
std::cerr << "No English locale specified." << std::endl;
return false;
}

const auto filename = path / en_path;
std::ifstream file(filename);
if (!file.is_open()) {
std::cerr << "Could not open file " << filename << std::endl;
return false;
}
nlohmann::json j;
file >> j;
return load_from_json(j);
const auto result = load_from_json(j);
file.close();
return result;
}
bool InstallerStrings::load_from_json(const nlohmann::json& json) {
for (const auto& item : json) {
Expand Down
2 changes: 1 addition & 1 deletion installer/InstallerStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InstallerStrings {
~InstallerStrings();

const std::string& get(const std::string& key);
bool load(const std::filesystem::path& path);
bool load(const nlohmann::json& json, const std::filesystem::path& path);
private:
std::map<std::string, std::string> strings{};
std::unordered_set<std::string> keys_used{};
Expand Down
4 changes: 2 additions & 2 deletions installer/RadioButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include "JsonHelper.h"

RadioButton::RadioButton(const nlohmann::json& json,
InstallerStrings& installerStrings) {
JsonHelper::get(json, "Property", property);
const std::string& property, InstallerStrings& installerStrings)
: property(property) {
JsonHelper::get(json, "Order", order);
JsonHelper::get(json, "Value", value);
JsonHelper::get(json, "X", x);
Expand Down
2 changes: 1 addition & 1 deletion installer/RadioButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class RadioButton : public Record {
public:
explicit RadioButton(const nlohmann::json& json,
InstallerStrings& installerStrings);
const std::string& property, InstallerStrings& installerStrings);
~RadioButton() = default;
MSIHANDLE getRecord() const override;
private:
Expand Down
10 changes: 5 additions & 5 deletions installer/RadioButtonTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

#include "RadioButtonTable.h"

RadioButtonTable::RadioButtonTable(const nlohmann::json& json,
InstallerStrings& installerStrings) {
std::cout << "Loading RadioButtonTable..." << std::endl;
for (const auto& item : json) {
properties.emplace_back(item, installerStrings);
RadioButtonTable::RadioButtonTable(const std::vector<Control>& controls) {
for (const auto& control : controls) {
for (const auto& radioButton : control.get_radio_buttons()) {
properties.emplace_back(radioButton);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions installer/RadioButtonTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

#include "Generator.h"
#include "RadioButton.h"
#include "Control.h"
#include "InstallerStrings.h"

class RadioButtonTable : public Generator<RadioButton> {
public:
explicit RadioButtonTable(const nlohmann::json& json,
InstallerStrings& installerStrings);
explicit RadioButtonTable(const std::vector<Control>& controls);
~RadioButtonTable() = default;
bool generate(MSIHANDLE hDatabase) override;
private:
Expand Down
Loading

0 comments on commit 318e591

Please sign in to comment.