diff --git a/src/browser.c b/src/browser.c index f3bded6a031d8f5690475011e76269328c5ce09d..5dbccc3bb359761a56919e222ad88906c7dfecd2 100644 --- a/src/browser.c +++ b/src/browser.c @@ -283,7 +283,8 @@ struct dir * selected(void) { void showBrowser(void) { int ch, change; - struct dir *n; + char tmp[PATH_MAX]; + struct dir *n, *t, *d; bcur = dat->sub; bgraph = 1; @@ -355,6 +356,54 @@ void showBrowser(void) { } break; + /* refresh */ + case 'r': + if((n = showCalc(getpath(bcur, tmp))) != NULL) { + /* free current items */ + t = bcur; + bcur = bcur->parent; + while(t->prev != NULL) + t = t->prev; + d = t; + while(d != NULL) { + t = d; + d = t->next; + freedir(t); + } + + /* update parent dir */ + bcur->sub = n->sub; + bcur->files = n->files; + bcur->dirs = n->dirs; + bcur->size = n->size; + for(t = bcur->sub; t != NULL; t = t->next) + t->parent = bcur; + + /* update sizes of parent dirs */ + for(t = bcur; (t = t->parent) != NULL; ) { + t->size += bcur->size; + t->files += bcur->files; + t->dirs += bcur->dirs+1; + } + + /* add reference to parent dir */ + if(bcur->parent) { + t = calloc(sizeof(struct dir), 1); + t->name = malloc(3); + t->flags |= FF_PAR; + strcpy(t->name, ".."); + t->parent = bcur; + t->next = bcur->sub; + t->next->prev = t; + bcur->sub = t; + } + + bcur = bcur->sub; + free(n->name); + free(n); + } + break; + /* and other stuff */ case KEY_RESIZE: ncresize(); diff --git a/src/calc.c b/src/calc.c index 9143ae53f03816d91ffceca024b35ed4377f2073..1430c480357d0982903c5fd7eee3b227610afada 100644 --- a/src/calc.c +++ b/src/calc.c @@ -142,7 +142,7 @@ static void drawProgress(char *cdir) { prg = newwin(10, 60, winrows/2-3, wincols/2-30); box(prg, 0, 0); wattron(prg, A_BOLD); - mvwaddstr(prg, 0, 4, "Calculating..."); + mvwaddstr(prg, 0, 4, dat == NULL ? "Calculating..." : "Recalculating..."); wattroff(prg, A_BOLD); mvwprintw(prg, 2, 2, "Total files: %-8d dirs: %-8d size: %s", @@ -209,6 +209,8 @@ int updateProgress(char *path) { return(0); if(ch == KEY_RESIZE) { ncresize(); + if(dat != NULL) + drawBrowser(0); drawProgress(path); } } @@ -368,6 +370,7 @@ int calcDir(struct dir *dest, char *path) { struct dir *showCalc(char *path) { char tmp[PATH_MAX]; struct stat fs; + struct dir *t; /* init/reset global vars */ *lasterr = '\0'; @@ -378,12 +381,15 @@ struct dir *showCalc(char *path) { if(rpath(path, tmp) == NULL || lstat(tmp, &fs) != 0) { do { ncresize(); + if(dat != NULL) + drawBrowser(0); drawError(path); } while (getch() == KEY_RESIZE); return(NULL); } parent = calloc(sizeof(struct dir), 1); parent->size = sflags & SF_AS ? fs.st_size : fs.st_blocks * 512; + parent->flags |= FF_DIR; curdev = fs.st_dev; parent->name = malloc(strlen(tmp)+1); strcpy(parent->name, tmp); @@ -393,6 +399,14 @@ struct dir *showCalc(char *path) { freedir(parent); return(NULL); } + + /* remove reference to parent dir if we are in the parent dir */ + t = parent->sub; + parent->sub = t->next; + parent->sub->prev = NULL; + free(t->name); + free(t); + return(parent); } diff --git a/src/main.c b/src/main.c index 2edae42b177026eb9a925e721185f9ddb6493e31..11e0b8e99c456d8bfb24bfc90a9123a79400115a 100644 --- a/src/main.c +++ b/src/main.c @@ -46,6 +46,7 @@ int main(int argc, char **argv) { if(gd && settingsWin()) goto mainend; + dat = NULL; while((dat = showCalc(sdir)) == NULL) if(settingsWin()) goto mainend; diff --git a/src/util.c b/src/util.c index 46f0f92e0a9e2b2f16b01db73d07f6d6c27b45cd..6557155d0a951341ffae6517bbe6ab3332636697 100644 --- a/src/util.c +++ b/src/util.c @@ -90,6 +90,7 @@ void ncresize(void) { if(ch == 'i') sflags |= SF_IGNS; } + erase(); }