Skip to content

Commit

Permalink
fixup backup and restore status
Browse files Browse the repository at this point in the history
Change-Id: I2065755c26a2b49f09ac8592c61faa9474ce2f57
  • Loading branch information
koush authored and myfluxi committed Jul 5, 2012
1 parent 337d7ef commit 44dab28
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
3 changes: 2 additions & 1 deletion common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ void ui_clear_key_queue();
void ui_print(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
void ui_printlogtail(int nb_lines);

void ui_reset_text_col();
void ui_set_show_text(int value);
void ui_set_nice(int enabled);
#define ui_nice_print(...) ui_set_nice(1); ui_print(__VA_ARGS__); ui_set_nice(0)
int ui_was_niced();
int ui_get_text_cols();

// Display some header text followed by a menu of items, which appears
// at the top of the screen (in place of any scrolling ui_print()
Expand Down
14 changes: 6 additions & 8 deletions nandroid.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ static void yaffs_callback(const char* filename)
strcpy(tmp, justfile);
if (tmp[strlen(tmp) - 1] == '\n')
tmp[strlen(tmp) - 1] = NULL;
if (strlen(tmp) < 30)
ui_nice_print("%s", tmp);
tmp[ui_get_text_cols() - 1] = '\0';
yaffs_files_count++;
if (yaffs_files_total != 0)
ui_nice_print("%s\n", tmp);
if (!ui_was_niced() && yaffs_files_total != 0)
ui_set_progress((float)yaffs_files_count / (float)yaffs_files_total);
ui_reset_text_col();
if (!ui_was_niced())
ui_delete_line();
}

static void compute_directory_stats(const char* directory)
Expand Down Expand Up @@ -108,10 +109,7 @@ static int mkyaffs2image_wrapper(const char* backup_path, const char* backup_fil

static int tar_compress_wrapper(const char* backup_path, const char* backup_file_image, int callback) {
char tmp[PATH_MAX];
if (strcmp(backup_path, "/data") == 0 && volume_for_path("/sdcard") == NULL)
sprintf(tmp, "cd $(dirname %s) ; touch %s.tar ; tar cv --exclude 'media' $(basename %s) | split -a 1 -b 1000000000 /proc/self/fd/0 %s.tar. ; exit $?", backup_path, backup_file_image, backup_path, backup_file_image);
else
sprintf(tmp, "cd $(dirname %s) ; touch %s.tar ; tar cv $(basename %s) | split -a 1 -b 1000000000 /proc/self/fd/0 %s.tar. ; exit $?", backup_path, backup_file_image, backup_path, backup_file_image);
sprintf(tmp, "cd $(dirname %s) ; touch %s.tar ; (tar cv %s $(basename %s) | split -a 1 -b 1000000000 /proc/self/fd/0 %s.tar.) 2> /proc/self/fd/1 ; exit $?", backup_path, backup_file_image, strcmp(backup_path, "/data") == 0 && is_data_media() ? "--exclude 'media'" : "", backup_path, backup_file_image);

FILE *fp = __popen(tmp, "r");
if (fp == NULL) {
Expand Down
27 changes: 19 additions & 8 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,24 @@ static long delta_milliseconds(struct timeval from, struct timeval to) {

static struct timeval lastupdate = (struct timeval) {0};
static int ui_nice = 0;
static int ui_niced = 0;
void ui_set_nice(int enabled) {
ui_nice = enabled;
}
#define NICE_INTERVAL 100
int ui_was_niced() {
return ui_niced;
}
int ui_get_text_cols() {
return text_cols;
}
void ui_delete_line() {
pthread_mutex_lock(&gUpdateMutex);
text[text_row][0] = '\0';
text_row = (text_row - 1 + text_rows) % text_rows;
text_col = 0;
pthread_mutex_unlock(&gUpdateMutex);
}

void ui_print(const char *fmt, ...)
{
Expand All @@ -861,11 +876,14 @@ void ui_print(const char *fmt, ...)

// if we are running 'ui nice' mode, we do not want to force a screen update
// for this line if not necessary.
ui_niced = 0;
if (ui_nice) {
struct timeval curtime;
gettimeofday(&curtime, NULL);
if (delta_milliseconds(lastupdate, curtime) < 1000)
if (delta_milliseconds(lastupdate, curtime) < NICE_INTERVAL) {
ui_niced = 1;
return;
}
lastupdate = curtime;
}

Expand Down Expand Up @@ -910,13 +928,6 @@ void ui_printlogtail(int nb_lines) {
ui_log_stdout=1;
}

void ui_reset_text_col()
{
pthread_mutex_lock(&gUpdateMutex);
text_col = 0;
pthread_mutex_unlock(&gUpdateMutex);
}

#define MENU_ITEM_HEADER " > "
#define MENU_ITEM_HEADER_LENGTH strlen(MENU_ITEM_HEADER)

Expand Down

0 comments on commit 44dab28

Please sign in to comment.