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 | 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 | 313 | static int setup_block_action(const gchar *name, const gchar *attr, GError **error) |
| 288 | 314 | { |
| 289 | 315 | int id = -1; |
| ... | ... | @@ -392,30 +418,20 @@ GtkAction * ui_get_action(GtkWidget *widget, const gchar *name, GHashTable *hash |
| 392 | 418 | } |
| 393 | 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 | 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 | 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 | 437 | else if(!g_strcasecmp(name,"copy")) |
| ... | ... | @@ -434,16 +450,9 @@ GtkAction * ui_get_action(GtkWidget *widget, const gchar *name, GHashTable *hash |
| 434 | 450 | }; |
| 435 | 451 | callback = cbk; |
| 436 | 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 | 454 | if(id < 0) |
| 441 | - { | |
| 442 | - *error = g_error_new(ERROR_DOMAIN,EINVAL,_("Unexpected or invalid mode attribute: \"%s\"" ), attr); | |
| 443 | 455 | return NULL; |
| 444 | - } | |
| 445 | - | |
| 446 | - nm = g_strconcat(name,attr,NULL); | |
| 447 | 456 | } |
| 448 | 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 | 84 | #endif // WIN32 |
| 85 | 85 | |
| 86 | 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 | 89 | static HKEY predefined[] = { HKEY_CURRENT_USER, HKEY_USERS, HKEY_LOCAL_MACHINE }; |
| 90 | 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 | 93 | for(f=0;f<G_N_ELEMENTS(predefined);f++) |
| 94 | 94 | { |
| ... | ... | @@ -99,7 +99,9 @@ gchar * get_last_error_msg(void) |
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | + trace("Cant open \"%s\"",path); | |
| 102 | 103 | g_free(path); |
| 104 | + | |
| 103 | 105 | return FALSE; |
| 104 | 106 | } |
| 105 | 107 | #else |
| ... | ... | @@ -164,14 +166,14 @@ gchar * get_last_error_msg(void) |
| 164 | 166 | |
| 165 | 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 | 171 | DWORD data; |
| 170 | 172 | gboolean ret = def; |
| 171 | 173 | unsigned long datalen = sizeof(data); |
| 172 | 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 | 178 | if(datatype == REG_DWORD) |
| 177 | 179 | ret = data ? TRUE : FALSE; |
| ... | ... | @@ -207,14 +209,14 @@ gchar * get_last_error_msg(void) |
| 207 | 209 | |
| 208 | 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 | 214 | DWORD data; |
| 213 | 215 | gint ret = def; |
| 214 | 216 | unsigned long datalen = sizeof(data); |
| 215 | 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 | 221 | if(datatype == REG_DWORD) |
| 220 | 222 | ret = (gint) data; |
| ... | ... | @@ -255,14 +257,16 @@ gchar * get_last_error_msg(void) |
| 255 | 257 | unsigned long datalen = sizeof(data); |
| 256 | 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 | 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 | 265 | ret = (char *) malloc(datalen+1); |
| 266 | + | |
| 264 | 267 | memcpy(ret,data,datalen); |
| 265 | 268 | ret[datalen+1] = 0; |
| 269 | + trace("%s\\%s=\"%s\"",group,key,ret); | |
| 266 | 270 | } |
| 267 | 271 | else if(def) |
| 268 | 272 | { |
| ... | ... | @@ -353,13 +357,13 @@ void set_boolean_to_config(const gchar *group, const gchar *key, gboolean val) |
| 353 | 357 | |
| 354 | 358 | HKEY hKey; |
| 355 | 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 | 362 | trace("Creating key %s",path); |
| 359 | 363 | if(RegCreateKeyEx(HKEY_CURRENT_USER,path,0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp) == ERROR_SUCCESS) |
| 360 | 364 | { |
| 361 | 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 | 368 | SetLastError(rc); |
| 365 | 369 | ... | ... |