Commit 16fa4bcec4df89f69171908e4f1d606721a49df0
1 parent
73683f2e
Exists in
master
and in
5 other branches
Corrigindo tratamento do registry em windows
Showing
3 changed files
with
52 additions
and
40 deletions
Show diff stats
src/gtk/actions.c
| @@ -284,6 +284,32 @@ static int id_from_array(const gchar *key, const gchar **array, GError **error) | @@ -284,6 +284,32 @@ static int id_from_array(const gchar *key, const gchar **array, GError **error) | ||
| 284 | return -1; | 284 | return -1; |
| 285 | } | 285 | } |
| 286 | 286 | ||
| 287 | +static int get_attribute_id(const gchar *name, const gchar *key, gchar **nm, const gchar **src, const gchar **names, const gchar **values, GError **error) | ||
| 288 | +{ | ||
| 289 | + const gchar *attr = ui_get_attribute(key,names,values); | ||
| 290 | + int id; | ||
| 291 | + | ||
| 292 | + if(!attr) | ||
| 293 | + { | ||
| 294 | + *error = g_error_new(ERROR_DOMAIN,EINVAL,_("Attribute \"%s\" is invalid or undefined" ), key); | ||
| 295 | + return -1; | ||
| 296 | + } | ||
| 297 | + | ||
| 298 | + id = id_from_array(attr,src,error); | ||
| 299 | + if(id >= 0) | ||
| 300 | + { | ||
| 301 | + if(*nm) | ||
| 302 | + g_free(*nm); | ||
| 303 | + *nm = g_strconcat(name,attr,NULL); | ||
| 304 | + return id; | ||
| 305 | + } | ||
| 306 | + | ||
| 307 | + if(!*error) | ||
| 308 | + *error = g_error_new(ERROR_DOMAIN,EINVAL,_("Unexpected or invalid %s attribute: \"%s\"" ), key, attr); | ||
| 309 | + | ||
| 310 | + return -1; | ||
| 311 | +} | ||
| 312 | + | ||
| 287 | static int setup_block_action(const gchar *name, const gchar *attr, GError **error) | 313 | static int setup_block_action(const gchar *name, const gchar *attr, GError **error) |
| 288 | { | 314 | { |
| 289 | int id = -1; | 315 | int id = -1; |
| @@ -392,30 +418,20 @@ GtkAction * ui_get_action(GtkWidget *widget, const gchar *name, GHashTable *hash | @@ -392,30 +418,20 @@ GtkAction * ui_get_action(GtkWidget *widget, const gchar *name, GHashTable *hash | ||
| 392 | } | 418 | } |
| 393 | else if(!g_strcasecmp(name,"paste")) | 419 | else if(!g_strcasecmp(name,"paste")) |
| 394 | { | 420 | { |
| 421 | + static const GCallback cbk[] = { G_CALLBACK(paste_clipboard_action), | ||
| 422 | + G_CALLBACK(paste_next_action), | ||
| 423 | + G_CALLBACK(paste_file_action) | ||
| 424 | + }; | ||
| 425 | + static const gchar * src[] = { "clipboard", "next", "file", NULL }; | ||
| 426 | + | ||
| 427 | + callback = cbk; | ||
| 395 | action_type = ACTION_TYPE_TABLE; | 428 | action_type = ACTION_TYPE_TABLE; |
| 396 | - attr = ui_get_attribute("src",names,values); | ||
| 397 | 429 | ||
| 398 | - if(!attr) | ||
| 399 | - { | ||
| 400 | - *error = g_error_new(ERROR_DOMAIN,EINVAL,_("%s action needs src attribute" ), name); | 430 | + trace("%s",__FUNCTION__); |
| 431 | + id = get_attribute_id(name,"src",&nm,src,names,values,error); | ||
| 432 | + trace("%s",__FUNCTION__); | ||
| 433 | + if(id < 0) | ||
| 401 | return NULL; | 434 | return NULL; |
| 402 | - } | ||
| 403 | - else | ||
| 404 | - { | ||
| 405 | - static const GCallback cbk[] = { G_CALLBACK(paste_clipboard_action), | ||
| 406 | - G_CALLBACK(paste_next_action), | ||
| 407 | - G_CALLBACK(paste_file_action) | ||
| 408 | - }; | ||
| 409 | - static const gchar * src[] = { "clipboard", "next", "file", NULL }; | ||
| 410 | - | ||
| 411 | - id = id_from_array(attr,src,error); | ||
| 412 | - if(id < 0) | ||
| 413 | - return NULL; | ||
| 414 | - | ||
| 415 | - callback = cbk; | ||
| 416 | - } | ||
| 417 | - | ||
| 418 | - nm = g_strconcat(name,attr, NULL); | ||
| 419 | 435 | ||
| 420 | } | 436 | } |
| 421 | else if(!g_strcasecmp(name,"copy")) | 437 | else if(!g_strcasecmp(name,"copy")) |
| @@ -434,16 +450,9 @@ GtkAction * ui_get_action(GtkWidget *widget, const gchar *name, GHashTable *hash | @@ -434,16 +450,9 @@ GtkAction * ui_get_action(GtkWidget *widget, const gchar *name, GHashTable *hash | ||
| 434 | }; | 450 | }; |
| 435 | callback = cbk; | 451 | callback = cbk; |
| 436 | action_type = ACTION_TYPE_TABLE; | 452 | action_type = ACTION_TYPE_TABLE; |
| 437 | - attr = ui_get_attribute("mode",names,values); | ||
| 438 | - | ||
| 439 | - id = id_from_array(attr,src,error); | 453 | + id = get_attribute_id(name,"mode",&nm,src,names,values,error); |
| 440 | if(id < 0) | 454 | if(id < 0) |
| 441 | - { | ||
| 442 | - *error = g_error_new(ERROR_DOMAIN,EINVAL,_("Unexpected or invalid mode attribute: \"%s\"" ), attr); | ||
| 443 | return NULL; | 455 | return NULL; |
| 444 | - } | ||
| 445 | - | ||
| 446 | - nm = g_strconcat(name,attr,NULL); | ||
| 447 | } | 456 | } |
| 448 | else if(!g_strcasecmp(name,"save")) | 457 | else if(!g_strcasecmp(name,"save")) |
| 449 | { | 458 | { |
src/gtk/common/config.c
| @@ -84,11 +84,11 @@ gchar * get_last_error_msg(void) | @@ -84,11 +84,11 @@ gchar * get_last_error_msg(void) | ||
| 84 | #endif // WIN32 | 84 | #endif // WIN32 |
| 85 | 85 | ||
| 86 | #ifdef WIN_REGISTRY_ENABLED | 86 | #ifdef WIN_REGISTRY_ENABLED |
| 87 | - static BOOL registry_open_key(const gchar *group, const gchar *key, REGSAM samDesired, HKEY *hKey) | 87 | + static BOOL registry_open_key(const gchar *group, REGSAM samDesired, HKEY *hKey) |
| 88 | { | 88 | { |
| 89 | static HKEY predefined[] = { HKEY_CURRENT_USER, HKEY_USERS, HKEY_LOCAL_MACHINE }; | 89 | static HKEY predefined[] = { HKEY_CURRENT_USER, HKEY_USERS, HKEY_LOCAL_MACHINE }; |
| 90 | int f; | 90 | int f; |
| 91 | - gchar * path = g_strdup_printf("%s\\%s\\%s",registry_path,group,key); | 91 | + gchar * path = g_strdup_printf("%s\\%s",registry_path,group); |
| 92 | 92 | ||
| 93 | for(f=0;f<G_N_ELEMENTS(predefined);f++) | 93 | for(f=0;f<G_N_ELEMENTS(predefined);f++) |
| 94 | { | 94 | { |
| @@ -99,7 +99,9 @@ gchar * get_last_error_msg(void) | @@ -99,7 +99,9 @@ gchar * get_last_error_msg(void) | ||
| 99 | } | 99 | } |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | + trace("Cant open \"%s\"",path); | ||
| 102 | g_free(path); | 103 | g_free(path); |
| 104 | + | ||
| 103 | return FALSE; | 105 | return FALSE; |
| 104 | } | 106 | } |
| 105 | #else | 107 | #else |
| @@ -164,14 +166,14 @@ gchar * get_last_error_msg(void) | @@ -164,14 +166,14 @@ gchar * get_last_error_msg(void) | ||
| 164 | 166 | ||
| 165 | HKEY key_handle; | 167 | HKEY key_handle; |
| 166 | 168 | ||
| 167 | - if(registry_open_key(group,key,KEY_READ,&key_handle)) | 169 | + if(registry_open_key(group,KEY_READ,&key_handle)) |
| 168 | { | 170 | { |
| 169 | DWORD data; | 171 | DWORD data; |
| 170 | gboolean ret = def; | 172 | gboolean ret = def; |
| 171 | unsigned long datalen = sizeof(data); | 173 | unsigned long datalen = sizeof(data); |
| 172 | unsigned long datatype; | 174 | unsigned long datatype; |
| 173 | 175 | ||
| 174 | - if(RegQueryValueExA(key_handle,NULL,NULL,&datatype,(BYTE *) &data,&datalen) == ERROR_SUCCESS) | 176 | + if(RegQueryValueExA(key_handle,key,NULL,&datatype,(BYTE *) &data,&datalen) == ERROR_SUCCESS) |
| 175 | { | 177 | { |
| 176 | if(datatype == REG_DWORD) | 178 | if(datatype == REG_DWORD) |
| 177 | ret = data ? TRUE : FALSE; | 179 | ret = data ? TRUE : FALSE; |
| @@ -207,14 +209,14 @@ gchar * get_last_error_msg(void) | @@ -207,14 +209,14 @@ gchar * get_last_error_msg(void) | ||
| 207 | 209 | ||
| 208 | HKEY key_handle; | 210 | HKEY key_handle; |
| 209 | 211 | ||
| 210 | - if(registry_open_key(group,key,KEY_READ,&key_handle)) | 212 | + if(registry_open_key(group,KEY_READ,&key_handle)) |
| 211 | { | 213 | { |
| 212 | DWORD data; | 214 | DWORD data; |
| 213 | gint ret = def; | 215 | gint ret = def; |
| 214 | unsigned long datalen = sizeof(data); | 216 | unsigned long datalen = sizeof(data); |
| 215 | unsigned long datatype; | 217 | unsigned long datatype; |
| 216 | 218 | ||
| 217 | - if(RegQueryValueExA(key_handle,NULL,NULL,&datatype,(BYTE *) &data,&datalen) == ERROR_SUCCESS) | 219 | + if(RegQueryValueExA(key_handle,key,NULL,&datatype,(BYTE *) &data,&datalen) == ERROR_SUCCESS) |
| 218 | { | 220 | { |
| 219 | if(datatype == REG_DWORD) | 221 | if(datatype == REG_DWORD) |
| 220 | ret = (gint) data; | 222 | ret = (gint) data; |
| @@ -255,14 +257,16 @@ gchar * get_last_error_msg(void) | @@ -255,14 +257,16 @@ gchar * get_last_error_msg(void) | ||
| 255 | unsigned long datalen = sizeof(data); | 257 | unsigned long datalen = sizeof(data); |
| 256 | gchar *ret = NULL; | 258 | gchar *ret = NULL; |
| 257 | 259 | ||
| 258 | - if(!registry_open_key(group,key,KEY_READ,&key_handle)) | 260 | + if(!registry_open_key(group,KEY_READ,&key_handle)) |
| 259 | return g_strdup(def); | 261 | return g_strdup(def); |
| 260 | 262 | ||
| 261 | - if(RegQueryValueExA(key_handle,NULL,NULL,&datatype,data,&datalen) == ERROR_SUCCESS) | 263 | + if(RegQueryValueExA(key_handle,key,NULL,&datatype,data,&datalen) == ERROR_SUCCESS) |
| 262 | { | 264 | { |
| 263 | ret = (char *) malloc(datalen+1); | 265 | ret = (char *) malloc(datalen+1); |
| 266 | + | ||
| 264 | memcpy(ret,data,datalen); | 267 | memcpy(ret,data,datalen); |
| 265 | ret[datalen+1] = 0; | 268 | ret[datalen+1] = 0; |
| 269 | + trace("%s\\%s=\"%s\"",group,key,ret); | ||
| 266 | } | 270 | } |
| 267 | else if(def) | 271 | else if(def) |
| 268 | { | 272 | { |
| @@ -353,13 +357,13 @@ void set_boolean_to_config(const gchar *group, const gchar *key, gboolean val) | @@ -353,13 +357,13 @@ void set_boolean_to_config(const gchar *group, const gchar *key, gboolean val) | ||
| 353 | 357 | ||
| 354 | HKEY hKey; | 358 | HKEY hKey; |
| 355 | DWORD disp; | 359 | DWORD disp; |
| 356 | - gchar * path = g_strdup_printf("%s\\%s\\%s",registry_path,group,key); | 360 | + gchar * path = g_strdup_printf("%s\\%s",registry_path,group); |
| 357 | 361 | ||
| 358 | trace("Creating key %s",path); | 362 | trace("Creating key %s",path); |
| 359 | if(RegCreateKeyEx(HKEY_CURRENT_USER,path,0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp) == ERROR_SUCCESS) | 363 | if(RegCreateKeyEx(HKEY_CURRENT_USER,path,0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp) == ERROR_SUCCESS) |
| 360 | { | 364 | { |
| 361 | DWORD value = val ? 1 : 0; | 365 | DWORD value = val ? 1 : 0; |
| 362 | - LONG rc = RegSetValueEx(hKey, NULL, 0, REG_DWORD,(const BYTE *) &value,sizeof(value)); | 366 | + LONG rc = RegSetValueEx(hKey, key, 0, REG_DWORD,(const BYTE *) &value,sizeof(value)); |
| 363 | 367 | ||
| 364 | SetLastError(rc); | 368 | SetLastError(rc); |
| 365 | 369 |
src/gtk/uiparser/parsefile.c