edeforas / Astree

Astree is a free open source optical ray tracing and design software
GNU Lesser General Public License v3.0
76 stars 9 forks source link

Glass catalogs path for AppImage #29

Open ghost opened 4 years ago

ghost commented 4 years ago

I try to use AppImage builds, but seems like there are some issues with glass catalog path.

Actually, according ../src/gui/MainWindow.cpp, Astree use next path for sGlassPath:

std::string MainWindow::get_glass_path() const
{

...

#ifdef __unix__ //linux

    string sAppPath = QCoreApplication::applicationDirPath().toStdString();
    string sGlassPath = sAppPath + "/../share/astree/glass/"; //not very clean but should work
    return sGlassPath;
#endif

    return "invalid glass path";
}

Inside AppImage (if extract it as $ ./Astree*.AppImage --appimage-extract) there is /glass/ catalog, but its path looks next:

/squashfs-root/usr/glass

So, if I run AppImage build Astree recognize only built-in materials (Air; Vacuum; Water).

As result, on opening Newton_BK7_diagonals.astree sample BK7 could not be loaded from ../glass/common_glass.agf: "Glass BK7 doesn't exist in catalog!"

pic.1

edeforas commented 4 years ago

Hi, can you make a PR ? thanks! Or can you copy/paste the good lines for linux and std::string MainWindow::get_glass_path() const ?

edeforas commented 4 years ago

By the way does Astree launch in full screen correctly?

ghost commented 4 years ago

Or can you copy/paste the good lines for linux and std::string MainWindow::get_glass_path() const?

As I can see in initially @probonopd proposed to use ../share/astree/glass/, but actual path (... sAppPath + "/../share/astree/glass/" ...) include one extra / as first path character; think, this extra / should be removed.

By the way does Astree launch in full screen correctly?

NO! Yeah, there is issue with fullscreen too.

I suggest issue exits with size of some widgets, because I can't maximize window until move/reorder few widgets on left pane.

ghost commented 4 years ago

I hope path issue now fixed, but can't verify it just now so will test builds later today.

If all would be OK I will close this issue.

edeforas commented 4 years ago

thanks

ghost commented 4 years ago

UPD: Last fix does NOT help; not solved yet.

Need deeper review internal AppImage structure and glass folder path.

edeforas commented 4 years ago

thanks anyway !

probonopd commented 4 years ago

So you have

appdir/usr/bin/astree
appdir/usr/share/astree/glass

Correct?

Then it should work... what does QCoreApplication::applicationDirPath() return?

ghost commented 4 years ago

So you have

appdir/usr/bin/astree
appdir/usr/share/astree/glass

Check actual AppImage build:

If extract it, paths looks next:

$ ./Astree-dc626b8-x86_64.AppImage --appimage-extract
squashfs-root/.DirIcon
squashfs-root/AppRun
squashfs-root/astree.desktop
squashfs-root/astree.svg
squashfs-root/usr
squashfs-root/usr/bin
squashfs-root/usr/bin/astree
...
squashfs-root/usr/glass
...
probonopd commented 4 years ago

squashfs-root/usr/glass looks wrong to me, should be squashfs-root/usr/share/glass?

RocketEnvy commented 2 years ago

Since this might break AppImage again, and I'm not certain this is optimal, I'm not doing a pull request. However, I made the following changes to get non-AppImage Astree Glass Catalogue to work in Linux: `$ git diff *cpp diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 675c7ea..d78598f 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -3,7 +3,8 @@ // copyright Etienne de Foras ( the author ) mailto: etienne.deforas@gmail.com

include "FileUtil.h"

- +#include +#include

include "MainWindow.h"

include "ui_MainWindow.h"

include

@@ -46,9 +47,10 @@ MainWindow::MainWindow(QWidget parent) //load all glass catalog string sGlassPath = get_glass_path(); vector vsCatalog=FileUtil::list(sGlassPath+".agf"); + for(unsigned int i=0;i<vsCatalog.size();i++) {

The makefile didn't install the catalogs so I copied them by hand to /usr/share/astree/glass.

It might be better to use QStandardPaths::AppDataLocation, QStandardPaths::AppLocalDataLocation, or even QStandardPaths::AppConfigLocation so you don't have to worry about where to put stuff for each OS. I don't know anything about AppImage except I use some that store stuff in those locations on the regular hard drive, FreeCad for instance.

probonopd commented 2 years ago

Indeed:

If an application is relying on QStringList QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); the XDG_DATA_DIRS environment variable must be exported to <inside the AppDir>/usr/share/ in the AppDir by AppRun. (Note that linuxdeployqt does not use an AppRun file, just a symlink, and as a result this does not work there.)

As a fallback, you can use QString QCoreApplication::applicationDirPath() instead and construct a relative path to the application's data files from there.

For an example, see: https://github.com/KaidanIM/Kaidan/commit/da38011b55a1aa5d17764647ecd699deb4be437f

As a result, it should work both in normal installations and in relocatable installations such as AppImages.

Source: https://github.com/AppImage/AppImageKit/wiki/Bundling-Qt-apps

edeforas commented 2 years ago

Hello thanks for the PR! So, agree to merge ?