Fix issue 506: Missing 'parent directory' in fileselector

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1994 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2012-09-17 21:11:44 +00:00
parent 56cdbc4c10
commit 95b537e5f0
3 changed files with 80 additions and 42 deletions

View File

@ -380,26 +380,37 @@ void Read_list_of_files(T_Fileselector *list, byte selected_format)
#endif #endif
while ((entry=readdir(current_directory))) while ((entry=readdir(current_directory)))
{ {
// On ignore le répertoire courant // Ignore 'current directory' entry
if ( !strcmp(entry->d_name, ".")) if ( !strcmp(entry->d_name, "."))
{ {
continue; continue;
} }
stat(entry->d_name,&Infos_enreg); stat(entry->d_name,&Infos_enreg);
// et que l'élément trouvé est un répertoire // entries tagged "directory" :
if( S_ISDIR(Infos_enreg.st_mode) && if( S_ISDIR(Infos_enreg.st_mode))
// et que c'est ".."
(!strcmp(entry->d_name, PARENT_DIR) ||
// ou qu'il n'est pas caché
Config.Show_hidden_directories ||
!File_is_hidden(entry->d_name, entry->d_name)))
{ {
// On rajoute le répertoire à la liste // On Windows, the presence of a "parent directory" entry has proven
// unreliable on non-physical drives :
// Sometimes it's missing, sometimes it's present even at root...
// We skip it here and add a specific check after the loop
#if defined(__WIN32__)
if (!strcmp(entry->d_name, PARENT_DIR))
continue;
#endif
// Don't display hidden file, unless requested by options
if (!Config.Show_hidden_directories &&
File_is_hidden(entry->d_name, entry->d_name))
{
continue;
}
// Add to list
Add_element_to_list(list, entry->d_name, Format_filename(entry->d_name, 19, 1), 1, ICON_NONE); Add_element_to_list(list, entry->d_name, Format_filename(entry->d_name, 19, 1), 1, ICON_NONE);
list->Nb_directories++; list->Nb_directories++;
} }
else if (S_ISREG(Infos_enreg.st_mode) && //Il s'agit d'un fichier else if (S_ISREG(Infos_enreg.st_mode) && // It's a file
(Config.Show_hidden_files || //Il n'est pas caché (Config.Show_hidden_files || // Not hidden
!File_is_hidden(entry->d_name, entry->d_name))) !File_is_hidden(entry->d_name, entry->d_name)))
{ {
const char * ext = filter; const char * ext = filter;
@ -407,7 +418,7 @@ void Read_list_of_files(T_Fileselector *list, byte selected_format)
{ {
if (Check_extension(entry->d_name, ext)) if (Check_extension(entry->d_name, ext))
{ {
// On rajoute le fichier à la liste // Add to list
Add_element_to_list(list, entry->d_name, Format_filename(entry->d_name, 19, 0), 0, ICON_NONE); Add_element_to_list(list, entry->d_name, Format_filename(entry->d_name, 19, 0), 0, ICON_NONE);
list->Nb_files++; list->Nb_files++;
// Stop searching // Stop searching
@ -422,17 +433,34 @@ void Read_list_of_files(T_Fileselector *list, byte selected_format)
} }
} }
} }
if (list->Nb_files==0 && list->Nb_directories==0)
{ // Now here's OS-specific code to determine if "parent directory" entry
// This can happen on some empty network drives. // should appear.
// Add a dummy entry because the fileselector doesn't
// seem to support empty list.
Add_element_to_list(list, ".",Format_filename(".",19,1),1,ICON_NONE);
}
#if defined(__MORPHOS__) || defined(__AROS__) || defined (__amigaos4__) || defined(__amigaos__) #if defined(__MORPHOS__) || defined(__AROS__) || defined (__amigaos4__) || defined(__amigaos__)
Add_element_to_list(list, "/", Format_filename("/",19,1), 1, ICON_NONE); // on amiga systems, / means parent. And there is no .. // Amiga systems: always
Add_element_to_list(list, PARENT_DIR, Format_filename(PARENT_DIR,19,1), 1, ICON_NONE);
list->Nb_directories ++; list->Nb_directories ++;
#elif defined (__WIN32__)
// Windows :
if (((current_path[0]>='a'&&current_path[0]<='z')||(current_path[0]>='A'&&current_path[0]<='Z')) &&
current_path[1]==':' &&
(
(current_path[2]=='\0') ||
(current_path[2]=='/'&&current_path[3]=='\0') ||
(current_path[2]=='\\'&&current_path[3]=='\0')
))
{
// Path is X:\ or X:/ or X:
// so don't display parent directory
}
else
{
Add_element_to_list(list, PARENT_DIR, Format_filename(PARENT_DIR,19,1), 1, ICON_NONE);
list->Nb_directories ++;
}
#elif defined (__MINT__) #elif defined (__MINT__)
T_Fileselector_item *item=NULL; T_Fileselector_item *item=NULL;
// check if ".." exists if not add it // check if ".." exists if not add it
@ -443,12 +471,12 @@ void Read_list_of_files(T_Fileselector *list, byte selected_format)
for (item = list->First; (((item != NULL) && (bFound==false))); item = item->Next){ for (item = list->First; (((item != NULL) && (bFound==false))); item = item->Next){
if (item->Type == 1){ if (item->Type == 1){
if(strncmp(item->Full_name,"..",(sizeof(char)*2))==0) bFound=true; if(strncmp(item->Full_name,PARENT_DIR,(sizeof(char)*2))==0) bFound=true;
} }
} }
if(!bFound){ if(!bFound){
Add_element_to_list(list, "..",Format_filename("/",19,1),1,ICON_NONE); // add if not present Add_element_to_list(list,PARENT_DIR,Format_filename(PARENT_DIR,19,1),1,ICON_NONE); // add if not present
list->Nb_directories ++; list->Nb_directories ++;
} }
@ -462,6 +490,14 @@ void Read_list_of_files(T_Fileselector *list, byte selected_format)
#endif #endif
current_path = NULL; current_path = NULL;
if (list->Nb_files==0 && list->Nb_directories==0)
{
// This can happen on some empty network drives.
// Add a dummy entry because the fileselector doesn't
// seem to support empty list.
Add_element_to_list(list, ".",Format_filename(".",19,1),1,ICON_NONE);
}
Recount_files(list); Recount_files(list);
} }

View File

@ -485,22 +485,23 @@ static const T_Help_table helptable_credits[] =
HELP_TITLE(" BUGFINDERS") HELP_TITLE(" BUGFINDERS")
HELP_TEXT ("") HELP_TEXT ("")
//HELP_TEXT ("0----5----0----5----0----5----0----5----0--X") //HELP_TEXT ("0----5----0----5----0----5----0----5----0--X")
HELP_TEXT (" anibiqme antdzeryn blumunkee ") HELP_TEXT (" Akira anibiqme antdzeryn ")
HELP_TEXT (" BDCIron Ced DarkDefende ") HELP_TEXT (" blumunkee BDCIron Ced ")
HELP_TEXT (" DawnBringer El Topo falenblood ") HELP_TEXT (" DarkDefende DawnBringer El Topo ")
HELP_TEXT (" fanickbux fano fogbot121 ") HELP_TEXT (" falenblood fanickbux fano ")
HELP_TEXT (" Frost Grimmy Gürkan Sengün ") HELP_TEXT (" fogbot121 freehand Frost ")
HELP_TEXT (" Hatch HoraK-FDF iLKke ") HELP_TEXT (" Grimmy Gürkan Sengün Hatch ")
HELP_TEXT (" Iw2evk jackfrost128 Jamon ") HELP_TEXT (" HoraK-FDF iLKke Iw2evk ")
HELP_TEXT (" keito kusma lmemsm ") HELP_TEXT (" jackfrost128 Jamon keito ")
HELP_TEXT (" Lord Graga Lorenzo Gatti MagerValp ") HELP_TEXT (" kusma lmemsm Lord Graga ")
HELP_TEXT (" maymunbeyin mind MooZ ") HELP_TEXT (" Lorenzo Gatti MagerValp maymunbeyin ")
HELP_TEXT (" Pasi Kallinen the Peach petter ") HELP_TEXT (" mind MooZ Pasi Kallinen ")
HELP_TEXT (" PheeL Ravey1138 richienyhus ") HELP_TEXT (" the Peach petter PheeL ")
HELP_TEXT (" rixard sm4tik spratek ") HELP_TEXT (" Ravey1138 richienyhus rixard ")
HELP_TEXT (" Surt tape.yrm TeeEmCee ") HELP_TEXT (" sm4tik spratek Surt ")
HELP_TEXT (" tempest Timo Kurrpa titus^Rab ") HELP_TEXT (" tape.yrm TeeEmCee tempest ")
HELP_TEXT (" Tobé yakumo2975 00ai99 ") HELP_TEXT (" Timo Kurrpa titus^Rab Tobé ")
HELP_TEXT (" yakumo2975 00ai99")
HELP_TEXT ("") HELP_TEXT ("")
HELP_TEXT (" ... posted the annoying bug reports.") HELP_TEXT (" ... posted the annoying bug reports.")
HELP_TEXT ("") HELP_TEXT ("")

View File

@ -321,7 +321,7 @@ int Directory_exists(char * directory)
int File_is_hidden(const char *fname, const char *full_name) int File_is_hidden(const char *fname, const char *full_name)
{ {
#if defined(__amigaos4__) || defined(__AROS__) || defined(__MORPHOS__) || defined(__amigaos__) || defined(__MINT__) #if defined(__amigaos4__) || defined(__AROS__) || defined(__MORPHOS__) || defined(__amigaos__) || defined(__MINT__)
// False (unable to determine, or irrrelevent for platform) // False (unable to determine, or irrelevent for platform)
(void)fname;//unused (void)fname;//unused
(void)full_name;//unused (void)full_name;//unused
return 0; return 0;
@ -336,10 +336,11 @@ int File_is_hidden(const char *fname, const char *full_name)
return (att&FILE_ATTRIBUTE_HIDDEN)?1:0; return (att&FILE_ATTRIBUTE_HIDDEN)?1:0;
#else #else
(void)full_name;//unused (void)full_name;//unused
return fname[0]=='.'; // On linux/unix (default), files are considered hidden if their name
// begins with a .
// As a special case, we'll consider 'parent directory' (..) never hidden.
return fname[0]=='.' && !strcmp(entry->d_name, PARENT_DIR);
#endif #endif
} }
// Taille de fichier, en octets // Taille de fichier, en octets
int File_length(const char * fname) int File_length(const char * fname)