static int load_index(int fips, void **base, size_t *size) { const char *map_path = roadmap_db_map_path (); char name[30]; char filename[512]; const char *suffix = "index"; snprintf (name, sizeof (name), "%05d_%s%s", fips, suffix, ROADMAP_DATA_TYPE); roadmap_path_format (filename, sizeof (filename), map_path, name); roadmap_log(ROADMAP_DEBUG,"index filename: %s", filename); RoadMapFile file = roadmap_file_open (filename, "r"); if (!ROADMAP_FILE_IS_VALID(file)) { return -1; } *size = favail(file); *base = malloc (*size); int res = roadmap_file_read (file, *base, *size); roadmap_file_close (file); if (res != (int)*size) { free (*base); return -1; } return 0; }
void editor_db_delete (int map_id) { char name[100]; const char *map_path; map_path = roadmap_db_map_path(); snprintf (name, sizeof(name), "edt%05d.dat", map_id); if (roadmap_file_exists (map_path, name)) { char **files; char **cursor; char directory[512]; char full_name[512]; /* Delete notes wav files */ /* FIXME this is broken for multiple counties */ roadmap_path_format (directory, sizeof (directory), roadmap_path_user (), "markers"); files = roadmap_path_list (directory, ".wav"); for (cursor = files; *cursor != NULL; ++cursor) { roadmap_path_format (full_name, sizeof (full_name), directory, *cursor); roadmap_file_remove (NULL, full_name); } /* Remove the actual editor file */ roadmap_file_remove (map_path, name); } }
int editor_db_open (int map_id) { char name[100]; const char *map_path; char file_name[512]; int do_read = 0; editor_log_push ("editor_db_open"); #ifndef IPHONE map_path = roadmap_db_map_path(); #else map_path = roadmap_path_preferred("maps"); #endif //IPHONE if (!map_path) { editor_log (ROADMAP_ERROR, "Can't find editor path"); editor_log_pop (); return -1; } snprintf (name, sizeof(name), "edt%05d.dat", map_id); roadmap_path_format (file_name, sizeof (file_name), map_path, name); if (roadmap_file_exists (map_path, name)) { EditorDataFile = roadmap_file_open(file_name, "rw"); do_read = 1; } else { roadmap_path_create (map_path); EditorDataFile = roadmap_file_open(file_name, "w"); roadmap_file_write (EditorDataFile, &DB_SIGNATURE, sizeof (int)); } do { if (!ROADMAP_FILE_IS_VALID(EditorDataFile)) { editor_log (ROADMAP_ERROR, "Can't open/create new database: %s/%s", map_path, name); editor_log_pop (); return -1; } if (do_read) { do_read = 0; if (editor_db_read () == -1) { editor_db_free (); //roadmap_messagebox("Error", "Offline data file is currupt: Re-Initializing data"); roadmap_log (ROADMAP_ERROR, "Offline data file is currupt: Re-Initializing data"); roadmap_file_close (EditorDataFile); roadmap_file_remove (NULL, file_name); EditorDataFile = roadmap_file_open(file_name, "w"); roadmap_file_write (EditorDataFile, &DB_SIGNATURE, sizeof (int)); } } } while (do_read); EditorActiveMap = map_id; editor_log_pop (); return 0; }
int editor_db_open (int map_id) { char name[100]; const char *map_path; char *file_name; int do_read = 0; editor_log_push ("editor_db_open"); map_path = roadmap_db_map_path(); if (!map_path) { editor_log (ROADMAP_ERROR, "Can't find editor path"); editor_log_pop (); return -1; } snprintf (name, sizeof(name), "edt%05d.dat", map_id); file_name = roadmap_path_join(map_path, name); if (roadmap_file_exists (map_path, name)) { EditorDataFile = roadmap_file_open(file_name, "rw"); do_read = 1; } else { roadmap_path_create (map_path); EditorDataFile = roadmap_file_open(file_name, "w"); } #ifdef WIN32 roadmap_path_free(map_path); #endif do { if (!ROADMAP_FILE_IS_VALID(EditorDataFile)) { editor_log (ROADMAP_ERROR, "Can't open/create new database: %s/%s", map_path, name); roadmap_path_free(file_name); editor_log_pop (); return -1; } if (do_read) { do_read = 0; if (editor_db_read () == -1) { editor_db_free (); roadmap_messagebox("Error", "Offline data file is currupt: Re-Initializing data"); roadmap_file_close (EditorDataFile); roadmap_file_remove (NULL, file_name); EditorDataFile = roadmap_file_open(file_name, "w"); } } } while (do_read); roadmap_path_free(file_name); EditorActiveMap = map_id; editor_log_pop (); return 0; }
void roadmap_log_init(){ long fileSize; const char *log_path; const char *log_path_temp; const char * path; const char * name; char lineFromLog[300]; #if defined (__SYMBIAN32__) #if defined (WINSCW) path = "C:\\"; name = "waze_log.txt"; #else path = roadmap_db_map_path(); name = "waze_log.txt"; #endif #elif defined(ANDROID) roadmap_path_sdcard(); name = "waze_log.txt"; #elif !defined (J2ME) path = roadmap_path_user(); name = "postmortem"; #endif fileSize = roadmap_file_length(path,name); if (fileSize > 0 ){ // file exists if(fileSize>MAX_SIZE_LOG_FILE){ FILE * LogFile = roadmap_file_fopen(path,name,"sa+"); FILE * tempLogFile = roadmap_file_fopen(path,"temp_log_file.txt","sa+"); fseek(LogFile, 0, SEEK_END-TO_KEEP_LOG_SIZE); fgets (lineFromLog,300, LogFile ); while (1){ fgets (lineFromLog,300, LogFile ); if(feof(LogFile)) break; fputs (lineFromLog,tempLogFile ); } fclose(LogFile); fclose(tempLogFile); log_path = roadmap_path_join (path, name); log_path_temp = roadmap_path_join (path, "temp_log_file.txt"); roadmap_file_remove (path, name); rename(log_path_temp,log_path); roadmap_path_free (log_path); roadmap_path_free (log_path_temp); } } }
const char *editor_sync_get_export_path (void) { static char path[1024]; static int initialized = 0; if (!initialized) { #ifdef IPHONE roadmap_path_format (path, sizeof (path), roadmap_path_preferred("maps"), "queue"); #else roadmap_path_format (path, sizeof (path), roadmap_db_map_path (), "queue"); #endif //IPHONE roadmap_path_create (path); initialized = 1; } return path; }
const char *roadmap_log_path() { #if defined (__SYMBIAN32__) #if defined (WINSCW) return ("C:\\"); #else return (roadmap_db_map_path()); #endif #elif defined(ANDROID) // Only sdcard can be accessed for reading // For the debug purposes the log is appended return ( roadmap_path_sdcard()); #elif !defined (J2ME) return (roadmap_path_user()); #else //return ("file:///e:/FreeMap"); #endif }
static void roadmap_square_unmap (void *context) { RoadMapSquareContext *square_context = (RoadMapSquareContext *) context; if (square_context->type != RoadMapSquareType) { roadmap_log(ROADMAP_FATAL, "cannot unmap (bad context type)"); } #ifndef J2ME roadmap_city_write_file (roadmap_db_map_path(), "city_index", 0); #endif roadmap_city_free (); roadmap_square_unload_all (); if (RoadMapSquareActive == square_context) { RoadMapSquareActive = NULL; } roadmap_hash_free (square_context->SquareHash); free (square_context->Square); free (square_context); }
void roadmap_square_rebuild_index (void) { roadmap_file_remove(roadmap_db_map_path(), "city_index"); roadmap_square_load_index(); roadmap_city_write_file (roadmap_db_map_path(), "city_index", 0); }