edit file descriptions

This commit is contained in:
Andrew Pamment 2018-05-12 19:22:01 +10:00
parent 9d0cbb85a8
commit aa73e420c1
2 changed files with 95 additions and 2 deletions

3
utils/filecenter/editor.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
/usr/bin/vi $1

View File

@ -22,7 +22,9 @@ int file_directory_count = 0;
CDKSCREEN *cdkscreen = 0;
//CDKMENTRY *desc_entry = 0;
WINDOW *desc_win = 0;
WINDOW *instruction_win = 0;
char instructions[] = "t - toggle approval\na - approve all\nu - unapprove all\nd - delete file\nm - move file\ns - scan for files\ne - edit description";
char *bbspath;
char *configpath;
@ -619,6 +621,94 @@ static int moveFile(EObjectType cdktype, void *object, void *clientData, chtype
// refreshCDKScreen(cdkscreen);
}
static int editFileID(EObjectType cdktyp, void *object, void *clientData, chtype input) {
FILE *fptr;
CDKSCROLL *s = (CDKSCROLL *)object;
int index = getCDKScrollCurrent(s);
struct stat st;
char buffer[PATH_MAX];
sqlite3 *db;
sqlite3_stmt *res;
int rc;
char sql_update[] = "UPDATE files SET description=? WHERE filename LIKE ?";
snprintf(buffer, PATH_MAX, "/tmp/filecenter_id.txt");
fptr = fopen(buffer, "w");
if (!fptr) {
return FALSE;
}
fputs(f[index]->description, fptr);
fclose(fptr);
snprintf(buffer, PATH_MAX, "./editor.sh");
if (stat(buffer, &st) != 0) {
snprintf(buffer, PATH_MAX, "/usr/bin/nano");
if (stat(buffer, &st) != 0) {
snprintf(buffer, PATH_MAX, "/usr/bin/vi");
if (stat(buffer, &st) != 0) {
return FALSE;
}
}
}
strncat(buffer, " /tmp/filecenter_id.txt", PATH_MAX);
def_prog_mode();
savetty();
system(buffer);
resetty();
reset_prog_mode();
snprintf(buffer, PATH_MAX, "/tmp/filecenter_id.txt");
if (stat(buffer, &st) != 0) {
return FALSE;
}
fptr = fopen(buffer, "r");
if (!fptr) {
return FALSE;
}
free(f[index]->description);
f[index]->description = (char *)malloc(sizeof(char) * (st.st_size + 1));
memset(f[index]->description, 0, st.st_size + 1);
fread(f[index]->description, 1, st.st_size, fptr);
fclose(fptr);
unlink(buffer);
// update file descripiton
snprintf(buffer, PATH_MAX, "%s/%s.sq3", bbspath, file_directories[current_dir]->file_subs[current_sub]->database);
rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) {
return FALSE;
}
sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql_update, -1, &res, 0);
sqlite3_bind_text(res, 1, f[index]->description, -1, 0);
sqlite3_bind_text(res, 2, f[index]->name, -1, 0);
sqlite3_step(res);
sqlite3_finalize(res);
sqlite3_close(db);
// update display
refreshCDKScreen(cdkscreen);
werase(desc_win);
waddstr(desc_win, f[index]->description);
wrefresh(desc_win);
werase(instruction_win);
waddstr(instruction_win, instructions);
wrefresh(instruction_win);
}
static int scanFiles(EObjectType cdktype, void *object, void *clientData, chtype input) {
DIR *ind = opendir(file_directories[current_dir]->file_subs[current_sub]->upload_path);
FILE *fptr;
@ -955,6 +1045,7 @@ void list_files(int dir, int sub) {
bindCDKObject (vSCROLL, scrollList, 't', approveFile, NULL);
bindCDKObject (vSCROLL, scrollList, 'd', deleteFile, NULL);
bindCDKObject (vSCROLL, scrollList, 's', scanFiles, NULL);
bindCDKObject (vSCROLL, scrollList, 'e', editFileID, NULL);
while(1) {
selection = activateCDKScroll(scrollList, 0);
@ -1020,7 +1111,6 @@ int main(int argc, char **argv) {
CDK_PARAMS params;
WINDOW *cursesWin = 0;
CDKSCROLL *scrollList = 0;
WINDOW *instruction_win = 0;
int selection;
char **filedirs;
char buffer[PATH_MAX];
@ -1051,7 +1141,7 @@ int main(int argc, char **argv) {
desc_win = newwin(10, 46, 14, 1);
instruction_win = newwin(10, 32, 14, 47);
waddstr(instruction_win, "t - toggle approval\na - approve all\nu - unapprove all\nd - delete file\nm - move file\ns - scan for files");
waddstr(instruction_win, instructions);
wrefresh(instruction_win);