From b74a903d5ce2bfcc0b7cca07e366e8e2b80d9d08 Mon Sep 17 00:00:00 2001 From: hiro Date: Mon, 15 Jan 2007 05:04:21 +0000 Subject: vi Ch git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1478 ee746299-78ed-0310-b773-934348b2243d --- libsylph/utils.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'libsylph/utils.c') diff --git a/libsylph/utils.c b/libsylph/utils.c index 677cffc3..5e3ba645 100644 --- a/libsylph/utils.c +++ b/libsylph/utils.c @@ -1829,6 +1829,28 @@ const gchar *get_startup_dir(void) return startup_dir; } +#ifdef G_OS_WIN32 +static gchar *get_win32_special_folder_path(gint nfolder) +{ + gchar *folder = NULL; + HRESULT hr; + + if (G_WIN32_HAVE_WIDECHAR_API()) { + wchar_t path[MAX_PATH + 1]; + hr = SHGetFolderPathW(NULL, nfolder, NULL, 0, path); + if (hr == S_OK) + folder = g_utf16_to_utf8(path, -1, NULL, NULL, NULL); + } else { + gchar path[MAX_PATH + 1]; + hr = SHGetFolderPathA(NULL, nfolder, NULL, 0, path); + if (hr == S_OK) + folder = g_locale_to_utf8(path, -1, NULL, NULL, NULL); + } + + return folder; +} +#endif + const gchar *get_home_dir(void) { #ifdef G_OS_WIN32 @@ -1853,23 +1875,7 @@ const gchar *get_document_dir(void) HRESULT hr; if (!document_dir) { - if (G_WIN32_HAVE_WIDECHAR_API()) { - wchar_t path[MAX_PATH + 1]; - hr = SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, - path); - if (hr == S_OK) { - document_dir = g_utf16_to_utf8 - (path, -1, NULL, NULL, NULL); - } - } else { - gchar path[MAX_PATH + 1]; - hr = SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, 0, - path); - if (hr == S_OK) { - document_dir = g_locale_to_utf8 - (path, -1, NULL, NULL, NULL); - } - } + document_dir = get_win32_special_folder_path(CSIDL_PERSONAL); if (!document_dir) document_dir = get_home_dir(); } @@ -1884,15 +1890,16 @@ const gchar *get_rc_dir(void) { if (!rc_dir) { #ifdef G_OS_WIN32 - const gchar *appdata; + gchar *appdata; - appdata = g_getenv("APPDATA"); + appdata = get_win32_special_folder_path(CSIDL_APPDATA); if (appdata) rc_dir = g_strconcat(appdata, G_DIR_SEPARATOR_S, RC_DIR, NULL); else rc_dir = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, RC_DIR, NULL); + g_free(appdata); #else rc_dir = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, RC_DIR, NULL); -- cgit v1.2.3