move Get_unicode_filename() to io.c. correclty select last directory in
filesel
This commit is contained in:
parent
b67ce603a7
commit
e68c16dd34
@ -2326,6 +2326,9 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
|
|||||||
Sort_list_of_files(&Filelist);
|
Sort_list_of_files(&Filelist);
|
||||||
// Set the fileselector bar on the directory we're coming from
|
// Set the fileselector bar on the directory we're coming from
|
||||||
pos = Find_file_in_fileselector(&Filelist, previous_directory);
|
pos = Find_file_in_fileselector(&Filelist, previous_directory);
|
||||||
|
strcpy(Selector_filename, previous_directory);
|
||||||
|
if (!Get_Unicode_Filename(Selector_filename_unicode, Selector_filename, "."))
|
||||||
|
Selector_filename_unicode[0] = 0;
|
||||||
Highlight_file((pos >= 0) ? pos : 0);
|
Highlight_file((pos >= 0) ? pos : 0);
|
||||||
// display the 1st visible files
|
// display the 1st visible files
|
||||||
Prepare_and_display_filelist(Selector->Position,Selector->Offset,file_scroller,0);
|
Prepare_and_display_filelist(Selector->Position,Selector->Offset,file_scroller,0);
|
||||||
|
|||||||
63
src/io.c
63
src/io.c
@ -693,6 +693,69 @@ void Get_full_filename(char * output_name, const char * file_name, const char *
|
|||||||
strcat(output_name,file_name);
|
strcat(output_name,file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a file name to unicode characters
|
||||||
|
*
|
||||||
|
* @param filename_unicode the output buffer of MAX_PATH_CHARACTERS wide characters
|
||||||
|
* @param filename the input file name
|
||||||
|
* @param directory the input file directory
|
||||||
|
* @return 0 if no conversion has taken place.
|
||||||
|
* @return 1 if the unicode filename has been retrieved
|
||||||
|
*/
|
||||||
|
int Get_Unicode_Filename(word * filename_unicode, const char * filename, const char * directory)
|
||||||
|
{
|
||||||
|
#if defined(WIN32)
|
||||||
|
int i = 0, j = 0;
|
||||||
|
WCHAR shortPath[MAX_PATH_CHARACTERS];
|
||||||
|
WCHAR longPath[MAX_PATH_CHARACTERS];
|
||||||
|
|
||||||
|
// copy the full path to a wide character buffer :
|
||||||
|
while (directory[0] != '\0')
|
||||||
|
shortPath[i++] = *directory++;
|
||||||
|
if (i > 0 && shortPath[i-1] != '\\') // add path separator only if it is missing
|
||||||
|
shortPath[i++] = '\\';
|
||||||
|
while (filename[0] != '\0')
|
||||||
|
shortPath[i++] = *filename++;
|
||||||
|
shortPath[i++] = 0;
|
||||||
|
if (GetLongPathNameW(shortPath, longPath, MAX_PATH_CHARACTERS) == 0)
|
||||||
|
return 0;
|
||||||
|
i = 0;
|
||||||
|
while (longPath[j] != 0)
|
||||||
|
{
|
||||||
|
if (longPath[j] == '\\')
|
||||||
|
i = 0;
|
||||||
|
else
|
||||||
|
filename_unicode[i++] = longPath[j];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
filename_unicode[i++] = 0;
|
||||||
|
return 1;
|
||||||
|
#elif defined(ENABLE_FILENAMES_ICONV)
|
||||||
|
char * input = (char *)filename;
|
||||||
|
size_t inbytesleft = strlen(filename);
|
||||||
|
char * output = (char *)filename_unicode;
|
||||||
|
size_t outbytesleft = (MAX_PATH_CHARACTERS - 1) * 2;
|
||||||
|
(void)directory; // unused
|
||||||
|
if (cd_utf16 != (iconv_t)-1)
|
||||||
|
{
|
||||||
|
size_t r = iconv(cd_utf16, &input, &inbytesleft, &output, &outbytesleft);
|
||||||
|
if (r != (size_t)-1)
|
||||||
|
{
|
||||||
|
output[0] = '\0';
|
||||||
|
output[1] = '\0';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
(void)filename_unicode;
|
||||||
|
(void)filename;
|
||||||
|
(void)directory;
|
||||||
|
// not implemented
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/// Lock file used to prevent several instances of grafx2 from harming each others' backups
|
/// Lock file used to prevent several instances of grafx2 from harming each others' backups
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HANDLE Lock_file_handle = INVALID_HANDLE_VALUE;
|
HANDLE Lock_file_handle = INVALID_HANDLE_VALUE;
|
||||||
|
|||||||
2
src/io.h
2
src/io.h
@ -154,6 +154,8 @@ void For_each_directory_entry(const char * directory_name, void * pdata, T_File_
|
|||||||
/// The point is simply to insert a PATH_SEPARATOR when needed.
|
/// The point is simply to insert a PATH_SEPARATOR when needed.
|
||||||
void Get_full_filename(char * output_name, const char * file_name, const char * directory_name);
|
void Get_full_filename(char * output_name, const char * file_name, const char * directory_name);
|
||||||
|
|
||||||
|
int Get_Unicode_Filename(word * filename_unicode, const char * filename, const char * directory);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Appends a file or directory name to an existing directory name.
|
/// Appends a file or directory name to an existing directory name.
|
||||||
/// As a special case, when the new item is equal to PARENT_DIR, this
|
/// As a special case, when the new item is equal to PARENT_DIR, this
|
||||||
|
|||||||
62
src/main.c
62
src/main.c
@ -592,68 +592,6 @@ CT_ASSERT(sizeof(T_Components)==3);
|
|||||||
// when sizeof(T_Palette) is not 768.
|
// when sizeof(T_Palette) is not 768.
|
||||||
CT_ASSERT(sizeof(T_Palette)==768);
|
CT_ASSERT(sizeof(T_Palette)==768);
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a file name to unicode characters
|
|
||||||
*
|
|
||||||
* @param filename_unicode the output buffer of MAX_PATH_CHARACTERS wide characters
|
|
||||||
* @param filename the input file name
|
|
||||||
* @param directory the input file directory
|
|
||||||
* @return 0 if no conversion has taken place.
|
|
||||||
* @return 1 if the unicode filename has been retrieved
|
|
||||||
*/
|
|
||||||
static int Get_Unicode_Filename(word * filename_unicode, const char * filename, const char * directory)
|
|
||||||
{
|
|
||||||
#if defined(WIN32)
|
|
||||||
int i = 0, j = 0;
|
|
||||||
WCHAR shortPath[MAX_PATH_CHARACTERS];
|
|
||||||
WCHAR longPath[MAX_PATH_CHARACTERS];
|
|
||||||
|
|
||||||
// copy the full path to a wide character buffer :
|
|
||||||
while (directory[0] != '\0')
|
|
||||||
shortPath[i++] = *directory++;
|
|
||||||
if (i > 0 && shortPath[i-1] != '\\') // add path separator only if it is missing
|
|
||||||
shortPath[i++] = '\\';
|
|
||||||
while (filename[0] != '\0')
|
|
||||||
shortPath[i++] = *filename++;
|
|
||||||
shortPath[i++] = 0;
|
|
||||||
if (GetLongPathNameW(shortPath, longPath, MAX_PATH_CHARACTERS) == 0)
|
|
||||||
return 0;
|
|
||||||
i = 0;
|
|
||||||
while (longPath[j] != 0)
|
|
||||||
{
|
|
||||||
if (longPath[j] == '\\')
|
|
||||||
i = 0;
|
|
||||||
else
|
|
||||||
filename_unicode[i++] = longPath[j];
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
filename_unicode[i++] = 0;
|
|
||||||
return 1;
|
|
||||||
#elif defined(ENABLE_FILENAMES_ICONV)
|
|
||||||
char * input = (char *)filename;
|
|
||||||
size_t inbytesleft = strlen(filename);
|
|
||||||
char * output = (char *)filename_unicode;
|
|
||||||
size_t outbytesleft = (MAX_PATH_CHARACTERS - 1) * 2;
|
|
||||||
(void)directory; // unused
|
|
||||||
if (cd_utf16 != (iconv_t)-1)
|
|
||||||
{
|
|
||||||
size_t r = iconv(cd_utf16, &input, &inbytesleft, &output, &outbytesleft);
|
|
||||||
if (r != (size_t)-1)
|
|
||||||
{
|
|
||||||
output[0] = '\0';
|
|
||||||
output[1] = '\0';
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
#else
|
|
||||||
(void)filename_unicode;
|
|
||||||
(void)filename;
|
|
||||||
(void)directory;
|
|
||||||
// not implemented
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the program.
|
* Initialize the program.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user