static int roadmap_help_prepare (void) {

   const char *path;


   /* First look for the user directory. */
   path = roadmap_path_user();
   if (roadmap_file_exists(path, RDM_MANUAL)) {
      roadmap_help_make_url (path);
      return 1;
   }


   /* Then look throughout the system path list. */

   for (path = roadmap_path_first("config");
         path != NULL;
         path = roadmap_path_next("config", path))
   {
      if (roadmap_file_exists(path, RDM_MANUAL)) {

         roadmap_help_make_url (path);
         return 1;
      }
   }

   roadmap_log(ROADMAP_ERROR, "manual not found");
   return 0;
}
Beispiel #2
0
const char *roadmap_path_search_icon (const char *name)
{
   static char result[256];

   sprintf (result, "%s\\icons\\rm_%s.png", roadmap_path_user(), name);
   if (roadmap_file_exists(NULL, result)) return result;

   sprintf (result, "\\Storage Card\\Roadmap\\icons\\rm_%s.png", name);
   if (roadmap_file_exists(NULL, result)) return result;

   return NULL; /* Not found. */
}
Beispiel #3
0
const char *roadmap_db_map_path (void) {

   const char *map_path;
   static char map_path_static[512];
   static int map_path_initialized = 0;
   
   if (!map_path_initialized) { 
   
	#ifdef J2ME
      map_path = roadmap_path_preferred("maps");;
      strncpy_safe (map_path_static, map_path, sizeof (map_path_static));
	#elif defined (WIN32)
		map_path = roadmap_path_join (roadmap_path_user(), "maps");
		strncpy_safe (map_path_static, map_path, sizeof (map_path_static));
		roadmap_path_free (map_path);
	#elif IPHONE
	   map_path = roadmap_path_join (roadmap_main_bundle_path(), "maps");
	   strncpy_safe (map_path_static, map_path, sizeof (map_path_static));
	   roadmap_path_free (map_path);
	#else
	   map_path = roadmap_path_first ("maps");
	   while (map_path && !roadmap_file_exists (map_path,"")) {
	   	map_path = roadmap_path_next ("maps", map_path);
	   }
	   if (map_path) {
			strncpy_safe (map_path_static, map_path, sizeof (map_path_static));
	   } else {
	   	map_path_static[0] = '\0';
	   }
	#endif
		map_path_initialized = 1;
   }
   	
   return map_path_static;
}
Beispiel #4
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);
   }
}
Beispiel #5
0
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;
}
Beispiel #6
0
static void roadmap_config_update (RoadMapConfig *config, int force) {

   FILE *file;
   const char *value;
   const char *p = NULL;
   RoadMapConfigItem *item;


   if (force || (config->state == ROADMAP_CONFIG_DIRTY))
   {
#ifndef J2ME
	   for ( p = roadmap_path_first( config->set );
			   p != NULL;
			   p = roadmap_path_next( config->set, p ) )
	   {
		   if ( roadmap_file_exists( p, "" ) )
			   break;
	   }
#endif
	   if ( p == NULL )
	   {
		   p = roadmap_path_config();
	   }
	   
#ifdef J2ME
	   char file_name[100];
	   sprintf(file_name,"%s_j2me",config->name);
	   file = roadmap_file_fopen (p, file_name, "w");
#else
   	   file = roadmap_file_fopen ( p, config->name, "w" );
#endif
	  

       if ( file )
       {

         for (item = config->first_item; item != NULL; item = item->next) {

            if ((! force) && (item->state == ROADMAP_CONFIG_SHARED)) continue;

            if (item->value != NULL) {
               value = item->value;
            } else {
               value = item->default_value;
            }
#ifdef J2ME
            char name_to_write[100]; // this will be of the category.type name
            sprintf(name_to_write,"%s.%s", item->category, item->name);
            roadmap_config_write_name_value_to_binary(name_to_write,value,file);
#else
			fprintf (file, "%s.%s: %s\n", item->category, item->name, value);
#endif            
         }

         fclose (file);
         config->state = ROADMAP_CONFIG_CLEAN;
      }
   }
}
Beispiel #7
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;
}
Beispiel #8
0
void editor_db_delete (int map_id) {

   char name[100];
  	const char *map_path;

#ifdef WIN32
	map_path = roadmap_path_join (roadmap_path_user(), "maps");
#else
   map_path = roadmap_path_first ("maps");
   while (map_path && !roadmap_file_exists (map_path,"")) {
   	map_path = roadmap_path_next ("maps", map_path);
   }
#endif
   snprintf (name, sizeof(name), "edt%05d.dat", map_id);
   
   if (roadmap_file_exists (map_path, name)) {

      char **files;
      char **cursor;
      char *directory;

      /* Delete notes wav files */
      /* FIXME this is broken for multiple counties */
      directory = roadmap_path_join (roadmap_path_user (), "markers");
      files = roadmap_path_list (directory, ".wav");

      for (cursor = files; *cursor != NULL; ++cursor) {

         char *full_name = roadmap_path_join (directory, *cursor);
         roadmap_file_remove (NULL, full_name);

         free (full_name);
      }

      free (directory);

      /* Remove the actual editor file */
      roadmap_file_remove (map_path, name);
   }
#ifdef WIN32
   roadmap_path_free(map_path);
#endif
}
Beispiel #9
0
/*  Name        : upload_error_callback( int size )
 *  Purpose     : Upload callback: Error
 *
 */
static void download_cache_clear( void )
{
    int i;
    for ( i = 0; i < VOICE_DOWNLOAD_CACHE_SIZE; ++i )
    {
        if ( gVoiceDownloadCache[i] == NULL )
            break;
        // Remove the file
        if ( roadmap_file_exists( "", gVoiceDownloadCache[i] ) )
        {
            roadmap_file_remove( "", gVoiceDownloadCache[i] );
        }
        free( gVoiceDownloadCache[i] );
        gVoiceDownloadCache[i] = NULL;
    }

}
Beispiel #10
0
/*  Name        : download_cache_add( const char* file_path )
 *  Purpose     : Adds the downloaded file to the cache
 *
 */
static void download_cache_add( const char* file_path )
{

    if ( gVoiceDownloadCache[gVoiceDownloadCacheCurIndex] != NULL )
    {
        char *file_path = gVoiceDownloadCache[gVoiceDownloadCacheCurIndex];
        // Remove the file
        if ( roadmap_file_exists( "", file_path ) )
        {
            roadmap_file_remove( "", file_path );
        }
        free( file_path );
    }

    gVoiceDownloadCache[gVoiceDownloadCacheCurIndex] = strdup( file_path );
    gVoiceDownloadCacheCurIndex = ( gVoiceDownloadCacheCurIndex + 1 ) % VOICE_DOWNLOAD_CACHE_SIZE;
}
Beispiel #11
0
/*  Name        : roadmap_recorder_voice_download()
 *  Purpose     : Constructs the url and downloads the voice.
 *
 *  Params     : (in) voice_id - the voice id to download
 *
 *             : (out) download_cb - the full path to the downloaded voice file - user responsibility to
 *             		deallocate the memory!!!!
 *
 *  Notes      :
 *
 */
BOOL roadmap_recorder_voice_download( const char* voice_id,  void* context_cb, VoiceDownloadCallback download_cb )
{
    BOOL res = FALSE;
    char *url;
    char  *voice_file, *voice_path;
    DownloadContext* context;

    roadmap_log( ROADMAP_DEBUG, "Downloading the voice.  ID: %s", voice_id );

    // Target file name from the voice id
    voice_file = malloc( strlen( voice_id ) + strlen( ROADMAP_VOICE_DOWNLOAD_FILE_SUFFIX ) + 1 );
    strcpy( voice_file, voice_id );
    strcat( voice_file, ROADMAP_VOICE_DOWNLOAD_FILE_SUFFIX );

    // Target full path for the output
    voice_path = roadmap_path_join( roadmap_path_voices(), voice_file );
    if (roadmap_file_exists( NULL, voice_path ) )
    {
        // Add file to cache
        download_cache_add( voice_path );
        // The file exists - no need to download
        download_cb( context_cb, 0, voice_path );
        roadmap_path_free( voice_path );
    }
    else
    {
        url = get_download_url( voice_id );
        // Init the download process context
        context = malloc( sizeof( DownloadContext ) );
        context->voice_path = voice_path;
        context->context_cb = context_cb;
        context->download_cb = download_cb;
        context->data = NULL;
        // Show the message
        ssd_progress_msg_dialog_show( roadmap_lang_get( "Downloading voice ..." ) );
        // Start the process
        roadmap_http_async_copy( &gHttpAsyncCallbacks, context, url ,0 );
        free( url );
    }

    free( voice_file );

    return res;
}
Beispiel #12
0
int roadmap_sound_list_add ( RoadMapSoundList list, const char *name )
{
  const char* full_name;
  if ( list->count == MAX_SOUND_LIST ) return SND_LIST_ERR_LIST_FULL;

  full_name = get_full_name( name );

  if ( !roadmap_file_exists( full_name, NULL ) )
  {
     roadmap_log( ROADMAP_ERROR, "File %s doesn't exist! Cannot add to the list.", full_name );
     return SND_LIST_ERR_NO_FILE;
  }

  strncpy (list->list[list->count], name, sizeof(list->list[0]));
  list->list[list->count][sizeof(list->list[0])-1] = '\0';
  list->count++;

  return list->count - 1;
}
Beispiel #13
0
static void roadmap_config_update (RoadMapConfig *config, int force) {

   FILE *file;
   const char *value;
   const char *p;
   RoadMapConfigItem *item;


   if (force || (config->state == ROADMAP_CONFIG_DIRTY))
   {
	   for ( p = roadmap_path_first( config->set );
			   p != NULL;
			   p = roadmap_path_next( config->set, p ) )
	   {
		   if ( roadmap_file_exists( p, "" ) )
			   break;
	   }
	   if ( p == NULL )
	   {
		   p = roadmap_path_config();
	   }
	   file = roadmap_file_fopen ( p, config->name, "w" );

       if ( file )
       {

         for (item = config->first_item; item != NULL; item = item->next) {

            if ((! force) && (item->state == ROADMAP_CONFIG_SHARED)) continue;

            if (item->value != NULL) {
               value = item->value;
            } else {
               value = item->default_value;
            }
            fprintf (file, "%s.%s: %s\n", item->category, item->name, value);
         }

         fclose (file);
         config->state = ROADMAP_CONFIG_CLEAN;
      }
   }
}