[easytag] Refactor querying of package installation path



commit eb48363cfab4b128d55f83ea5ab693416892412f
Author: David King <amigadave amigadave com>
Date:   Mon Feb 24 14:25:03 2014 +0000

    Refactor querying of package installation path

 src/win32/win32dep.c |   93 ++++++++++++++++++++++++--------------------------
 src/win32/win32dep.h |    4 +-
 2 files changed, 47 insertions(+), 50 deletions(-)
---
diff --git a/src/win32/win32dep.c b/src/win32/win32dep.c
index db7025f..d8d05d1 100644
--- a/src/win32/win32dep.c
+++ b/src/win32/win32dep.c
@@ -72,58 +72,55 @@ void str_replace_char (gchar *str, gchar in_char, gchar out_char);
  */
 
 /* Determine Easytag Paths during Runtime */
-const char *weasytag_install_dir(void) {
-       static gboolean initialized = FALSE;
-
-       if (!initialized) {
-               char *tmp = NULL;
-               if (G_WIN32_HAVE_WIDECHAR_API()) {
-                       wchar_t winstall_dir[MAXPATHLEN];
-                       if (GetModuleFileNameW(NULL, winstall_dir,
-                                       MAXPATHLEN) > 0) {
-                               tmp = g_utf16_to_utf8(winstall_dir, -1,
-                                       NULL, NULL, NULL);
-                       }
-               } else {
-                       gchar cpinstall_dir[MAXPATHLEN];
-                       if (GetModuleFileNameA(NULL, cpinstall_dir,
-                                       MAXPATHLEN) > 0) {
-                               tmp = g_locale_to_utf8(cpinstall_dir,
-                                       -1, NULL, NULL, NULL);
-                       }
-               }
-
-               if (tmp == NULL) {
-                       tmp = g_win32_error_message(GetLastError());
-            //Log_Print("GetModuleFileName error: %s", tmp);
-            g_print("GetModuleFileName error: %s", tmp);
-            g_print("\n");
-                       g_free(tmp);
-                       return NULL;
-               } else {
-                       install_dir = g_path_get_dirname(tmp);
-                       g_free(tmp);
-                       initialized = TRUE;
-               }
-       }
-
-       return install_dir;
+const gchar *
+weasytag_install_dir (void)
+{
+    static gboolean initialized = FALSE;
+
+    if (!initialized)
+    {
+        gchar *tmp;
+
+        tmp = g_win32_get_package_installation_directory_of_module (NULL);
+
+        if (tmp == NULL)
+        {
+            tmp = g_win32_error_message (GetLastError ());
+            g_debug ("GetModuleFileName error: %s", tmp);
+            g_free (tmp);
+            return NULL;
+        }
+        else
+        {
+            install_dir = tmp;
+            initialized = TRUE;
+        }
+    }
+
+    return install_dir;
 }
 
-const char *weasytag_locale_dir(void) {
-       static gboolean initialized = FALSE;
+const gchar *
+weasytag_locale_dir (void)
+{
+    static gboolean initialized = FALSE;
 
-       if (!initialized) {
-               const char *inst_dir = weasytag_install_dir();
-               if (inst_dir != NULL) {
-                       locale_dir = g_build_filename (inst_dir, "..", "lib", "locale", NULL);
-                       initialized = TRUE;
-               } else {
-                       return NULL;
-               }
-       }
+    if (!initialized)
+    {
+        const gchar *inst_dir = weasytag_install_dir ();
+
+        if (inst_dir != NULL)
+        {
+            locale_dir = g_build_filename (inst_dir, "lib", "locale", NULL);
+            initialized = TRUE;
+        }
+        else
+        {
+            return NULL;
+        }
+    }
 
-       return locale_dir;
+    return locale_dir;
 }
 
 /* Miscellaneous */
diff --git a/src/win32/win32dep.h b/src/win32/win32dep.h
index cdfda7d..59cf681 100644
--- a/src/win32/win32dep.h
+++ b/src/win32/win32dep.h
@@ -50,8 +50,8 @@ G_BEGIN_DECLS
 /* Windows helper functions */
 
 /* Determine EasyTAG paths */
-const char *weasytag_install_dir(void);
-const char *weasytag_locale_dir(void);
+const gchar * weasytag_install_dir (void);
+const gchar * weasytag_locale_dir (void);
 
 /* Misc */
 extern char *ET_Win32_Get_Audio_File_Player (void);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]