1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
/** Remove a file from list with the given action
* id - file id
* action - action to perform
* 1 file to ok
* 2 file to incomplete
* -1 file to incomplete if possible, else remove
*/
void file_remove(u32 id, int action)
{ file f;
f.id = id;
file_set::iterator i = fs.find(f);
// move cursor away
if(cursor == id) cursor_down();
if(cursor == id) cursor_up();
if(cursor == id) cursor = 0;
if(action != 1 &&
i->size >= incomplete_min_size &&
(u64)segment_summ(i->seg) * 100 / i->size >= incomplete_percent)
{ action = 2;
}
char n1[0x100];
char n2[0x100];
cache_close(i->h);
snprintf(n1, sizeof(n1), "%s/%s", dir_temp, i->name.c_str());
if(action == 0)
{ // just close
}
else if(action == 1)
{ snprintf(n2, sizeof(n2), "%s/%s", dir_ok, i->name.c_str());
seg(*i, dir_temp, false);
cache_move(n1, n2);
}
else if(action == 2)
{ snprintf(n2, sizeof(n2), "%s/%s", dir_incomplete, i->name.c_str());
seg(*i, dir_incomplete, true, true);
seg(*i, dir_temp, false);
cache_move(n1, n2);
}
else if(action == -1)
{ seg(*i, dir_temp, false);
cache_move(n1, ""); // unlink
}
ffs_remove(i->size, i->tag);
fs.erase(i);
sort_files();
}
|