aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/win32
diff options
context:
space:
mode:
authorGravatar Alex Bennee <alex@bennee.com>2010-07-14 16:04:37 +0100
committerGravatar Alex Bennee <alex@bennee.com>2010-07-14 16:04:37 +0100
commit4103b09671b40013e10cab4d556fd65465fa800f (patch)
tree8be548ec2b569d858f0b2e4f9152d0b47f4684c9 /src/win32
parenta3e202820fd12e3c368c9ed2446740e9b1d16fd7 (diff)
EasyTag 2.1.6
Diffstat (limited to 'src/win32')
-rwxr-xr-xsrc/win32/gtkwin32dep.c236
-rwxr-xr-xsrc/win32/gtkwin32dep.h43
-rwxr-xr-xsrc/win32/win32dep.c648
-rwxr-xr-xsrc/win32/win32dep.h51
-rwxr-xr-xsrc/win32/win_easytag.c147
5 files changed, 789 insertions, 336 deletions
diff --git a/src/win32/gtkwin32dep.c b/src/win32/gtkwin32dep.c
new file mode 100755
index 0000000..af5d73b
--- /dev/null
+++ b/src/win32/gtkwin32dep.c
@@ -0,0 +1,236 @@
+/*
+ * easytag
+ *
+ * File: win32dep.c
+ * Date: June, 2002
+ * Description: Windows dependant code for Easytag
+ * this code if largely taken from win32 Gaim and Pidgin
+ *
+ * Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ */
+#include <windows.h>
+#include <io.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <winuser.h>
+
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkwin32.h>
+
+#include "resource.h"
+
+#include <libintl.h>
+
+#include "win32dep.h"
+//#include "../log.h"
+
+
+
+/*
+ * GLOBALS
+ */
+HINSTANCE exe_hInstance = 0;
+HINSTANCE dll_hInstance = 0;
+HWND messagewin_hwnd;
+
+typedef BOOL (CALLBACK* LPFNFLASHWINDOWEX)(PFLASHWINFO);
+static LPFNFLASHWINDOWEX MyFlashWindowEx = NULL;
+
+/*
+ * PUBLIC CODE
+ */
+
+HINSTANCE wineasytag_exe_hinstance (void)
+{
+ return exe_hInstance;
+}
+
+HINSTANCE wineasytag_dll_hinstance(void) {
+ return dll_hInstance;
+}
+
+void wineasytag_shell_execute(const char *target, const char *verb, const char *clazz) {
+
+ g_return_if_fail(target != NULL);
+ g_return_if_fail(verb != NULL);
+
+ if (G_WIN32_HAVE_WIDECHAR_API()) {
+ SHELLEXECUTEINFOW wsinfo;
+ wchar_t *w_uri, *w_verb, *w_clazz = NULL;
+
+ w_uri = g_utf8_to_utf16(target, -1, NULL, NULL, NULL);
+ w_verb = g_utf8_to_utf16(verb, -1, NULL, NULL, NULL);
+
+ memset(&wsinfo, 0, sizeof(wsinfo));
+ wsinfo.cbSize = sizeof(wsinfo);
+ wsinfo.lpVerb = w_verb;
+ wsinfo.lpFile = w_uri;
+ wsinfo.nShow = SW_SHOWNORMAL;
+ if (clazz != NULL) {
+ w_clazz = g_utf8_to_utf16(clazz, -1, NULL, NULL, NULL);
+ wsinfo.fMask |= SEE_MASK_CLASSNAME;
+ wsinfo.lpClass = w_clazz;
+ }
+
+ if(!ShellExecuteExW(&wsinfo))
+ g_print("Error opening URI: %s error: %d\n",
+ target, (int) wsinfo.hInstApp);
+
+ g_free(w_uri);
+ g_free(w_verb);
+ g_free(w_clazz);
+ } else {
+ SHELLEXECUTEINFOA sinfo;
+ gchar *locale_uri;
+
+ locale_uri = g_locale_from_utf8(target, -1, NULL, NULL, NULL);
+
+ memset(&sinfo, 0, sizeof(sinfo));
+ sinfo.cbSize = sizeof(sinfo);
+ sinfo.lpVerb = verb;
+ sinfo.lpFile = locale_uri;
+ sinfo.nShow = SW_SHOWNORMAL;
+ if (clazz != NULL) {
+ sinfo.fMask |= SEE_MASK_CLASSNAME;
+ sinfo.lpClass = clazz;
+ }
+
+ if(!ShellExecuteExA(&sinfo))
+ g_print("Error opening URI: %s error: %d\n",
+ target, (int) sinfo.hInstApp);
+
+ g_free(locale_uri);
+ }
+
+}
+
+void wineasytag_notify_uri(const char *uri) {
+ /* We'll allow whatever URI schemes are supported by the
+ * default http browser.
+ */
+ wineasytag_shell_execute(uri, "open", "http");
+}
+
+/*
+#define EASYTAG_WM_FOCUS_REQUEST (WM_APP + 13)
+#define EASYTAG_WM_PROTOCOL_HANDLE (WM_APP + 14)
+
+static LRESULT CALLBACK message_window_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
+
+ if (msg == PIDGIN_WM_FOCUS_REQUEST) {
+ g_print("Got external Buddy List focus request.");
+ purple_blist_set_visible(TRUE);
+ return TRUE;
+ } else if (msg == PIDGIN_WM_PROTOCOL_HANDLE) {
+ char *proto_msg = (char *) lparam;
+ g_print("Got protocol handler request: %s\n", proto_msg ? proto_msg : "");
+ purple_got_protocol_handler_uri(proto_msg);
+ return TRUE;
+ }
+
+ return DefWindowProc(hwnd, msg, wparam, lparam);
+}*/
+
+/*static HWND wineasytag_message_window_init(void) {
+ HWND win_hwnd;
+ WNDCLASSEX wcx;
+ LPCTSTR wname;
+
+ wname = TEXT("WinpidginMsgWinCls");
+
+ wcx.cbSize = sizeof(wcx);
+ wcx.style = 0;
+ wcx.lpfnWndProc = message_window_handler;
+ wcx.cbClsExtra = 0;
+ wcx.cbWndExtra = 0;
+ wcx.hInstance = wineasytag_exe_hinstance();
+ wcx.hIcon = NULL;
+ wcx.hCursor = NULL;
+ wcx.hbrBackground = NULL;
+ wcx.lpszMenuName = NULL;
+ wcx.lpszClassName = wname;
+ wcx.hIconSm = NULL;
+
+ RegisterClassEx(&wcx);
+
+ // Create the window
+ if(!(win_hwnd = CreateWindow(wname, TEXT("WinpidginMsgWin"), 0, 0, 0, 0, 0,
+ NULL, NULL, winpidgin_exe_hinstance(), 0))) {
+
+ g_print("Unable to create message window.\n");
+ return NULL;
+ }
+
+ return win_hwnd;
+}*/
+
+void wineasytag_init(HINSTANCE hint) {
+
+ g_print("wineasytag_init start\n");
+
+ exe_hInstance = hint;
+
+ /* IdleTracker Initialization */
+ ////if(!wineasytag_set_idlehooks())
+ //// g_print("Failed to initialize idle tracker\n");
+
+ ////wineasytag_spell_init();
+ g_print("GTK+ :%u.%u.%u\n",
+ gtk_major_version, gtk_minor_version, gtk_micro_version);
+
+ ////messagewin_hwnd = wineasytag_message_window_init();
+
+ MyFlashWindowEx = (LPFNFLASHWINDOWEX) weasytag_find_and_loadproc("user32.dll", "FlashWindowEx");
+
+ g_print("wineasytag_init end\n");
+}
+
+void wineasytag_post_init(void) {
+
+ //purple_prefs_add_none(PIDGIN_PREFS_ROOT "/win32");
+ //purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/win32/blink_im", TRUE);
+
+ //purple_signal_connect(pidgin_conversations_get_handle(),
+ // "displaying-im-msg", &gtkwin32_handle, PURPLE_CALLBACK(wineasytag_conv_im_blink),
+ // NULL);
+
+}
+
+/* Windows Cleanup */
+
+void wineasytag_cleanup(void) {
+ g_print("wineasytag_cleanup\n");
+
+ if(messagewin_hwnd)
+ DestroyWindow(messagewin_hwnd);
+
+ /* Idle tracker cleanup */
+ ////wineasytag_remove_idlehooks();
+
+}
+
+/* DLL initializer */
+/* suppress gcc "no previous prototype" warning */
+/*BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
+ dll_hInstance = hinstDLL;
+ return TRUE;
+}*/
+
diff --git a/src/win32/gtkwin32dep.h b/src/win32/gtkwin32dep.h
new file mode 100755
index 0000000..71d49a2
--- /dev/null
+++ b/src/win32/gtkwin32dep.h
@@ -0,0 +1,43 @@
+/*
+ * gtkwin32dep.h UI Win32 Specific Functionality
+ * easytag
+ *
+ * File: win32dep.h
+ *
+ * Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ */
+#ifndef _GTKWIN32DEP_H_
+#define _GTKWIN32DEP_H_
+#include <windows.h>
+#include <gtk/gtk.h>
+
+HINSTANCE wineasytag_dll_hinstance(void);
+HINSTANCE wineasytag_exe_hinstance(void);
+
+
+/* Misc */
+void wineasytag_notify_uri(const char *uri);
+void wineasytag_shell_execute(const char *target, const char *verb, const char *clazz);
+
+/* init / cleanup */
+void wineasytag_init(HINSTANCE);
+void wineasytag_post_init(void);
+void wineasytag_cleanup(void);
+
+#endif /* _GTKWIN32DEP_H_ */
+
diff --git a/src/win32/win32dep.c b/src/win32/win32dep.c
index cccde13..35e32d6 100755
--- a/src/win32/win32dep.c
+++ b/src/win32/win32dep.c
@@ -4,7 +4,7 @@
* File: win32dep.c
* Date: June, 2002
* Description: Windows dependant code for Easytag
- * this code if largely taken from win32 gaim
+ * this code if largely taken from win32 Gaim and Purple
*
* Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com>
*
@@ -28,7 +28,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <winuser.h>
-#include <shlobj.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -36,12 +35,8 @@
#include <gtk/gtk.h>
#include <glib.h>
-#if GLIB_CHECK_VERSION(2,6,0)
-# include <glib/gstdio.h>
-#else
-# define g_fopen fopen
-# define g_unlink unlink
-#endif
+#include <glib/gstdio.h>
+
#include <gdk/gdkwin32.h>
#include "resource.h"
@@ -65,6 +60,7 @@
typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHA)(HWND, int, HANDLE, DWORD, LPSTR);
typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHW)(HWND, int, HANDLE, DWORD, LPWSTR);
+// Defined also in "#include <shlobj.h>"
typedef enum
{
SHGFP_TYPE_CURRENT = 0, // current value for user, verify it exists
@@ -74,44 +70,22 @@ typedef enum
/*
* LOCALS
*/
-static char app_data_dir[MAX_PATH + 1] = "C:";
-static char install_dir[MAXPATHLEN];
-static char lib_dir[MAXPATHLEN];
-static char locale_dir[MAXPATHLEN];
-
-static void str_replace_char (gchar *str, gchar in_char, gchar out_char);
+static char *app_data_dir = NULL, *install_dir = NULL,
+ *lib_dir = NULL, *locale_dir = NULL;
-/*
- * GLOBALS
- */
-HINSTANCE ET_exe_hInstance = 0;
-HINSTANCE ET_dll_hInstance = 0;
-
-/*
- * PROTOS
- */
-LPFNSHGETFOLDERPATHA MySHGetFolderPathA = NULL;
-LPFNSHGETFOLDERPATHW MySHGetFolderPathW = NULL;
+static HINSTANCE libeasytagdll_hInstance = 0;
-FARPROC ET_Win32_Find_And_Loadproc (char*, char*);
-char* ET_Win32_Data_Dir (void);
/*
* PUBLIC CODE
*/
-HINSTANCE ET_Win32_Hinstance (void)
-{
- return ET_exe_hInstance;
-}
-
/* Escape windows dir separators. This is needed when paths are saved,
and on being read back have their '\' chars used as an escape char.
Returns an allocated string which needs to be freed.
*/
-char *ET_Win32_Escape_Dirsep (const char *filename)
-{
+char *weasytag_escape_dirsep(const char *filename) {
int sepcount = 0;
const char *tmp = filename;
char *ret;
@@ -136,49 +110,18 @@ char *ET_Win32_Escape_Dirsep (const char *filename)
return ret;
}
-/* this is used by libmp4v2 : what is it doing here you think ? well...search! */
-int gettimeofday (struct timeval *t, void *foo)
-{
- struct _timeb temp;
-
- if (t != 0) {
- _ftime(&temp);
- t->tv_sec = temp.time; /* seconds since 1-1-1970 */
- t->tv_usec = temp.millitm * 1000; /* microseconds */
- }
- return (0);
-}
-
-
-/* emulate the unix function */
-int mkstemp (char *template)
-{
- int fd = -1;
-
- char *str = mktemp(template);
- if(str != NULL)
- {
- fd = open(str, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
- }
-
- return fd;
-}
-
/* Determine whether the specified dll contains the specified procedure.
If so, load it (if not already loaded). */
-FARPROC ET_Win32_Find_And_Loadproc (char *dllname, char *procedure)
-{
+FARPROC weasytag_find_and_loadproc(const char *dllname, const char *procedure) {
HMODULE hmod;
BOOL did_load = FALSE;
FARPROC proc = 0;
- if(!(hmod=GetModuleHandle(dllname)))
- {
- //Log_Print(_("DLL '%s' not found. Try loading it..."), dllname);
- g_printf(_("DLL '%s' not found. Try loading it..."), dllname);
+ if(!(hmod = GetModuleHandle(dllname))) {
+ //Log_Print(_("DLL '%s' not already loaded. Try loading it..."), dllname);
+ g_printf(_("DLL '%s' not already loaded. Try loading it..."), dllname);
g_print("\n");
- if(!(hmod = LoadLibrary(dllname)))
- {
+ if(!(hmod = LoadLibrary(dllname))) {
//Log_Print(_("DLL '%s' could not be loaded"), dllname);
g_print(_("DLL '%s' could not be loaded"), dllname);
g_print("\n");
@@ -188,20 +131,17 @@ FARPROC ET_Win32_Find_And_Loadproc (char *dllname, char *procedure)
did_load = TRUE;
}
- if((proc=GetProcAddress(hmod, procedure)))
- {
+ if((proc = GetProcAddress(hmod, procedure))) {
//Log_Print(_("This version of '%s' contains '%s'"), dllname, procedure);
g_print(_("This version of '%s' contains '%s'"), dllname, procedure);
g_print("\n");
return proc;
}
- else
- {
+ else {
//Log_Print(_("Function '%s' not found in dll '%s'"), procedure, dllname);
g_print(_("Function '%s' not found in dll '%s'"), procedure, dllname);
g_print("\n");
- if(did_load)
- {
+ if(did_load) {
/* unload dll */
FreeLibrary(hmod);
}
@@ -211,122 +151,401 @@ FARPROC ET_Win32_Find_And_Loadproc (char *dllname, char *procedure)
/* Determine Easytag Paths during Runtime */
-char* ET_Win32_Install_Dir (void)
-{
- HMODULE hmod;
- char* buf;
+/* Get paths to special Windows folders. */
+char *weasytag_get_special_folder(int folder_type) {
+ static LPFNSHGETFOLDERPATHA MySHGetFolderPathA = NULL;
+ static LPFNSHGETFOLDERPATHW MySHGetFolderPathW = NULL;
+ char *retval = NULL;
- hmod = GetModuleHandle(NULL);
- if ( hmod == 0 )
- {
- buf = g_win32_error_message( GetLastError() );
- //Log_Print("GetModuleHandle error: %s\n", buf);
- g_print("GetModuleHandle error: %s\n", buf);
- g_free(buf);
- return NULL;
- }
- if (GetModuleFileName( hmod, (char*)&install_dir, MAXPATHLEN ) == 0)
- {
- buf = g_win32_error_message( GetLastError() );
- //Log_Print("GetModuleFileName error: %s\n", buf);
- g_print("GetModuleFileName error: %s\n", buf);
- g_free(buf);
- return NULL;
- }
- buf = g_path_get_dirname( install_dir );
- strcpy( (char*)&install_dir, buf );
- g_free( buf );
+ if (!MySHGetFolderPathW) {
+ MySHGetFolderPathW = (LPFNSHGETFOLDERPATHW)
+ weasytag_find_and_loadproc("shfolder.dll", "SHGetFolderPathW");
+ }
+
+ if (MySHGetFolderPathW) {
+ wchar_t utf_16_dir[MAX_PATH + 1];
+
+ if (SUCCEEDED(MySHGetFolderPathW(NULL, folder_type, NULL,
+ SHGFP_TYPE_CURRENT, utf_16_dir))) {
+ retval = g_utf16_to_utf8(utf_16_dir, -1, NULL, NULL, NULL);
+ }
+ }
+
+ if (!retval) {
+ if (!MySHGetFolderPathA) {
+ MySHGetFolderPathA = (LPFNSHGETFOLDERPATHA)
+ weasytag_find_and_loadproc("shfolder.dll", "SHGetFolderPathA");
+ }
+ if (MySHGetFolderPathA) {
+ char locale_dir[MAX_PATH + 1];
+
+ if (SUCCEEDED(MySHGetFolderPathA(NULL, folder_type, NULL,
+ SHGFP_TYPE_CURRENT, locale_dir))) {
+ retval = g_locale_to_utf8(locale_dir, -1, NULL, NULL, NULL);
+ }
+ }
+ }
- return (char*)&install_dir;
+ return retval;
}
+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;
+ }
+ }
-char *ET_Win32_Lib_Dir (void)
-{
- strcpy(lib_dir, ET_Win32_Install_Dir());
- g_strlcat(lib_dir, G_DIR_SEPARATOR_S "library", sizeof(lib_dir));
- return (char*)&lib_dir;
+ return install_dir;
}
-char *ET_Win32_Locale_Dir (void)
-{
- strcpy(locale_dir, ET_Win32_Install_Dir());
- g_strlcat(locale_dir, G_DIR_SEPARATOR_S "locale", sizeof(locale_dir));
- return (char*)&locale_dir;
+const char *weasytag_lib_dir(void) {
+ static gboolean initialized = FALSE;
+
+ if (!initialized) {
+ const char *inst_dir = weasytag_install_dir();
+ if (inst_dir != NULL) {
+ lib_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "library", inst_dir);
+ initialized = TRUE;
+ } else {
+ return NULL;
+ }
+ }
+
+ return lib_dir;
}
-char *ET_Win32_Data_Dir (void)
-{
- return (char*)&app_data_dir;
+const char *weasytag_locale_dir(void) {
+ static gboolean initialized = FALSE;
+
+ if (!initialized) {
+ const char *inst_dir = weasytag_install_dir();
+ if (inst_dir != NULL) {
+ locale_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "locale", inst_dir);
+ initialized = TRUE;
+ } else {
+ return NULL;
+ }
+ }
+
+ return locale_dir;
}
+const char *weasytag_data_dir(void) {
+
+ if (!app_data_dir) {
+ /* Set app data dir, used by easytag_home_dir */
+ const char *newenv = g_getenv("EASYTAGHOME");
+ if (newenv)
+ app_data_dir = g_strdup(newenv);
+ else {
+ app_data_dir = weasytag_get_special_folder(CSIDL_APPDATA);
+ if (!app_data_dir)
+ app_data_dir = g_strdup("C:");
+ }
+
+ //ET_Win32_Path_Replace_Backslashes(app_data_dir);
+
+ //Log_Print(_("EasyTAG settings dir: '%s'"), app_data_dir);
+ g_print(_("EasyTAG settings dir: '%s'"), app_data_dir);
+ g_print("\n");
+ }
+
+ return app_data_dir;
+}
/* Miscellaneous */
-gboolean ET_Win32_Read_Reg_String (HKEY key, char* sub_key, char* val_name, LPBYTE data, LPDWORD data_len)
-{
- HKEY hkey;
- gboolean ret = FALSE;
+gboolean weasytag_write_reg_string(HKEY rootkey, const char *subkey, const char *valname,
+ const char *value) {
+ HKEY reg_key;
+ gboolean success = FALSE;
+
+ if(G_WIN32_HAVE_WIDECHAR_API()) {
+ wchar_t *wc_subkey = g_utf8_to_utf16(subkey, -1, NULL,
+ NULL, NULL);
+
+ if(RegOpenKeyExW(rootkey, wc_subkey, 0,
+ KEY_SET_VALUE, &reg_key) == ERROR_SUCCESS) {
+ wchar_t *wc_valname = NULL;
+
+ if (valname)
+ wc_valname = g_utf8_to_utf16(valname, -1,
+ NULL, NULL, NULL);
+
+ if(value) {
+ wchar_t *wc_value = g_utf8_to_utf16(value, -1,
+ NULL, NULL, NULL);
+ int len = (wcslen(wc_value) * sizeof(wchar_t)) + 1;
+ if(RegSetValueExW(reg_key, wc_valname, 0, REG_SZ,
+ (LPBYTE)wc_value, len
+ ) == ERROR_SUCCESS)
+ success = TRUE;
+ g_free(wc_value);
+ } else
+ if(RegDeleteValueW(reg_key, wc_valname) == ERROR_SUCCESS)
+ success = TRUE;
+
+ g_free(wc_valname);
+ }
+ g_free(wc_subkey);
+ } else {
+ char *cp_subkey = g_locale_from_utf8(subkey, -1, NULL,
+ NULL, NULL);
+ if(RegOpenKeyExA(rootkey, cp_subkey, 0,
+ KEY_SET_VALUE, &reg_key) == ERROR_SUCCESS) {
+ char *cp_valname = NULL;
+ if(valname)
+ cp_valname = g_locale_from_utf8(valname, -1,
+ NULL, NULL, NULL);
+
+ if (value) {
+ char *cp_value = g_locale_from_utf8(value, -1,
+ NULL, NULL, NULL);
+ int len = strlen(cp_value) + 1;
+ if(RegSetValueExA(reg_key, cp_valname, 0, REG_SZ,
+ cp_value, len
+ ) == ERROR_SUCCESS)
+ success = TRUE;
+ g_free(cp_value);
+ } else
+ if(RegDeleteValueA(reg_key, cp_valname) == ERROR_SUCCESS)
+ success = TRUE;
+
+ g_free(cp_valname);
+ }
+ g_free(cp_subkey);
+ }
- if(ERROR_SUCCESS == RegOpenKeyEx(key, sub_key, 0, KEY_QUERY_VALUE, &hkey))
- {
- if (ERROR_SUCCESS == RegQueryValueEx(hkey, val_name, 0, NULL, data, data_len))
- ret = TRUE;
- RegCloseKey(key);
- }
- return ret;
+ if(reg_key != NULL)
+ RegCloseKey(reg_key);
+
+ return success;
}
-/* find a default player executable */
-char* ET_Win32_Get_Audio_File_Player (void)
-{
- DWORD len = 256;
- char key_value[256];
+static HKEY _reg_open_key(HKEY rootkey, const char *subkey, REGSAM access) {
+ HKEY reg_key = NULL;
+ LONG rv;
+
+ if(G_WIN32_HAVE_WIDECHAR_API()) {
+ wchar_t *wc_subkey = g_utf8_to_utf16(subkey, -1, NULL,
+ NULL, NULL);
+ rv = RegOpenKeyExW(rootkey, wc_subkey, 0, access, &reg_key);
+ g_free(wc_subkey);
+ } else {
+ char *cp_subkey = g_locale_from_utf8(subkey, -1, NULL,
+ NULL, NULL);
+ rv = RegOpenKeyExA(rootkey, cp_subkey, 0, access, &reg_key);
+ g_free(cp_subkey);
+ }
- char *player;
+ if (rv != ERROR_SUCCESS) {
+ char *errmsg = g_win32_error_message(rv);
+ g_print("Could not open reg key '%s' subkey '%s'. Message: (%ld) %s\n",
+ ((rootkey == HKEY_LOCAL_MACHINE) ? "HKLM" :
+ (rootkey == HKEY_CURRENT_USER) ? "HKCU" :
+ (rootkey == HKEY_CLASSES_ROOT) ? "HKCR" : "???"),
+ subkey, rv, errmsg);
+ g_free(errmsg);
+ }
- if(ET_Win32_Read_Reg_String(HKEY_CURRENT_USER, "Software\\foobar2000", "InstallDir", key_value, &len))
- {
- player = g_strconcat(key_value, "\\foobar2000.exe", NULL);
- }
- else if(ET_Win32_Read_Reg_String(HKEY_CURRENT_USER, "Software\\Winamp", "", key_value, &len))
- {
- player = g_strconcat(key_value, "\\winamp.exe", NULL);
- }
- else
- {
- player = g_strdup("");
+ return reg_key;
+}
+
+static gboolean _reg_read(HKEY reg_key, const char *valname, LPDWORD type, LPBYTE data, LPDWORD data_len) {
+ LONG rv;
+
+ if(G_WIN32_HAVE_WIDECHAR_API()) {
+ wchar_t *wc_valname = NULL;
+ if (valname)
+ wc_valname = g_utf8_to_utf16(valname, -1, NULL, NULL, NULL);
+ rv = RegQueryValueExW(reg_key, wc_valname, 0, type, data, data_len);
+ g_free(wc_valname);
+ } else {
+ char *cp_valname = NULL;
+ if(valname)
+ cp_valname = g_locale_from_utf8(valname, -1, NULL, NULL, NULL);
+ rv = RegQueryValueExA(reg_key, cp_valname, 0, type, data, data_len);
+ g_free(cp_valname);
+ }
+
+ if (rv != ERROR_SUCCESS) {
+ char *errmsg = g_win32_error_message(rv);
+ g_print("Could not read from reg key value '%s'. Message: (%ld) %s\n",
+ valname, rv, errmsg);
+ g_free(errmsg);
+ }
+
+ return (rv == ERROR_SUCCESS);
+}
+
+gboolean weasytag_read_reg_dword(HKEY rootkey, const char *subkey, const char *valname, LPDWORD result) {
+
+ DWORD type;
+ DWORD nbytes;
+ HKEY reg_key = _reg_open_key(rootkey, subkey, KEY_QUERY_VALUE);
+ gboolean success = FALSE;
+
+ if(reg_key) {
+ if(_reg_read(reg_key, valname, &type, (LPBYTE)result, &nbytes))
+ success = TRUE;
+ RegCloseKey(reg_key);
+ }
+
+ return success;
+}
+
+char *weasytag_read_reg_string(HKEY rootkey, const char *subkey, const char *valname) {
+
+ DWORD type;
+ DWORD nbytes;
+ HKEY reg_key = _reg_open_key(rootkey, subkey, KEY_QUERY_VALUE);
+ char *result = NULL;
+
+ if(reg_key) {
+ if(_reg_read(reg_key, valname, &type, NULL, &nbytes) && type == REG_SZ) {
+ LPBYTE data;
+ if(G_WIN32_HAVE_WIDECHAR_API())
+ data = (LPBYTE) g_new(wchar_t, ((nbytes + 1) / sizeof(wchar_t)) + 1);
+ else
+ data = (LPBYTE) g_malloc(nbytes + 1);
+
+ if(_reg_read(reg_key, valname, &type, data, &nbytes)) {
+ if(G_WIN32_HAVE_WIDECHAR_API()) {
+ wchar_t *wc_temp = (wchar_t*) data;
+ wc_temp[nbytes / sizeof(wchar_t)] = '\0';
+ result = g_utf16_to_utf8(wc_temp, -1,
+ NULL, NULL, NULL);
+ } else {
+ char *cp_temp = (char*) data;
+ cp_temp[nbytes] = '\0';
+ result = g_locale_to_utf8(cp_temp, -1,
+ NULL, NULL, NULL);
+ }
+ }
+ g_free(data);
+ }
+ RegCloseKey(reg_key);
+ }
+
+ return result;
+}
+
+
+void weasytag_init(void) {
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ char *newenv;
+
+ //Log_Print(_("weasytag_init start..."));
+ g_print(_("weasytag_init start..."));
+ g_print("\n");
+ //Log_Print(_("EasyTAG version: %s"),VERSION);
+ //g_print(_("EasyTAG version: %s"),VERSION);
+ //g_print("\n");
+
+ g_print(_("Glib version: %u.%u.%u\n"),glib_major_version, glib_minor_version, glib_micro_version);
+
+ /* Winsock init */
+ wVersionRequested = MAKEWORD( 2, 2 );
+ WSAStartup( wVersionRequested, &wsaData );
+
+ /* Confirm that the winsock DLL supports 2.2 */
+ /* Note that if the DLL supports versions greater than
+ 2.2 in addition to 2.2, it will still return 2.2 in
+ wVersion since that is the version we requested. */
+ if(LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
+ g_print("Could not find a usable WinSock DLL. Oh well.\n");
+ WSACleanup();
}
-
- //Log_Print(_("Audio player: '%s'"), player);
- g_print(_("Audio player: '%s'"), player);
+
+ /* Set Environmental Variables */
+
+ //Log_Print(_("weasytag_init end..."));
+ g_print(_("weasytag_init end..."));
g_print("\n");
+}
- return player;
+/* Windows Cleanup */
+
+void weasytag_cleanup(void) {
+ //Log_Print("weasytag_cleanup");
+ g_print("weasytag_cleanup\n");
+
+ /* winsock cleanup */
+ WSACleanup();
+
+ g_free(app_data_dir);
+ app_data_dir = NULL;
+
+ libeasytagdll_hInstance = NULL;
+}
+
+/* DLL initializer */
+/* suppress gcc "no previous prototype" warning */
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
+ libeasytagdll_hInstance = hinstDLL;
+ return TRUE;
}
-void ET_Win32_Notify_Uri (const char *uri)
+
+/* this is used by libmp4v2 : what is it doing here you think ? well...search! */
+int gettimeofday (struct timeval *t, void *foo)
{
- SHELLEXECUTEINFO sinfo;
-
- memset(&sinfo, 0, sizeof(sinfo));
- sinfo.cbSize = sizeof(sinfo);
- sinfo.fMask = SEE_MASK_CLASSNAME;
- sinfo.lpVerb = "open";
- sinfo.lpFile = uri;
- sinfo.nShow = SW_SHOWNORMAL;
- sinfo.lpClass = "http";
-
- /* We'll allow whatever URI schemes are supported by the
- default http browser.
- */
- if(!ShellExecuteEx(&sinfo))
- //Log_Print("Error opening URI: %s error: %d\n", uri, (int)sinfo.hInstApp);
- g_print("Error opening URI: %s error: %d\n", uri, (int)sinfo.hInstApp);
+ struct _timeb temp;
+
+ if (t != 0) {
+ _ftime(&temp);
+ t->tv_sec = temp.time; /* seconds since 1-1-1970 */
+ t->tv_usec = temp.millitm * 1000; /* microseconds */
+ }
+ return (0);
}
+/* emulate the unix function */
+int mkstemp (char *template)
+{
+ int fd = -1;
+
+ char *str = mktemp(template);
+ if(str != NULL)
+ {
+ fd = open(str, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+ }
+
+ return fd;
+}
void str_replace_char (gchar *str, gchar in_char, gchar out_char)
{
@@ -338,8 +557,6 @@ void str_replace_char (gchar *str, gchar in_char, gchar out_char)
}
}
-
-
/* Remove trailing '/' if any */
void ET_Win32_Path_Remove_Trailing_Slash (gchar *path)
{
@@ -372,97 +589,32 @@ void ET_Win32_Path_Replace_Slashes (gchar *path)
str_replace_char(path, '/', '\\');
}
-void ET_Win32_Init (HINSTANCE hint)
+/* find a default player executable */
+char* ET_Win32_Get_Audio_File_Player (void)
{
- WORD wVersionRequested;
- WSADATA wsaData;
- char *newenv;
-
- ET_exe_hInstance = hint;
-
- /* Winsock init */
- wVersionRequested = MAKEWORD( 2, 2 );
- WSAStartup( wVersionRequested, &wsaData );
+ char *key_value;
+ char *player;
- /* Confirm that the winsock DLL supports 2.2 */
- /* Note that if the DLL supports versions greater than
- 2.2 in addition to 2.2, it will still return 2.2 in
- wVersion since that is the version we requested. */
- if ( LOBYTE( wsaData.wVersion ) != 2
- || HIBYTE( wsaData.wVersion ) != 2 )
+ if (key_value=weasytag_read_reg_string(HKEY_CURRENT_USER, "Software\\foobar2000", "InstallDir"))
{
- g_print("Could not find a usable WinSock DLL. Oh well.\n");
- WSACleanup();
- }
-
- /* Set app data dir, used by easytag_home_dir */
- newenv = (char*)g_getenv("EASYTAGHOME");
- if(!newenv)
+ player = g_strconcat(key_value, "\\foobar2000.exe", NULL);
+ g_free(key_value);
+
+ }else if(key_value=weasytag_read_reg_string(HKEY_CURRENT_USER, "Software\\Winamp", ""))
{
-#if GLIB_CHECK_VERSION(2,6,0)
- if ((MySHGetFolderPathW = (LPFNSHGETFOLDERPATHW) ET_Win32_Find_And_Loadproc("shfolder.dll", "SHGetFolderPathW")))
- {
- wchar_t utf_16_dir[MAX_PATH +1];
- char *temp;
- MySHGetFolderPathW(NULL, CSIDL_APPDATA, NULL,
- SHGFP_TYPE_CURRENT, utf_16_dir);
- temp = g_utf16_to_utf8(utf_16_dir, -1, NULL, NULL, NULL);
- g_strlcpy(app_data_dir, temp, sizeof(app_data_dir));
- g_free(temp);
- } else if ((MySHGetFolderPathA = (LPFNSHGETFOLDERPATHA) ET_Win32_Find_And_Loadproc("shfolder.dll", "SHGetFolderPathA")))
- {
- char locale_dir[MAX_PATH + 1];
- char *temp;
- MySHGetFolderPathA(NULL, CSIDL_APPDATA, NULL,
- SHGFP_TYPE_CURRENT, locale_dir);
- temp = g_locale_to_utf8(locale_dir, -1, NULL, NULL, NULL);
- g_strlcpy(app_data_dir, temp, sizeof(app_data_dir));
- g_free(temp);
- }
-#else
- if ((MySHGetFolderPathA = (LPFNSHGETFOLDERPATHA) ET_Win32_Find_And_Loadproc("shfolder.dll", "SHGetFolderPathA")))
- {
- MySHGetFolderPathA(NULL, CSIDL_APPDATA, NULL,
- SHGFP_TYPE_CURRENT, app_data_dir);
- }
-#endif
- else
- {
- strcpy(app_data_dir, "C:");
- }
- }
- else
+ player = g_strconcat(key_value, "\\winamp.exe", NULL);
+ g_free(key_value);
+
+ }else
{
- g_strlcpy(app_data_dir, newenv, sizeof(app_data_dir));
+ player = g_strdup("");
}
-
- //ET_Win32_Path_Replace_Backslashes(app_data_dir);
-
- //Log_Print(_("EasyTAG settings dir: '%s'"), app_data_dir);
- g_print(_("EasyTAG settings dir: '%s'"), app_data_dir);
+
+ //Log_Print(_("Audio player: '%s'"), player);
+ g_print(_("Audio player: '%s'"), player);
g_print("\n");
- newenv = g_strdup_printf("HOME=%s", app_data_dir);
-
- if (putenv(newenv)<0)
- g_print("putenv failed\n");
- g_free(newenv);
-
+ return player;
}
-/* Windows Cleanup */
-
-void ET_Win32_Cleanup (void)
-{
- /* winsock cleanup */
- WSACleanup();
- ET_dll_hInstance = NULL;
-}
-
-/* DLL initializer */
-BOOL WINAPI DllMain ( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
-{
- ET_dll_hInstance = hinstDLL;
- return TRUE;
-}
diff --git a/src/win32/win32dep.h b/src/win32/win32dep.h
index 302ba0a..5a12ba3 100755
--- a/src/win32/win32dep.h
+++ b/src/win32/win32dep.h
@@ -23,7 +23,7 @@
#ifndef _WIN32DEP_H_
#define _WIN32DEP_H_
-
+#include <shlobj.h>
#include <winsock2.h>
#include <process.h>
#include <gtk/gtk.h>
@@ -45,41 +45,42 @@
** win32dep.c
**/
/* Windows helper functions */
-extern int mkstemp(char *template);
-
-extern HINSTANCE ET_Win32_Hinstance (void);
-extern gboolean ET_Win32_Read_Reg_String (HKEY key, char* sub_key, char* val_name, LPBYTE data, LPDWORD data_len);
-extern char *ET_Win32_Escape_Dirsep (const char *filename);
+FARPROC weasytag_find_and_loadproc(const char *dllname, const char *procedure);
+char *weasytag_read_reg_string(HKEY rootkey, const char *subkey, const char *valname); /* needs to be g_free'd */
+gboolean weasytag_write_reg_string(HKEY rootkey, const char *subkey, const char *valname, const char *value);
+char *weasytag_escape_dirsep(const char *filename); /* needs to be g_free'd */
+
+/* Determine EasyTAG paths */
+char *weasytag_get_special_folder(int folder_type);
+const char *weasytag_install_dir(void);
+const char *weasytag_lib_dir(void);
+const char *weasytag_locale_dir(void);
+const char *weasytag_data_dir(void);
-/* Determine ET paths */
-extern char* ET_Win32_Install_Dir (void);
-extern char* ET_Win32_Lib_Dir (void);
-extern char* ET_Win32_Locale_Dir (void);
-extern char* ET_Win32_Data_Dir (void);
+/* init / cleanup */
+void weasytag_init(void);
+void weasytag_cleanup(void);
/* Misc */
-extern char * ET_Win32_Get_Audio_File_Player (void);
-extern void ET_Win32_Notify_Uri (const char *uri);
+extern char *ET_Win32_Get_Audio_File_Player (void);
-/* init / cleanup */
-extern void ET_Win32_Init (HINSTANCE);
-extern void ET_Win32_Cleanup (void);
+extern void ET_Win32_Path_Remove_Trailing_Slash (gchar *path);
+extern void ET_Win32_Path_Remove_Trailing_Backslash (gchar *path);
+extern void ET_Win32_Path_Replace_Backslashes (gchar *path);
+extern void ET_Win32_Path_Replace_Slashes (gchar *path);
-extern void ET_Win32_Path_Remove_Trailing_Slash (gchar *path);
-extern void ET_Win32_Path_Remove_Trailing_Backslash (gchar *path);
-extern void ET_Win32_Path_Replace_Backslashes (gchar *path);
-extern void ET_Win32_Path_Replace_Slashes (gchar *path);
+extern int mkstemp (char *template);
/*
* MACROS
*/
/*
- * ET specific
+ * EasyTAG specific
*/
-#define DATADIR ET_Win32_Install_Dir()
-#define LIBDIR ET_Win32_Lib_Dir()
-#define LOCALEDIR ET_Win32_Locale_Dir()
-//#define PACKAGE_DATA_DIR DATADIR
+#define DATADIR weasytag_install_dir()
+#define LIBDIR weasytag_lib_dir()
+#define LOCALEDIR weasytag_locale_dir()
#endif /* _WIN32DEP_H_ */
+
diff --git a/src/win32/win_easytag.c b/src/win32/win_easytag.c
index 21f4bac..8aaa825 100755
--- a/src/win32/win_easytag.c
+++ b/src/win32/win_easytag.c
@@ -112,34 +112,9 @@ static BOOL read_reg_string(HKEY key, char* sub_key, char* val_name, LPBYTE data
return ret;
}
-static void dll_prep() {
- char path[MAX_PATH + 1];
+static void common_dll_prep(const char *path) {
HMODULE hmod;
HKEY hkey;
- char gtkpath[MAX_PATH + 1];
- DWORD plen;
-
- plen = sizeof(gtkpath);
- hkey = HKEY_CURRENT_USER;
- if (!read_reg_string(hkey, "SOFTWARE\\GTK\\2.0", "Path",
- (LPBYTE) &gtkpath, &plen)) {
- hkey = HKEY_LOCAL_MACHINE;
- if (!read_reg_string(hkey, "SOFTWARE\\GTK\\2.0", "Path",
- (LPBYTE) &gtkpath, &plen)) {
- printf("GTK+ Path Registry Key not found. "
- "Assuming GTK+ is in the PATH.\n");
- return;
- }
- }
-
- /* this value is replaced during a successful RegQueryValueEx() */
- plen = sizeof(path);
- /* Determine GTK+ dll path .. */
- if (!read_reg_string(hkey, "SOFTWARE\\GTK\\2.0", "DllPath",
- (LPBYTE) &path, &plen)) {
- strcpy(path, gtkpath);
- strcat(path, "\\bin");
- }
printf("GTK+ path found: %s\n", path);
@@ -212,27 +187,49 @@ static void dll_prep() {
}
}
-static char* lcid_to_posix(LCID lcid) {
+static void dll_prep() {
+ char path[MAX_PATH + 1];
+ HKEY hkey;
+ char gtkpath[MAX_PATH + 1];
+ DWORD plen;
+
+ plen = sizeof(gtkpath);
+ hkey = HKEY_CURRENT_USER;
+ if (!read_reg_string(hkey, "SOFTWARE\\GTK\\2.0", "Path",
+ (LPBYTE) &gtkpath, &plen)) {
+ hkey = HKEY_LOCAL_MACHINE;
+ if (!read_reg_string(hkey, "SOFTWARE\\GTK\\2.0", "Path",
+ (LPBYTE) &gtkpath, &plen)) {
+ printf("GTK+ Path Registry Key not found. "
+ "Assuming GTK+ is in the PATH.\n");
+ return;
+ }
+ }
+
+ /* this value is replaced during a successful RegQueryValueEx() */
+ plen = sizeof(path);
+ /* Determine GTK+ dll path .. */
+ if (!read_reg_string(hkey, "SOFTWARE\\GTK\\2.0", "DllPath",
+ (LPBYTE) &path, &plen)) {
+ strcpy(path, gtkpath);
+ strcat(path, "\\bin");
+ }
+
+ common_dll_prep(path);
+}
+
+static char* wineasytag_lcid_to_posix(LCID lcid) {
char *posix = NULL;
int lang_id = PRIMARYLANGID(lcid);
int sub_id = SUBLANGID(lcid);
switch (lang_id) {
+ case LANG_AFRIKAANS: posix = "af"; break;
case LANG_ARABIC: posix = "ar"; break;
case LANG_AZERI: posix = "az"; break;
case LANG_BENGALI: posix = "bn"; break;
case LANG_BULGARIAN: posix = "bg"; break;
case LANG_CATALAN: posix = "ca"; break;
- case LANG_CHINESE:
- switch (sub_id) {
- case SUBLANG_CHINESE_SIMPLIFIED:
- posix = "zh_CN"; break;
- case SUBLANG_CHINESE_TRADITIONAL:
- posix = "zh_TW"; break;
- default:
- posix = "zh"; break;
- }
- break;
case LANG_CZECH: posix = "cs"; break;
case LANG_DANISH: posix = "da"; break;
case LANG_ESTONIAN: posix = "et"; break;
@@ -261,9 +258,11 @@ static char* lcid_to_posix(LCID lcid) {
case LANG_HINDI: posix = "hi"; break;
case LANG_HUNGARIAN: posix = "hu"; break;
case LANG_ICELANDIC: break;
+ case LANG_INDONESIAN: posix = "id"; break;
case LANG_ITALIAN: posix = "it"; break;
case LANG_JAPANESE: posix = "ja"; break;
case LANG_GEORGIAN: posix = "ka"; break;
+ case LANG_KANNADA: posix = "kn"; break;
case LANG_KOREAN: posix = "ko"; break;
case LANG_LITHUANIAN: posix = "lt"; break;
case LANG_MACEDONIAN: posix = "mk"; break;
@@ -279,6 +278,7 @@ static char* lcid_to_posix(LCID lcid) {
break;
case LANG_PUNJABI: posix = "pa"; break;
case LANG_POLISH: posix = "pl"; break;
+ case LANG_PASHTO: posix = "ps"; break;
case LANG_PORTUGUESE:
switch (sub_id) {
case SUBLANG_PORTUGUESE_BRAZILIAN:
@@ -289,6 +289,9 @@ static char* lcid_to_posix(LCID lcid) {
break;
case LANG_ROMANIAN: posix = "ro"; break;
case LANG_RUSSIAN: posix = "ru"; break;
+ case LANG_SLOVAK: posix = "sk"; break;
+ case LANG_SLOVENIAN: posix = "sl"; break;
+ case LANG_ALBANIAN: posix = "sq"; break;
/* LANG_CROATIAN == LANG_SERBIAN == LANG_BOSNIAN */
case LANG_SERBIAN:
switch (sub_id) {
@@ -303,9 +306,6 @@ static char* lcid_to_posix(LCID lcid) {
posix = "hr"; break;
}
break;
- case LANG_SLOVAK: posix = "sk"; break;
- case LANG_SLOVENIAN: posix = "sl"; break;
- case LANG_ALBANIAN: posix = "sq"; break;
case LANG_SWEDISH: posix = "sv"; break;
case LANG_TAMIL: posix = "ta"; break;
case LANG_TELUGU: posix = "te"; break;
@@ -314,12 +314,20 @@ static char* lcid_to_posix(LCID lcid) {
case LANG_UKRAINIAN: posix = "uk"; break;
case LANG_VIETNAMESE: posix = "vi"; break;
case LANG_XHOSA: posix = "xh"; break;
+ case LANG_CHINESE:
+ switch (sub_id) {
+ case SUBLANG_CHINESE_SIMPLIFIED:
+ posix = "zh_CN"; break;
+ case SUBLANG_CHINESE_TRADITIONAL:
+ posix = "zh_TW"; break;
+ default:
+ posix = "zh"; break;
+ }
+ break;
case LANG_URDU: break;
- case LANG_INDONESIAN: break;
case LANG_BELARUSIAN: break;
case LANG_LATVIAN: break;
case LANG_ARMENIAN: break;
- case LANG_AFRIKAANS: break;
case LANG_FAEROESE: break;
case LANG_MALAY: break;
case LANG_KAZAK: break;
@@ -328,7 +336,6 @@ static char* lcid_to_posix(LCID lcid) {
case LANG_UZBEK: break;
case LANG_TATAR: break;
case LANG_ORIYA: break;
- case LANG_KANNADA: break;
case LANG_MALAYALAM: break;
case LANG_ASSAMESE: break;
case LANG_MARATHI: break;
@@ -358,7 +365,7 @@ static char* lcid_to_posix(LCID lcid) {
- Check NSIS Installer Language reg value
- Use default user locale
*/
-static const char *get_locale() {
+static const char *wineasytag_get_locale() {
const char *locale = NULL;
LCID lcid = 0;
char data[10];
@@ -373,23 +380,23 @@ static const char *get_locale() {
if (read_reg_string(HKEY_CURRENT_USER, "SOFTWARE\\easytag",
"Installer Language", (LPBYTE) &data, &datalen)) {
- if ((locale = lcid_to_posix(atoi(data))))
+ if ((locale = wineasytag_lcid_to_posix(atoi(data))))
return locale;
}
// List of LCID : http://www.microsoft.com/globaldev/reference/lcid-all.mspx
lcid = GetUserDefaultLCID();
- if ((locale = lcid_to_posix(lcid)))
+ if ((locale = wineasytag_lcid_to_posix(lcid)))
return locale;
return "en";
}
-static void set_locale() {
+static void wineasytag_set_locale() {
const char *locale = NULL;
char envstr[25];
- locale = get_locale();
+ locale = wineasytag_get_locale();
snprintf(envstr, 25, "LANG=%s", locale);
printf("Setting locale: %s\n", envstr);
@@ -397,9 +404,9 @@ static void set_locale() {
}
#if 0
-#define WM_FOCUS_REQUEST (WM_APP + 13)
+#define EASYTAG_WM_FOCUS_REQUEST (WM_APP + 13)
-static BOOL set_running() {
+static BOOL wineasytag_set_running() {
HANDLE h;
if ((h = CreateMutex(NULL, FALSE, "easytag_is_running"))) {
@@ -407,7 +414,7 @@ static BOOL set_running() {
HWND msg_win;
if((msg_win = FindWindow(TEXT("WineasytagMsgWinCls"), NULL)))
- if(SendMessage(msg_win, WM_FOCUS_REQUEST, (WPARAM) NULL, (LPARAM) NULL))
+ if(SendMessage(msg_win, EASYTAG_WM_FOCUS_REQUEST, (WPARAM) NULL, (LPARAM) NULL))
return FALSE;
/* If we get here, the focus request wasn't successful */
@@ -476,13 +483,18 @@ int _stdcall
WinMain (struct HINSTANCE__ *hInstance, struct HINSTANCE__ *hPrevInstance,
char *lpszCmdLine, int nCmdShow) {
char errbuf[512];
+ char pidgin_dir[MAX_PATH];
+ char exe_name[MAX_PATH];
HMODULE hmod;
+ char *tmp;
+ int easytag_argc = __argc;
+ char **easytag_argv = __argv;
/* If debug or help or version flag used, create console for output */
if (strstr(lpszCmdLine, "-d") || strstr(lpszCmdLine, "-h") || strstr(lpszCmdLine, "-v")) {
/* If stdout hasn't been redirected to a file, alloc a console
* (_istty() doesn't work for stuff using the GUI subsystem) */
- if (_fileno(stdout) == -1) {
+ if (_fileno(stdout) == -1 || _fileno(stdout) == -2) {
LPFNATTACHCONSOLE MyAttachConsole = NULL;
if ((hmod = GetModuleHandle("kernel32.dll"))) {
MyAttachConsole =
@@ -496,12 +508,14 @@ WinMain (struct HINSTANCE__ *hInstance, struct HINSTANCE__ *hPrevInstance,
}
}
}
+
#if 0
/* Load exception handler if we have it */
- if (GetModuleFileName(NULL, gaimdir, MAX_PATH) != 0) {
- char *tmp = gaimdir;
+ if (GetModuleFileName(NULL, easytag_dir, MAX_PATH) != 0) {
char *prev = NULL;
+ tmp = easytag_dir;
+ /* primitive dirname() */
while ((tmp = strchr(tmp, '\\'))) {
prev = tmp;
tmp++;
@@ -509,9 +523,15 @@ WinMain (struct HINSTANCE__ *hInstance, struct HINSTANCE__ *hPrevInstance,
if (prev) {
prev[0] = '\0';
- strcat(gaimdir, "\\exchndl.dll");
- if (LoadLibrary(gaimdir))
+
+ /* prev++ will now point to the executable file name */
+ strcpy(exe_name, prev + 1);
+
+ strcat(easytag_dir, "\\exchndl.dll");
+ if (LoadLibrary(easytag_dir))
printf("Loaded exchndl.dll\n");
+
+ prev[0] = '\0';
}
} else {
DWORD dw = GetLastError();
@@ -519,18 +539,19 @@ WinMain (struct HINSTANCE__ *hInstance, struct HINSTANCE__ *hPrevInstance,
snprintf(errbuf, 512,
"Error getting module filename. Error: (%u) %s",
(UINT) dw, err_msg);
- printf(errbuf);
+ printf("%s", errbuf);
MessageBox(NULL, errbuf, NULL, MB_OK | MB_TOPMOST);
+ easytag_dir[0] = '\0';
}
#endif
dll_prep();
- set_locale();
+ wineasytag_set_locale();
/* If help or version flag used, do not check Mutex */
- //if (!strstr(lpszCmdLine, "-h") && !strstr(lpszCmdLine, "-v"))
- // if (!getenv("GAIM_MULTI_INST") && !wgaim_set_running())
- // return 0;
+ /*if (!strstr(lpszCmdLine, "-h") && !strstr(lpszCmdLine, "-v"))
+ if (!getenv("GAIM_MULTI_INST") && !wineasytag_set_running())
+ return 0;*/
set_proxy();
@@ -548,11 +569,11 @@ WinMain (struct HINSTANCE__ *hInstance, struct HINSTANCE__ *hPrevInstance,
(UINT) dw, err_msg,
mod_not_found ? "\n" : "",
mod_not_found ? "This probably means that a dependency (like GTK+, libogg or libvorbis) can't be found." : "");
- printf(errbuf);
+ printf("%s", errbuf);
MessageBox(NULL, errbuf, TEXT("Error"), MB_OK | MB_TOPMOST);
return 0;
}
- return easytag_main (hInstance, __argc, __argv);
+ return easytag_main (hInstance, easytag_argc, easytag_argv);
}