diff options
author | kazer_ <kazer_@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2010-11-02 16:37:16 +0000 |
---|---|---|
committer | kazer_ <kazer_@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2010-11-02 16:37:16 +0000 |
commit | 8be75e2a5a1436685ef455dfea24c3f90fc38327 (patch) | |
tree | b6e59f9bbc21e959ddabc7f1f2695df8cbd85686 /navit/popup.c | |
parent | 07ec9aad8d1e3cd399ca5cacf52fa25b5681142d (diff) | |
download | navit-svn-8be75e2a5a1436685ef455dfea24c3f90fc38327.tar.gz |
Fix:Core:Applied patch from jwernerny to fix inconsistent distortion.txt handling
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@3638 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/popup.c')
-rw-r--r-- | navit/popup.c | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/navit/popup.c b/navit/popup.c index 5addaccc..8d20d2e1 100644 --- a/navit/popup.c +++ b/navit/popup.c @@ -1,6 +1,6 @@ /** * Navit, a modular navigation system. - * Copyright (C) 2005-2008 Navit Team + * Copyright (C) 2005-2008, 2010 Navit Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -61,21 +61,62 @@ popup_set_no_passing(struct popup_item *item, void *param) #endif +/** + * @brief Get the user data directory. + * @param[in] create - create the directory if it does not exist + * + * @return char * to the data directory string. + * + * returns the directory used to store user data files (center.txt, + * destination.txt, bookmark.txt, ...) + * + */ +char* +popup_get_user_data_directory(gboolean create) { + char *dir; + dir = getenv("NAVIT_USER_DATADIR"); + if (create && !file_exists(dir)) { + dbg(0,"creating dir %s\n", dir); + if (file_mkdir(dir,0)) { + dbg(0,"failed creating dir %s\n", dir); + return NULL; + } + } + return dir; +} /* end: popup_get_user_data_directory(gboolean create) */ + static void popup_traffic_distortion(struct item *item, char *attr) { - FILE *map=fopen("distortion.txt","a"); - struct coord c; - struct map_rect *mr; - fprintf(map,"type=traffic_distortion %s\n",attr); - mr=map_rect_new(item->map,NULL); - item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo); - while (item_coord_get(item, &c, 1)) { - fprintf(map,"0x%x 0x%x\n",c.x,c.y); - } - fclose(map); -} + /* add the configuration directory to the name of the file to use */ + char *dist_filename = g_strjoin(NULL, popup_get_user_data_directory(TRUE), + "/distortion.txt", NULL); + if (dist_filename) /* if we built the filename */ + { + FILE *map=fopen(dist_filename,"a"); + if (map) /* if the file was opened */ + { + struct coord c; + struct map_rect *mr; + fprintf(map,"type=traffic_distortion %s\n",attr); + mr=map_rect_new(item->map,NULL); + item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo); + while (item_coord_get(item, &c, 1)) { + fprintf(map,"0x%x 0x%x\n",c.x,c.y); + } + fclose(map); + } + else + { + dbg(0,"could not open file for distortions !!", item); + + } /* else - if (map) */ + g_free(dist_filename); /* free the file name */ + } /* if (dist_filename) */ + +} /* end: popup_traffic_distortion(..) */ + static void popup_traffic_distortion_blocked(struct item *item) { |