diff --git a/utils/filecenter/main.c b/utils/filecenter/main.c index 565890e..9593187 100644 --- a/utils/filecenter/main.c +++ b/utils/filecenter/main.c @@ -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], "%s (missing)", basename(f[fcount]->name)); if (f[fcount]->approved == 1) { // unapprove missing file - //doDisapprove(fcount); + doDisapprove(fcount); } } else if (f[fcount]->approved) { sprintf(filenames[fcount], "%s (approved)", 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