From 010aaa89e392284e69d809bf2b0647e05a9b30c0 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Wed, 13 Jul 2022 23:35:05 -0400 Subject: [PATCH] Embed Feature Flag Data --- launcher/CMakeLists.txt | 14 ++++--- launcher/src/client/launcher.cpp | 60 ++++++++++++++--------------- media-layer/core/src/audio/file.cpp | 2 +- mods/src/server/server.cpp | 2 +- mods/src/sound/repository.cpp | 4 +- scripts/install-dependencies.sh | 3 +- 6 files changed, 43 insertions(+), 42 deletions(-) diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 3df16ebd6..11113b0f0 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -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" diff --git a/launcher/src/client/launcher.cpp b/launcher/src/client/launcher.cpp index f3c703662..f1744cbb8 100644 --- a/launcher/src/client/launcher.cpp +++ b/launcher/src/client/launcher.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -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 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 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 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); } } diff --git a/media-layer/core/src/audio/file.cpp b/media-layer/core/src/audio/file.cpp index d91ac1636..e5a03003c 100644 --- a/media-layer/core/src/audio/file.cpp +++ b/media-layer/core/src/audio/file.cpp @@ -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); } diff --git a/mods/src/server/server.cpp b/mods/src/server/server.cpp index 9a9225e8d..d8baac4ea 100644 --- a/mods/src/server/server.cpp +++ b/mods/src/server/server.cpp @@ -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; } diff --git a/mods/src/sound/repository.cpp b/mods/src/sound/repository.cpp index fc3b2f196..ee271d859 100644 --- a/mods/src/sound/repository.cpp +++ b/mods/src/sound/repository.cpp @@ -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); } diff --git a/scripts/install-dependencies.sh b/scripts/install-dependencies.sh index 6978ecf34..9ac1b1f9e 100755 --- a/scripts/install-dependencies.sh +++ b/scripts/install-dependencies.sh @@ -30,7 +30,8 @@ run() { # Host Dependencies Needed For Compile queue_pkg \ - libwayland-bin + libwayland-bin \ + xxd # Host Dependencies Needed For Running queue_pkg \