From 5790b817f9655d48afcdfef02363651a2430ec18 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Mon, 13 Apr 2009 19:32:40 +0200 Subject: [PATCH] Re-added recalculating (sub)directories --- src/browser.c | 46 ++++++++++------------------------------------ src/calc.c | 22 ++++++++++++++++++++-- src/calc.h | 1 + src/main.c | 1 + 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/src/browser.c b/src/browser.c index 08cddd8..e9ac8ad 100644 --- a/src/browser.c +++ b/src/browser.c @@ -295,10 +295,6 @@ int browse_draw() { } - -#define toggle(x,y) if(x & y) x -=y; else x |= y -#define hideinfo if(stbrowse.flags & BF_INFO) stbrowse.flags -= BF_INFO - void browse_key_sel(int change) { struct dir *n, *cur, par; int i, max; @@ -327,7 +323,12 @@ void browse_key_sel(int change) { } + +#define toggle(x,y) if(x & y) x -=y; else x |= y +#define hideinfo if(stbrowse.flags & BF_INFO) stbrowse.flags -= BF_INFO + int browse_key(int ch) { + char tmp[PATH_MAX]; struct dir *n; switch(ch) { @@ -403,41 +404,14 @@ int browse_key(int ch) { stbrowse.cur = stbrowse.cur->parent->parent->sub; break; - /* refresh * + /* refresh */ case 'r': hideinfo; - drawBrowser(0); - if((n = showCalc(getpath(bcur, tmp))) != NULL) { - * free current items * - d = bcur; - bcur = bcur->parent; - while(d != NULL) { - t = d; - d = t->next; - freedir(t); - } - - * update parent dir * - bcur->sub = n->sub; - bcur->items = n->items; - bcur->size = n->size; - bcur->asize = n->asize; - 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->asize += bcur->asize; - t->items += bcur->items; - } - - bcur = bcur->sub; - free(n->name); - free(n); - } + stcalc.sterr = ST_BROWSE; + stcalc.orig = stbrowse.cur->parent; + strcpy(stcalc.cur, getpath(stbrowse.cur, tmp)); + pstate = ST_CALC; break; - */ /* and other stuff */ case 'q': diff --git a/src/calc.c b/src/calc.c index 373f180..5aa4063 100644 --- a/src/calc.c +++ b/src/calc.c @@ -386,15 +386,33 @@ void calc_process() { t->size = fs.st_blocks * S_BLKSIZE; t->asize = fs.st_size; t->flags |= FF_DIR; + if(stcalc.orig) { + t->parent = stcalc.orig->parent; + t->next = stcalc.orig->next; + } t->name = (char *) malloc(strlen(tmp)+1); - strcpy(t->name, tmp); + strcpy(t->name, stcalc.orig ? stcalc.orig->name : tmp); stcalc.parent = t; stcalc.curdev = fs.st_dev; /* start calculating */ if(!calc_dir(stcalc.parent, tmp) && !stcalc.err) { pstate = ST_BROWSE; - stbrowse.cur = stcalc.parent; + stbrowse.cur = stcalc.parent->sub; + + /* update references and free original item */ + if(stcalc.orig) { + if(stcalc.orig->parent) { + t = stcalc.orig->parent->sub; + if(t == stcalc.orig) + stcalc.orig->parent->sub = stcalc.parent; + else if(t != NULL) + for(; t->next!=NULL; t=t->next) + if(t->next == stcalc.orig) + t->next = stcalc.parent; + } + freedir(stcalc.orig); + } return; } diff --git a/src/calc.h b/src/calc.h index 187208f..fa8f0f0 100644 --- a/src/calc.h +++ b/src/calc.h @@ -34,6 +34,7 @@ struct state_calc { char lasterr[PATH_MAX]; /* last unreadable dir/item */ char errmsg[128]; /* error message, when err=1 */ struct dir *parent; /* parent directory for the calculation */ + struct dir *orig; /* original directory, when recalculating */ dev_t curdev; /* current device we're calculating on */ suseconds_t lastupdate; /* time of the last screen update */ int anpos; /* position of the animation string */ diff --git a/src/main.c b/src/main.c index 309d8b8..f40dffe 100644 --- a/src/main.c +++ b/src/main.c @@ -141,6 +141,7 @@ int main(int argc, char **argv) { pstate = ST_CALC; stcalc.sterr = ST_QUIT; + stcalc.orig = NULL; stbrowse.flags = BF_SIZE | BF_DESC; stbrowse.graph = 0;