summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2010-10-23 20:36:43 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2010-10-23 20:36:43 +0200
commitf201398dbed3f3ad914d7071d23a64ae0b81027f (patch)
tree0a3a9f784d5655bf21eea613cd5064c6c61d86e9 /src
parent6ce209bd9d5a74ac15d48505c32bf138128105c9 (diff)
Modified interface when prompting for a destination to store data
Diffstat (limited to 'src')
-rw-r--r--src/adv.c2
-rw-r--r--src/askloc.c156
-rw-r--r--src/dirn.c4
-rw-r--r--src/ntfs_udl.c21
-rw-r--r--src/phrecn.c2
-rw-r--r--src/ppartsel.c4
6 files changed, 122 insertions, 67 deletions
diff --git a/src/adv.c b/src/adv.c
index 7921be3..9a0b529 100644
--- a/src/adv.c
+++ b/src/adv.c
@@ -476,7 +476,7 @@ void interface_adv(disk_t *disk_car, const int verbose,const int dump_ind, const
if(*current_cmd!=NULL)
image_dd=get_default_location();
else
- image_dd=ask_location("Do you want to save partition file image.dd in %s%s ? [Y/N]", "", NULL);
+ image_dd=ask_location("Please select where to store the file image.dd, an image of the partition", "", NULL);
#else
image_dd=get_default_location();
#endif
diff --git a/src/askloc.c b/src/askloc.c
index 93b08e7..42501af 100644
--- a/src/askloc.c
+++ b/src/askloc.c
@@ -56,16 +56,23 @@
#include "list.h"
#include "dir.h"
#include "askloc.h"
+#include "log.h"
extern const char *monstr[];
#define INTER_DIR (LINES-25+16)
+#define Y_DIR 8
+#ifdef __MINGW32__
+#define SPATH_SEP "\\"
+#define PATH_SEP '\\'
+#else
#define SPATH_SEP "/"
#define PATH_SEP '/'
+#endif
#if defined(__CYGWIN__)
-/* /cygdrive/c/ => */
-#define PATH_DRIVE_LENGTH 9
+/* /cygdrive/c/ */
+#define CYGDRIVE_LEN 9
#endif
#define ASK_LOCATION_WAITKEY 0
@@ -104,11 +111,22 @@ static void set_parent_directory(char *dst_directory)
if(dst_directory[i]==PATH_SEP)
last_sep=i;
#ifdef __CYGWIN__
- /* /cygdrive */
- if(last_sep>PATH_DRIVE_LENGTH)
- dst_directory[last_sep]='\0';
+ if(memcmp(dst_directory, "/cygdrive", 9)==0)
+ {
+ if(last_sep > CYGDRIVE_LEN)
+ dst_directory[last_sep]='\0';
+ else
+ dst_directory[CYGDRIVE_LEN]='\0';
+ }
+ else if(last_sep>0)
+ dst_directory[last_sep]='\0';
+ else if(last_sep==0 && dst_directory[1]=='\0')
+ strcpy(dst_directory, "/cygdrive");
else
- dst_directory[PATH_DRIVE_LENGTH]='\0';
+ {
+ dst_directory[0]=PATH_SEP;
+ dst_directory[1]='\0';
+ }
#elif defined(DJGPP) || defined(__OS2__)
if(last_sep > 2 )
dst_directory[last_sep]='\0'; /* subdirectory */
@@ -117,10 +135,13 @@ static void set_parent_directory(char *dst_directory)
else
dst_directory[0]='\0'; /* drive list */
#else
- if(last_sep>1)
+ if(last_sep>0)
dst_directory[last_sep]='\0';
else
+ {
+ dst_directory[0]=PATH_SEP;
dst_directory[1]='\0';
+ }
#endif
}
@@ -130,7 +151,7 @@ char *ask_location(const char*msg, const char *src_dir, const char *dst_org)
char *res=NULL;
int quit;
WINDOW *window=newwin(0,0,0,0); /* full screen */
- aff_copy(window);
+ aff_copy_short(window);
if(dst_org != NULL)
strncpy(dst_directory, dst_org, sizeof(dst_directory));
else
@@ -142,7 +163,7 @@ char *ask_location(const char*msg, const char *src_dir, const char *dst_org)
.list = TD_LIST_HEAD_INIT(dir_list.list),
.name = {0}
};
- wmove(window,7,0);
+ wmove(window,5,0);
wclrtoeol(window); /* before addstr for BSD compatibility */
if(has_colors())
wbkgdset(window,' ' | A_BOLD | COLOR_PAIR(0));
@@ -161,26 +182,39 @@ char *ask_location(const char*msg, const char *src_dir, const char *dst_org)
#else
dir=opendir(dst_directory);
#endif
- if(dir!=NULL)
+ if(dir==NULL)
+ {
+ log_info("opendir(%s) failed\n", dst_directory);
+ strncpy(dst_directory, SPATH_SEP, sizeof(dst_directory));
+ dir=opendir(dst_directory);
+ }
+ if(dir==NULL)
+ {
+ td_getcwd(dst_directory, sizeof(dst_directory));
+ dir=opendir(dst_directory);
+ }
+ if(dir==NULL)
+ return NULL;
{
- struct dirent *dir_entrie;
file_info_t *file_info;
file_info=(file_info_t*)MALLOC(sizeof(*file_info));
- do
+ while(1)
{
char current_file[4096];
+ struct dirent *dir_entrie;
dir_entrie=readdir(dir);
- /* if dir_entrie exists
- * there is enough room to store the filename
- * dir_entrie->d_name is ".", ".." or something that doesn't begin by a "."
- * */
- if(dir_entrie!=NULL
- && strlen(dst_directory)+1+strlen(file_info->name)+1<=sizeof(current_file) &&
- (dir_entrie->d_name[0]!='.' ||
- dir_entrie->d_name[1]=='\0' ||
- (dir_entrie->d_name[1]=='.' && dir_entrie->d_name[2]=='\0'))
+ if(dir_entrie==NULL)
+ break;
+ /* hide filename beginning by '.' except '.' and '..' */
+ if(dir_entrie->d_name[0]=='.' &&
+ !dir_entrie->d_name[1]=='\0' &&
+ !(dir_entrie->d_name[1]=='.' && dir_entrie->d_name[2]=='\0'))
+ continue;
+ if(strlen(dst_directory)+1+strlen(file_info->name)+1<=sizeof(current_file)
#ifdef __CYGWIN__
- && (strlen(dst_directory)>PATH_DRIVE_LENGTH || dir_entrie->d_name[0]!='.')
+ && (memcmp(dst_directory, "/cygdrive", 9)!=0 ||
+ (dst_directory[9]!='\0' && dst_directory[10]!='\0') ||
+ dir_entrie->d_name[0]!='.')
#endif
)
{
@@ -207,7 +241,7 @@ char *ask_location(const char*msg, const char *src_dir, const char *dst_org)
#endif
#ifdef __CYGWIN__
/* Fix Drive list */
- if(strlen(dst_directory)<=PATH_DRIVE_LENGTH)
+ if(memcmp(dst_directory, "/cygdrive", 9)==0 && (dst_directory[10]=='\0' || dst_directory[11]=='\0'))
{
file_info->stat.st_mode=LINUX_S_IFDIR|LINUX_S_IRWXUGO;
file_info->stat.st_mtime=0;
@@ -220,7 +254,7 @@ char *ask_location(const char*msg, const char *src_dir, const char *dst_org)
file_info=(file_info_t*)MALLOC(sizeof(*file_info));
}
}
- } while(dir_entrie!=NULL);
+ }
free(file_info);
closedir(dir);
}
@@ -240,22 +274,31 @@ char *ask_location(const char*msg, const char *src_dir, const char *dst_org)
pos_num=0;
old_LINES=LINES;
}
- aff_copy(window);
- wmove(window,7,0);
-#ifdef __CYGWIN__
- if(strlen(dst_directory)<=PATH_DRIVE_LENGTH)
- wprintw(window,"To select a drive, use the arrow keys.");
- else
- wprintw(window,"To select another directory, use the arrow keys.");
-#elif defined(DJGPP) || defined(__OS2__)
- if(dst_directory[0]=='\0')
- wprintw(window,"To select a drive, use the arrow keys.");
- else
- wprintw(window,"To select another directory, use the arrow keys.");
-#else
- wprintw(window,"To select another directory, use the arrow keys.");
-#endif
- {
+ aff_copy_short(window);
+ wmove(window,4,0);
+ wprintw(window,"Keys: ");
+
+ if(has_colors())
+ wbkgdset(window,' ' | A_BOLD | COLOR_PAIR(0));
+ waddstr(window, "Arrow");
+ if(has_colors())
+ wbkgdset(window,' ' | COLOR_PAIR(0));
+ wprintw(window," keys to select another directory");
+ wmove(window, 5, 6);
+ if(has_colors())
+ wbkgdset(window,' ' | A_BOLD | COLOR_PAIR(0));
+ waddstr(window, "C");
+ if(has_colors())
+ wbkgdset(window,' ' | COLOR_PAIR(0));
+ wprintw(window, " when the destination is correct");
+ wmove(window, 6, 6);
+ if(has_colors())
+ wbkgdset(window,' ' | A_BOLD | COLOR_PAIR(0));
+ waddstr(window, "Q");
+ if(has_colors())
+ wbkgdset(window,' ' | COLOR_PAIR(0));
+ waddstr(window," to quit");
+ {
struct td_list_head *file_walker = NULL;
int i=0;
td_list_for_each(file_walker,&dir_list.list)
@@ -265,7 +308,7 @@ char *ask_location(const char*msg, const char *src_dir, const char *dst_org)
{
file_info_t *file_info;
file_info=td_list_entry(file_walker, file_info_t, list);
- wmove(window,8-1+i-offset,0);
+ wmove(window, Y_DIR - 1 + i - offset, 0);
wclrtoeol(window); /* before addstr for BSD compatibility */
if(file_walker==current_file)
{
@@ -283,38 +326,43 @@ char *ask_location(const char*msg, const char *src_dir, const char *dst_org)
if(offset+INTER_DIR<=i)
break;
}
- wmove(window, 8+INTER_DIR, 4);
+ wmove(window, Y_DIR + INTER_DIR, 4);
wclrtoeol(window);
if(file_walker!=&dir_list.list && file_walker->next!=&dir_list.list)
wprintw(window, "Next");
}
+ aff_txt(2, window, msg, src_dir);
+ wmove(window,7,0);
+ wclrtoeol(window); /* before addstr for BSD compatibility */
if(strcmp(dst_directory,".")==0)
{
- aff_txt(4, window, msg, src_dir, "the program is running from");
+ wprintw(window, "Current directory");
dst_directory_ok=1;
}
else
{
#ifdef __CYGWIN__
- if(strlen(dst_directory)>PATH_DRIVE_LENGTH)
+ if(memcmp(dst_directory, "/cygdrive", 9)!=0 ||
+ (dst_directory[9]!='\0' && dst_directory[10]!='\0'))
{
char beautifull_dst_directory[4096];
- cygwin_conv_to_win32_path(dst_directory, beautifull_dst_directory);
- aff_txt(4, window, msg, src_dir, beautifull_dst_directory);
+ if(cygwin_conv_path (CCP_POSIX_TO_WIN_A | CCP_ABSOLUTE, dst_directory, beautifull_dst_directory, sizeof(beautifull_dst_directory))==0)
+ wprintw(window, "Directory %s", beautifull_dst_directory);
+ else
+ wprintw(window, "Directory %s", dst_directory);
dst_directory_ok=1;
}
#elif defined(DJGPP) || defined(__OS2__)
if(strlen(dst_directory)>0)
{
- aff_txt(4, window, msg, src_dir, dst_directory);
+ wprintw(window, "Directory %s", dst_directory);
dst_directory_ok=1;
}
#else
- aff_txt(4, window, msg, src_dir, dst_directory);
+ wprintw(window, "Directory %s", dst_directory);
dst_directory_ok=1;
#endif
}
- wclrtoeol(window); /* before addstr for BSD compatibility */
wrefresh(window);
do
{
@@ -328,16 +376,16 @@ char *ask_location(const char*msg, const char *src_dir, const char *dst_org)
{ /* When the user clicks left mouse button */
if((event.bstate & BUTTON1_CLICKED) || (event.bstate & BUTTON1_DOUBLE_CLICKED))
{
- if(event.y >=8 && event.y<8+INTER_DIR)
+ if(event.y >= Y_DIR && event.y < Y_DIR + INTER_DIR)
{
const int pos_num_old=pos_num;
/* Disk selection */
- while(pos_num > event.y-(8-offset) && current_file->prev!=&dir_list.list)
+ while(pos_num > event.y - (Y_DIR - offset) && current_file->prev!=&dir_list.list)
{
current_file=current_file->prev;
pos_num--;
}
- while(pos_num < event.y-(8-offset) && current_file->next!=&dir_list.list)
+ while(pos_num < event.y - (Y_DIR - offset) && current_file->next!=&dir_list.list)
{
current_file=current_file->next;
pos_num++;
@@ -360,6 +408,8 @@ char *ask_location(const char*msg, const char *src_dir, const char *dst_org)
{
case 'y':
case 'Y':
+ case 'c':
+ case 'C':
if(dst_directory_ok>0)
{
res=strdup(dst_directory);
@@ -368,6 +418,8 @@ char *ask_location(const char*msg, const char *src_dir, const char *dst_org)
break;
case 'n':
case 'N':
+ case 'q':
+ case 'Q':
res=NULL;
quit=ASK_LOCATION_QUIT;
break;
diff --git a/src/dirn.c b/src/dirn.c
index 2d47179..0883064 100644
--- a/src/dirn.c
+++ b/src/dirn.c
@@ -279,10 +279,10 @@ static long int dir_aff_ncurses(disk_t *disk, const partition_t *partition, dir_
if(dir_data->local_dir==NULL)
{
if(LINUX_S_ISDIR(pos->stat.st_mode)!=0)
- dir_data->local_dir=ask_location("Are you sure you want to copy %s and any files below to the directory %s ? [Y/N]",
+ dir_data->local_dir=ask_location("Please select a destination where %s and any files below will be copied.",
dir_data->current_directory, NULL);
else
- dir_data->local_dir=ask_location("Are you sure you want to copy %s to the directory %s ? [Y/N]",
+ dir_data->local_dir=ask_location("Please select a destination where %s will be copied.",
dir_data->current_directory, NULL);
}
if(dir_data->local_dir!=NULL)
diff --git a/src/ntfs_udl.c b/src/ntfs_udl.c
index b93c381..e319b2b 100644
--- a/src/ntfs_udl.c
+++ b/src/ntfs_udl.c
@@ -1201,7 +1201,6 @@ static void ntfs_undelete_menu_ncurses(disk_t *disk_car, const partition_t *part
{
file_info_t *file_info;
struct tm *tm_p;
- char str[11];
char datestr[80];
file_info=td_list_entry(file_walker, file_info_t, list);
wmove(window, 6-1+i-offset, 0);
@@ -1226,12 +1225,16 @@ static void ntfs_undelete_menu_ncurses(disk_t *disk_car, const partition_t *part
} else {
strncpy(datestr, " ",sizeof(datestr));
}
- mode_string(file_info->stat.st_mode,str);
- wprintw(window, "%s %5u %5u ",
- str, (unsigned int)file_info->stat.st_uid, (unsigned int)file_info->stat.st_gid);
- wprintw(window, "%7llu", (long long unsigned int)file_info->stat.st_size);
- /* screen may overlap due to long filename */
- wprintw(window, " %s %s", datestr, file_info->name);
+ if(COLS <= 1+17+1+7+1)
+ wprintw(window, "%s %s %7llu", file_info->name, datestr, (long long unsigned int)file_info->stat.st_size);
+ else
+ {
+ const unsigned int nbr=COLS - (1+17+1+7+1);
+ if(strlen(file_info->name) < nbr)
+ wprintw(window, "%-*s %s %7llu", nbr, file_info->name, datestr, (long long unsigned int)file_info->stat.st_size);
+ else
+ wprintw(window, "%-*s %s %7llu", nbr, &file_info->name[strlen(file_info->name) - nbr], datestr, (long long unsigned int)file_info->stat.st_size);
+ }
if((file_info->status&FILE_STATUS_MARKED)!=0 && has_colors())
wbkgdset(window,' ' | COLOR_PAIR(0));
if(file_walker==current_file)
@@ -1373,10 +1376,10 @@ static void ntfs_undelete_menu_ncurses(disk_t *disk_car, const partition_t *part
{
char *res;
if(LINUX_S_ISDIR(file_info->stat.st_mode)!=0)
- res=ask_location("Are you sure you want to copy %s and any files below to the directory %s ? [Y/N]",
+ res=ask_location("Please select a destination where %s and any files below will be copied.",
file_info->name, NULL);
else
- res=ask_location("Are you sure you want to copy %s to the directory %s ? [Y/N]",
+ res=ask_location("Please select a destination where %s will be copied.",
file_info->name, NULL);
dir_data->local_dir=res;
opts.dest=res;
diff --git a/src/phrecn.c b/src/phrecn.c
index 1d50c10..cf951bb 100644
--- a/src/phrecn.c
+++ b/src/phrecn.c
@@ -818,7 +818,7 @@ int photorec(disk_t *disk_car, partition_t *partition, const int verbose, const
if(res!=NULL)
*res='\0';
}
- res=ask_location("Warning: no free space available. Do you want to save recovered files in %s%s ? [Y/N]\nDo not choose to write the files to the same partition they were stored on.", "", dst);
+ res=ask_location("Warning: no free space available. Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", dst);
free(dst);
if(res==NULL)
status=STATUS_QUIT;
diff --git a/src/ppartsel.c b/src/ppartsel.c
index 880d88a..320298a 100644
--- a/src/ppartsel.c
+++ b/src/ppartsel.c
@@ -153,7 +153,7 @@ void menu_photorec(disk_t *disk_car, const int verbose, const char *recup_dir, f
else
{
#ifdef HAVE_NCURSES
- res=ask_location("Do you want to save recovered files in %s%s ? [Y/N]\nDo not choose to write the files to the same partition they were stored on.", "", NULL);
+ 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
@@ -407,7 +407,7 @@ void menu_photorec(disk_t *disk_car, const int verbose, const char *recup_dir, f
res=(char *)recup_dir;
else
{
- res=ask_location("Do you want to save recovered files in %s%s ? [Y/N]\nDo not choose to write the files to the same partition they were stored on.", "", NULL);
+ 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)
{
char *new_recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1);