Commit 829166255b535e38e0594e0cf9e10cfb2a9ad420
1 parent
805acac1
Exists in
master
and in
1 other branch
Adding convenienct method for open windows registry.
Showing
3 changed files
with
42 additions
and
1 deletions
Show diff stats
src/include/v3270.h
| ... | ... | @@ -31,6 +31,10 @@ |
| 31 | 31 | |
| 32 | 32 | #define V3270_H_INCLUDED 1 |
| 33 | 33 | |
| 34 | + #ifdef _WIN32 | |
| 35 | + #include <windows.h> | |
| 36 | + #endif // _WIN32 | |
| 37 | + | |
| 34 | 38 | #include <glib.h> |
| 35 | 39 | #include <gtk/gtk.h> |
| 36 | 40 | #include <lib3270.h> |
| ... | ... | @@ -306,6 +310,10 @@ |
| 306 | 310 | // Convenience |
| 307 | 311 | LIB3270_EXPORT void gtk_entry_set_printf(GtkEntry *entry, const gchar *fmt, ...) G_GNUC_PRINTF(2,3); |
| 308 | 312 | |
| 313 | +#ifdef _WIN32 | |
| 314 | + LIB3270_EXPORT gboolean v3270_win32_create_regkey(GtkWidget *widget, REGSAM samDesired, PHKEY phkResult); | |
| 315 | +#endif // _WIN32 | |
| 316 | + | |
| 309 | 317 | G_END_DECLS |
| 310 | 318 | |
| 311 | 319 | #endif // V3270_H_INCLUDED | ... | ... |
src/include/v3270/settings.h
| ... | ... | @@ -50,8 +50,8 @@ |
| 50 | 50 | #ifdef _WIN32 |
| 51 | 51 | |
| 52 | 52 | LIB3270_EXPORT gboolean v3270_load_registry(GtkWidget *widget, HKEY hKey, const gchar *group_name); |
| 53 | - | |
| 54 | 53 | LIB3270_EXPORT void v3270_to_registry(GtkWidget *widget, HKEY hKey, const gchar *group_name); |
| 54 | + LIB3270_EXPORT LSTATUS v3270_win32_create_regkey(LPCSTR lpSubKey, REGSAM samDesired, PHKEY phkResult); | |
| 55 | 55 | |
| 56 | 56 | #endif // _WIN32 |
| 57 | 57 | ... | ... |
src/terminal/windows/registry.c
| ... | ... | @@ -37,6 +37,8 @@ |
| 37 | 37 | #include <lib3270/log.h> |
| 38 | 38 | #include <lib3270/trace.h> |
| 39 | 39 | |
| 40 | + static const HKEY predefined[] = { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }; | |
| 41 | + | |
| 40 | 42 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 41 | 43 | |
| 42 | 44 | static void save_by_pspec(GtkWidget *widget, GParamSpec *pspec, HKEY hKey) |
| ... | ... | @@ -269,3 +271,34 @@ |
| 269 | 271 | |
| 270 | 272 | return TRUE; |
| 271 | 273 | } |
| 274 | + | |
| 275 | + gboolean v3270_win32_open_regkey(GtkWidget *widget, HKEY *hKey, REGSAM samDesired) { | |
| 276 | + | |
| 277 | + const gchar * session_name = GTK_V3270(widget)->session.name; | |
| 278 | + | |
| 279 | + if(!session_name) | |
| 280 | + session_name = g_get_application_name(); | |
| 281 | + | |
| 282 | + size_t ix; | |
| 283 | + g_autofree gchar * path = g_strjoin("\\software\\",session_name,NULL); | |
| 284 | + | |
| 285 | + // Remove delimiters | |
| 286 | + static const gchar delim[] = { ':', '.', '?' }; | |
| 287 | + for(ix = 0; ix < G_N_ELEMENTS(delim); ix++) { | |
| 288 | + | |
| 289 | + gchar * p = strchr(path,delim[ix]); | |
| 290 | + if(p) | |
| 291 | + *p = 0; | |
| 292 | + } | |
| 293 | + | |
| 294 | + for(ix=0;ix < G_N_ELEMENTS(predefined);ix++) { | |
| 295 | + | |
| 296 | + if(RegOpenKeyEx(predefined[ix],path,0,samDesired,hKey) == ERROR_SUCCESS) | |
| 297 | + return TRUE; | |
| 298 | + | |
| 299 | + } | |
| 300 | + | |
| 301 | + return FALSE; | |
| 302 | + | |
| 303 | + } | |
| 304 | + | ... | ... |