From 0fd8ba7de9bf480582563a684367d050047339df Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 11 Mar 2022 20:02:38 -0500 Subject: [PATCH] Improve AppImages & Safer OpenAL --- CMakeLists.txt | 1 + dependencies/CMakeLists.txt | 4 +- dependencies/zenity/CMakeLists.txt | 2 +- dependencies/zenity/src | 2 +- launcher/src/bootstrap.c | 47 +++++++++++++---------- media-layer/core/src/audio/api.cpp | 19 ++++++--- media-layer/proxy/CMakeLists.txt | 2 +- scripts/generate-appimage-builder-yaml.js | 9 +++-- scripts/install-dependencies.sh | 3 +- 9 files changed, 54 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e463696f..c41a8d80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ endif() # Specify Installation Paths set(MCPI_INSTALL_DIR "lib/${MCPI_VARIANT_NAME}") set(MCPI_LIB_DIR "${MCPI_INSTALL_DIR}/lib") +set(MCPI_BIN_DIR "${MCPI_INSTALL_DIR}/bin") set(MCPI_FALLBACK_LIB_DIR "${MCPI_INSTALL_DIR}/fallback-lib") # Build Mode diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt index 9096eac3..8d2df00a 100644 --- a/dependencies/CMakeLists.txt +++ b/dependencies/CMakeLists.txt @@ -16,7 +16,7 @@ endif() if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE) add_subdirectory(glfw) endif() -# Zenity (Minimal AppImage Build) -if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE AND MCPI_IS_APPIMAGE_BUILD) +# Zenity (Minimal Build) +if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE) add_subdirectory(zenity) endif() diff --git a/dependencies/zenity/CMakeLists.txt b/dependencies/zenity/CMakeLists.txt index 4c14aa82..7356ab09 100644 --- a/dependencies/zenity/CMakeLists.txt +++ b/dependencies/zenity/CMakeLists.txt @@ -12,4 +12,4 @@ add_subdirectory(src EXCLUDE_FROM_ALL) add_custom_target(zenity-build ALL DEPENDS zenity) # Install -install(TARGETS zenity DESTINATION "bin") +install(TARGETS zenity DESTINATION "${MCPI_BIN_DIR}") diff --git a/dependencies/zenity/src b/dependencies/zenity/src index 6f08afb7..4663a865 160000 --- a/dependencies/zenity/src +++ b/dependencies/zenity/src @@ -1 +1 @@ -Subproject commit 6f08afb7989c420282654eee9dea9d5df01e914a +Subproject commit 4663a8656d8c12be00286ee10aae2ff55ff589af diff --git a/launcher/src/bootstrap.c b/launcher/src/bootstrap.c index 0a92fa38..1c9f9847 100644 --- a/launcher/src/bootstrap.c +++ b/launcher/src/bootstrap.c @@ -148,6 +148,29 @@ void pre_bootstrap() { ERR("AppImage: Unable To Fix Current Directory: %s", strerror(errno)); } #endif + + // Get Binary Directory + char *binary_directory = get_binary_directory(); + + // Configure PATH + { + // Add Library Directory + char *new_path; + safe_asprintf(&new_path, "%s/bin", binary_directory); + // Add Existing PATH + { + char *value = get_env_safe("PATH"); + if (strlen(value) > 0) { + string_append(&new_path, ":%s", value); + } + } + // Set And Free + set_and_print_env("PATH", new_path); + free(new_path); + } + + // Free Binary Directory + free(binary_directory); } // Bootstrap @@ -158,14 +181,13 @@ void bootstrap(int argc, char *argv[]) { char *binary_directory = get_binary_directory(); // Handle AppImage + char *usr_prefix = NULL; #ifdef MCPI_IS_APPIMAGE_BUILD - char *usr_prefix = getenv("APPDIR"); + usr_prefix = getenv("APPDIR"); +#endif if (usr_prefix == NULL) { usr_prefix = ""; } -#else - char *usr_prefix = ""; -#endif // Configure LD_LIBRARY_PATH { @@ -265,23 +287,6 @@ void bootstrap(int argc, char *argv[]) { free(new_ld_preload); } - // Configure PATH - { - // Add Library Directory - char *new_path; - safe_asprintf(&new_path, "%s/lib", binary_directory); - // Add Existing PATH - { - char *value = get_env_safe("PATH"); - if (strlen(value) > 0) { - string_append(&new_path, ":%s", value); - } - } - // Set And Free - set_and_print_env("PATH", new_path); - free(new_path); - } - // Resolve Binary Path & Set MCPI_DIRECTORY { // Resolve Full Binary Path diff --git a/media-layer/core/src/audio/api.cpp b/media-layer/core/src/audio/api.cpp index 44fe4fdf..8460eebf 100644 --- a/media-layer/core/src/audio/api.cpp +++ b/media-layer/core/src/audio/api.cpp @@ -15,11 +15,12 @@ static std::vector &get_sources() { return sources; } -#define AL_ERROR_CHECK() \ +#define AL_ERROR_CHECK() AL_ERROR_CHECK_MANUAL(alGetError()) +#define AL_ERROR_CHECK_MANUAL(val) \ { \ - ALenum err = alGetError(); \ - if (err != AL_NO_ERROR) { \ - ERR("OpenAL Error: %s", alGetString(err)); \ + ALenum __err = val; \ + if (__err != AL_NO_ERROR) { \ + ERR("OpenAL Error: %s", alGetString(__err)); \ } \ } @@ -81,7 +82,15 @@ void media_audio_play(const char *source, const char *name, float x, float y, fl // Create Source ALuint al_source; alGenSources(1, &al_source); - AL_ERROR_CHECK(); + // Special Out-Of-Memory Handling + { + ALenum err = alGetError(); + if (err == AL_OUT_OF_MEMORY) { + return; + } else { + AL_ERROR_CHECK_MANUAL(err); + } + } // Set Properties alSourcef(al_source, AL_PITCH, pitch); diff --git a/media-layer/proxy/CMakeLists.txt b/media-layer/proxy/CMakeLists.txt index b2ae49aa..3e8d9fc7 100644 --- a/media-layer/proxy/CMakeLists.txt +++ b/media-layer/proxy/CMakeLists.txt @@ -12,7 +12,7 @@ if(BUILD_NATIVE_COMPONENTS) target_link_libraries(media-layer-proxy-client media-layer-headers reborn-headers ${MEDIA_LAYER_PROXY_LIBS}) target_compile_definitions(media-layer-proxy-client PRIVATE -DMEDIA_LAYER_PROXY_CLIENT) # Install - install(TARGETS media-layer-proxy-client DESTINATION "${MCPI_LIB_DIR}") + install(TARGETS media-layer-proxy-client DESTINATION "${MCPI_BIN_DIR}") endif() if(BUILD_ARM_COMPONENTS) diff --git a/scripts/generate-appimage-builder-yaml.js b/scripts/generate-appimage-builder-yaml.js index 0462d838..23136f71 100755 --- a/scripts/generate-appimage-builder-yaml.js +++ b/scripts/generate-appimage-builder-yaml.js @@ -32,7 +32,7 @@ if (mode === 'client') { 'libgtk-3-0', 'libglib2.0-0', 'libgdk-pixbuf2.0-0', - 'libcanberra-gtk3-module', + 'shared-mime-info', 'libfreeimage3', 'libopenal1' ); @@ -52,6 +52,7 @@ const packageExclusions = [ // Exclude Unneeded Packages 'humanity-icon-theme', 'adwaita-icon-theme', + 'libxml2', '*systemd*', 'dconf-service', 'dconf-gsettings-backend', @@ -102,7 +103,8 @@ const files = { 'usr/share/doc/*/TODO.*', 'usr/include', 'usr/share/locale', - 'usr/share/help' + 'usr/share/help', + 'usr/bin/update-mime-database' ] }; @@ -120,7 +122,8 @@ const runtime = { GTK_PATH: `\${APPDIR}/usr/lib/${triplet}/gtk-3.0`, GTK_DATA_PREFIX: '${APPDIR}', GTK_THEME: 'Default', - APPDIR_LIBRARY_PATH: `\${APPDIR}/usr/lib/${triplet}:\${APPDIR}/lib/${triplet}:\${APPDIR}/usr/lib:\${APPDIR}/usr/lib/${triplet}/gdk-pixbuf-2.0/2.10.0/loaders` + XDG_DATA_DIRS: '${APPDIR}/share:${APPDIR}/usr/share', + APPDIR_LIBRARY_PATH: `\${APPDIR}/usr/lib/${triplet}:\${APPDIR}/usr/${triplet}/lib:\${APPDIR}/lib/${triplet}:\${APPDIR}/usr/lib:\${APPDIR}/usr/lib/${triplet}/gdk-pixbuf-2.0/2.10.0/loaders` } : undefined, preserve: arch !== 'armhf' ? [ // On non-ARM32 systems, an ARM32 linker is embedded, this diff --git a/scripts/install-dependencies.sh b/scripts/install-dependencies.sh index 203e92cd..3b714549 100755 --- a/scripts/install-dependencies.sh +++ b/scripts/install-dependencies.sh @@ -95,6 +95,7 @@ queue_pkg \ strace \ fuse \ gtk-update-icon-cache \ + shared-mime-info \ sed # Install Queue @@ -115,4 +116,4 @@ sudo rm -f /usr/local/bin/appimagetool sudo ln -s /opt/appimagetool.AppDir/AppRun /usr/local/bin/appimagetool # Install appimage-builder -sudo pip3 install 'git+https://github.com/TheBrokenRail/appimage-builder.git' +sudo pip3 install 'git+https://github.com/TheBrokenRail/appimage-builder.git@combined'