/pidgin/main: b833eaa6c76f: Log reader: fix some Trilian-related...

Tomasz Wasilczyk twasilczyk at pidgin.im
Sun Dec 8 12:25:44 EST 2013


Changeset: b833eaa6c76f9e2e3834d7c05447ed1873de12ab
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2013-12-08 18:25 +0100
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/b833eaa6c76f

Description:

Log reader: fix some Trilian-related warnings in debug output. Refs #15279

diffstat:

 libpurple/plugins/log_reader.c |  21 ++++++++++++++----
 libpurple/win32/win32dep.c     |  46 ++++++++++++++++++++++++++++++++++++++++++
 libpurple/win32/win32dep.h     |   1 +
 3 files changed, 63 insertions(+), 5 deletions(-)

diffs (117 lines):

diff --git a/libpurple/plugins/log_reader.c b/libpurple/plugins/log_reader.c
--- a/libpurple/plugins/log_reader.c
+++ b/libpurple/plugins/log_reader.c
@@ -2452,6 +2452,7 @@ init_plugin(PurplePlugin *plugin)
 static void log_reader_init_prefs(void) {
 	char *path;
 #ifdef _WIN32
+	const gchar *reg_key;
 	char *folder;
 	gboolean found = FALSE;
 #endif
@@ -2542,7 +2543,11 @@ static void log_reader_init_prefs(void) 
 	 */
 
 	path = NULL;
-	if ((folder = wpurple_read_reg_string(HKEY_CLASSES_ROOT, "Trillian.SkinZip\\shell\\Add\\command\\", NULL))) {
+	folder = NULL;
+	reg_key = "Trillian.SkinZip\\shell\\Add\\command\\";
+	if (wpurple_reg_val_exists(HKEY_CLASSES_ROOT, reg_key, NULL))
+		folder = wpurple_read_reg_string(HKEY_CLASSES_ROOT, reg_key, NULL);
+	if (folder) {
 		char *value = folder;
 		char *temp;
 
@@ -2610,15 +2615,21 @@ static void log_reader_init_prefs(void) 
 #else
 		gchar *contents = NULL;
 
-		purple_debug_info("Trillian talk.ini read",
-				  "Reading %s\n", path);
-		if (!g_file_get_contents(path, &contents, NULL, &error)) {
+		if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
+			purple_debug_info("Trillian talk.ini read",
+				"Reading %s\n", path);
+		} else {
+			g_free(path);
+			path = NULL;
+		}
+		
+		if (path && !g_file_get_contents(path, &contents, NULL, &error)) {
 			purple_debug_error("Trillian talk.ini read",
 					   "Error reading talk.ini: %s\n",
 					   (error && error->message) ? error->message : "Unknown error");
 			if (error)
 				g_error_free(error);
-		} else {
+		} else if (contents) {
 			char *cursor, *line;
 			line = cursor = contents;
 			while (*cursor) {
diff --git a/libpurple/win32/win32dep.c b/libpurple/win32/win32dep.c
--- a/libpurple/win32/win32dep.c
+++ b/libpurple/win32/win32dep.c
@@ -291,6 +291,52 @@ static gboolean _reg_read(HKEY reg_key, 
 	return (rv == ERROR_SUCCESS);
 }
 
+gboolean wpurple_reg_val_exists(HKEY rootkey, const char *subkey, const char *valname)
+{
+	HKEY hkey;
+	LONG retv;
+	DWORD index;
+	wchar_t name_buffer[100];
+	BOOL exists = FALSE;
+	wchar_t *wc_valname = NULL;
+	wchar_t *wc_subkey;
+
+	if (subkey == NULL)
+		return FALSE;
+
+	wc_subkey = g_utf8_to_utf16(subkey, -1, NULL, NULL, NULL);
+	retv = RegOpenKeyExW(rootkey, wc_subkey, 0, KEY_ENUMERATE_SUB_KEYS, &hkey);
+	g_free(wc_subkey);
+
+	if (retv != ERROR_SUCCESS)
+		return FALSE;
+
+	if (valname[0] == '\0' || valname == NULL) {
+		RegCloseKey(hkey);
+		return TRUE;
+	}
+
+	wc_valname = g_utf8_to_utf16(valname, -1, NULL, NULL, NULL);
+	index = 0;
+	while (TRUE)
+	{
+		DWORD name_size = sizeof(name_buffer);
+		retv = RegEnumValueW(hkey, index++, name_buffer, &name_size,
+			NULL, NULL, NULL, NULL);
+		if (retv != ERROR_SUCCESS)
+			break;
+		name_size /= sizeof(wchar_t);
+		if (wcsncmp(name_buffer, wc_valname, name_size) == 0) {
+			exists = TRUE;
+			break;
+		}
+	}
+	g_free(wc_valname);
+
+	RegCloseKey(hkey);
+	return exists;
+}
+
 gboolean wpurple_read_reg_dword(HKEY rootkey, const char *subkey, const char *valname, LPDWORD result) {
 
 	DWORD type;
diff --git a/libpurple/win32/win32dep.h b/libpurple/win32/win32dep.h
--- a/libpurple/win32/win32dep.h
+++ b/libpurple/win32/win32dep.h
@@ -54,6 +54,7 @@ typedef struct {
  **/
 /* Windows helper functions */
 FARPROC wpurple_find_and_loadproc(const char *dllname, const char *procedure);
+gboolean wpurple_reg_val_exists(HKEY rootkey, const char *subkey, const char *valname);
 gboolean wpurple_read_reg_dword(HKEY rootkey, const char *subkey, const char *valname, LPDWORD result);
 char *wpurple_read_reg_string(HKEY rootkey, const char *subkey, const char *valname); /* needs to be g_free'd */
 gboolean wpurple_write_reg_string(HKEY rootkey, const char *subkey, const char *valname, const char *value);



More information about the Commits mailing list