From cc437409aa329e884d2a5c2e1367bfdff02779bc Mon Sep 17 00:00:00 2001 From: Oliver Duis Date: Tue, 11 Oct 2011 17:14:37 +0200 Subject: [PATCH] Fixed crash on start on some Windows configurations see issue 1022 --- rtengine/safegtk.cc | 20 ++++++++++++++++++++ rtengine/safegtk.h | 2 ++ rtgui/editorpanel.cc | 2 +- rtgui/filecatalog.cc | 2 +- rtgui/placesbrowser.cc | 2 +- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/rtengine/safegtk.cc b/rtengine/safegtk.cc index fcd6117d2..e90ee7b6c 100644 --- a/rtengine/safegtk.cc +++ b/rtengine/safegtk.cc @@ -25,6 +25,7 @@ #include #ifdef WIN32 #include +#include #else #include #endif @@ -351,3 +352,22 @@ int safe_g_mkdir_with_parents(const Glib::ustring& dirName, int mode) { return ::g_mkdir_with_parents(dirName.c_str(), mode); } + +Glib::ustring safe_get_user_picture_dir() { + #ifdef WIN32 + + // get_user_special_dir/pictures crashes on some Windows configurations. + // so we use the safe native functions here + WCHAR pathW[MAX_PATH]={0}; + if (SHGetSpecialFolderPathW(NULL,pathW,CSIDL_MYPICTURES,false)) { + char pathA[MAX_PATH]; + WideCharToMultiByte(CP_UTF8,0,pathW,-1,pathA,MAX_PATH,0,0); + return Glib::ustring(pathA); + } else return Glib::ustring("C:\\"); + + #else + + return Glib::get_user_special_dir (G_USER_DIRECTORY_PICTURES); + + #endif +} \ No newline at end of file diff --git a/rtengine/safegtk.h b/rtengine/safegtk.h index 010044d59..831f73035 100644 --- a/rtengine/safegtk.h +++ b/rtengine/safegtk.h @@ -39,4 +39,6 @@ bool safe_file_test (const Glib::ustring& filename, Glib::FileTest test); int safe_g_remove(const Glib::ustring& filename); int safe_g_rename(const Glib::ustring& oldFilename, const Glib::ustring& newFilename); int safe_g_mkdir_with_parents(const Glib::ustring& dirName, int mode); + +Glib::ustring safe_get_user_picture_dir(); #endif diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index 2948ec136..993b33eba 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -258,7 +258,7 @@ EditorPanel::EditorPanel (FilePanel* filePanel) if (safe_file_test (options.lastSaveAsPath, Glib::FILE_TEST_IS_DIR)) saveAsDialog = new SaveAsDialog (options.lastSaveAsPath); else - saveAsDialog = new SaveAsDialog (Glib::get_user_special_dir (G_USER_DIRECTORY_PICTURES)); + saveAsDialog = new SaveAsDialog (safe_get_user_picture_dir()); saveAsDialog->set_default_size (options.saveAsDialogWidth, options.saveAsDialogHeight); diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 6cad42963..3841771f2 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -1475,7 +1475,7 @@ void FileCatalog::buttonBrowsePathPressed () { } else if (FirstChar=="!"){ // user's pictures directory //DecodedPathPrefix = g_get_user_special_dir(G_USER_DIRECTORY_PICTURES); - DecodedPathPrefix = Glib::get_user_special_dir (G_USER_DIRECTORY_PICTURES); + DecodedPathPrefix = safe_get_user_picture_dir(); } if (DecodedPathPrefix!=""){ diff --git a/rtgui/placesbrowser.cc b/rtgui/placesbrowser.cc index 8e6eebec7..51d12f5f0 100644 --- a/rtgui/placesbrowser.cc +++ b/rtgui/placesbrowser.cc @@ -102,7 +102,7 @@ void PlacesBrowser::refreshPlacesList () { } // append pictures directory - hfile = Gio::File::create_for_path (Glib::get_user_special_dir (G_USER_DIRECTORY_PICTURES)); + hfile = Gio::File::create_for_path (safe_get_user_picture_dir()); if (hfile && hfile->query_exists()) { try { Glib::RefPtr info = safe_query_file_info (hfile);