diff --git a/src/Makefile.am b/src/Makefile.am index 098d0847..a6348332 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -296,12 +296,12 @@ file_C = filegen.c \ file_H = ext2.h ext2_common.h filegen.h file_jpg.h file_sp3.h file_tar.h file_tiff.h file_txt.h ole.h pe.h suspend.h -photorec_C = photorec.c phcfg.c addpart.c dir.c exfatp.c ext2grp.c ext2_dir.c ext2p.c fat_dir.c fatp.c file_found.c geometry.c ntfs_dir.c ntfsp.c pdisksel.c poptions.c sessionp.c setdate.c dfxml.c +photorec_C = photorec.c phcfg.c addpart.c chgarch.c dir.c exfatp.c ext2grp.c ext2_dir.c ext2p.c fat_dir.c fatp.c file_found.c geometry.c ntfs_dir.c ntfsp.c pdisksel.c phcli.c poptions.c sessionp.c setdate.c dfxml.c -photorec_H = photorec.h phcfg.h addpart.h dir.h exfatp.h ext2grp.h ext2p.h ext2_dir.h ext2_inc.h fat_dir.h fatp.h file_found.h geometry.h memmem.h ntfs_dir.h ntfsp.h ntfs_inc.h pdisksel.h poptions.h sessionp.h setdate.h dfxml.h +photorec_H = photorec.h phcfg.h addpart.h chgarch.h dir.h exfatp.h ext2grp.h ext2p.h ext2_dir.h ext2_inc.h fat_dir.h fatp.h file_found.h geometry.h memmem.h ntfs_dir.h ntfsp.h ntfs_inc.h pdisksel.h phcli.h poptions.h sessionp.h setdate.h dfxml.h -photorec_ncurses_C = addpartn.c askloc.c chgarch.c chgarchn.c chgtype.c chgtypen.c fat_cluster.c fat_unformat.c geometryn.c hiddenn.c intrfn.c nodisk.c parti386n.c partgptn.c partmacn.c partsunn.c partxboxn.c pbanner.c pblocksize.c pdiskseln.c pfree_whole.c phbf.c phbs.c phnc.c phrecn.c ppartseln.c psearchn.c -photorec_ncurses_H = addpartn.h askloc.h chgarch.h chgarchn.h chgtype.h chgtypen.h fat_cluster.h fat_unformat.h geometryn.h hiddenn.h intrfn.h nodisk.h parti386n.h partgptn.h partmacn.h partsunn.h partxboxn.h pblocksize.h pdiskseln.h pfree_whole.h pnext.h phbf.h phbs.h phnc.h phrecn.h ppartseln.h psearch.h psearchn.h +photorec_ncurses_C = addpartn.c askloc.c chgarchn.c chgtype.c chgtypen.c fat_cluster.c fat_unformat.c geometryn.c hiddenn.c intrfn.c nodisk.c parti386n.c partgptn.c partmacn.c partsunn.c partxboxn.c pbanner.c pblocksize.c pdiskseln.c pfree_whole.c phbf.c phbs.c phnc.c phrecn.c ppartseln.c psearchn.c +photorec_ncurses_H = addpartn.h askloc.h chgarchn.h chgtype.h chgtypen.h fat_cluster.h fat_unformat.h geometryn.h hiddenn.h intrfn.h nodisk.h parti386n.h partgptn.h partmacn.h partsunn.h partxboxn.h pblocksize.h pdiskseln.h pfree_whole.h pnext.h phbf.h phbs.h phnc.h phrecn.h ppartseln.h psearch.h psearchn.h photorec_SOURCES = phmain.c $(photorec_C) $(photorec_H) $(photorec_ncurses_C) $(photorec_ncurses_H) $(file_C) $(file_H) $(base_C) $(base_H) partgptro.c $(fs_C) $(fs_H) $(ICON_PHOTOREC) suspend_no.c diff --git a/src/phcli.c b/src/phcli.c new file mode 100644 index 00000000..ebb106ee --- /dev/null +++ b/src/phcli.c @@ -0,0 +1,273 @@ +/* + + File: phcli.c + + Copyright (C) 1998-2008,2014 Christophe GRENIER + + This software is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write the Free Software Foundation, Inc., 51 + Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#include /* isdigit */ +#include "types.h" +#include "common.h" +#include "filegen.h" +#include "log.h" +#include "photorec.h" +#include "ext2grp.h" +#include "geometry.h" +#include "poptions.h" +#include "phcli.h" + +typedef enum { INIT_SPACE_WHOLE, INIT_SPACE_PREINIT, INIT_SPACE_EXT2_GROUP, INIT_SPACE_EXT2_INODE } init_mode_t; + +static int spacerange_cmp(const struct td_list_head *a, const struct td_list_head *b) +{ + const alloc_data_t *space_a=td_list_entry_const(a, const alloc_data_t, list); + const alloc_data_t *space_b=td_list_entry_const(b, const alloc_data_t, list); + if(space_a->start < space_b->start) + return -1; + if(space_a->start > space_b->start) + return 1; + return space_a->end - space_b->end; +} + +static int file_select_cli(file_enable_t *files_enable, char**current_cmd) +{ + int keep_asking; + log_info("\nInterface File Select\n"); + do + { + file_enable_t *file_enable; + keep_asking=0; + while(*current_cmd[0]==',') + (*current_cmd)++; + if(strncmp(*current_cmd,"everything",10)==0) + { + int enable_status; + keep_asking=1; + (*current_cmd)+=10; + while(*current_cmd[0]==',') + (*current_cmd)++; + if(strncmp(*current_cmd,"enable",6)==0) + { + (*current_cmd)+=6; + enable_status=1; + } + else if(strncmp(*current_cmd,"disable",7)==0) + { + (*current_cmd)+=7; + enable_status=0; + } + else + { + log_critical("Syntax error %s\n",*current_cmd); + return -1; + } + for(file_enable=&files_enable[0];file_enable->file_hint!=NULL;file_enable++) + file_enable->enable=enable_status; + } + else + { + unsigned int cmd_length=0; + while((*current_cmd)[cmd_length]!='\0' && (*current_cmd)[cmd_length]!=',') + cmd_length++; + for(file_enable=&files_enable[0];file_enable->file_hint!=NULL;file_enable++) + { + if(file_enable->file_hint->extension!=NULL && + strlen(file_enable->file_hint->extension)==cmd_length && + memcmp(file_enable->file_hint->extension,*current_cmd,cmd_length)==0) + { + keep_asking=1; + (*current_cmd)+=cmd_length; + while(*current_cmd[0]==',') + (*current_cmd)++; + if(strncmp(*current_cmd,"enable",6)==0) + { + (*current_cmd)+=6; + file_enable->enable=1; + } + else if(strncmp(*current_cmd,"disable",7)==0) + { + (*current_cmd)+=7; + file_enable->enable=0; + } + else + { + log_critical("Syntax error %s\n",*current_cmd); + return -1; + } + } + } + } + } while(keep_asking>0); + return 0; +} + +int menu_photorec_cli(list_part_t *list_part, struct ph_param *params, struct ph_options *options, alloc_data_t*list_search_space) +{ + unsigned int user_blocksize=0; + init_mode_t mode_init_space=(td_list_empty(&list_search_space->list)?INIT_SPACE_WHOLE:INIT_SPACE_PREINIT); + params->partition=(list_part->next!=NULL ? list_part->next->part : list_part->part); + while(1) + { + while(params->cmd_run[0]==',') + params->cmd_run++; + if(params->cmd_run[0]=='\0') + return 0; + if(strncmp(params->cmd_run,"search",6)==0) + { + params->cmd_run+=6; + if(mode_init_space==INIT_SPACE_EXT2_GROUP) + { + params->blocksize=ext2_fix_group(list_search_space, params->disk, params->partition); + if(params->blocksize==0) + { + log_error("Not a valid ext2/ext3/ext4 filesystem"); + return -1; + } + } + else if(mode_init_space==INIT_SPACE_EXT2_INODE) + { + params->blocksize=ext2_fix_inode(list_search_space, params->disk, params->partition); + if(params->blocksize==0) + { + log_error("Not a valid ext2/ext3/ext4 filesystem"); + return -1; + } + } + if(td_list_empty(&list_search_space->list)) + { + init_search_space(list_search_space, params->disk, params->partition); + } + if(params->carve_free_space_only>0) + { + params->blocksize=remove_used_space(params->disk, params->partition, list_search_space); + } + if(user_blocksize > 0) + params->blocksize=user_blocksize; + return 1; + } + else if(strncmp(params->cmd_run,"options",7)==0) + { + params->cmd_run+=7; + interface_options_photorec_cli(options, ¶ms->cmd_run); + } + else if(strncmp(params->cmd_run,"fileopt",7)==0) + { + params->cmd_run+=7; + if(file_select_cli(options->list_file_format, ¶ms->cmd_run) < 0) + return -1; + } + else if(strncmp(params->cmd_run,"blocksize,",10)==0) + { + params->cmd_run+=10; + user_blocksize=atoi(params->cmd_run); + while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0') + params->cmd_run++; + } + else if(strncmp(params->cmd_run,"geometry,",9)==0) + { + params->cmd_run+=9; + change_geometry_cli(params->disk, ¶ms->cmd_run); + } + else if(strncmp(params->cmd_run,"inter",5)==0) + { /* Start interactive mode */ + params->cmd_run=NULL; + return 0; + } + else if(strncmp(params->cmd_run,"wholespace",10)==0) + { + params->cmd_run+=10; + params->carve_free_space_only=0; + } + else if(strncmp(params->cmd_run,"freespace",9)==0) + { + params->cmd_run+=9; + params->carve_free_space_only=1; + } + else if(strncmp(params->cmd_run,"ext2_group,",11)==0) + { + unsigned int groupnr; + params->cmd_run+=11; + options->mode_ext2=1; + groupnr=atoi(params->cmd_run); + while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0') + params->cmd_run++; + if(mode_init_space==INIT_SPACE_WHOLE) + mode_init_space=INIT_SPACE_EXT2_GROUP; + if(mode_init_space==INIT_SPACE_EXT2_GROUP) + { + alloc_data_t *new_free_space; + new_free_space=(alloc_data_t*)MALLOC(sizeof(*new_free_space)); + /* Temporary storage, values need to be multiplied by group size and aligned */ + new_free_space->start=groupnr; + new_free_space->end=groupnr; + new_free_space->file_stat=NULL; + new_free_space->data=1; + if(td_list_add_sorted_uniq(&new_free_space->list, &list_search_space->list, spacerange_cmp)) + free(new_free_space); + } + } + else if(strncmp(params->cmd_run,"ext2_inode,",11)==0) + { + unsigned int inodenr; + params->cmd_run+=11; + options->mode_ext2=1; + inodenr=atoi(params->cmd_run); + while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0') + params->cmd_run++; + if(mode_init_space==INIT_SPACE_WHOLE) + mode_init_space=INIT_SPACE_EXT2_INODE; + if(mode_init_space==INIT_SPACE_EXT2_INODE) + { + alloc_data_t *new_free_space; + new_free_space=(alloc_data_t*)MALLOC(sizeof(*new_free_space)); + /* Temporary storage, values need to be multiplied by group size and aligned */ + new_free_space->start=inodenr; + new_free_space->end=inodenr; + new_free_space->file_stat=NULL; + new_free_space->data=1; + if(td_list_add_sorted_uniq(&new_free_space->list, &list_search_space->list, spacerange_cmp)) + free(new_free_space); + } + } + else if(isdigit(params->cmd_run[0])) + { + list_part_t *element; + const unsigned int order= atoi(params->cmd_run); + while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0') + params->cmd_run++; + for(element=list_part;element!=NULL && element->part->order!=order;element=element->next); + if(element!=NULL) + params->partition=element->part; + } + else + { + log_critical("Syntax error in command line: %s\n", params->cmd_run); + return -1; + } + } +} diff --git a/src/phcli.h b/src/phcli.h new file mode 100644 index 00000000..263ca473 --- /dev/null +++ b/src/phcli.h @@ -0,0 +1,30 @@ +/* + + File: phcli.h + + Copyright (C) 2014 Christophe GRENIER + + This software is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write the Free Software Foundation, Inc., 51 + Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + */ +#ifdef __cplusplus +extern "C" { +#endif + +int menu_photorec_cli(list_part_t *list_part, struct ph_param *params, struct ph_options *options, alloc_data_t*list_search_space); + +#ifdef __cplusplus +} /* closing brace for extern "C" */ +#endif diff --git a/src/phrecn.c b/src/phrecn.c index 88fef16e..f94152ab 100644 --- a/src/phrecn.c +++ b/src/phrecn.c @@ -562,7 +562,7 @@ void interface_options_photorec_ncurses(struct ph_options *options) #define INTER_FSELECT_Y (LINES-2) #define INTER_FSELECT (LINES-10) -static void interface_file_select_ncurses(file_enable_t *files_enable) +void interface_file_select_ncurses(file_enable_t *files_enable) { int current_element_num=0; int offset=0; @@ -574,6 +574,7 @@ static void interface_file_select_ncurses(file_enable_t *files_enable) {'q',"Quit","Return to main menu"}, {0,NULL,NULL} }; + log_info("\nInterface File Select\n"); #if defined(KEY_MOUSE) && defined(ENABLE_MOUSE) mousemask(ALL_MOUSE_EVENTS, NULL); #endif @@ -746,81 +747,3 @@ static void interface_file_select_ncurses(file_enable_t *files_enable) } } #endif - -void interface_file_select(file_enable_t *files_enable, char**current_cmd) -{ - log_info("\nInterface File Select\n"); - if(*current_cmd!=NULL) - { - int keep_asking; - do - { - file_enable_t *file_enable; - keep_asking=0; - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"everything",10)==0) - { - int enable_status; - keep_asking=1; - (*current_cmd)+=10; - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"enable",6)==0) - { - (*current_cmd)+=6; - enable_status=1; - } - else if(strncmp(*current_cmd,"disable",7)==0) - { - (*current_cmd)+=7; - enable_status=0; - } - else - { - log_critical("Syntax error %s\n",*current_cmd); - return; - } - for(file_enable=&files_enable[0];file_enable->file_hint!=NULL;file_enable++) - file_enable->enable=enable_status; - } - else - { - unsigned int cmd_length=0; - while((*current_cmd)[cmd_length]!='\0' && (*current_cmd)[cmd_length]!=',') - cmd_length++; - for(file_enable=&files_enable[0];file_enable->file_hint!=NULL;file_enable++) - { - if(file_enable->file_hint->extension!=NULL && - strlen(file_enable->file_hint->extension)==cmd_length && - memcmp(file_enable->file_hint->extension,*current_cmd,cmd_length)==0) - { - keep_asking=1; - (*current_cmd)+=cmd_length; - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"enable",6)==0) - { - (*current_cmd)+=6; - file_enable->enable=1; - } - else if(strncmp(*current_cmd,"disable",7)==0) - { - (*current_cmd)+=7; - file_enable->enable=0; - } - else - { - log_critical("Syntax error %s\n",*current_cmd); - return; - } - } - } - } - } while(keep_asking>0); - return; - } -#ifdef HAVE_NCURSES - interface_file_select_ncurses(files_enable); -#endif -} diff --git a/src/phrecn.h b/src/phrecn.h index be6c0204..0a2ecbdd 100644 --- a/src/phrecn.h +++ b/src/phrecn.h @@ -24,8 +24,8 @@ extern "C" { #endif int photorec(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space); -void interface_file_select(file_enable_t *files_enable, char**current_cmd); #ifdef HAVE_NCURSES +void interface_file_select_ncurses(file_enable_t *files_enable); void interface_options_photorec_ncurses(struct ph_options *options); #endif diff --git a/src/ppartseln.c b/src/ppartseln.c index d35c8663..501089fd 100644 --- a/src/ppartseln.c +++ b/src/ppartseln.c @@ -45,31 +45,16 @@ #include "log.h" #include "log_part.h" #include "hdaccess.h" -#include "ext2grp.h" #include "pfree_whole.h" +#include "phcli.h" #include "ppartseln.h" #include "askloc.h" -#include "geometry.h" #include "geometryn.h" #include "addpartn.h" #include "intrfn.h" -#include "poptions.h" extern const arch_fnct_t arch_none; -typedef enum { INIT_SPACE_WHOLE, INIT_SPACE_PREINIT, INIT_SPACE_EXT2_GROUP, INIT_SPACE_EXT2_INODE } init_mode_t; - -static int spacerange_cmp(const struct td_list_head *a, const struct td_list_head *b) -{ - const alloc_data_t *space_a=td_list_entry_const(a, const alloc_data_t, list); - const alloc_data_t *space_b=td_list_entry_const(b, const alloc_data_t, list); - if(space_a->start < space_b->start) - return -1; - if(space_a->start > space_b->start) - return 1; - return space_a->end - space_b->end; -} - #ifdef HAVE_NCURSES #define INTER_SELECT_X 0 #define INTER_SELECT_Y (LINES-2) @@ -79,12 +64,10 @@ static int spacerange_cmp(const struct td_list_head *a, const struct td_list_hea void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_data_t*list_search_space) { list_part_t *list_part; +#ifdef HAVE_NCURSES list_part_t *current_element; unsigned int current_element_num; - unsigned int user_blocksize=0; int done=0; - init_mode_t mode_init_space=(td_list_empty(&list_search_space->list)?INIT_SPACE_WHOLE:INIT_SPACE_PREINIT); -#ifdef HAVE_NCURSES int command; unsigned int offset=0; unsigned int menu=0; @@ -103,6 +86,37 @@ void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_da if(list_part==NULL) return; log_all_partitions(params->disk, list_part); + if(params->cmd_run!=NULL) + { + if(menu_photorec_cli(list_part, params, options, list_search_space) > 0) + { + if(params->recup_dir==NULL) + { + char *res; +#ifdef HAVE_NCURSES + res=ask_location("Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", NULL); +#else + res=get_default_location(); +#endif + if(res!=NULL) + { + params->recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1); + strcpy(params->recup_dir,res); + strcat(params->recup_dir,"/"); + strcat(params->recup_dir,DEFAULT_RECUP_DIR); + free(res); + } + } + if(params->recup_dir!=NULL) + photorec(params, options, list_search_space); + } + } + if(params->cmd_run!=NULL) + { + part_free_list(list_part); + return; + } +#ifdef HAVE_NCURSES if(list_part->next!=NULL) { current_element_num=1; @@ -114,320 +128,160 @@ void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_da current_element=list_part; } while(done==0) - { - if(params->cmd_run!=NULL) - { - while(params->cmd_run[0]==',') - params->cmd_run++; - if(params->cmd_run[0]=='\0') - { - part_free_list(list_part); - return; - } - if(strncmp(params->cmd_run,"search",6)==0) - { - params->cmd_run+=6; - if(params->recup_dir==NULL) - { - char *res; -#ifdef HAVE_NCURSES - res=ask_location("Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", NULL); -#else - res=get_default_location(); + { /* ncurses interface */ + list_part_t *element; + unsigned int i; + aff_copy(stdscr); + wmove(stdscr,4,0); + wprintw(stdscr,"%s",params->disk->description_short(params->disk)); + mvwaddstr(stdscr,6,0,msg_PART_HEADER_LONG); +#if defined(KEY_MOUSE) && defined(ENABLE_MOUSE) + mousemask(ALL_MOUSE_EVENTS, NULL); #endif - if(res!=NULL) - { - params->recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1); - strcpy(params->recup_dir,res); - strcat(params->recup_dir,"/"); - strcat(params->recup_dir,DEFAULT_RECUP_DIR); - free(res); - } - } - if(params->recup_dir!=NULL) - { - params->partition=current_element->part; - if(mode_init_space==INIT_SPACE_EXT2_GROUP) - { - params->blocksize=ext2_fix_group(list_search_space, params->disk, params->partition); - if(params->blocksize==0) - display_message("Not a valid ext2/ext3/ext4 filesystem"); - } - else if(mode_init_space==INIT_SPACE_EXT2_INODE) - { - params->blocksize=ext2_fix_inode(list_search_space, params->disk, params->partition); - if(params->blocksize==0) - display_message("Not a valid ext2/ext3/ext4 filesystem"); - } - if(td_list_empty(&list_search_space->list)) - { - init_search_space(list_search_space, params->disk, params->partition); - } - if(params->carve_free_space_only>0) - { - params->blocksize=remove_used_space(params->disk, params->partition, list_search_space); - } - if(user_blocksize > 0) - params->blocksize=user_blocksize; - photorec(params, options, list_search_space); - } - } - else if(strncmp(params->cmd_run,"options",7)==0) + for(i=0,element=list_part; element!=NULL && inext,i++) + { + if(icmd_run+=7; - interface_options_photorec_cli(options, ¶ms->cmd_run); - } - else if(strncmp(params->cmd_run,"fileopt",7)==0) + wattrset(stdscr, A_REVERSE); + waddstr(stdscr, ">"); + aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,params->disk,element->part); + wattroff(stdscr, A_REVERSE); + } else { - params->cmd_run+=7; - interface_file_select(options->list_file_format, ¶ms->cmd_run); - } - else if(strncmp(params->cmd_run,"blocksize,",10)==0) - { - params->cmd_run+=10; - user_blocksize=atoi(params->cmd_run); - while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0') - params->cmd_run++; - } - else if(strncmp(params->cmd_run,"geometry,",9)==0) - { - params->cmd_run+=9; - change_geometry_cli(params->disk, ¶ms->cmd_run); - } - else if(strncmp(params->cmd_run,"inter",5)==0) - { /* Start interactive mode */ - params->cmd_run=NULL; - } - else if(strncmp(params->cmd_run,"wholespace",10)==0) - { - params->cmd_run+=10; - params->carve_free_space_only=0; - } - else if(strncmp(params->cmd_run,"freespace",9)==0) - { - params->cmd_run+=9; - params->carve_free_space_only=1; - } - else if(strncmp(params->cmd_run,"ext2_group,",11)==0) - { - unsigned int groupnr; - params->cmd_run+=11; - options->mode_ext2=1; - groupnr=atoi(params->cmd_run); - while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0') - params->cmd_run++; - if(mode_init_space==INIT_SPACE_WHOLE) - mode_init_space=INIT_SPACE_EXT2_GROUP; - if(mode_init_space==INIT_SPACE_EXT2_GROUP) - { - alloc_data_t *new_free_space; - new_free_space=(alloc_data_t*)MALLOC(sizeof(*new_free_space)); - /* Temporary storage, values need to be multiplied by group size and aligned */ - new_free_space->start=groupnr; - new_free_space->end=groupnr; - new_free_space->file_stat=NULL; - new_free_space->data=1; - if(td_list_add_sorted_uniq(&new_free_space->list, &list_search_space->list, spacerange_cmp)) - free(new_free_space); - } - } - else if(strncmp(params->cmd_run,"ext2_inode,",11)==0) - { - unsigned int inodenr; - params->cmd_run+=11; - options->mode_ext2=1; - inodenr=atoi(params->cmd_run); - while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0') - params->cmd_run++; - if(mode_init_space==INIT_SPACE_WHOLE) - mode_init_space=INIT_SPACE_EXT2_INODE; - if(mode_init_space==INIT_SPACE_EXT2_INODE) - { - alloc_data_t *new_free_space; - new_free_space=(alloc_data_t*)MALLOC(sizeof(*new_free_space)); - /* Temporary storage, values need to be multiplied by group size and aligned */ - new_free_space->start=inodenr; - new_free_space->end=inodenr; - new_free_space->file_stat=NULL; - new_free_space->data=1; - if(td_list_add_sorted_uniq(&new_free_space->list, &list_search_space->list, spacerange_cmp)) - free(new_free_space); - } - } - else if(isdigit(params->cmd_run[0])) - { - list_part_t *element; - unsigned int order; - order= atoi(params->cmd_run); - while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0') - params->cmd_run++; - for(element=list_part;element!=NULL && element->part->order!=order;element=element->next); - if(element!=NULL) - current_element=element; - } - else - { - log_critical("Syntax error in command line: %s\n", params->cmd_run); - part_free_list(list_part); - return; + waddstr(stdscr, " "); + aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,params->disk,element->part); } } -#ifdef HAVE_NCURSES - else - { /* ncurses interface */ - list_part_t *element; - unsigned int i; - aff_copy(stdscr); - wmove(stdscr,4,0); - wprintw(stdscr,"%s",params->disk->description_short(params->disk)); - mvwaddstr(stdscr,6,0,msg_PART_HEADER_LONG); + wmove(stdscr,7+INTER_SELECT,5); + wclrtoeol(stdscr); + if(element!=NULL) + wprintw(stdscr, "Next"); + command = wmenuSelect(stdscr, INTER_SELECT_Y+1, INTER_SELECT_Y, INTER_SELECT_X, menuMain, 8, + (options->expert==0?"SOFQ":"SOFGQ"), MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, menu); #if defined(KEY_MOUSE) && defined(ENABLE_MOUSE) - mousemask(ALL_MOUSE_EVENTS, NULL); -#endif - for(i=0,element=list_part; element!=NULL && inext,i++) - { - if(i"); - aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,params->disk,element->part); - wattroff(stdscr, A_REVERSE); - } else - { - waddstr(stdscr, " "); - aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,params->disk,element->part); + if(event.y >=7 && event.y<7+INTER_SELECT) + { + /* Disk selection */ + while(current_element_num > event.y-(7-offset) && current_element->prev!=NULL) + { + current_element=current_element->prev; + current_element_num--; + } + while(current_element_num < event.y-(7-offset) && current_element->next!=NULL) + { + current_element=current_element->next; + current_element_num++; + } + if(event.bstate & BUTTON1_DOUBLE_CLICKED) + command='S'; + } + else + command = menu_to_command(INTER_SELECT_Y+1, INTER_SELECT_Y, INTER_SELECT_X, menuMain, 8, + (options->expert==0?"SOFQ":"SOFGQ"), MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, event.y, event.x); } } - wmove(stdscr,7+INTER_SELECT,5); - wclrtoeol(stdscr); - if(element!=NULL) - wprintw(stdscr, "Next"); - command = wmenuSelect(stdscr, INTER_SELECT_Y+1, INTER_SELECT_Y, INTER_SELECT_X, menuMain, 8, - (options->expert==0?"SOFQ":"SOFGQ"), MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, menu); -#if defined(KEY_MOUSE) && defined(ENABLE_MOUSE) - if(command == KEY_MOUSE) - { - MEVENT event; - if(getmouse(&event) == OK) - { /* When the user clicks left mouse button */ - if((event.bstate & BUTTON1_CLICKED) || (event.bstate & BUTTON1_DOUBLE_CLICKED)) + } +#endif + switch(command) + { + case KEY_UP: + if(current_element!=NULL && current_element->prev!=NULL) + { + current_element=current_element->prev; + current_element_num--; + } + break; + case KEY_PPAGE: + for(i=0; (signed)iprev!=NULL; i++) + { + current_element=current_element->prev; + current_element_num--; + } + break; + case KEY_DOWN: + if(current_element->next!=NULL) + { + current_element=current_element->next; + current_element_num++; + } + break; + case KEY_NPAGE: + for(i=0; (signed)inext!=NULL; i++) + { + current_element=current_element->next; + current_element_num++; + } + break; + case 's': + case 'S': + if(current_element!=NULL) + { + params->partition=current_element->part; + ask_mode_ext2(params->disk, params->partition, &options->mode_ext2, ¶ms->carve_free_space_only); + menu=0; + if(params->recup_dir==NULL) { - if(event.y >=7 && event.y<7+INTER_SELECT) + char *res; + res=ask_location("Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", NULL); + if(res!=NULL) { - /* Disk selection */ - while(current_element_num > event.y-(7-offset) && current_element->prev!=NULL) - { - current_element=current_element->prev; - current_element_num--; - } - while(current_element_num < event.y-(7-offset) && current_element->next!=NULL) - { - current_element=current_element->next; - current_element_num++; - } - if(event.bstate & BUTTON1_DOUBLE_CLICKED) - command='S'; + params->recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1); + strcpy(params->recup_dir,res); + strcat(params->recup_dir,"/"); + strcat(params->recup_dir,DEFAULT_RECUP_DIR); + free(res); } - else - command = menu_to_command(INTER_SELECT_Y+1, INTER_SELECT_Y, INTER_SELECT_X, menuMain, 8, - (options->expert==0?"SOFQ":"SOFGQ"), MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, event.y, event.x); + } + if(params->recup_dir!=NULL) + { + if(td_list_empty(&list_search_space->list)) + { + init_search_space(list_search_space, params->disk, params->partition); + } + if(params->carve_free_space_only>0) + { + aff_copy(stdscr); + wmove(stdscr,5,0); + wprintw(stdscr, "Filesystem analysis, please wait...\n"); + wrefresh(stdscr); + params->blocksize=remove_used_space(params->disk, params->partition, list_search_space); + /* Only free space is carved, list_search_space is modified. + * To carve the whole space, need to quit and reselect the params->partition */ + done = 1; + } + photorec(params, options, list_search_space); } } - } -#endif - switch(command) - { - case KEY_UP: - if(current_element!=NULL && current_element->prev!=NULL) - { - current_element=current_element->prev; - current_element_num--; - } - break; - case KEY_PPAGE: - for(i=0; (signed)iprev!=NULL; i++) - { - current_element=current_element->prev; - current_element_num--; - } - break; - case KEY_DOWN: - if(current_element->next!=NULL) - { - current_element=current_element->next; - current_element_num++; - } - break; - case KEY_NPAGE: - for(i=0; (signed)inext!=NULL; i++) - { - current_element=current_element->next; - current_element_num++; - } - break; - case 's': - case 'S': - if(current_element!=NULL) - { - params->partition=current_element->part; - ask_mode_ext2(params->disk, params->partition, &options->mode_ext2, ¶ms->carve_free_space_only); - menu=0; - if(params->recup_dir==NULL) - { - char *res; - res=ask_location("Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", NULL); - if(res!=NULL) - { - params->recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1); - strcpy(params->recup_dir,res); - strcat(params->recup_dir,"/"); - strcat(params->recup_dir,DEFAULT_RECUP_DIR); - free(res); - } - } - if(params->recup_dir!=NULL) - { - if(td_list_empty(&list_search_space->list)) - { - init_search_space(list_search_space, params->disk, params->partition); - } - if(params->carve_free_space_only>0) - { - aff_copy(stdscr); - wmove(stdscr,5,0); - wprintw(stdscr, "Filesystem analysis, please wait...\n"); - wrefresh(stdscr); - params->blocksize=remove_used_space(params->disk, params->partition, list_search_space); - /* Only free space is carved, list_search_space is modified. - * To carve the whole space, need to quit and reselect the params->partition */ - done = 1; - } - photorec(params, options, list_search_space); - } - } - break; - case 'o': - case 'O': - { - interface_options_photorec_ncurses(options); - menu=1; - } - break; - case 'f': - case 'F': - interface_file_select(options->list_file_format, ¶ms->cmd_run); - menu=2; - break; - case 'g': - case 'G': - if(options->expert!=0) - if(change_geometry_ncurses(params->disk)) - done=1; - break; + break; + case 'o': + case 'O': + { + interface_options_photorec_ncurses(options); + menu=1; + } + break; + case 'f': + case 'F': + interface_file_select_ncurses(options->list_file_format); + menu=2; + break; + case 'g': + case 'G': + if(options->expert!=0) + if(change_geometry_ncurses(params->disk)) + done=1; + break; case 'a': case 'A': if(params->disk->arch != &arch_none) @@ -437,18 +291,17 @@ void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_da current_element_num=0; } break; - case 'q': - case 'Q': - done = 1; - break; - } - if(current_element_num=offset+INTER_SELECT) - offset=current_element_num-INTER_SELECT+1; + case 'q': + case 'Q': + done = 1; + break; } -#endif + if(current_element_num=offset+INTER_SELECT) + offset=current_element_num-INTER_SELECT+1; } +#endif log_info("\n"); part_free_list(list_part); }