LAview.Core/src/core/AppDirs.vala

103 lines
2.5 KiB
Vala
Raw Normal View History

2018-02-21 14:54:21 +03:00
/**
* System calls.
*/
2016-12-08 04:20:49 +03:00
namespace Get {
2018-02-21 14:54:21 +03:00
/**
* Gets library path.
* @param so_path out path to shared library.
* @param addr initialization method source address.
*/
2016-12-08 04:20:49 +03:00
extern void library_path (string so_path, void *addr);
}
2016-12-07 19:36:43 +03:00
2018-02-21 14:54:21 +03:00
/**
* LaTeX view.
*
* Public system of data view in the LaTeX format.
*/
2016-12-07 19:36:43 +03:00
namespace LAview.Core {
2018-02-21 14:54:21 +03:00
/**
* Application directories/paths.
*/
2016-12-07 19:36:43 +03:00
class AppDirs {
2018-02-21 14:54:21 +03:00
/**
* Shared library path.
*/
2016-12-07 19:36:43 +03:00
public static File so_path;
2018-02-21 14:54:21 +03:00
/**
* Binary directory.
*/
2016-12-07 19:36:43 +03:00
public static File exec_dir;
2018-02-21 14:54:21 +03:00
/**
* Common directory (parent to binary and shared).
*/
2016-12-07 19:36:43 +03:00
public static File common_dir;
2018-02-21 14:54:21 +03:00
/**
* Data Plugins directory.
*/
2016-12-07 19:36:43 +03:00
public static string data_plugins_dir;
2018-02-21 14:54:21 +03:00
/**
* Object Plugins directory.
*/
2016-12-07 19:36:43 +03:00
public static string object_plugins_dir;
2018-02-21 14:54:21 +03:00
/**
* User Interface Glade files directory.
*/
2016-12-07 19:36:43 +03:00
public static string ui_dir;
2018-02-21 14:54:21 +03:00
/**
* Settings/GLib Schemas directory.
*/
2016-12-07 19:36:43 +03:00
public static string settings_dir;
2018-02-21 14:54:21 +03:00
/**
* Temporary directory.
*/
2016-12-07 19:36:43 +03:00
public static string temp_dir;
2018-02-21 14:54:21 +03:00
/**
* Cache in temporary directory.
*/
2016-12-07 19:36:43 +03:00
public static string cache_dir;
2018-02-21 14:54:21 +03:00
/**
* Initialization.
* @throws FileError file i/o error.
*/
2016-12-07 19:36:43 +03:00
public static void init () throws FileError {
char _so_path[256];
2016-12-08 04:20:49 +03:00
Get.library_path ((string)_so_path, (void*)init);
2016-12-07 19:36:43 +03:00
so_path = File.new_for_path ((string)_so_path);
exec_dir = so_path.get_parent ();
common_dir = exec_dir.get_parent ();
ui_dir = Path.build_path (Path.DIR_SEPARATOR_S, common_dir.get_path(),
"share/laview-core-"+Config.VERSION_MAJOR.to_string()+"/ui");
settings_dir = Path.build_path (Path.DIR_SEPARATOR_S, common_dir.get_path(), "share/glib-2.0/schemas");
string w32dhack_sdir = settings_dir+"/laview-core-"+Config.VERSION_MAJOR.to_string();
if (File.new_for_path(w32dhack_sdir+"/gschemas.compiled").query_exists ())
settings_dir = w32dhack_sdir;
data_plugins_dir = Path.build_path (Path.DIR_SEPARATOR_S, exec_dir.get_path(),
"laview-core-"+Config.VERSION_MAJOR.to_string()+"/data-plugins");
object_plugins_dir = Path.build_path (Path.DIR_SEPARATOR_S, exec_dir.get_path(),
"laview-core-"+Config.VERSION_MAJOR.to_string()+"/object-plugins");
temp_dir = DirUtils.make_tmp ("laview-core-XXXXXX.temp");
cache_dir = Path.build_path (Path.DIR_SEPARATOR_S, AppDirs.temp_dir, "cache");
}
2018-02-21 14:54:21 +03:00
/**
* Termination.
* @throws Error any error.
*/
2016-12-07 19:36:43 +03:00
public static void terminate () throws Error {
rm_rf (File.new_for_path(temp_dir));
}
}
}