rpi plugins fix + paths enhancements #94

Store the full relative path to found `.rpi` plugins, relative to the
standard Plugins directory, as specified by wxWidgets.

This fixes the problem of plugins being in a subdirectory while only the
basename was stored, making the plugins unusable.

This is done by using `wxFileName::GetFullPath()` instead of
`wxFileName::GetFullName()` with a relative filename instance.

Make a `GetPluginsDir()` method on the app class to simplify getting
this directory, and for possible future overrides.

Also make some minor, functionally equivalent changes to
`get_config_path()` in `wxvbam.cpp`:

- use the new `GetPluginsDir()` method for the plugins directory when
  building the config file search path

- print the XdgConfigDir on all platforms, since the function works on
  all platforms

- make a `add_nonstandard_path` macro which duplicates the `add_path`
  macro for wxWidgets standard paths but for any arbitrary string path

- use `wxFileName` methods to make the XDG config directory path instead
  of string concatenation

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2019-03-07 07:13:07 -08:00
parent 6a98f3c200
commit 530af14030
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
4 changed files with 26 additions and 10 deletions

View File

@ -1775,8 +1775,8 @@ public:
ch->Clear();
ch->Append(_("None"));
plugins.clear();
const wxString& plpath = wxStandardPaths::Get().GetPluginsDir();
wxDir::GetAllFiles(plpath, &plugins, wxT("*.rpi"));
const wxString plpath = wxGetApp().GetPluginsDir();
wxDir::GetAllFiles(plpath, &plugins, wxT("*.rpi"), wxDIR_FILES | wxDIR_DIRS);
for (int i = 0; i < plugins.size(); i++) {
wxDynamicLibrary dl(plugins[i], wxDL_VERBATIM | wxDL_NOW);
@ -1798,7 +1798,7 @@ public:
s += wxT(": ");
s += wxString(rpi->Name, wxConvUTF8, sizeof(rpi->Name));
fn.MakeRelativeTo(plpath);
plugins[i] = fn.GetFullName();
plugins[i] = fn.GetFullPath();
ch->Append(s);
if (plugins[i] == gopts.filter_plugin)

View File

@ -1336,7 +1336,7 @@ DrawingPanelBase::DrawingPanelBase(int _width, int _height)
break;
wxFileName fpn(gopts.filter_plugin);
fpn.MakeAbsolute(wxStandardPaths::Get().GetPluginsDir());
fpn.MakeAbsolute(wxGetApp().GetPluginsDir());
if (!filt_plugin.Load(fpn.GetFullPath(), wxDL_VERBATIM | wxDL_NOW))
break;

View File

@ -48,6 +48,14 @@ static void get_config_path(wxPathList& path, bool exists = true)
if ((wxDirExists(s) && wxIsWritable(s)) || ((!exists || !wxDirExists(s)) && parent.IsDirWritable())) \
path.Add(s); \
} while (0)
#define add_nonstandard_path(p) \
do { \
const wxString& s = p; \
wxFileName parent = wxFileName::DirName(s + wxT("//..")); \
parent.MakeAbsolute(); \
if ((wxDirExists(s) && wxIsWritable(s)) || ((!exists || !wxDirExists(s)) && parent.IsDirWritable())) \
path.Add(s); \
} while (0)
static bool debug_dumped = false;
@ -58,10 +66,8 @@ static void get_config_path(wxPathList& path, bool exists = true)
wxLogDebug(wxT("GetResourcesDir(): %s"), stdp.GetResourcesDir().mb_str());
wxLogDebug(wxT("GetDataDir(): %s"), stdp.GetDataDir().mb_str());
wxLogDebug(wxT("GetLocalDataDir(): %s"), stdp.GetLocalDataDir().mb_str());
wxLogDebug(wxT("GetPluginsDir(): %s"), stdp.GetPluginsDir().mb_str());
#if defined(__WXGTK__)
wxLogDebug(wxT("plugins_dir: %s"), wxGetApp().GetPluginsDir().mb_str());
wxLogDebug(wxT("XdgConfigDir: %s"), get_xdg_user_config_home() + current_app_name);
#endif
debug_dumped = true;
}
@ -74,12 +80,16 @@ static void get_config_path(wxPathList& path, bool exists = true)
wxString new_config(get_xdg_user_config_home());
if (!wxDirExists(old_config) && wxIsWritable(new_config))
{
path.Add(new_config + current_app_name);
wxFileName new_path(new_config, wxEmptyString);
new_path.AppendDir(current_app_name);
new_path.MakeAbsolute();
add_nonstandard_path(new_path.GetFullPath());
}
else
{
// config is in $HOME/.vbam/vbam.conf
path.Add(old_config);
add_nonstandard_path(old_config);
}
#endif
@ -90,7 +100,7 @@ static void get_config_path(wxPathList& path, bool exists = true)
add_path(GetResourcesDir());
add_path(GetDataDir());
add_path(GetLocalDataDir());
add_path(GetPluginsDir());
add_nonstandard_path(wxGetApp().GetPluginsDir());
}
static void tack_full_path(wxString& s, const wxString& app = wxEmptyString)
@ -103,6 +113,11 @@ static void tack_full_path(wxString& s, const wxString& app = wxEmptyString)
s += wxT("\n\t") + full_config_path[i] + app;
}
const wxString wxvbamApp::GetPluginsDir()
{
return wxStandardPaths::Get().GetPluginsDir();
}
wxString wxvbamApp::GetConfigurationPath()
{
#if defined(__WXMSW__) || defined(__APPLE__)

View File

@ -87,6 +87,7 @@ public:
virtual void OnInitCmdLine(wxCmdLineParser&);
virtual bool OnCmdLineParsed(wxCmdLineParser&);
wxString GetConfigurationPath();
const wxString GetPluginsDir();
wxString GetAbsolutePath(wxString path);
// name of a file to load at earliest opportunity
wxString pending_load;