HANDLE hTimer = NULL;
static VOID CALLBACK update_progress(PVOID lpParam, BOOLEAN TimerOrWaitFired) {
- print_progress(SDB_PROGRESS_STAGE_TRANSFERRING);
+ if (hTimer != NULL) {
+ print_progress(SDB_PROGRESS_STAGE_TRANSFERRING);
+ }
}
static void init_sync_progress_timer(void) {
D("failed to DeleteTimerQueueTimer()\n");
return;
}
+ hTimer = NULL;
}
#endif
unsigned percent = 0;
unsigned speed = 0;
unsigned progress_bytes = 0;
+ static int is_finished = 0;
+
+ /* initialize timer */
+ if (stage == SDB_PROGRESS_STAGE_STARTED) {
+ init_sync_progress_timer();
+ is_finished = 0;
+ }
+ /* calc progress information */
sdb_mutex_lock(&prg_info_lock, "read written_bytes. print_progress()");
progress_bytes = g_prg_info.written_bytes;
sdb_mutex_unlock(&prg_info_lock, "read written_bytes. print_progress()");
speed = calc_progress_speed(stage, progress_bytes);
percent = calc_progress_percent(progress_bytes);
- //TODO: consider current window size.
- fprintf(stdout,"\r%s %30s\t%3d%%\t%7d%s\t%5dKB/s", g_prg_info.tag, g_prg_info.file_name,
+ /* print progress information */
+ sdb_mutex_lock(&prg_print_lock, "print progress info. print_progress()");
+ if (!is_finished) {
+ //TODO: consider current window size.
+ fprintf(stdout,"\r%s %30s\t%3d%%\t%7d%s\t%5dKB/s", g_prg_info.tag, g_prg_info.file_name,
percent, (progress_bytes/g_prg_info.flag_size), g_prg_info.byte_flag, speed);
- fflush(stdout);
+ fflush(stdout);
+ }
+ sdb_mutex_unlock(&prg_print_lock, "print progress info. print_progress()");
- if (stage == SDB_PROGRESS_STAGE_STARTED) {
- init_sync_progress_timer();
- } else if (stage == SDB_PROGRESS_STAGE_FINISHED) {
+ /* deinitialize timer and print '\n' */
+ if (stage == SDB_PROGRESS_STAGE_FINISHED) {
deinit_sync_progress_timer();
+
+ sdb_mutex_lock(&prg_print_lock, "print progress info. print_progress()");
fprintf(stdout,"\n");
+ fflush(stdout);
+ is_finished = 1;
+ sdb_mutex_unlock(&prg_print_lock, "print progress info. print_progress()");
}
}