1 /*************************************************************************** 2 $RCSfile$ 3 ------------------- 4 cvs : $Id$ 5 begin : Mon Mar 01 2004 6 copyright : (C) 2004 by Martin Preuss 7 email : martin@libchipcard.de 8 9 *************************************************************************** 10 * * 11 * This library is free software; you can redistribute it and/or * 12 * modify it under the terms of the GNU Lesser General Public * 13 * License as published by the Free Software Foundation; either * 14 * version 2.1 of the License, or (at your option) any later version. * 15 * * 16 * This library is distributed in the hope that it will be useful, * 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 19 * Lesser General Public License for more details. * 20 * * 21 * You should have received a copy of the GNU Lesser General Public * 22 * License along with this library; if not, write to the Free Software * 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 24 * MA 02111-1307 USA * 25 * * 26 ***************************************************************************/ 27 28 29 30 #ifndef GWENHYWFAR_PATHMANAGER_H 31 #define GWENHYWFAR_PATHMANAGER_H 32 33 #include <gwenhywfar/error.h> 34 #include <gwenhywfar/stringlist.h> 35 #include <gwenhywfar/buffer.h> 36 37 38 typedef enum { 39 /** relative to the current working directory at calling time */ 40 GWEN_PathManager_RelModeCwd=0, 41 /** 42 * This mode is interpreted differently in Windows and non-Windows systems 43 * due to the different handling of paths. 44 * <ul> 45 * <li> 46 * Windows: Releative to the folder in which the currently running 47 * executable is located. 48 * </li> 49 * <li> 50 * Non-Windows: Relative to the installation prefix of the currently 51 * running executable 52 * </li> 53 * </ul> 54 */ 55 GWEN_PathManager_RelModeExe, 56 /** relative to the user's home directory */ 57 GWEN_PathManager_RelModeHome 58 } GWEN_PATHMANAGER_RELMODE; 59 60 61 #ifdef __cplusplus 62 extern "C" { 63 #endif 64 65 66 /** @name Path Management 67 * 68 * Gwenhywfar keeps track of registered directory paths for itself 69 * and for other libraries. 70 * 71 * The paths are registered and stored in one global object (of 72 * GWEN_DB_NODE type), so write-access to this GWEN_PathManager 73 * functions is unfortunately not thread-safe. 74 * 75 * This technique is used internally to 76 * determine some important paths. 77 */ 78 /*@{*/ 79 80 /** 81 * Register a path to be managed by the global GWEN_PathManager 82 * module. This must be done before calling one of the other 83 * functions of this group. The actual path is not yet set. 84 * 85 * @param destLib The name of the library that this path is supposed to 86 * belong to. 87 * 88 * @param pathName A string identifier for this registered path. 89 * 90 * @return Zero on success, or GWEN_ERROR_INVALID if the @c 91 * pathName already exists. 92 */ 93 GWENHYWFAR_API 94 int GWEN_PathManager_DefinePath(const char *destLib, 95 const char *pathName); 96 97 /** 98 * Unregister a path that was registered by 99 * GWEN_PathManager_DefinePath(). 100 * 101 * @param destLib The name of the library that this path is supposed to 102 * belong to. 103 * 104 * @param pathName A string identifier for this registered path. 105 * 106 * @return Zero on success, or GWEN_ERROR_NOT_FOUND if the @c 107 * pathName was not found. 108 */ 109 GWENHYWFAR_API 110 int GWEN_PathManager_UndefinePath(const char *destLib, 111 const char *pathName); 112 113 114 /** 115 * Add a directory path entry to a registered path entry in the 116 * global GWEN_PathManager. 117 * 118 * @param callingLib The name of the library that adds this path entry. 119 * 120 * @param destLib The name of the library that this path is supposed to 121 * belong to. 122 * 123 * @param pathName A string identifier for this registered path. 124 * 125 * @param pathValue The actual directory path that should be added to 126 * this registered path. 127 * 128 * @param rm path relative to what? (see @ref GWEN_PathManager_RelModeCwd) 129 * 130 * @return Zero on success, or GWEN_ERROR_NOT_FOUND if the @c 131 * pathName was not found. 132 */ 133 GWENHYWFAR_API 134 int GWEN_PathManager_AddPath(const char *callingLib, 135 const char *destLib, 136 const char *pathName, 137 const char *pathValue); 138 139 /** 140 * Same as @ref GWEN_PathManager_AddPath but the path to add is given 141 * relative to some directory. The "relmode" argument chooses the base 142 * directory to which the given sub-directory path is appended and the 143 * result is added to this PathManager: 144 * 145 * - RelModeCwd appends the path to the current working directory at 146 * the time of calling. So future changes to the CWD do not affect 147 * this setting. 148 * 149 * - RelModeExe appends the path to the prefix of the installation 150 * location of the calling executable. This function looks up the 151 * current working directory, removes the last component (i.e. the 152 * "/bin/") to get the prefix, then adds the given relative path to 153 * it. 154 * 155 * - RelModeHome appends the path to the return value of 156 * GWEN_Directory_GetHomeDirectory(). 157 * 158 * All three variantes will then add the resulting path 159 * to the PathManager. 160 * 161 * @param callingLib The name of the library that adds this path entry. 162 * 163 * @param destLib The name of the library that this path is supposed to 164 * belong to. 165 * 166 * @param pathName A string identifier for this registered path. 167 * 168 * @param pathValue The actual directory path relative to the prefix 169 * of the current working directory that should be added to this 170 * registered path. 171 * 172 * @param rm The Flag to choose the starting directory to which the 173 * path is appended. 174 * 175 * @return Zero on success, or GWEN_ERROR_NOT_FOUND if the @c 176 * pathName was not found. 177 */ 178 GWENHYWFAR_API 179 int GWEN_PathManager_AddRelPath(const char *callingLib, 180 const char *destLib, 181 const char *pathName, 182 const char *pathValue, 183 GWEN_PATHMANAGER_RELMODE rm); 184 /** 185 * Add a directory path entry to a registered path entry in the 186 * global GWEN_PathManager by looking up the directory path in the 187 * Windows registry. 188 * 189 * On non-windows platforms, the function does nothing and returns 190 * zero, so you can safely call this in your multi-platform code. 191 * 192 * Note: Gwenhywfar-2.6.0 and older used to lookup the paths under 193 * HKEY_CURRENT_USER, but with gwen-2.6.1 this was changed to 194 * HKEY_LOCAL_MACHINE because we're talking about installation paths 195 * as opposed to per-user configuration settings. 196 * 197 * @param callingLib The name of the library that adds this path entry. 198 * 199 * @param destLib The name of the library that this path is supposed to 200 * belong to. 201 * 202 * @param pathName A string identifier for this registered path. 203 * 204 * @param keypath The key's path in the windows registry under 205 * HKEY_LOCAL_MACHINE, e.g. "Software\MyProgram\Paths". 206 * 207 * @param varname The variable name of the string variable with the 208 * actual directory path. 209 * 210 * @return Zero on success, or nonzero if the @c pathName or the 211 * registry key was not found. 212 */ 213 GWENHYWFAR_API 214 int GWEN_PathManager_AddPathFromWinReg(const char *callingLib, 215 const char *destLib, 216 const char *pathName, 217 const char *keypath, 218 const char *varname); 219 220 /** 221 * Insert a directory path entry to a registered path entry in the 222 * global GWEN_PathManager. While @ref GWEN_PathManager_AddPath adds a path 223 * to the end of the list for this particular @c pathName this function 224 * here inserts it at the beginning of the list. This can be used e.g. to 225 * ensure that plugins/files from a given path take precedence over already 226 * added paths. 227 * 228 * @param callingLib The name of the library that adds this path entry. 229 * 230 * @param destLib The name of the library that this path is supposed to 231 * belong to. 232 * 233 * @param pathName A string identifier for this registered path. 234 * 235 * @param pathValue The actual directory path that should be added to 236 * this registered path. 237 */ 238 GWENHYWFAR_API 239 int GWEN_PathManager_InsertPath(const char *callingLib, 240 const char *destLib, 241 const char *pathName, 242 const char *pathValue); 243 244 /** 245 * Same as @ref GWEN_PathManager_InsertPath but the path to insert is given 246 * relative to some directory. The "relmode" argument chooses the base 247 * directory to which the given sub-directory path is appended and the 248 * result is added to this PathManager: 249 * 250 * - RelModeCwd appends the path to the current working directory at 251 * the time of calling. So future changes to the CWD do not affect 252 * this setting. 253 * 254 * - RelModeExe appends the path to the prefix of the installation 255 * location of the calling executable. This function looks up the 256 * current working directory, removes the last component (i.e. the 257 * "/bin/") to get the prefix, then adds the given relative path to 258 * it. 259 * 260 * - RelModeHome appends the path to the return value of 261 * GWEN_Directory_GetHomeDirectory(). 262 * 263 * All three variantes will then add the resulting path 264 * to the PathManager. 265 * 266 * @param callingLib The name of the library that adds this path entry. 267 * 268 * @param destLib The name of the library that this path is supposed to 269 * belong to. 270 * 271 * @param pathName A string identifier for this registered path. 272 * 273 * @param pathValue The actual directory path relative to the prefix 274 * of the current working directory that should be added to this 275 * registered path. 276 * 277 * @param rm The Flag to choose the starting directory to which the 278 * path is appended. 279 * 280 * @return Zero on success, or GWEN_ERROR_NOT_FOUND if the @c 281 * pathName was not found. 282 */ 283 GWENHYWFAR_API 284 int GWEN_PathManager_InsertRelPath(const char *callingLib, 285 const char *destLib, 286 const char *pathName, 287 const char *pathValue, 288 GWEN_PATHMANAGER_RELMODE rm); 289 290 291 /** 292 * Removes a directory path entry from a registered path entry in 293 * the global GWEN_PathManager. 294 * 295 * @param callingLib The name of the library that added this path entry. 296 * 297 * @param destLib The name of the library that this path is supposed to 298 * belong to. 299 * 300 * @param pathName A string identifier for this registered path. 301 * 302 * @param pathValue The actual directory path that should be added to 303 * this registered path. 304 * 305 * @return Zero on success, or nonzero if the @c pathName was not 306 * found. 307 */ 308 GWENHYWFAR_API 309 int GWEN_PathManager_RemovePath(const char *callingLib, 310 const char *destLib, 311 const char *pathName, 312 const char *pathValue); 313 314 /** 315 * Removes all directory path entries that were registered by the 316 * @c callingLib from the global GWEN_PathManager. 317 * 318 * @param callingLib The name of the library that added path entries. 319 * 320 * @return Zero on success. 321 */ 322 GWENHYWFAR_API 323 int GWEN_PathManager_RemovePaths(const char *callingLib); 324 325 326 /** 327 * This function checks whether the path list for @c pathName has changed 328 * since the last call to this function (i.e. whether paths have been 329 * added, inserted or removed). 330 * 331 * @param destLib The name of the library that this path is supposed to 332 * belong to. 333 * 334 * @param pathName A string identifier for this registered path. 335 * 336 * @return Zero on success, or GWEN_ERROR_NOT_FOUND if the @c 337 * pathName was not found. 338 */ 339 GWENHYWFAR_API 340 int GWEN_PathManager_PathChanged(const char *destLib, 341 const char *pathName); 342 343 /** 344 * Returns a string list of all path entries that exist under the 345 * registered @c pathName. 346 * 347 * @param destLib The name of the library that this path is supposed to 348 * belong to. 349 * 350 * @param pathName A string identifier for this registered path. 351 * 352 * @return A newly allocated @ref GWEN_STRINGLIST with all added 353 * path entries, or NULL if no path entry or no registered @c 354 * pathName exists. Delete this list with @ref GWEN_StringList_free() 355 * when no longer needed. 356 */ 357 GWENHYWFAR_API 358 GWEN_STRINGLIST *GWEN_PathManager_GetPaths(const char *destLib, 359 const char *pathName); 360 361 362 /** 363 * This functions tries to find a given file using all 364 * path entries under the registered @c pathName. 365 * 366 * @param destLib The name of the library that this path is supposed to 367 * belong to. 368 * 369 * @param pathName A string identifier for this registered path. 370 * 371 * @param fileName Name of the file (may contain partial paths, like in 372 * "dialogs/testdialog.xml" 373 * 374 * @param fbuf buffer to receive the full path to access the file 375 * 376 * @return 0 on success (in that case @c fbuf will be filled), an 377 * error code otherwise. 378 */ 379 GWENHYWFAR_API 380 int GWEN_PathManager_FindFile(const char *destLib, 381 const char *pathName, 382 const char *fileName, 383 GWEN_BUFFER *fbuf); 384 385 /** 386 * This function calls @ref GWEN_Directory_GetMatchingFilesRecursively() on every 387 * path entry under the registered @c pathName. 388 * 389 * @return 0 if ok, error code on error 390 * 391 * @param destLib The name of the library that this path is supposed to 392 * belong to. 393 * 394 * @param pathName A string identifier for this registered path. 395 * 396 * @param subFolderName if given then this folder name is appended to every path under 397 * the registered @c pathName before caling @ref GWEN_Directory_GetMatchingFilesRecursively() 398 * on it. You can use this parameter to search only in specific sub folders of the paths. 399 * 400 * @param sl string list to receive the paths of all matching files 401 */ 402 GWENHYWFAR_API 403 int GWEN_PathManager_GetMatchingFilesRecursively(const char *destLib, 404 const char *pathName, 405 const char *subFolderName, 406 GWEN_STRINGLIST *sl, 407 const char *mask); 408 409 /*@}*/ 410 411 #ifdef __cplusplus 412 } 413 #endif 414 415 416 #endif /* GWENHYWFAR_PATHMANAGER_H */ 417