Skip to content

Commit

Permalink
Merge pull request openscad#5395 from openscad/fix-resource-folder-lo…
Browse files Browse the repository at this point in the history
…okup

Fix resource folder lookup (fixes openscad#5394).
  • Loading branch information
t-paul authored Oct 28, 2024
2 parents 0ab2ba2 + 0910d51 commit 7f05c62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
20 changes: 9 additions & 11 deletions src/openscad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>
#include <boost/optional.hpp>
#include <boost/dll.hpp>

#ifdef ENABLE_CGAL
#include <CGAL/assertions.h>
Expand All @@ -66,6 +67,7 @@
#include "platform/PlatformUtils.h"
#include "RenderStatistic.h"
#include "utils/StackCheck.h"
#include "printutils.h"


#ifdef ENABLE_PYTHON
Expand Down Expand Up @@ -226,15 +228,15 @@ 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, "");
bindtextdomain("openscad", locale_path.c_str());
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());
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/platform/PlatformUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
".",
"..",
"../..",
Expand Down

0 comments on commit 7f05c62

Please sign in to comment.