Embed Feature Flag Data

This commit is contained in:
TheBrokenRail 2022-07-13 23:35:05 -04:00
parent 0e32fd36c8
commit 010aaa89e3
6 changed files with 43 additions and 42 deletions

View File

@ -8,7 +8,14 @@ add_executable(launcher src/bootstrap.c src/patchelf.c src/crash-report.c)
if(MCPI_SERVER_MODE)
target_sources(launcher PRIVATE src/server/launcher.c)
else()
target_sources(launcher PRIVATE src/client/launcher.cpp)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/available-feature-flags.c"
COMMAND xxd -i available-feature-flags "${CMAKE_CURRENT_BINARY_DIR}/available-feature-flags.c"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/client/available-feature-flags"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/client"
VERBATIM
)
target_sources(launcher PRIVATE src/client/launcher.cpp "${CMAKE_CURRENT_BINARY_DIR}/available-feature-flags.c")
endif()
target_link_libraries(launcher reborn-util)
# RPath
@ -18,11 +25,6 @@ set_target_properties(launcher PROPERTIES INSTALL_RPATH "$ORIGIN/lib/native")
install(TARGETS launcher DESTINATION "${MCPI_INSTALL_DIR}")
install_symlink("../${MCPI_INSTALL_DIR}/launcher" "bin/${MCPI_VARIANT_NAME}")
# Install Available Feature Flags List
if(NOT MCPI_SERVER_MODE)
install(FILES "src/client/available-feature-flags" DESTINATION "${MCPI_INSTALL_DIR}")
endif()
# Install Desktop Entry
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/launcher.desktop"
"[Desktop Entry]\n"

View File

@ -1,4 +1,4 @@
#include <fstream>
#include <sstream>
#include <cstring>
#include <cerrno>
#include <sys/wait.h>
@ -36,46 +36,44 @@ static std::string strip_feature_flag_default(std::string flag, bool *default_re
}
// Load Available Feature Flags
extern unsigned char available_feature_flags[];
extern unsigned int available_feature_flags_len;
static void load_available_feature_flags(std::function<void(std::string)> callback) {
// Get Path
char *binary_directory = get_binary_directory();
std::string path = std::string(binary_directory) + "/available-feature-flags";
free(binary_directory);
// Load File
std::ifstream stream(path);
if (stream && stream.good()) {
std::vector<std::string> lines;
// Read File
{
std::string line;
while (std::getline(stream, line)) {
if (line.length() > 0) {
// Verify Line
if (line.find('|') == std::string::npos) {
lines.push_back(line);
} else {
// Invalid Line
ERR("Feature Flag Contains Invalid '|'");
}
std::string data(available_feature_flags, available_feature_flags + available_feature_flags_len);
std::stringstream stream(data);
// Store Lines
std::vector<std::string> lines;
// Read File
{
std::string line;
while (std::getline(stream, line)) {
if (line.length() > 0) {
// Verify Line
if (line.find('|') == std::string::npos) {
lines.push_back(line);
} else {
// Invalid Line
ERR("Feature Flag Contains Invalid '|'");
}
}
}
}
// Sort
std::sort(lines.begin(), lines.end(), [](std::string a, std::string b) {
// Strip Defaults
std::string stripped_a = strip_feature_flag_default(a, NULL);
std::string stripped_b = strip_feature_flag_default(b, NULL);
// Sort
std::sort(lines.begin(), lines.end(), [](std::string a, std::string b) {
// Strip Defaults
std::string stripped_a = strip_feature_flag_default(a, NULL);
std::string stripped_b = strip_feature_flag_default(b, NULL);
// Sort
return stripped_a < stripped_b;
});
// Run Callbacks
for (std::string line : lines) {
callback(line);
}
// Close File
stream.close();
} else {
ERR("Unable To Load Available Feature Flags");
return stripped_a < stripped_b;
});
// Run Callbacks
for (std::string &line : lines) {
callback(line);
}
}

View File

@ -229,7 +229,7 @@ ALuint _media_audio_get_buffer(const char *source, const char *name) {
// Delete Buffers
void _media_audio_delete_buffers() {
if (_media_audio_is_loaded()) {
for (auto it : buffers) {
for (auto &it : buffers) {
if (it.second && alIsBuffer(it.second)) {
alDeleteBuffers(1, &it.second);
}

View File

@ -415,7 +415,7 @@ static bool is_ip_in_blacklist(const char *ip) {
return false;
} else {
// Check List
for (std::string x : ips) {
for (std::string &x : ips) {
if (x.compare(ip) == 0) {
return true;
}

View File

@ -370,8 +370,8 @@ std::string _sound_pick(std::string sound) {
void _sound_resolve_all() {
std::string source = _sound_get_source_file();
if (source.size() > 0) {
for (auto it : repository) {
for (std::string name : it.second) {
for (auto &it : repository) {
for (std::string &name : it.second) {
// Zero Volume Prevents An OpenAL Source From Being Allocated While Still Resolving The Sound
media_audio_play(source.c_str(), name.c_str(), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f);
}

View File

@ -30,7 +30,8 @@ run() {
# Host Dependencies Needed For Compile
queue_pkg \
libwayland-bin
libwayland-bin \
xxd
# Host Dependencies Needed For Running
queue_pkg \