diff --git a/ChangeLog b/ChangeLog index 76a13c77f..358250474 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-04-16 Enrico Tröger + + * src/build.c, src/dialogs.c, src/document.c, src/utils.c: + Use g_stat() instead of stat() to prevent file read errors on Win32. + Prevent unnecessary filename encoding conversions on Win32. + + 2007-04-16 Nick Treleaven * src/filetypes.c: diff --git a/src/build.c b/src/build.c index 34b9babd4..2465fb3a7 100644 --- a/src/build.c +++ b/src/build.c @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef G_OS_UNIX # include @@ -153,7 +154,7 @@ static GPid build_view_tex_file(gint idx, gint mode) locale_filename = utils_get_locale_from_utf8(view_file); // check wether view_file exists - if (stat(locale_filename, &st) != 0) + if (g_stat(locale_filename, &st) != 0) { msgwin_status_add(_("Failed to view %s (make sure it is already compiled)"), view_file); utils_free_pointers(executable, view_file, locale_filename, NULL); @@ -354,9 +355,9 @@ static GPid build_link_file(gint idx) object_file = g_strdup_printf("%s.o", executable); // check wether object file (file.o) exists - if (stat(object_file, &st) == 0) + if (g_stat(object_file, &st) == 0) { // check wether src is newer than object file - if (stat(locale_filename, &st2) == 0) + if (g_stat(locale_filename, &st2) == 0) { if (st2.st_mtime > st.st_mtime) { @@ -546,7 +547,7 @@ static gchar *prepare_run_script(gint idx) } // check whether executable exists - if (stat(check_executable, &st) != 0) + if (g_stat(check_executable, &st) != 0) { utf8_check_executable = utils_get_utf8_from_locale(check_executable); msgwin_status_add(_("Failed to execute %s (make sure it is already built)"), diff --git a/src/dialogs.c b/src/dialogs.c index 01c4d18d0..a49687a38 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -39,6 +39,7 @@ #ifdef HAVE_SYS_TYPES_H # include #endif +#include #include "dialogs.h" @@ -674,8 +675,13 @@ void dialogs_show_file_properties(gint idx) #if defined(HAVE_SYS_STAT_H) && defined(TIME_WITH_SYS_TIME) && defined(HAVE_SYS_TYPES_H) +#ifdef G_OS_WIN32 + // don't try to convert the filename on Windows, it should be already in UTF8 + locale_filename = g_strdup(doc_list[idx].file_name); +#else locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name); - if (stat(locale_filename, &st) == 0) +#endif + if (g_stat(locale_filename, &st) == 0) { // first copy the returned string and the trim it, to not modify the static glibc string // g_strchomp() is used to remove trailing EOL chars, which are there for whatever reason diff --git a/src/document.c b/src/document.c index 22cf7d55f..6ab10bad6 100644 --- a/src/document.c +++ b/src/document.c @@ -48,6 +48,8 @@ #include #include +#include + #include "document.h" #include "support.h" #include "sciwrappers.h" @@ -609,19 +611,16 @@ static gboolean load_text_file(const gchar *locale_filename, const gchar *utf8_f filedata->bom = FALSE; filedata->readonly = FALSE; - if (stat(locale_filename, &st) != 0) + if (g_stat(locale_filename, &st) != 0) { msgwin_status_add(_("Could not open file %s (%s)"), utf8_filename, g_strerror(errno)); + dialogs_show_msgbox(0, "%s %s", utf8_filename, locale_filename); return FALSE; } filedata->mtime = st.st_mtime; -#ifdef G_OS_WIN32 - if (! g_file_get_contents(utf8_filename, &filedata->data, NULL, &err)) -#else if (! g_file_get_contents(locale_filename, &filedata->data, NULL, &err)) -#endif { msgwin_status_add(err->message); g_error_free(err); @@ -742,7 +741,11 @@ gint document_open_file(gint idx, const gchar *filename, gint pos, gboolean read // try to get the UTF-8 equivalent for the filename, fallback to filename if error locale_filename = g_strdup(filename); +#ifdef G_OS_WIN32 // on Win32 we only use locale_filename because it is already UTF8. I hope + utf8_filename = g_strdup(locale_filename); +#else utf8_filename = utils_get_utf8_from_locale(locale_filename); +#endif // if file is already open, switch to it and go idx = document_find_by_filename(utf8_filename, FALSE); @@ -913,9 +916,13 @@ static gboolean document_update_timestamp(gint idx) g_return_val_if_fail(DOC_IDX_VALID(idx), FALSE); +#ifdef G_OS_WIN32 + // don't try to convert the filename on Windows, it should be already in UTF8 + locale_filename = g_strdup(doc_list[idx].file_name); +#else locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name); - - if (stat(locale_filename, &st) != 0) +#endif + if (g_stat(locale_filename, &st) != 0) { msgwin_status_add(_("Could not open file %s (%s)"), doc_list[idx].file_name, g_strerror(errno)); diff --git a/src/utils.c b/src/utils.c index 8a6bd2167..1cb888eec 100644 --- a/src/utils.c +++ b/src/utils.c @@ -332,8 +332,13 @@ gboolean utils_check_disk_status(gint idx, gboolean force) if (! force && doc_list[idx].last_check > (t - GEANY_CHECK_FILE_DELAY)) return FALSE; +#ifdef G_OS_WIN32 + // don't try to convert the filename on Windows, it should be already in UTF8 + locale_filename = g_strdup(doc_list[idx].file_name); +#else locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name); - if (stat(locale_filename, &st) != 0) +#endif + if (g_stat(locale_filename, &st) != 0) { // TODO: warn user file on disk is missing } @@ -1432,17 +1437,29 @@ gboolean utils_wrap_string(gchar *string, gint wrapstart) gchar *utils_get_locale_from_utf8(const gchar *utf8_text) { +#ifdef G_OS_WIN32 + // just do nothing on Windows platforms, this ifdef is just to prevent unwanted conversions + // which would result in wrongly converted strings + return g_strdup(utf8_text); +#else gchar *locale_text = g_locale_from_utf8(utf8_text, -1, NULL, NULL, NULL); if (locale_text == NULL) locale_text = g_strdup(utf8_text); return locale_text; +#endif } gchar *utils_get_utf8_from_locale(const gchar *locale_text) { +#ifdef G_OS_WIN32 + // just do nothing on Windows platforms, this ifdef is just to prevent unwanted conversions + // which would result in wrongly converted strings + return g_strdup(locale_text); +#else gchar *utf8_text = g_locale_to_utf8(locale_text, -1, NULL, NULL, NULL); if (utf8_text == NULL) utf8_text = g_strdup(locale_text); return utf8_text; +#endif }