From 55cc6cb1246e7b2742ffd0aff39e133801a892f2 Mon Sep 17 00:00:00 2001 From: Torsten Paul Date: Sun, 27 Oct 2024 18:28:38 +0100 Subject: [PATCH 1/2] Use boost::dll::program_location() for detecting the resource location. --- src/openscad.cc | 18 ++++++++---------- src/platform/PlatformUtils.cc | 1 - 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/openscad.cc b/src/openscad.cc index 3eba976d36e..a3be9c31a88 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -42,6 +42,7 @@ #include #include #include +#include #ifdef ENABLE_CGAL #include @@ -66,6 +67,7 @@ #include "platform/PlatformUtils.h" #include "RenderStatistic.h" #include "utils/StackCheck.h" +#include "printutils.h" #ifdef ENABLE_PYTHON @@ -234,7 +236,7 @@ void localization_init() { bind_textdomain_codeset("openscad", "UTF-8"); textdomain("openscad"); } else { - LOG("Could not initialize localization."); + LOG("Could not initialize localization (application path is '%1$s').", PlatformUtils::applicationPath()); } } @@ -656,15 +658,6 @@ int main(int argc, char **argv) int rc = 0; StackCheck::inst(); -#ifdef OPENSCAD_QTGUI - { // Need a dummy app instance to get the application path but it needs to be destroyed before the GUI is launched. - QCoreApplication app(argc, argv); - PlatformUtils::registerApplicationPath(app.applicationDirPath().toLocal8Bit().constData()); - } -#else - PlatformUtils::registerApplicationPath(fs::absolute(boost::filesystem::path(argv[0]).parent_path()).generic_string()); -#endif - #ifdef Q_OS_MACOS bool isGuiLaunched = getenv("GUI_LAUNCHED") != nullptr; auto nslog = [](const Message& msg, void *userdata) { @@ -675,6 +668,9 @@ int main(int argc, char **argv) PlatformUtils::ensureStdIO(); #endif + const auto applicationPath = weakly_canonical(boost::dll::program_location().parent_path()).generic_string(); + PlatformUtils::registerApplicationPath(applicationPath); + #ifdef ENABLE_CGAL // Always throw exceptions from CGAL, so we can catch instead of crashing on bad geometry. CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); @@ -929,6 +925,8 @@ int main(int argc, char **argv) } } + PRINTDB("Application location detected as %s", applicationPath); + auto cmdlinemode = false; if (!output_files.empty()) { // cmd-line mode cmdlinemode = true; diff --git a/src/platform/PlatformUtils.cc b/src/platform/PlatformUtils.cc index aa2d131ac43..33b8d2be57e 100644 --- a/src/platform/PlatformUtils.cc +++ b/src/platform/PlatformUtils.cc @@ -52,7 +52,6 @@ static std::string lookupResourcesPath() const char *searchpath[] = { RESOURCE_FOLDER("../share/openscad"), RESOURCE_FOLDER("../../share/openscad"), - "usr/share/openscad", // AppImage, no build suffix ".", "..", "../..", From 0910d5177555354ee44800ba783857526a1377b7 Mon Sep 17 00:00:00 2001 From: Torsten Paul Date: Sun, 27 Oct 2024 18:35:13 +0100 Subject: [PATCH 2/2] Use const reference as suggested by linter. --- src/openscad.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openscad.cc b/src/openscad.cc index a3be9c31a88..30ee3f79948 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -228,7 +228,7 @@ void set_render_color_scheme(const std::string& color_scheme, const bool exit_if */ void localization_init() { fs::path po_dir(PlatformUtils::resourcePath("locale")); - std::string locale_path(po_dir.string()); + const std::string& locale_path(po_dir.string()); if (fs::is_directory(locale_path)) { setlocale(LC_ALL, "");