Skip to content

Commit

Permalink
Fix crash when trying to start Synfig installed into path containing …
Browse files Browse the repository at this point in the history
…with non-latin characters. Most common for Windows users.
  • Loading branch information
morevnaproject committed Mar 14, 2016
1 parent 526198a commit 0ad6ad3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 25 deletions.
1 change: 1 addition & 0 deletions ETL/ETL/_stringf.h
Expand Up @@ -291,6 +291,7 @@ inline std::string
current_working_directory()
{
char dir[256];
// TODO: current_working_directory() should use Glib::locale_to_utf8()
std::string ret(getcwd(dir,sizeof(dir)));
return ret;
}
Expand Down
17 changes: 7 additions & 10 deletions synfig-core/src/synfig/main.cpp
Expand Up @@ -159,11 +159,11 @@ static void broken_pipe_signal (int /*sig*/) {

bool retrieve_modules_to_load(String filename,std::list<String> &modules_to_load)
{
std::ifstream file(filename.c_str());
std::ifstream file(Glib::locale_from_utf8(filename).c_str());

if(!file)
{
// warning("Cannot open "+filename);
synfig::warning("Cannot open "+filename);
return false;
}

Expand Down Expand Up @@ -204,11 +204,8 @@ synfig::Main::Main(const synfig::String& basepath,ProgressCallback *cb):
#ifdef ENABLE_NLS
String locale_dir;
locale_dir = locale_path;
#ifdef _WIN32
locale_dir = Glib::locale_from_utf8(locale_dir);
#endif

bindtextdomain("synfig", locale_path.c_str() );
bindtextdomain("synfig", Glib::locale_from_utf8(locale_path).c_str() );
bind_textdomain_codeset("synfig", "UTF-8");
#endif

Expand Down Expand Up @@ -342,15 +339,12 @@ synfig::Main::Main(const synfig::String& basepath,ProgressCallback *cb):
if(getenv("HOME"))
locations.push_back(strprintf("%s/Library/Synfig/%s", getenv("HOME"), MODULE_LIST_FILENAME));
#endif
#ifdef _WIN32
locations.push_back("C:\\Program Files\\Synfig\\etc\\" MODULE_LIST_FILENAME);
#endif
}

for(i=0;i<locations.size();i++)
if(retrieve_modules_to_load(locations[i],modules_to_load))
{
synfig::info(_("Loading modules from %s"), locations[i].c_str());
synfig::info(_("Loading modules from %s"), Glib::locale_from_utf8(locations[i]).c_str());
if(cb)cb->task(strprintf(_("Loading modules from %s"),locations[i].c_str()));
break;
}
Expand Down Expand Up @@ -626,5 +620,8 @@ synfig::get_binary_path(const String &fallback_path)
// (usually should come from argv[0])
result = etl::absolute_path(fallback_path);
}

result = Glib::locale_to_utf8(result);

return result;
}
6 changes: 5 additions & 1 deletion synfig-core/src/synfig/module.cpp
Expand Up @@ -36,6 +36,7 @@
#include "general.h"
#include <synfig/localization.h>
#include "type.h"
#include <glibmm.h>

#ifndef USE_CF_BUNDLES
#include <ltdl.h>
Expand Down Expand Up @@ -73,7 +74,10 @@ Module::subsys_init(const String &prefix)
lt_dladdsearchdir(".");
if(getenv("HOME"))
lt_dladdsearchdir(strprintf("%s/.local/share/synfig/modules", getenv("HOME")).c_str());
lt_dladdsearchdir((prefix+"/lib/synfig/modules").c_str());
lt_dladdsearchdir((Glib::locale_from_utf8(prefix) + \
ETL_DIRECTORY_SEPARATOR + "lib" + \
ETL_DIRECTORY_SEPARATOR + "synfig" + \
ETL_DIRECTORY_SEPARATOR + "modules" ).c_str());
#ifdef LIBDIR
lt_dladdsearchdir(LIBDIR"/synfig/modules");
#endif
Expand Down
5 changes: 1 addition & 4 deletions synfig-core/src/tool/main.cpp
Expand Up @@ -94,10 +94,7 @@ int main(int argc, char* argv[])
boost::filesystem::path locale_path =
binary_path.parent_path().parent_path();
locale_path = locale_path/"share"/"locale";
#ifdef _WIN32
locale_path = Glib::locale_from_utf8(locale_path.string());
#endif
bindtextdomain("synfig", locale_path.string().c_str() );
bindtextdomain("synfig", Glib::locale_from_utf8(locale_path.string()).c_str() );
bind_textdomain_codeset("synfig", "UTF-8");
textdomain("synfig");
#endif
Expand Down
7 changes: 1 addition & 6 deletions synfig-studio/src/gui/main.cpp
Expand Up @@ -78,16 +78,11 @@ int main(int argc, char **argv)
#ifdef ENABLE_NLS
String locale_dir;
locale_dir = etl::dirname(etl::dirname(binary_path))+ETL_DIRECTORY_SEPARATOR+"share"+ETL_DIRECTORY_SEPARATOR+"locale";
#ifdef _WIN32
locale_dir = Glib::locale_from_utf8(locale_dir);
#endif

setlocale(LC_ALL, "");
bindtextdomain(GETTEXT_PACKAGE, locale_dir.c_str() );
bindtextdomain(GETTEXT_PACKAGE, Glib::locale_from_utf8(locale_dir).c_str() );
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
#endif

{
SmartFILE file(IPC::make_connection());
if(file)
Expand Down
5 changes: 1 addition & 4 deletions synfig-studio/src/synfigapp/main.cpp
Expand Up @@ -118,11 +118,8 @@ synfigapp::Main::Main(const synfig::String &basepath, synfig::ProgressCallback *
#ifdef ENABLE_NLS
String locale_dir;
locale_dir = etl::dirname(basepath)+ETL_DIRECTORY_SEPARATOR+"share"+ETL_DIRECTORY_SEPARATOR+"locale";
#ifdef _WIN32
locale_dir = Glib::locale_from_utf8(locale_dir);
#endif

bindtextdomain(GETTEXT_PACKAGE, locale_dir.c_str() );
bindtextdomain(GETTEXT_PACKAGE, Glib::locale_from_utf8(locale_dir).c_str() );
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
#endif

Expand Down

0 comments on commit 0ad6ad3

Please sign in to comment.