Solving issue #706: Files containing non-Latin characters won't open when supplied as command line argument
This commit is contained in:
parent
72aa44858b
commit
6d1d3f761e
@ -132,6 +132,35 @@ void safe_build_subdir_list (Glib::RefPtr<Gio::File> &dir, std::vector<Glib::ust
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For an unknown reason, Glib::filename_to_utf8 doesn't work on Windows, so we're using
|
||||||
|
* Glib::filename_to_utf8 for Linux/Apple and Glib::locale_to_utf8 for Windows
|
||||||
|
*/
|
||||||
|
Glib::ustring safe_filename_to_utf8 (const std::string& src)
|
||||||
|
{
|
||||||
|
Glib::ustring utf8_str;
|
||||||
|
#ifdef _WIN32
|
||||||
|
#ifdef GLIBMM_EXCEPTIONS_ENABLED
|
||||||
|
try {
|
||||||
|
utf8_str = Glib::locale_to_utf8(src);
|
||||||
|
}
|
||||||
|
catch (const Glib::ConvertError& e) {
|
||||||
|
utf8_str = Glib::convert_with_fallback(src, "UTF8", "LATIN1","?");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
std::auto_ptr<Glib::Error> error;
|
||||||
|
utf8_str = locale_to_utf8(src, error);
|
||||||
|
if (error.get())
|
||||||
|
utf8_str = Glib::convert_with_fallback(src, "UTF8", "LATIN1","?", error);
|
||||||
|
}
|
||||||
|
#endif //GLIBMM_EXCEPTIONS_ENABLED
|
||||||
|
#else
|
||||||
|
utf8_str = Glib::filename_to_utf8(src);
|
||||||
|
#endif
|
||||||
|
return utf8_str;
|
||||||
|
}
|
||||||
|
|
||||||
Glib::ustring safe_locale_to_utf8 (const std::string& src)
|
Glib::ustring safe_locale_to_utf8 (const std::string& src)
|
||||||
{
|
{
|
||||||
Glib::ustring utf8_str;
|
Glib::ustring utf8_str;
|
||||||
|
@ -26,6 +26,7 @@ void safe_build_subdir_list (Glib::RefPtr<Gio::File> &dir, std::vector<Glib::ust
|
|||||||
bool safe_spawn_command_line_async (const Glib::ustring& cmd_utf8);
|
bool safe_spawn_command_line_async (const Glib::ustring& cmd_utf8);
|
||||||
bool safe_spawn_command_line_sync (const Glib::ustring& cmd_utf8);
|
bool safe_spawn_command_line_sync (const Glib::ustring& cmd_utf8);
|
||||||
|
|
||||||
|
Glib::ustring safe_filename_to_utf8 (const std::string& src);
|
||||||
Glib::ustring safe_locale_to_utf8 (const std::string& src); // from rtengine
|
Glib::ustring safe_locale_to_utf8 (const std::string& src); // from rtengine
|
||||||
std::string safe_locale_from_utf8 (const Glib::ustring& utf8_str);
|
std::string safe_locale_from_utf8 (const Glib::ustring& utf8_str);
|
||||||
std::string safe_filename_from_utf8 (const Glib::ustring& utf8_str);
|
std::string safe_filename_from_utf8 (const Glib::ustring& utf8_str);
|
||||||
|
@ -157,7 +157,7 @@ int processLineParams( int argc, char **argv )
|
|||||||
case 'o': // outputfile or dir
|
case 'o': // outputfile or dir
|
||||||
if( iArg+1 <argc ){
|
if( iArg+1 <argc ){
|
||||||
iArg++;
|
iArg++;
|
||||||
outputPath = safe_locale_to_utf8 (argv[iArg]);
|
outputPath = safe_filename_to_utf8 (argv[iArg]);
|
||||||
if( safe_file_test (outputPath, Glib::FILE_TEST_IS_DIR))
|
if( safe_file_test (outputPath, Glib::FILE_TEST_IS_DIR))
|
||||||
outputDirectory=true;
|
outputDirectory=true;
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ int processLineParams( int argc, char **argv )
|
|||||||
case 'p': // processing parameters for all inputs
|
case 'p': // processing parameters for all inputs
|
||||||
if( iArg+1 <argc ){
|
if( iArg+1 <argc ){
|
||||||
iArg++;
|
iArg++;
|
||||||
processingParams = safe_locale_to_utf8 ( argv[iArg] );
|
processingParams = safe_filename_to_utf8 ( argv[iArg] );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
@ -191,11 +191,11 @@ int processLineParams( int argc, char **argv )
|
|||||||
case 'c': // MUST be last option
|
case 'c': // MUST be last option
|
||||||
while( iArg+1 <argc ){
|
while( iArg+1 <argc ){
|
||||||
iArg++;
|
iArg++;
|
||||||
if( !safe_file_test( safe_locale_to_utf8(argv[iArg]), Glib::FILE_TEST_EXISTS )){
|
if( !safe_file_test( safe_filename_to_utf8(argv[iArg]), Glib::FILE_TEST_EXISTS )){
|
||||||
std::cerr << argv[iArg] << " doesn't exist."<< std::endl;
|
std::cerr << argv[iArg] << " doesn't exist."<< std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if( safe_file_test( safe_locale_to_utf8(argv[iArg]), Glib::FILE_TEST_IS_DIR )){
|
if( safe_file_test( safe_filename_to_utf8(argv[iArg]), Glib::FILE_TEST_IS_DIR )){
|
||||||
isDirectory = true;
|
isDirectory = true;
|
||||||
std::vector<Glib::ustring> names;
|
std::vector<Glib::ustring> names;
|
||||||
Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path ( argv[iArg] );
|
Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path ( argv[iArg] );
|
||||||
@ -213,7 +213,7 @@ int processLineParams( int argc, char **argv )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
inputFiles.push_back( safe_locale_to_utf8 (argv[iArg]) );
|
inputFiles.push_back( safe_filename_to_utf8 (argv[iArg]) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -242,7 +242,7 @@ int processLineParams( int argc, char **argv )
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
argv1 = safe_locale_to_utf8 ( argv[iArg] );
|
argv1 = safe_filename_to_utf8 ( argv[iArg] );
|
||||||
if( outputDirectory ){
|
if( outputDirectory ){
|
||||||
options.savePathFolder = outputPath;
|
options.savePathFolder = outputPath;
|
||||||
options.saveUsePathTemplate = false;
|
options.saveUsePathTemplate = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user