Initial commit
[fillmore] / src / marina / AppDirs.vala
1 /* Copyright 2009-2010 Yorba Foundation
2  *
3  * This software is licensed under the GNU LGPL (version 2.1 or later).
4  * See the COPYING file in this distribution. 
5  */
6
7 extern const string _PREFIX;
8
9
10 public class AppDirs {
11     static File exec_dir;
12     static string program_name;
13
14     public static void init(string arg0, string program_name) {
15         File exec_file = File.new_for_path(Environment.find_program_in_path(arg0));
16         exec_dir = exec_file.get_parent();
17         AppDirs.program_name = program_name;
18     }
19
20     public static void terminate() {
21     }
22
23     public static File get_exec_dir() {
24         return exec_dir;
25     }
26
27     public static File get_resources_dir() {
28         File exec_dir = get_exec_dir();
29         File install_dir = get_install_dir();
30         File return_value;
31         if (install_dir != null) {
32             return_value = install_dir.get_child("share").get_child(program_name);
33         } else {    // running locally
34             return_value = exec_dir;
35         }
36         return return_value.get_child("resources");
37     }
38
39     static File? get_install_dir() {
40         File prefix_dir = File.new_for_path(_PREFIX);
41         return exec_dir.has_prefix(prefix_dir) ? prefix_dir : null;
42     }
43 }
44