The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

SearchPaths.vala in /libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Circle boundaries heads/master
1 /* 2 Copyright (C) 2012 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 namespace BirdFont { 16 17 /** Look for files in default folders on different operating systems. */ 18 public class SearchPaths { 19 20 private static string resources_folder = ""; 21 22 public static File find_file (string? dir, string name) { 23 File f = search_file (dir, name); 24 25 if (!f.query_exists ()) { 26 warning (@"Did not find file $name"); 27 } 28 29 return f; 30 } 31 32 public static File search_file (string? dir, string name) { 33 File f; 34 string d = (dir == null) ? "" : (!) dir; 35 string resources; 36 string bundle_path = (BirdFont.bundle_path != null) ? (!) BirdFont.bundle_path : ""; 37 38 resources = (is_null (resources_folder)) ? "" : resources_folder; 39 40 f = get_file (resources + "/" + d + "/", name); 41 if (likely (f.query_exists ())) return f; 42 43 f = get_file (resources + "/", name); 44 if (likely (f.query_exists ())) return f; 45 46 f = get_file ("resources/", name); 47 if (likely (f.query_exists ())) return f; 48 49 f = get_file (resources + "/", name + "/"); 50 if (likely (f.query_exists ())) return f; 51 52 f = get_file (BirdFont.exec_path + "/" + d + "/", name); 53 if (likely (f.query_exists ())) return f; 54 55 f = get_file (BirdFont.exec_path + "/", name + "/"); 56 if (likely (f.query_exists ())) return f; 57 58 f = get_file (BirdFont.exec_path + "\\" + d + "\\", name); 59 if (likely (f.query_exists ())) return f; 60 61 f = get_file (BirdFont.exec_path + "\\", name + "\\"); 62 if (likely (f.query_exists ())) return f; 63 64 f = get_file (bundle_path + "/Contents/Resources/birdfont_resources/", d + "/" + name); 65 if (likely (f.query_exists ())) return f; 66 67 f = get_file (bundle_path + "/Contents/Resources/birdfont_resources/", name + "/"); 68 if (likely (f.query_exists ())) return f; 69 70 f = get_file ("./" + d + "/", name); 71 if (likely (f.query_exists ())) return f; 72 73 f = get_file ("../" + d + "/", name); 74 if (likely (f.query_exists ())) return f; 75 76 f = get_file (".\\" + d + "\\", name); 77 if (likely (f.query_exists ())) return f; 78 79 f = get_file ("", name); 80 if (likely (f.query_exists ())) return f; 81 82 f = get_file (d + "\\", name); 83 if (likely (f.query_exists ())) return f; 84 85 f = get_file (@"$PREFIX/share/birdfont/" + d + "/", name); 86 if (likely (f.query_exists ())) return f; 87 88 f = get_file (@"/usr/local/share/birdfont/" + d + "/", name); 89 if (likely (f.query_exists ())) return f; 90 91 f = get_file (@"resources/linux/", name); 92 if (likely (f.query_exists ())) return f; 93 94 f = get_file (@"/usr/share/birdfont/" + d + "/", name); 95 if (likely (f.query_exists ())) return f; 96 97 return f; 98 } 99 100 public static string get_locale_directory () { 101 string f = ""; 102 string resources; 103 string bundle_path = (BirdFont.bundle_path != null) ? (!) BirdFont.bundle_path : ""; 104 105 resources = (is_null (resources_folder)) ? "" : resources_folder; 106 107 f = resources + "\\locale\\sv\\LC_MESSAGES\\birdfont.mo"; 108 if (exists (f)) { 109 return resources + "\\locale"; 110 } 111 112 if (!is_null (BirdFont.exec_path)) { 113 f = BirdFont.exec_path + "/Contents/Resources/birdfont_resources/locale/sv/LC_MESSAGES/birdfont.mo"; 114 if (exists (f)) { 115 return BirdFont.exec_path + "/Contents/birdfont_resources/Resources/locale"; 116 } 117 118 f = BirdFont.exec_path + "\\locale\\sv\\LC_MESSAGES\\birdfont.mo"; 119 if (exists (f)) { 120 return BirdFont.exec_path + "\\locale"; 121 } 122 } 123 124 f = "./build/locale/sv/LC_MESSAGES/birdfont.mo"; 125 if (exists (f)) { 126 return "./build/locale"; 127 } 128 129 f = ".\\locale\\sv\\LC_MESSAGES\\birdfont.mo"; 130 if (exists (f)) { 131 return ".\\locale"; 132 } 133 134 f = PREFIX + "/share/locale/sv/LC_MESSAGES/birdfont.mo"; 135 if (exists (f)) { 136 return PREFIX + "/share/locale/"; 137 } 138 139 f = "/usr/share/locale/sv/LC_MESSAGES/birdfont.mo"; 140 if (exists (f)) { 141 return "/usr/share/locale"; 142 } 143 144 f = BirdFont.exec_path + "/Contents/Resources/birdfont_resources/locale"; 145 if (exists (f)) { 146 return BirdFont.exec_path + "/Contents/Resources/birdfont_resources/locale"; 147 } 148 149 f = bundle_path + "/Contents/Resources/birdfont_resources/locale"; 150 if (exists (f)) { 151 return bundle_path + "/Contents/Resources/birdfont_resources/locale"; 152 } 153 154 warning ("translations not found"); 155 return "/usr/share/locale"; 156 } 157 158 public static File get_char_database () { 159 File f; 160 string bundle_path = (BirdFont.bundle_path != null) ? (!) BirdFont.bundle_path : ""; 161 162 f = (!) File.new_for_path (PREFIX + "/share/unicode/NamesList.txt"); 163 if (f.query_exists ()) { 164 return f; 165 } 166 167 f = (!) File.new_for_path (PREFIX + "/share/unicode/ucd/NamesList.txt"); 168 if (f.query_exists ()) { 169 return f; 170 } 171 172 f = (!) File.new_for_path (".\\NamesList.txt"); 173 if (f.query_exists ()) { 174 return f; 175 } 176 177 f = (!) File.new_for_path ("/usr/share/unicode/NamesList.txt"); 178 if (f.query_exists ()) { 179 return f; 180 } 181 182 f = (!) File.new_for_path (BirdFont.exec_path + "/Contents/Resources/NamesList.txt"); 183 if (f.query_exists ()) { 184 return f; 185 } 186 187 f = (!) File.new_for_path (bundle_path + "/Contents/Resources/NamesList.txt"); 188 if (f.query_exists ()) { 189 return f; 190 } 191 192 f = (!) File.new_for_path ("/usr/share/unicode/ucd/NamesList.txt"); 193 if (f.query_exists ()) { 194 return f; 195 } 196 197 warning ("ucd not found"); 198 199 return f; 200 } 201 202 static File get_file (string? path, string name) { 203 StringBuilder fn = new StringBuilder (); 204 string p = (path == null) ? "" : (!) path; 205 fn.append (p); 206 fn.append ((!) name); 207 208 return File.new_for_path (fn.str); 209 } 210 211 static bool exists (string file) { 212 File f = File.new_for_path (file); 213 return f.query_exists (); 214 } 215 216 public static void set_resources_folder (string res) { 217 resources_folder = res; 218 } 219 } 220 221 } 222