From 65717e6d745db3c59ffb5f70ee557a9202f0c1cf Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Mon, 31 Jul 2017 18:01:44 -0400 Subject: Expand io api for tav, resolve filename to local directory --- src/io/resource.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/io/resource.cpp') diff --git a/src/io/resource.cpp b/src/io/resource.cpp index dfb851d58..bc6c9f7b0 100644 --- a/src/io/resource.cpp +++ b/src/io/resource.cpp @@ -181,11 +181,37 @@ Glib::ustring get_filename(Type type, char const *filename, char const *locale) return result; } +/* + * Similar to get_filename, but takes a path (or filename) for relative resolution + * + * path - A directory or filename that is considered local to the path resolution. + * filename - The filename that we are looking for. + */ +Glib::ustring get_filename(Glib::ustring path, Glib::ustring filename) +{ + // Test if it's a filename and get the parent directory instead + if (Glib::file_test(path, Glib::FILE_TEST_IS_REGULAR)) { + return get_filename(g_path_get_dirname(path.c_str()), filename); + } + if (g_path_is_absolute(filename.c_str())) { + if (Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) { + return filename; + } + } else { + Glib::ustring ret = Glib::build_filename(path, filename); + if (Glib::file_test(ret, Glib::FILE_TEST_EXISTS)) { + return ret; + } + } + return Glib::ustring(); +} + /* * Get's all the files in a given type, for all domain types. * * domain - Optional domain (overload), will check return domains if not. * type - The type of files, e.g. TEMPLATES + * path - Instead of Domain and Type, specify the path to get the files from. * extentions - A list of extensions to return, e.g. xml, svg * exclusions - A list of names to exclude e.g. default.xml */ -- cgit v1.2.3