From e8f11178ecc1a333976ba713f532fcae11931b16 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sun, 12 Mar 2017 13:19:04 +0100 Subject: Move storage into user directory and fix plugin search path --- libdino/src/plugin/loader.vala | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'libdino/src/plugin/loader.vala') diff --git a/libdino/src/plugin/loader.vala b/libdino/src/plugin/loader.vala index acb26ff4..42d7fa9b 100644 --- a/libdino/src/plugin/loader.vala +++ b/libdino/src/plugin/loader.vala @@ -14,17 +14,40 @@ public class Loader : Object { [CCode (has_target = false)] private delegate Type RegisterPluginFunction (Module module); + private string[] search_paths = new string[0]; private RootInterface[] plugins = new RootInterface[0]; private Info[] infos = new Info[0]; + public Loader(string? exec_str = null) { + search_paths += Application.get_storage_dir(); + if (exec_str != null) { + string exec_path = exec_str; + if (!exec_path.contains(Path.DIR_SEPARATOR_S)) { + exec_path = Environment.find_program_in_path(exec_str); + } + if (exec_path[0:5] != "/usr") { + search_paths += Path.get_dirname(exec_path); + } + } + foreach (string dir in Environment.get_system_data_dirs()) { + search_paths += Path.build_filename(dir, "dino"); + } + } + public RootInterface load(string name, Dino.Application app) throws Error { if (Module.supported () == false) { throw new Error (-1, 0, "Plugins are not supported"); } - Module module = Module.open ("plugins/" + name, ModuleFlags.BIND_LAZY); + Module module = null; + string path = ""; + foreach (string prefix in search_paths) { + path = Path.build_filename(prefix, "plugins", name); + module = Module.open (path, ModuleFlags.BIND_LAZY); + if (module != null) break; + } if (module == null) { - throw new Error (-1, 1, Module.error ()); + throw new Error (-1, 1, Module.error ().replace(path, name)); } void* function; -- cgit v1.2.3-54-g00ecf