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

Revisions

View the latest version of libbirdfont/SearchPaths.vala.
Parse more style attributes in SVG files
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/", d + "/" + name); 65 if (likely (f.query_exists ())) return f; 66 67 f = get_file (bundle_path + "/Contents/Resources/", name + "/"); 68 if (likely (f.query_exists ())) return f; 69 70 f = get_file (bundle_path + "/Contents/MacOS/", 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 (".\\" + d + "\\", name); 80 if (likely (f.query_exists ())) return f; 81 82 f = get_file ("", name); 83 if (likely (f.query_exists ())) return f; 84 85 f = get_file (d + "\\", name); 86 if (likely (f.query_exists ())) return f; 87 88 f = get_file (@"$PREFIX/share/birdfont/" + d + "/", name); 89 if (likely (f.query_exists ())) return f; 90 91 f = get_file (@"/usr/local/share/birdfont/" + d + "/", name); 92 if (likely (f.query_exists ())) return f; 93 94 f = get_file (@"resources/linux/", name); 95 if (likely (f.query_exists ())) return f; 96 97 f = get_file (@"/usr/share/birdfont/" + d + "/", name); 98 if (likely (f.query_exists ())) return f; 99 100 return f; 101 } 102 103 public static string get_locale_directory () { 104 string f = ""; 105 string resources; 106 string bundle_path = (BirdFont.bundle_path != null) ? (!) BirdFont.bundle_path : ""; 107 108 resources = (is_null (resources_folder)) ? "" : resources_folder; 109 110 f = resources + "\\locale\\sv\\LC_MESSAGES\\birdfont.mo"; 111 if (exists (f)) { 112 return resources + "\\locale"; 113 } 114 115 if (!is_null (BirdFont.exec_path)) { 116 f = BirdFont.exec_path + "/Contents/Resources/locale/sv/LC_MESSAGES/birdfont.mo"; 117 if (exists (f)) { 118 return BirdFont.exec_path + "/Contents/Resources/locale"; 119 } 120 121 f = BirdFont.exec_path + "\\locale\\sv\\LC_MESSAGES\\birdfont.mo"; 122 if (exists (f)) { 123 return BirdFont.exec_path + "\\locale"; 124 } 125 } 126 127 f = "./build/locale/sv/LC_MESSAGES/birdfont.mo"; 128 if (exists (f)) { 129 return "./build/locale"; 130 } 131 132 f = ".\\locale\\sv\\LC_MESSAGES\\birdfont.mo"; 133 if (exists (f)) { 134 return ".\\locale"; 135 } 136 137 f = PREFIX + "/share/locale/sv/LC_MESSAGES/birdfont.mo"; 138 if (exists (f)) { 139 return PREFIX + "/share/locale/"; 140 } 141 142 f = "/usr/share/locale/sv/LC_MESSAGES/birdfont.mo"; 143 if (exists (f)) { 144 return "/usr/share/locale"; 145 } 146 147 f = BirdFont.exec_path + "/Contents/Resources/locale"; 148 if (exists (f)) { 149 return BirdFont.exec_path + "/Contents/Resources/locale"; 150 } 151 152 f = bundle_path + "/Contents/Resources/locale"; 153 if (exists (f)) { 154 return bundle_path + "/Contents/Resources/locale"; 155 } 156 157 warning ("translations not found"); 158 return "/usr/share/locale"; 159 } 160 161 public static File get_char_database () { 162 File f; 163 string bundle_path = (BirdFont.bundle_path != null) ? (!) BirdFont.bundle_path : ""; 164 165 f = (!) File.new_for_path (PREFIX + "/share/unicode/NamesList.txt"); 166 if (f.query_exists ()) { 167 return f; 168 } 169 170 f = (!) File.new_for_path (PREFIX + "/share/unicode/ucd/NamesList.txt"); 171 if (f.query_exists ()) { 172 return f; 173 } 174 175 f = (!) File.new_for_path (".\\NamesList.txt"); 176 if (f.query_exists ()) { 177 return f; 178 } 179 180 f = (!) File.new_for_path ("/usr/share/unicode/NamesList.txt"); 181 if (f.query_exists ()) { 182 return f; 183 } 184 185 f = (!) File.new_for_path (BirdFont.exec_path + "/Contents/Resources/NamesList.txt"); 186 if (f.query_exists ()) { 187 return f; 188 } 189 190 f = (!) File.new_for_path (bundle_path + "/Contents/Resources/NamesList.txt"); 191 if (f.query_exists ()) { 192 return f; 193 } 194 195 f = (!) File.new_for_path ("/usr/share/unicode/ucd/NamesList.txt"); 196 if (f.query_exists ()) { 197 return f; 198 } 199 200 warning ("ucd not found"); 201 202 return f; 203 } 204 205 static File get_file (string? path, string name) { 206 StringBuilder fn = new StringBuilder (); 207 string p = (path == null) ? "" : (!) path; 208 fn.append (p); 209 fn.append ((!) name); 210 211 return File.new_for_path (fn.str); 212 } 213 214 static bool exists (string file) { 215 File f = File.new_for_path (file); 216 return f.query_exists (); 217 } 218 219 public static void set_resources_folder (string res) { 220 resources_folder = res; 221 } 222 } 223 224 } 225