summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/phcfg.c266
-rw-r--r--src/phcfg.h3
-rw-r--r--src/photorec.c12
-rw-r--r--src/photorec.h1
-rw-r--r--src/phrecn.c22
6 files changed, 293 insertions, 13 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2d04d4f..42a8df9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -19,7 +19,7 @@ fs_H = analyse.h bfs.h bsd.h cramfs.h fat.h fatx.h ext2.h jfs_superblock.h jfs
testdisk_SOURCES = testdisk.c $(base_C) $(base_H) $(fs_C) $(fs_H) testdisk.h adv.c adv.h dir.c dir.h dirpart.c dirpart.h edit.c edit.h ext2_dir.c ext2_dir.h ext2_inc.h fat_adv.c fat_dir.c fat_dir.h geometry.c godmode.c godmode.h intrface.c intrface.h ntfs_adv.c ntfs_dir.c ntfs_dir.h ntfs_fix.c ntfs_inc.h rfs_dir.c rfs_dir.h $(ICON_TESTDISK) next.c next.h dimage.c dimage.h
#ntfs_udl.c ntfs_udl.h
-photorec_SOURCES = photorec.c photorec.h phrecn.c phrecn.h dir.c dir.h ext2p.c ext2p.h ext2_dir.c ext2_dir.h ext2_inc.h fat_dir.c fat_dir.h fatp.c fatp.h filegen.c filegen.h file_7z.c file_a.c file_ab.c file_ace.c file_aif.c file_all.c file_asf.c file_au.c file_bkf.c file_bld.c file_bmp.c file_bz2.c file_cab.c file_cam.c file_cm.c file_crw.c file_ctg.c file_cwk.c file_dat.c file_dbf.c file_dim.c file_dir.c file_djv.c file_doc.c file_dpx.c file_dsc.c file_dss.c file_dta.c file_dv.c file_dwg.c file_elf.c file_emf.c file_evt.c file_exe.c pe.h file_ext.c file_fcp.c file_fcs.c file_fh10.c file_fh5.c file_flac.c file_flv.c file_fs.c file_gif.c file_gz.c file_imb.c file_indd.c file_dump.c file_itu.c file_jpg.c file_jpg.h file_kdb.c file_lnk.c file_max.c file_mb.c file_mcd.c file_mdb.c file_mdf.c file_mid.c file_mkv.c file_mov.c file_mp3.c file_mpg.c file_mrw.c file_mus.c file_mysql.c file_njx.c file_ogg.c file_one.c file_orf.c file_pap.c file_pct.c file_pcx.c file_pdf.c file_png.c file_prc.c file_ps.c file_psd.c file_pst.c file_ptb.c file_qbb.c file_qdf.c file_qxd.c file_ra.c file_raf.c file_rar.c file_raw.c file_rdc.c file_reg.c file_res.c file_riff.c file_rm.c file_rns.c file_rpm.c file_sit.c file_skp.c file_spe.c file_spss.c file_stu.c file_swf.c file_tar.c file_tar.h file_tib.c file_tiff.c file_txt.c file_vmdk.c file_wpd.c file_wmf.c file_x3f.c file_xcf.c file_xm.c file_xsv.c file_zip.c memmem.h geometry.c list.c list.h ole.h ntfs_dir.c ntfs_dir.h ntfsp.c ntfsp.h ntfs_inc.h sessionp.c sessionp.h $(base_C) $(base_H) $(fs_C) $(fs_H) $(ICON_PHOTOREC)
+photorec_SOURCES = photorec.c photorec.h phcfg.c phcfg.h phrecn.c phrecn.h dir.c dir.h ext2p.c ext2p.h ext2_dir.c ext2_dir.h ext2_inc.h fat_dir.c fat_dir.h fatp.c fatp.h filegen.c filegen.h file_7z.c file_a.c file_ab.c file_ace.c file_aif.c file_all.c file_asf.c file_au.c file_bkf.c file_bld.c file_bmp.c file_bz2.c file_cab.c file_cam.c file_cm.c file_crw.c file_ctg.c file_cwk.c file_dat.c file_dbf.c file_dim.c file_dir.c file_djv.c file_doc.c file_dpx.c file_dsc.c file_dss.c file_dta.c file_dv.c file_dwg.c file_elf.c file_emf.c file_evt.c file_exe.c pe.h file_ext.c file_fcp.c file_fcs.c file_fh10.c file_fh5.c file_flac.c file_flv.c file_fs.c file_gif.c file_gz.c file_imb.c file_indd.c file_dump.c file_itu.c file_jpg.c file_jpg.h file_kdb.c file_lnk.c file_max.c file_mb.c file_mcd.c file_mdb.c file_mdf.c file_mid.c file_mkv.c file_mov.c file_mp3.c file_mpg.c file_mrw.c file_mus.c file_mysql.c file_njx.c file_ogg.c file_one.c file_orf.c file_pap.c file_pct.c file_pcx.c file_pdf.c file_png.c file_prc.c file_ps.c file_psd.c file_pst.c file_ptb.c file_qbb.c file_qdf.c file_qxd.c file_ra.c file_raf.c file_rar.c file_raw.c file_rdc.c file_reg.c file_res.c file_riff.c file_rm.c file_rns.c file_rpm.c file_sit.c file_skp.c file_spe.c file_spss.c file_stu.c file_swf.c file_tar.c file_tar.h file_tib.c file_tiff.c file_txt.c file_vmdk.c file_wpd.c file_wmf.c file_x3f.c file_xcf.c file_xm.c file_xsv.c file_zip.c memmem.h geometry.c list.c list.h ole.h ntfs_dir.c ntfs_dir.h ntfsp.c ntfsp.h ntfs_inc.h sessionp.c sessionp.h $(base_C) $(base_H) $(fs_C) $(fs_H) $(ICON_PHOTOREC)
#diskcp_SOURCES = diskcp.c types.h
diff --git a/src/phcfg.c b/src/phcfg.c
new file mode 100644
index 0000000..663b63c
--- /dev/null
+++ b/src/phcfg.c
@@ -0,0 +1,266 @@
+/*
+
+ File: phcfg.c
+
+ Copyright (C) 2008 Christophe GRENIER <grenier@cgsecurity.org>
+
+ 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 <config.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* getuid */
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+#include <stdio.h>
+#include <errno.h>
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#endif
+#include "types.h"
+#include "common.h"
+#include "filegen.h"
+#include "log.h"
+#include "phcfg.h"
+
+void reset_list_file_enable(file_enable_t *files_enable)
+{
+ file_enable_t *file_enable;
+ for(file_enable=files_enable;file_enable->file_hint!=NULL;file_enable++)
+ file_enable->enable=file_enable->file_hint->enable_by_default;
+}
+
+/*
+ PhotoRec should try to load the configuration from
+ - $HOME/.photorec.cfg
+ - $SBIN/photorec.cfg
+
+ PhotoRec stores the configuration in
+ - $HOME/.photorec.cfg
+ - DOS: $SBIN/photorec.cfg
+*/
+
+#define WIN_PHOTOREC_CFG "\\photorec.cfg"
+#define DOT_PHOTOREC_CFG "/.photorec.cfg"
+#define PHOTOREC_CFG "photorec.cfg"
+
+static FILE *file_options_save_aux(void)
+{
+ char *filename=NULL;
+#if defined(__CYGWIN__) || defined(__MINGW32__)
+ {
+ char *path;
+ path = getenv("USERPROFILE");
+ if (path == NULL)
+ path = getenv("HOMEPATH");
+ if(path!=NULL)
+ {
+ filename=(char*)MALLOC(strlen(path)+strlen(WIN_PHOTOREC_CFG)+1);
+ strcpy(filename, path);
+ strcat(filename, WIN_PHOTOREC_CFG);
+ }
+ }
+#endif
+#ifndef DJGPP
+ if(filename==NULL)
+ {
+ char *home;
+ home = getenv("HOME");
+#if 0
+ /* Using 'getpwuid' in statically linked applications requires at
+ runtime the shared libraries from the glibc version used for linking
+ */
+ if (home == NULL)
+ {
+ struct passwd *pw;
+ pw = getpwuid(getuid());
+ if (pw != NULL)
+ home = pw->pw_dir;
+ }
+#endif
+ if (home != NULL)
+ {
+ filename=(char*)MALLOC(strlen(home)+strlen(DOT_PHOTOREC_CFG)+1);
+ strcpy(filename, home);
+ strcat(filename, DOT_PHOTOREC_CFG);
+ }
+ }
+ if(filename!=NULL)
+ {
+ FILE*handle=NULL;
+ handle=fopen(filename,"wb");
+ if(handle)
+ {
+ log_info("Create file %s\n", filename);
+ free(filename);
+ return handle;
+ }
+ log_error("Can't create file %s: %s\n", filename, strerror(errno));
+ free(filename);
+ filename=NULL;
+ }
+#endif
+ {
+ FILE*handle=NULL;
+ handle=fopen(PHOTOREC_CFG,"wb");
+ if(handle)
+ {
+ log_info("Create file %s\n", PHOTOREC_CFG);
+ return handle;
+ }
+ log_error("Can't create file %s: %s\n", PHOTOREC_CFG, strerror(errno));
+ }
+ return NULL;
+}
+
+static FILE *file_options_load_aux(void)
+{
+#if defined(__CYGWIN__) || defined(__MINGW32__)
+ {
+ char *path;
+ path = getenv("USERPROFILE");
+ if (path == NULL)
+ path = getenv("HOMEPATH");
+ if(path!=NULL)
+ {
+ FILE*handle;
+ char *filename=NULL;
+ filename=(char*)MALLOC(strlen(path)+strlen(WIN_PHOTOREC_CFG)+1);
+ strcpy(filename, path);
+ strcat(filename, WIN_PHOTOREC_CFG);
+ handle=fopen(filename,"rb");
+ if(handle!=NULL)
+ {
+ log_info("Load parameters from %s\n", filename);
+ free(filename);
+ return handle;
+ }
+ free(filename);
+ }
+ }
+#endif
+#ifndef DJGPP
+ {
+ char *home;
+ home = getenv("HOME");
+#if 0
+ /* Using 'getpwuid' in statically linked applications requires at
+ runtime the shared libraries from the glibc version used for linking
+ */
+ if (home == NULL)
+ {
+ struct passwd *pw;
+ pw = getpwuid(getuid());
+ if (pw != NULL)
+ home = pw->pw_dir;
+ }
+#endif
+ if (home != NULL)
+ {
+ FILE*handle;
+ char *filename=NULL;
+ filename=(char*)MALLOC(strlen(home)+strlen(DOT_PHOTOREC_CFG)+1);
+ strcpy(filename, home);
+ strcat(filename, DOT_PHOTOREC_CFG);
+ handle=fopen(filename,"rb");
+ if(handle!=NULL)
+ {
+ log_info("Load parameters from %s\n", filename);
+ free(filename);
+ return handle;
+ }
+ free(filename);
+ }
+ }
+#endif
+ {
+ FILE*handle=NULL;
+ handle=fopen(PHOTOREC_CFG,"rb");
+ if(handle!=NULL)
+ {
+ log_info("Load parameters from %s\n", PHOTOREC_CFG);
+ return handle;
+ }
+ }
+ return NULL;
+}
+
+int file_options_save(const file_enable_t *files_enable)
+{
+ FILE *handle;
+ const file_enable_t *file_enable;
+ handle=file_options_save_aux();
+ if(handle==NULL)
+ return -1;
+ for(file_enable=&files_enable[0];file_enable->file_hint!=NULL;file_enable++)
+ if(file_enable->file_hint->extension!=NULL)
+ {
+ if(file_enable->enable==0)
+ fprintf(handle, "%s,disable\n", file_enable->file_hint->extension);
+ else
+ fprintf(handle, "%s,enable\n", file_enable->file_hint->extension);
+ }
+ fclose(handle);
+ return 0;
+}
+
+int file_options_load(file_enable_t *files_enable)
+{
+ FILE *handle;
+ char buffer[512];
+ reset_list_file_enable(files_enable);
+ handle=file_options_load_aux();
+ if(handle==NULL)
+ return -1;
+// TODO parse the file
+ while(fgets(buffer, sizeof(buffer)-1, handle)!=NULL)
+ {
+ const char *extension=&buffer[0];
+ char *extension_status;
+ buffer[sizeof(buffer)-1]='\0';
+ extension_status=strchr(buffer,',');
+ if(extension_status!=NULL)
+ {
+ file_enable_t *file_enable;
+ unsigned int cmd_length=extension_status-extension;
+ *extension_status='\0';
+ extension_status++;
+ log_info("extension=%s, extension_status=%s\n", extension, extension_status);
+ 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,extension,cmd_length)==0)
+ {
+ file_enable->enable=(strncmp(extension_status, "enable",6)==0);
+ }
+ }
+ }
+ }
+ fclose(handle);
+ return 0;
+}
+
diff --git a/src/phcfg.h b/src/phcfg.h
new file mode 100644
index 0000000..5417402
--- /dev/null
+++ b/src/phcfg.h
@@ -0,0 +1,3 @@
+void reset_list_file_enable(file_enable_t *files_enable);
+int file_options_save(const file_enable_t *files_enable);
+int file_options_load(file_enable_t *files_enable);
diff --git a/src/photorec.c b/src/photorec.c
index 71f4f0e..4321874 100644
--- a/src/photorec.c
+++ b/src/photorec.c
@@ -2,7 +2,7 @@
File: photorec.c
- Copyright (C) 1998-2007 Christophe GRENIER <grenier@cgsecurity.org>
+ Copyright (C) 1998-2008 Christophe GRENIER <grenier@cgsecurity.org>
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
@@ -79,6 +79,7 @@
#include "phrecn.h"
#include "hdaccess.h"
#include "sudo.h"
+#include "phcfg.h"
/* #define DEBUG_FILE_FINISH */
/* #define DEBUG_UPDATE_SEARCH_SPACE */
@@ -745,13 +746,6 @@ alloc_data_t * update_blocksize(unsigned int blocksize, alloc_data_t *list_searc
return list_search_space;
}
-void reset_list_file_enable(file_enable_t *files_enable)
-{
- file_enable_t *file_enable;
- for(file_enable=files_enable;file_enable->file_hint!=NULL;file_enable++)
- file_enable->enable=file_enable->file_hint->enable_by_default;
-}
-
int main( int argc, char **argv )
{
int i;
@@ -1051,7 +1045,7 @@ int main( int argc, char **argv )
disk->description(disk), disk->sector_size, disk->model);
}
log_info("\n");
- reset_list_file_enable(list_file_enable);
+ file_options_load(list_file_enable);
use_sudo=do_curses_photorec(verbose, recup_dir, list_disk, list_file_enable, cmd_device, &cmd_run);
#ifdef HAVE_NCURSES
end_ncurses();
diff --git a/src/photorec.h b/src/photorec.h
index 6334f41..8817efb 100644
--- a/src/photorec.h
+++ b/src/photorec.h
@@ -35,4 +35,3 @@ int sorfile_stat_ts(const void *p1, const void *p2);
unsigned int photorec_mkdir(const char *recup_dir, const unsigned int initial_dir_num);
void list_space_used(const file_recovery_t *file_recovery, const unsigned int sector_size);
void info_list_search_space(const alloc_data_t *list_search_space, const alloc_data_t *current_search_space, const unsigned int sector_size, const int keep_corrupted_file, const int verbose);
-
diff --git a/src/phrecn.c b/src/phrecn.c
index 4712a6e..9972a63 100644
--- a/src/phrecn.c
+++ b/src/phrecn.c
@@ -61,6 +61,7 @@
#include "log.h"
#include "hdaccess.h"
#include "file_tar.h"
+#include "phcfg.h"
/* #define DEBUG */
/* #define DEBUG_GET_NEXT_SECTOR */
@@ -2051,9 +2052,15 @@ static void interface_file_select_ncurses(file_enable_t *files_enable)
if(has_colors())
wbkgdset(stdscr,' ' | COLOR_PAIR(0));
if(enable_status==0)
- wprintw(stdscr," for default selection");
+ wprintw(stdscr," for default selection, ");
else
- wprintw(stdscr," to disable all file famillies");
+ wprintw(stdscr," to disable all file famillies, ");
+ if(has_colors())
+ wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(0));
+ wprintw(stdscr,"b");
+ if(has_colors())
+ wbkgdset(stdscr,' ' | COLOR_PAIR(0));
+ wprintw(stdscr," to save the settings");
command = wmenuSelect(stdscr,INTER_SELECT_Y, INTER_SELECT_X, menuAdv, 8,
"q", MENU_BUTTON | MENU_ACCEPT_OTHERS, menu);
switch(command)
@@ -2113,6 +2120,17 @@ static void interface_file_select_ncurses(file_enable_t *files_enable)
reset_list_file_enable(files_enable);
}
break;
+ case 'b':
+ case 'B':
+ if(file_options_save(files_enable)<0)
+ {
+ display_message("Failed to save the settings.");
+ }
+ else
+ {
+ display_message("Settings recorded successfully.");
+ }
+ break;
case 'q':
case 'Q':
return;