diff --git a/src/pw3270/main.c b/src/pw3270/main.c index c32736e..3666571 100644 --- a/src/pw3270/main.c +++ b/src/pw3270/main.c @@ -58,6 +58,10 @@ GtkOSXApplication * osxapp = NULL; #endif // HAVE_GTKMAC +#if defined( WIN32 ) + static const gchar * appname = PACKAGE_NAME; +#endif // WIN32 + /*--[ Implement ]------------------------------------------------------------------------------------*/ static int initialize(void) @@ -121,11 +125,45 @@ static void toplevel_setup(GtkWindow *window) } #if ! defined( WIN32 ) + static gboolean appname(const gchar *option_name, const gchar *value, gpointer data, GError **error) { g_set_application_name(value); return TRUE; } + +#else + +static gboolean datadir(const gchar *option_name, const gchar *value, gpointer data, GError **error) +{ + gchar * path = g_strconcat("SOFTWARE\\",appname,"\\datadir",NULL); + HKEY hKey; + DWORD disp; + int rc; + + rc = RegCreateKeyEx(HKEY_LOCAL_MACHINE,path,0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE|KEY_WOW64_64KEY,NULL,&hKey,&disp); + SetLastError(rc); + + trace("%s=\"%s\" create=%d",path,value,rc); + + if(rc == ERROR_SUCCESS) + { + trace("%s: Value set",__FUNCTION__); + RegSetValueEx(hKey,NULL,0,REG_SZ,(const BYTE *) value,strlen(value)+1); + RegCloseKey(hKey); + } + else + { + gchar *msg = g_win32_error_message(rc); + trace("%s failed: %s",__FUNCTION__,msg); + *error = g_error_new(ERROR_DOMAIN,EINVAL, "%s", msg); + g_free(msg); + } + + g_free(path); + return rc == ERROR_SUCCESS; +} + #endif // !win32 static gboolean optcolors(const gchar *option_name, const gchar *value, gpointer data, GError **error) @@ -149,10 +187,6 @@ static gboolean optcolors(const gchar *option_name, const gchar *value, gpointer int main(int argc, char *argv[]) { -#if defined( WIN32 ) - static const gchar * appname = PACKAGE_NAME; -#endif // WIN32 - static const gchar * session_name = PACKAGE_NAME; static const gchar * host = NULL; int rc = 0; @@ -215,6 +249,7 @@ int main(int argc, char *argv[]) { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME }, #else { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, + { "datadir", 'd', 0, G_OPTION_ARG_CALLBACK, datadir, N_( "Path to application data files" ), NULL }, #endif // WIN32 { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME }, { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, -- libgit2 0.21.2