Re-added recalculating (sub)directories

This commit is contained in:
Yorhel 2009-04-13 19:32:40 +02:00
parent b8877be907
commit 5790b817f9
4 changed files with 32 additions and 38 deletions

View file

@ -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) { void browse_key_sel(int change) {
struct dir *n, *cur, par; struct dir *n, *cur, par;
int i, max; 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) { int browse_key(int ch) {
char tmp[PATH_MAX];
struct dir *n; struct dir *n;
switch(ch) { switch(ch) {
@ -403,41 +404,14 @@ int browse_key(int ch) {
stbrowse.cur = stbrowse.cur->parent->parent->sub; stbrowse.cur = stbrowse.cur->parent->parent->sub;
break; break;
/* refresh * /* refresh */
case 'r': case 'r':
hideinfo; hideinfo;
drawBrowser(0); stcalc.sterr = ST_BROWSE;
if((n = showCalc(getpath(bcur, tmp))) != NULL) { stcalc.orig = stbrowse.cur->parent;
* free current items * strcpy(stcalc.cur, getpath(stbrowse.cur, tmp));
d = bcur; pstate = ST_CALC;
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);
}
break; break;
*/
/* and other stuff */ /* and other stuff */
case 'q': case 'q':

View file

@ -386,15 +386,33 @@ void calc_process() {
t->size = fs.st_blocks * S_BLKSIZE; t->size = fs.st_blocks * S_BLKSIZE;
t->asize = fs.st_size; t->asize = fs.st_size;
t->flags |= FF_DIR; t->flags |= FF_DIR;
if(stcalc.orig) {
t->parent = stcalc.orig->parent;
t->next = stcalc.orig->next;
}
t->name = (char *) malloc(strlen(tmp)+1); t->name = (char *) malloc(strlen(tmp)+1);
strcpy(t->name, tmp); strcpy(t->name, stcalc.orig ? stcalc.orig->name : tmp);
stcalc.parent = t; stcalc.parent = t;
stcalc.curdev = fs.st_dev; stcalc.curdev = fs.st_dev;
/* start calculating */ /* start calculating */
if(!calc_dir(stcalc.parent, tmp) && !stcalc.err) { if(!calc_dir(stcalc.parent, tmp) && !stcalc.err) {
pstate = ST_BROWSE; 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; return;
} }

View file

@ -34,6 +34,7 @@ struct state_calc {
char lasterr[PATH_MAX]; /* last unreadable dir/item */ char lasterr[PATH_MAX]; /* last unreadable dir/item */
char errmsg[128]; /* error message, when err=1 */ char errmsg[128]; /* error message, when err=1 */
struct dir *parent; /* parent directory for the calculation */ struct dir *parent; /* parent directory for the calculation */
struct dir *orig; /* original directory, when recalculating */
dev_t curdev; /* current device we're calculating on */ dev_t curdev; /* current device we're calculating on */
suseconds_t lastupdate; /* time of the last screen update */ suseconds_t lastupdate; /* time of the last screen update */
int anpos; /* position of the animation string */ int anpos; /* position of the animation string */

View file

@ -141,6 +141,7 @@ int main(int argc, char **argv) {
pstate = ST_CALC; pstate = ST_CALC;
stcalc.sterr = ST_QUIT; stcalc.sterr = ST_QUIT;
stcalc.orig = NULL;
stbrowse.flags = BF_SIZE | BF_DESC; stbrowse.flags = BF_SIZE | BF_DESC;
stbrowse.graph = 0; stbrowse.graph = 0;