Commit 507ad8ce7a8b8ffe9bb46d2ff6cb2823aa5478a7
1 parent
b25d6631
Exists in
master
and in
5 other branches
Incluindo parametro para definir o diretorio de dados do aplicativo via linha de comando em windows
Showing
1 changed file
with
39 additions
and
4 deletions
Show diff stats
src/pw3270/main.c
| @@ -58,6 +58,10 @@ | @@ -58,6 +58,10 @@ | ||
| 58 | GtkOSXApplication * osxapp = NULL; | 58 | GtkOSXApplication * osxapp = NULL; |
| 59 | #endif // HAVE_GTKMAC | 59 | #endif // HAVE_GTKMAC |
| 60 | 60 | ||
| 61 | +#if defined( WIN32 ) | ||
| 62 | + static const gchar * appname = PACKAGE_NAME; | ||
| 63 | +#endif // WIN32 | ||
| 64 | + | ||
| 61 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 65 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 62 | 66 | ||
| 63 | static int initialize(void) | 67 | static int initialize(void) |
| @@ -121,11 +125,45 @@ static void toplevel_setup(GtkWindow *window) | @@ -121,11 +125,45 @@ static void toplevel_setup(GtkWindow *window) | ||
| 121 | } | 125 | } |
| 122 | 126 | ||
| 123 | #if ! defined( WIN32 ) | 127 | #if ! defined( WIN32 ) |
| 128 | + | ||
| 124 | static gboolean appname(const gchar *option_name, const gchar *value, gpointer data, GError **error) | 129 | static gboolean appname(const gchar *option_name, const gchar *value, gpointer data, GError **error) |
| 125 | { | 130 | { |
| 126 | g_set_application_name(value); | 131 | g_set_application_name(value); |
| 127 | return TRUE; | 132 | return TRUE; |
| 128 | } | 133 | } |
| 134 | + | ||
| 135 | +#else | ||
| 136 | + | ||
| 137 | +static gboolean datadir(const gchar *option_name, const gchar *value, gpointer data, GError **error) | ||
| 138 | +{ | ||
| 139 | + gchar * path = g_strconcat("SOFTWARE\\",appname,"\\datadir",NULL); | ||
| 140 | + HKEY hKey; | ||
| 141 | + DWORD disp; | ||
| 142 | + int rc; | ||
| 143 | + | ||
| 144 | + rc = RegCreateKeyEx(HKEY_LOCAL_MACHINE,path,0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE|KEY_WOW64_64KEY,NULL,&hKey,&disp); | ||
| 145 | + SetLastError(rc); | ||
| 146 | + | ||
| 147 | + trace("%s=\"%s\" create=%d",path,value,rc); | ||
| 148 | + | ||
| 149 | + if(rc == ERROR_SUCCESS) | ||
| 150 | + { | ||
| 151 | + trace("%s: Value set",__FUNCTION__); | ||
| 152 | + RegSetValueEx(hKey,NULL,0,REG_SZ,(const BYTE *) value,strlen(value)+1); | ||
| 153 | + RegCloseKey(hKey); | ||
| 154 | + } | ||
| 155 | + else | ||
| 156 | + { | ||
| 157 | + gchar *msg = g_win32_error_message(rc); | ||
| 158 | + trace("%s failed: %s",__FUNCTION__,msg); | ||
| 159 | + *error = g_error_new(ERROR_DOMAIN,EINVAL, "%s", msg); | ||
| 160 | + g_free(msg); | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + g_free(path); | ||
| 164 | + return rc == ERROR_SUCCESS; | ||
| 165 | +} | ||
| 166 | + | ||
| 129 | #endif // !win32 | 167 | #endif // !win32 |
| 130 | 168 | ||
| 131 | static gboolean optcolors(const gchar *option_name, const gchar *value, gpointer data, GError **error) | 169 | 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 | @@ -149,10 +187,6 @@ static gboolean optcolors(const gchar *option_name, const gchar *value, gpointer | ||
| 149 | 187 | ||
| 150 | int main(int argc, char *argv[]) | 188 | int main(int argc, char *argv[]) |
| 151 | { | 189 | { |
| 152 | -#if defined( WIN32 ) | ||
| 153 | - static const gchar * appname = PACKAGE_NAME; | ||
| 154 | -#endif // WIN32 | ||
| 155 | - | ||
| 156 | static const gchar * session_name = PACKAGE_NAME; | 190 | static const gchar * session_name = PACKAGE_NAME; |
| 157 | static const gchar * host = NULL; | 191 | static const gchar * host = NULL; |
| 158 | int rc = 0; | 192 | int rc = 0; |
| @@ -215,6 +249,7 @@ int main(int argc, char *argv[]) | @@ -215,6 +249,7 @@ int main(int argc, char *argv[]) | ||
| 215 | { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME }, | 249 | { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME }, |
| 216 | #else | 250 | #else |
| 217 | { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, | 251 | { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, |
| 252 | + { "datadir", 'd', 0, G_OPTION_ARG_CALLBACK, datadir, N_( "Path to application data files" ), NULL }, | ||
| 218 | #endif // WIN32 | 253 | #endif // WIN32 |
| 219 | { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME }, | 254 | { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME }, |
| 220 | { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, | 255 | { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, |