diff --git a/src/intrf.c b/src/intrf.c index 3dde14c6..474a3e1f 100644 --- a/src/intrf.c +++ b/src/intrf.c @@ -1312,70 +1312,6 @@ char *ask_log_location(const char*filename) return NULL; } -/* - 0: no log - 1: append - 2: create -*/ -int ask_log_creation() -{ - unsigned int menu=0; - static struct MenuItem menuLogCreation[]= - { - {'C',"Create","Create a new log file"}, - {'A',"Append","Append information to log file"}, - {'Q',"No Log","Don't record anything"}, - {0,NULL,NULL} - }; - aff_copy(stdscr); - wmove(stdscr,5,0); - wprintw(stdscr,"TestDisk is a data recovery designed to help recover lost partitions"); - wmove(stdscr,6,0); - wprintw(stdscr,"and/or make non-booting disks bootable again when these symptoms"); - wmove(stdscr,7,0); - wprintw(stdscr,"are caused by faulty software, certain types of viruses or human error."); - wmove(stdscr,8,0); - wprintw(stdscr,"It can also be used to repair some filesystem errors."); - wmove(stdscr,10,0); - wprintw(stdscr,"Information gathered during TestDisk use can be recorded for later"); - wmove(stdscr,11,0); - wprintw(stdscr,"review. If you choose to create the text file, "); - if(has_colors()) - wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(0)); - wprintw(stdscr,"testdisk.log"); - if(has_colors()) - wbkgdset(stdscr,' ' | COLOR_PAIR(0)); - wprintw(stdscr," , it"); - wmove(stdscr,12,0); - wprintw(stdscr,"will contain TestDisk options, technical information and various"); - wmove(stdscr,13,0); - wprintw(stdscr,"outputs; including any folder/file names TestDisk was used to find and"); - wmove(stdscr,14,0); - wprintw(stdscr,"list onscreen."); - wmove(stdscr,16,0); - wprintw(stdscr,"Use arrow keys to select, then press Enter key:"); - while(1) - { - int command; - command = wmenuSelect_ext(stdscr,17, 0, menuLogCreation, 8, - "CAQ", MENU_VERT | MENU_VERT_WARN | MENU_BUTTON, &menu,NULL); - switch(command) - { - case 'C': - case 'c': - return 2; - case 'A': - case 'a': - return 1; - case 'Q': - case 'q': - return 0; - default: - break; - } - } -} - static int intrf_no_disk_ncurses(const char *prog_name) { aff_copy(stdscr); @@ -1901,11 +1837,6 @@ static void dir_aff_entry(WINDOW *window, struct file_info *dir_info) wprintw(window, " %s %s", datestr, dir_info->name); } #else -int ask_log_creation() -{ - return 0; -} - char *ask_log_location(const char*filename) { return NULL; diff --git a/src/intrf.h b/src/intrf.h index 67da251e..0559817b 100644 --- a/src/intrf.h +++ b/src/intrf.h @@ -94,6 +94,5 @@ void screen_buffer_to_log(void); int interface_partition_type(disk_t *disk_car, const int verbose, char**current_cmd); int intrf_no_disk(const char *prog_name); char *ask_log_location(const char*filename); -int ask_log_creation(void); char *ask_location(const char*msg, const char *src_dir); void dump_ncurses(const void *nom_dump, unsigned int lng); diff --git a/src/intrface.c b/src/intrface.c index 8fc4ff7d..63082d90 100644 --- a/src/intrface.c +++ b/src/intrface.c @@ -1524,3 +1524,68 @@ int interface_superblock(disk_t *disk_car,list_part_t *list_part, char**current_ return 0; } +#ifdef HAVE_NCURSES +int ask_testdisk_log_creation() +{ + unsigned int menu=0; + static struct MenuItem menuLogCreation[]= + { + {'C',"Create","Create a new log file"}, + {'A',"Append","Append information to log file"}, + {'Q',"No Log","Don't record anything"}, + {0,NULL,NULL} + }; + aff_copy(stdscr); + wmove(stdscr,5,0); + wprintw(stdscr,"TestDisk is a data recovery designed to help recover lost partitions"); + wmove(stdscr,6,0); + wprintw(stdscr,"and/or make non-booting disks bootable again when these symptoms"); + wmove(stdscr,7,0); + wprintw(stdscr,"are caused by faulty software, certain types of viruses or human error."); + wmove(stdscr,8,0); + wprintw(stdscr,"It can also be used to repair some filesystem errors."); + wmove(stdscr,10,0); + wprintw(stdscr,"Information gathered during TestDisk use can be recorded for later"); + wmove(stdscr,11,0); + wprintw(stdscr,"review. If you choose to create the text file, "); + if(has_colors()) + wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(0)); + wprintw(stdscr,"testdisk.log"); + if(has_colors()) + wbkgdset(stdscr,' ' | COLOR_PAIR(0)); + wprintw(stdscr," , it"); + wmove(stdscr,12,0); + wprintw(stdscr,"will contain TestDisk options, technical information and various"); + wmove(stdscr,13,0); + wprintw(stdscr,"outputs; including any folder/file names TestDisk was used to find and"); + wmove(stdscr,14,0); + wprintw(stdscr,"list onscreen."); + wmove(stdscr,16,0); + wprintw(stdscr,"Use arrow keys to select, then press Enter key:"); + while(1) + { + int command; + command = wmenuSelect_ext(stdscr,17, 0, menuLogCreation, 8, + "CAQ", MENU_VERT | MENU_VERT_WARN | MENU_BUTTON, &menu,NULL); + switch(command) + { + case 'C': + case 'c': + return TD_LOG_CREATE; + case 'A': + case 'a': + return TD_LOG_APPEND; + case 'Q': + case 'q': + return TD_LOG_REFUSED; + default: + break; + } + } +} +#else +int ask_testdisk_log_creation() +{ + return TD_LOG_REFUSED; +} +#endif diff --git a/src/intrface.h b/src/intrface.h index 2b5f3bc7..2b483724 100644 --- a/src/intrface.h +++ b/src/intrface.h @@ -31,4 +31,4 @@ int interface_write(disk_t *disk_car,list_part_t *list_part,const int can_search list_part_t *ask_structure(disk_t *disk_car,list_part_t *list_part, const int verbose, char **current_cmd); void interface_list(disk_t *disk_car, const int verbose, const int saveheader, const int backup, char **current_cmd); int interface_superblock(disk_t *disk_car,list_part_t *list_part,char**current_cmd); - +int ask_testdisklog_creation(void); diff --git a/src/log.c b/src/log.c index 34cfe48d..daad12c2 100644 --- a/src/log.c +++ b/src/log.c @@ -52,16 +52,26 @@ int log_set_levels(const unsigned int levels) return old_levels; } -int log_open(const char*default_filename, const char *mode, const char *prog_name, int argc, char**argv) +int log_open(const char*default_filename, const int mode, const int interface, const char *prog_name, int argc, char**argv) { const char*filename=default_filename; + if(mode!=TD_LOG_CREATE && mode!=TD_LOG_APPEND) + return mode; do { - log_handle=fopen(filename,mode); + log_handle=fopen(filename,(mode==TD_LOG_CREATE?"w":"a")); if(log_handle==NULL) + { + if(interface==0) + { + printf("Can't create %s file\n", default_filename); + return mode; + } filename=ask_log_location(filename); - } while(log_handle==NULL && filename!=NULL); - if(log_handle!=NULL) + if(filename==NULL) + return TD_LOG_REFUSED; + } + } while(log_handle==NULL); { int i; time_t my_time; @@ -76,7 +86,7 @@ int log_open(const char*default_filename, const char *mode, const char *prog_nam fprintf(log_handle,"\n\n"); fflush(log_handle); } - return (log_handle==NULL); + return TD_LOG_DONE; } int log_flush(void) diff --git a/src/log.h b/src/log.h index 5721e32e..1ae2d183 100644 --- a/src/log.h +++ b/src/log.h @@ -22,7 +22,7 @@ #ifndef _LOG_H #define _LOG_H int log_set_levels(const unsigned int levels); -int log_open(const char*default_filename, const char *mode, const char *prog_name, int argc, char**argv); +int log_open(const char*default_filename, const int mode, const int interface, const char *prog_name, int argc, char**argv); int log_flush(void); int log_close(void); int log_redirect(unsigned int level, const char *format, ...) __attribute__((format(printf, 2, 3))); @@ -32,6 +32,12 @@ void dump2_log(const void *dump_1, const void *dump_2,const unsigned int lng); void log_partition(const disk_t *disk_car,const partition_t *partition); #endif +#define TD_LOG_NONE 0 +#define TD_LOG_CREATE 1 +#define TD_LOG_APPEND 2 +#define TD_LOG_DONE 3 +#define TD_LOG_REFUSED 4 + #define LOG_LEVEL_DEBUG (1 << 0) /* x = 42 */ #define LOG_LEVEL_TRACE (1 << 1) /* Entering function x() */ #define LOG_LEVEL_QUIET (1 << 2) /* Quietable output */ diff --git a/src/photorec.c b/src/photorec.c index 29dd785d..fac4e69a 100644 --- a/src/photorec.c +++ b/src/photorec.c @@ -740,7 +740,8 @@ int main( int argc, char **argv ) { int i; int use_sudo=0; - int help=0, create_log=0, verbose=0; + int help=0, verbose=0; + int create_log=TD_LOG_NONE; int run_setlocale=1; int testdisk_mode=TESTDISK_O_RDONLY|TESTDISK_O_READAHEAD_32K; const char *recup_dir=NULL; @@ -881,11 +882,15 @@ int main( int argc, char **argv ) for(i=1;i0) - log_open("photorec.log",(create_log==1?"a":"w"),"PhotoRec",argc,argv); + create_log=log_open("photorec.log", create_log, 1, "PhotoRec", argc, argv); log_info("PhotoRec %s, Data Recovery Utility, %s\nChristophe GRENIER \nhttp://www.cgsecurity.org\n",VERSION,TESTDISKDATE); log_info(TESTDISK_OS); log_info(" (ewf lib: %s)\n", td_ewf_version()); diff --git a/src/testdisk.c b/src/testdisk.c index f04ee4bf..3698cc7b 100644 --- a/src/testdisk.c +++ b/src/testdisk.c @@ -95,7 +95,7 @@ int main( int argc, char **argv ) int i; int use_sudo=0; int help=0, verbose=0, dump_ind=0; - int create_log=0; /* 0: no_log, 1: append, 2 create */ + int create_log=TD_LOG_NONE; int do_list=0; int unit=UNIT_DEFAULT; int write_used; @@ -131,26 +131,21 @@ int main( int argc, char **argv ) return -1; } #endif + printf("TestDisk %s, Data Recovery Utility, %s\nChristophe GRENIER \nhttp://www.cgsecurity.org\n",VERSION,TESTDISKDATE); for(i=1;i\nhttp://www.cgsecurity.org\n",VERSION,TESTDISKDATE); if(help!=0) { printf("\n" \ @@ -286,13 +280,12 @@ int main( int argc, char **argv ) if(start_ncurses("TestDisk",argv[0])) return 1; #endif - if(argc==1) + if(argc==1 && create_log==TD_LOG_NONE) { verbose=1; - create_log=ask_log_creation(); - if(create_log>0) - log_open("testdisk.log",(create_log==1?"a":"w"),"TestDisk",argc,argv); + create_log=ask_testdisk_log_creation(); } + create_log=log_open("testdisk.log", create_log, 1, "TestDisk", argc, argv); log_info("TestDisk %s, Data Recovery Utility, %s\nChristophe GRENIER \nhttp://www.cgsecurity.org\n",VERSION,TESTDISKDATE); log_info(TESTDISK_OS); log_info(" (ext2fs lib: %s, ntfs lib: %s, reiserfs lib: %s, ewf lib: %s)\n",td_ext2fs_version(),td_ntfs_version(),td_reiserfs_version(), td_ewf_version());