So I just ran into this problem at another place

https://github.com/geany/geany-osx/issues/6

where some data files aren't read because absolute paths are used in the code. 
There are at least 5 plugins affected by this - I didn't notice this myself 
because I have these files installed at the given paths but people who only get 
the bundle run into this problem.

So now the question is what to do - there are unfortunately various problems:
1. Geany installation prefix can be different from the plugins installation 
prefix. So Geany itself should probably not contain the code for determining 
plugins data directory.
2. On OS X Geany and plugins can be built in two ways - without bundle 
(installed similarly to linux) and with bundle (all in one package). The first 
one is actually always done in order to create the bundle and is also useful 
for testing (apart from it also e.g. MacPorts uses this method) while the 
bundle is what normal users get from the Geany downloads site. Both of them are 
important and should be supported. This means that the correct method for 
determining path has to be determined dynamically unlike Windows or Linux where 
either relative or absolute paths are used and this cannot be done during 
configure.
3. There's no nice way to determine whether bundle is used or whether Geany is 
run from system paths. While there are some utility functions for this in the 
gtk-mac-integration library which Geany uses, this would mean this library has 
to be added as a dependency for all the affected plugins and this is something 
I'd like to avoid. The only method I'm aware of is to check if some of the 
environment variables defined by the launcher script are defined and if so, 
assume it's a bundle.
4. It would be nice to have the code determining the path at one place but 
because (1) isn't probably the good solution and because there's nothing like 
utilities library for geany-plugins, the code will have to be copied to all the 
affected plugins.

Taking the above into account I tried the following for the GeniusPaste plugin:

```
static gchar *get_data_dir(void)
{
    gchar *prefix = NULL;
    gchar *dir;

#ifdef G_OS_WIN32
    prefix = g_win32_get_package_installation_directory_of_module(NULL);
#elif defined(__APPLE__)
    if (g_getenv("GTK_PATH"))
        return g_build_filename(g_getenv("GTK_PATH"),
                    "share", "geany-plugins", PLUGIN, "pastebins", NULL);
#endif
    dir = g_build_filename(prefix ? prefix : "", PLUGINDATADIR, "pastebins", 
NULL);
    g_free(prefix);
    return dir;
}
```

For the bundle, GTK_PATH is defined and basically points to what `/usr` would 
contain on linux. When it's not defined, I assume it's not a bundle and that 
PLUGINDATADIR can be used. I tested this both for the bundle and non-bundle 
case and it works.

Is it OK to have a function like that copied to every affected plugin 
(basically the ones referencing either PLUGINDATADIR in the code or 
g_win32_get_package_installation_directory_of_module())? Or does anyone have a 
better idea how to do this?

cc @b4n 


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/issues/507#issuecomment-288447053

Reply via email to