From 829166255b535e38e0594e0cf9e10cfb2a9ad420 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 18 Dec 2019 14:00:44 -0300 Subject: [PATCH] Adding convenienct method for open windows registry. --- src/include/v3270.h | 8 ++++++++ src/include/v3270/settings.h | 2 +- src/terminal/windows/registry.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/include/v3270.h b/src/include/v3270.h index 1e3897e..e77dd3d 100644 --- a/src/include/v3270.h +++ b/src/include/v3270.h @@ -31,6 +31,10 @@ #define V3270_H_INCLUDED 1 + #ifdef _WIN32 + #include + #endif // _WIN32 + #include #include #include @@ -306,6 +310,10 @@ // Convenience LIB3270_EXPORT void gtk_entry_set_printf(GtkEntry *entry, const gchar *fmt, ...) G_GNUC_PRINTF(2,3); +#ifdef _WIN32 + LIB3270_EXPORT gboolean v3270_win32_create_regkey(GtkWidget *widget, REGSAM samDesired, PHKEY phkResult); +#endif // _WIN32 + G_END_DECLS #endif // V3270_H_INCLUDED diff --git a/src/include/v3270/settings.h b/src/include/v3270/settings.h index ab2bbd5..6824143 100644 --- a/src/include/v3270/settings.h +++ b/src/include/v3270/settings.h @@ -50,8 +50,8 @@ #ifdef _WIN32 LIB3270_EXPORT gboolean v3270_load_registry(GtkWidget *widget, HKEY hKey, const gchar *group_name); - LIB3270_EXPORT void v3270_to_registry(GtkWidget *widget, HKEY hKey, const gchar *group_name); + LIB3270_EXPORT LSTATUS v3270_win32_create_regkey(LPCSTR lpSubKey, REGSAM samDesired, PHKEY phkResult); #endif // _WIN32 diff --git a/src/terminal/windows/registry.c b/src/terminal/windows/registry.c index 74bf81f..9ded5bb 100644 --- a/src/terminal/windows/registry.c +++ b/src/terminal/windows/registry.c @@ -37,6 +37,8 @@ #include #include + static const HKEY predefined[] = { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }; + /*--[ Implement ]------------------------------------------------------------------------------------*/ static void save_by_pspec(GtkWidget *widget, GParamSpec *pspec, HKEY hKey) @@ -269,3 +271,34 @@ return TRUE; } + + gboolean v3270_win32_open_regkey(GtkWidget *widget, HKEY *hKey, REGSAM samDesired) { + + const gchar * session_name = GTK_V3270(widget)->session.name; + + if(!session_name) + session_name = g_get_application_name(); + + size_t ix; + g_autofree gchar * path = g_strjoin("\\software\\",session_name,NULL); + + // Remove delimiters + static const gchar delim[] = { ':', '.', '?' }; + for(ix = 0; ix < G_N_ELEMENTS(delim); ix++) { + + gchar * p = strchr(path,delim[ix]); + if(p) + *p = 0; + } + + for(ix=0;ix < G_N_ELEMENTS(predefined);ix++) { + + if(RegOpenKeyEx(predefined[ix],path,0,samDesired,hKey) == ERROR_SUCCESS) + return TRUE; + + } + + return FALSE; + + } + -- libgit2 0.21.2