delete files added to filecenter
This commit is contained in:
parent
486d592a26
commit
288b88b396
@ -178,6 +178,84 @@ static void doDisapprove(int index) {
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
static int deleteFile(EObjectType cdktype, void *object, void *clientData, chtype input) {
|
||||
CDKSCROLL *s = (CDKSCROLL *)object;
|
||||
|
||||
int index = getCDKScrollCurrent(s);
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
struct stat st;
|
||||
char database[PATH_MAX];
|
||||
int i;
|
||||
|
||||
char sql_delete[] = "DELETE FROM files WHERE filename LIKE ?";
|
||||
|
||||
if (index >= fcount) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
snprintf(database, PATH_MAX, "%s/%s.sq3", configpath, file_directories[current_dir]->file_subs[current_sub]->database);
|
||||
|
||||
rc = sqlite3_open(database, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
return FALSE;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
|
||||
rc = sqlite3_prepare_v2(db, sql_delete, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
return FALSE;
|
||||
}
|
||||
sqlite3_bind_text(res, 1, f[index]->name, -1, 0);
|
||||
|
||||
sqlite3_step(res);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
|
||||
if (stat(f[index]->name, &st) == 0) {
|
||||
remove(f[index]->name);
|
||||
}
|
||||
|
||||
free(f[index]->name);
|
||||
free(f[index]->description);
|
||||
free(f[index]);
|
||||
free(filenames[index]);
|
||||
|
||||
|
||||
for (i=index; i < fcount - 1; i++) {
|
||||
filenames[i] = filenames[i+1];
|
||||
f[i] = f[i+1];
|
||||
}
|
||||
|
||||
fcount--;
|
||||
|
||||
if (fcount == 0) {
|
||||
free(filenames);
|
||||
free(f);
|
||||
filenames = NULL;
|
||||
setCDKScrollItems(s, filenames, fcount, FALSE);
|
||||
eraseCDKScroll(s);
|
||||
drawCDKScroll(s, TRUE);
|
||||
refreshCDKScreen(cdkscreen);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
filenames = (char **)realloc(filenames, sizeof(char *) * (fcount));
|
||||
f = (struct files **)realloc(f, sizeof(struct files *) * (fcount));
|
||||
|
||||
|
||||
setCDKScrollItems(s, filenames, fcount, FALSE);
|
||||
eraseCDKScroll(s);
|
||||
drawCDKScroll(s, TRUE);
|
||||
refreshCDKScreen(cdkscreen);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int approveFile(EObjectType cdktype, void *object, void *clientData, chtype input) {
|
||||
CDKSCROLL *s = (CDKSCROLL *)object;
|
||||
|
||||
@ -263,7 +341,7 @@ void list_files(int dir, int sub) {
|
||||
sprintf(filenames[fcount], "</16>%s (missing)<!16>", basename(f[fcount]->name));
|
||||
if (f[fcount]->approved == 1) {
|
||||
// unapprove missing file
|
||||
//doDisapprove(fcount);
|
||||
doDisapprove(fcount);
|
||||
}
|
||||
} else if (f[fcount]->approved) {
|
||||
sprintf(filenames[fcount], "</24>%s (approved)<!24>", basename(f[fcount]->name));
|
||||
@ -276,10 +354,6 @@ void list_files(int dir, int sub) {
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
if (fcount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
scrollList = newCDKScroll(cdkscreen, 6, 4, 1, 36, 32, title, NULL, 0, FALSE, A_REVERSE, TRUE, TRUE);
|
||||
if (!scrollList) {
|
||||
for (i=0;i<fcount;i++) {
|
||||
@ -298,7 +372,7 @@ void list_files(int dir, int sub) {
|
||||
setCDKScrollItems(scrollList, filenames, fcount, FALSE);
|
||||
|
||||
bindCDKObject (vSCROLL, scrollList, 'a', approveFile, NULL);
|
||||
// bindCDKObject (vSCROLL, scrollList, 'd', deleteFile, NULL);
|
||||
bindCDKObject (vSCROLL, scrollList, 'd', deleteFile, NULL);
|
||||
|
||||
while(1) {
|
||||
selection = activateCDKScroll(scrollList, 0);
|
||||
@ -312,9 +386,10 @@ void list_files(int dir, int sub) {
|
||||
free(f[i]);
|
||||
free(filenames[i]);
|
||||
}
|
||||
|
||||
if (fcount != 0) {
|
||||
free(f);
|
||||
free(filenames);
|
||||
}
|
||||
fcount = 0;
|
||||
destroyCDKScroll(scrollList);
|
||||
}
|
||||
|
Reference in New Issue
Block a user