void ssd_dialog_wait (void) { while (RoadMapDialogCurrent) { roadmap_main_flush (); } }
/* * Called once one file was sent successfully. Starts the sending of the next file, if there is one. */ static void upload_done( void *context, const char *format, ... ) { upload_context * uContext = (upload_context *)context; int new_count; char ** new_cursor; const char * target_url; char * new_full_path; char msg[500]; int total; va_list ap; if(format){ va_start(ap, format); vsnprintf(msg,sizeof(msg),format,ap); va_end(ap); roadmap_log(ROADMAP_DEBUG,"done uploading log file : %s. Received response : %s",*uContext->cursor,msg); } new_cursor = (uContext->cursor)+1; new_count = (uContext->file_num)+1; total = uContext->total; roadmap_file_remove(NULL, uContext->full_path); // remove the previous file if(new_count==total){ // finished - sent all the files! in_process = 0 ; roadmap_path_list_free(uContext->files); ssd_progress_msg_dialog_hide(); roadmap_messagebox_timeout("Thank you!!!", "Logs submitted successfully to waze",3); }else{ // still more files - call the next one upload_context * new_context; sprintf (warning_message,"%s\n%d/%d",roadmap_lang_get("Uploading logs..."),new_count+1, total); ssd_progress_msg_dialog_show(warning_message); roadmap_main_flush(); new_full_path = roadmap_path_join( roadmap_path_debug(), *new_cursor ); new_context= malloc(sizeof(upload_context)); new_context->cursor = new_cursor; new_context->files = uContext->files; new_context->full_path = new_full_path; new_context->file_num = new_count; new_context->total = total; target_url = roadmap_config_get ( &RMCfgDebugInfoServer); if ( editor_upload_auto( new_full_path, &gUploadCallbackFunctions, target_url, LOG_UPLOAD_CONTENT_TYPE,(void *)new_context) ) { roadmap_log( ROADMAP_ERROR, "File upload error. for file %s , number %d", new_full_path, new_count); roadmap_path_free(new_full_path); roadmap_path_list_free (new_context->files); ssd_progress_msg_dialog_hide(); roadmap_messagebox_timeout("Error", "Error sending files",5); in_process = 0; } } roadmap_path_free(uContext->full_path); free(uContext); }
BOOL download_warning_fn ( char* dest_string ) { int progress; if (SyncProgressLoaded < 0) { return FALSE; } progress = 100 / SyncProgressItems * (SyncProgressCurrentItem - 1) + (100 / SyncProgressItems) * SyncProgressLoaded / SyncProgressTarget; snprintf (dest_string, ROADMAP_WARNING_MAX_LEN, "%s %s: %d%%%%", roadmap_lang_get("Progress status"), roadmap_lang_get(SyncProgressLabel), progress); roadmap_main_flush (); return TRUE; }
int export_sync (void) { int i; int res; char *messages[MAX_MSGS]; int num_msgs = 0; int fips; if (!editor_is_enabled ()) { return 0; } res = roadmap_file_free_space (roadmap_path_user()); #if !defined(__SYMBIAN32__) || defined(QTMOBILITY) if ((res >= 0) && (res < MIN_FREE_SPACE)) { roadmap_messagebox ("Error", "Please free at least 5MB of space before synchronizing."); return -1; } #endif roadmap_download_progress (0); snprintf (SyncProgressLabel, sizeof(SyncProgressLabel), "%s", roadmap_lang_get ("Preparing export data...")); roadmap_warning_register (download_warning_fn, "edtsync"); roadmap_main_flush (); roadmap_download_progress (0); snprintf (SyncProgressLabel, sizeof(SyncProgressLabel), "%s", roadmap_lang_get ("Uploading data...")); roadmap_main_flush (); Realtime_OfflineClose (); #ifndef J2ME res = sync_do_upload (); #endif Realtime_OfflineOpen (editor_sync_get_export_path (), editor_sync_get_export_name ()); fips = roadmap_locator_active (); if (fips < 0) { fips = 77001; } #if 0 if (roadmap_locator_activate (fips) == ROADMAP_US_OK) { now_t = time (NULL); map_time_t = atoi(roadmap_metadata_get_attribute ("Version", "UnixTime")); if ((map_time_t + 3600*24) > now_t) { /* Map is less than 24 hours old. * A new version may still be available. */ now_tm = *gmtime(&now_t); map_time_tm = *gmtime(&map_time_t); if (now_tm.tm_mday == map_time_tm.tm_mday) { goto end_sync; } else { /* new day - only download if new maps were already generated. */ if (now_tm.tm_hour < 2) goto end_sync; } } } #endif //0 SyncProgressItems = 1; SyncProgressCurrentItem = 0; roadmap_download_progress (0); snprintf (SyncProgressLabel, sizeof(SyncProgressLabel), "%s", roadmap_lang_get ("Downloading new maps...")); roadmap_label_clear (-1); navigate_graph_clear (-1); roadmap_main_flush (); #ifndef J2ME res = editor_download_update_map (&SyncDownloadCallbackFunctions); if (res == -1) { roadmap_messagebox ("Download Error", roadmap_lang_get("Error downloading map update")); } #endif for (i=0; i<num_msgs; i++) { roadmap_messagebox ("Info", messages[i]); free (messages[i]); } roadmap_warning_unregister (download_warning_fn); return 0; }
/////////////////////////////////////////////////////// // Compress files and prepare for upload int upload () { const char* directory = roadmap_path_debug(); const char* target_url; char *full_path; upload_context * context; #ifndef RIMAPI char **files = roadmap_path_list (directory, ".gz"); #else char ** files = malloc(sizeof(char *)*2); // temporary workaround, until path list is implemented files[0] = strdup(zipped_log_name); files[1] = NULL; #endif int count; int total; char **cursor; // Set the target to upload to sprintf (warning_message,"%s",roadmap_lang_get("Uploading logs...")); ssd_progress_msg_dialog_show(warning_message); roadmap_main_flush(); count = 0; for (cursor = files; *cursor != NULL; ++cursor) { count++; } cursor = files; total = count; count = 0; target_url = roadmap_config_get ( &RMCfgDebugInfoServer); context= malloc(sizeof(upload_context)); context->cursor = cursor; context->files = files; context->file_num = count; context->total = total; full_path = roadmap_path_join( directory, *cursor ); context->full_path = full_path; sprintf (warning_message,"%s\n%d/%d",roadmap_lang_get("Uploading logs..."),count+1, context->total); ssd_progress_msg_dialog_show(warning_message); roadmap_main_flush(); // this starts the async sending sequence. Further progress is done through the callbacks. if ( editor_upload_auto( full_path, &gUploadCallbackFunctions, target_url, LOG_UPLOAD_CONTENT_TYPE,(void *)context) ) { roadmap_log( ROADMAP_ERROR, "File upload error. for file %s ", full_path); roadmap_path_free(full_path); roadmap_path_list_free (files); ssd_progress_msg_dialog_hide(); free(context); return 0; } return 1; }
/////////////////////////////////////////////////////// // Compress files and prepare for upload int prepare_for_upload () { int res; char out_filename[256]; char **files; char **cursor; const char* directory; int count; int total; time_t now; struct tm *tms; char year[5], month[5], day[5]; #ifdef RIMAPI timeStruct time_s; #endif sprintf (warning_message,"%s",roadmap_lang_get("Preparing files for upload...")); ssd_progress_msg_dialog_show(warning_message); roadmap_main_flush(); //Count files for upload directory = roadmap_path_gps(); files = roadmap_path_list (directory, ".csv"); count = 1; //Counting also the postmortem for (cursor = files; *cursor != NULL; ++cursor) { count++; } total = count; count = 0; //Prepare log count++; sprintf (warning_message,"%s\n%d/%d",roadmap_lang_get("Preparing files for upload..."),count, total); ssd_progress_msg_dialog_show(warning_message); roadmap_main_flush(); // Building the filename time( &now ); tms = localtime( &now ); #ifdef RIMAPI roadmap_time_get_time(&time_s); tms->tm_hour = time_s.hours; tms->tm_min = time_s.minutes; #endif GET_2_DIGIT_STRING( tms->tm_mday, day ); GET_2_DIGIT_STRING( tms->tm_mon+1, month ); // Zero based from January GET_2_DIGIT_STRING( tms->tm_year-100, year ); // Year from 1900 snprintf(out_filename,256, "%s%s%s__%d_%d__%s_%d_%s__%s.gz", day, month, year, tms->tm_hour, tms->tm_min, RealTime_GetUserName(), RT_DEVICE_ID, roadmap_start_version(), roadmap_log_filename()); #ifndef RIMAPI res = roadmap_zlib_compress(roadmap_log_path(), roadmap_log_filename(), roadmap_path_debug(), out_filename, COMPRESSION_LEVEL,TRUE); #else // 0 = Z_OK = SUCCESS. 1 = failure. res = NOPH_ZLib_compress(roadmap_log_path(), roadmap_log_filename(), roadmap_path_debug(),out_filename,COMPRESSION_LEVEL); strcpy(zipped_log_name,out_filename); // emporary until path_list is implemented #endif if (res != Z_OK) { ssd_progress_msg_dialog_hide(); return 0; } //Prepare CSV files for (cursor = files; *cursor != NULL; ++cursor) { count++; sprintf (warning_message,"%s\n%d/%d",roadmap_lang_get("Preparing files for upload..."),count, total); ssd_progress_msg_dialog_show(warning_message); roadmap_main_flush(); sprintf(out_filename, "%s%s.gz", *cursor, RealTime_GetUserName()); #ifndef J2ME res = roadmap_zlib_compress(directory, *cursor, roadmap_path_debug(), out_filename, COMPRESSION_LEVEL,FALSE); #else // 0 = Z_OK = SUCCESS. 1 = failure. res = NOPH_ZLib_compress(directory, *cursor, roadmap_path_debug(),out_filename,COMPRESSION_LEVEL); #endif if (res != Z_OK) { ssd_progress_msg_dialog_hide(); return 0; } else { roadmap_file_remove(directory, *cursor); } } roadmap_path_list_free (files); ssd_progress_msg_dialog_hide(); return 1; }