Commit ae8854de92bd4ee26bf38e9e1ffcf738ff767798

Authored by perry.werneck@gmail.com
1 parent f4244f19

Melhorando montagem de nomes de arquivo

Showing 2 changed files with 76 additions and 32 deletions   Show diff stats
src/gtk/common/config.c
@@ -35,8 +35,18 @@ @@ -35,8 +35,18 @@
35 #include <glib/gstdio.h> 35 #include <glib/gstdio.h>
36 36
37 #ifdef WIN32 37 #ifdef WIN32
  38 +
38 #include <windows.h> 39 #include <windows.h>
39 #define WIN_REGISTRY_ENABLED 1 40 #define WIN_REGISTRY_ENABLED 1
  41 +
  42 + #ifndef KEY_WOW64_64KEY
  43 + #define KEY_WOW64_64KEY 0x0100
  44 + #endif // KEY_WOW64_64KEY
  45 +
  46 + #ifndef KEY_WOW64_32KEY
  47 + #define KEY_WOW64_32KEY 0x0200
  48 + #endif // KEY_WOW64_64KEY
  49 +
40 #endif // WIN32 50 #endif // WIN32
41 51
42 /*--[ Globals ]--------------------------------------------------------------------------------------*/ 52 /*--[ Globals ]--------------------------------------------------------------------------------------*/
@@ -469,13 +479,53 @@ void configuration_deinit(void) @@ -469,13 +479,53 @@ void configuration_deinit(void)
469 479
470 gchar * build_data_filename(const gchar *first_element, ...) 480 gchar * build_data_filename(const gchar *first_element, ...)
471 { 481 {
472 - va_list args;  
473 - GString * result;  
474 - const gchar * element; 482 + static const gchar * datadir = NULL;
  483 + const gchar * appname[] = { g_get_application_name(), PACKAGE_NAME };
  484 + GString * result = NULL;
  485 + const gchar * element;
  486 + va_list args;
  487 +
  488 + if(datadir)
  489 + result = g_string_new(datadir);
475 490
476 #if defined( WIN_REGISTRY_ENABLED ) 491 #if defined( WIN_REGISTRY_ENABLED )
  492 + if(!result)
  493 + {
  494 + // No predefined datadir, search registry
  495 + int p;
  496 +
  497 + for(p=0;p<G_N_ELEMENTS(appname) && !result;p++)
  498 + {
  499 + gchar * path = g_strconcat("SOFTWARE\\",appname[p],"\\datadir",NULL);
  500 + HKEY hKey = 0;
  501 + LONG rc = 0;
  502 +
  503 + // Note: This could be needed: http://support.microsoft.com/kb/556009
  504 + // http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx
  505 +
  506 + rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,path,0,KEY_QUERY_VALUE|KEY_WOW64_64KEY,&hKey);
  507 + SetLastError(rc);
477 508
478 - static const gchar *reg_datadir = "SOFTWARE\\"PACKAGE_NAME"\\datadir"; 509 + if(rc == ERROR_SUCCESS)
  510 + {
  511 + char data[4096];
  512 + unsigned long datalen = sizeof(data); // data field length(in), data returned length(out)
  513 + unsigned long datatype; // #defined in winnt.h (predefined types 0-11)
  514 +
  515 + if(RegQueryValueExA(hKey,NULL,NULL,&datatype,(LPBYTE) data,&datalen) == ERROR_SUCCESS)
  516 + result = g_string_new(g_strchomp(data));
  517 + RegCloseKey(hKey);
  518 + }
  519 +
  520 + g_free(path);
  521 + }
  522 + }
  523 +#endif // WIN_REGISTRY_ENABLED
  524 +
  525 +/*
  526 +#if defined( WIN_REGISTRY_ENABLED )
  527 +
  528 + gchar *reg_datadir = g_strconcat("SOFTWARE\\",g_get_application_name(),"\\datadir",NULL);
479 529
480 HKEY hKey = 0; 530 HKEY hKey = 0;
481 LONG rc = 0; 531 LONG rc = 0;
@@ -483,14 +533,6 @@ gchar * build_data_filename(const gchar *first_element, ...) @@ -483,14 +533,6 @@ gchar * build_data_filename(const gchar *first_element, ...)
483 // Note: This could be needed: http://support.microsoft.com/kb/556009 533 // Note: This could be needed: http://support.microsoft.com/kb/556009
484 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx 534 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx
485 535
486 -#ifndef KEY_WOW64_64KEY  
487 - #define KEY_WOW64_64KEY 0x0100  
488 -#endif // KEY_WOW64_64KEY  
489 -  
490 -#ifndef KEY_WOW64_32KEY  
491 - #define KEY_WOW64_32KEY 0x0200  
492 -#endif // KEY_WOW64_64KEY  
493 -  
494 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,reg_datadir,0,KEY_QUERY_VALUE|KEY_WOW64_64KEY,&hKey); 536 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,reg_datadir,0,KEY_QUERY_VALUE|KEY_WOW64_64KEY,&hKey);
495 SetLastError(rc); 537 SetLastError(rc);
496 538
@@ -554,35 +596,37 @@ gchar * build_data_filename(const gchar *first_element, ...) @@ -554,35 +596,37 @@ gchar * build_data_filename(const gchar *first_element, ...)
554 596
555 result = g_string_new(APPDATA); 597 result = g_string_new(APPDATA);
556 598
557 -#else 599 +#endif
558 600
559 - static const gchar *datadir = NULL; 601 +*/
560 602
561 - if(!datadir) 603 + if(!result)
562 { 604 {
  605 + // Search for application folder on system data dirs
563 const gchar * const * dir = g_get_system_data_dirs(); 606 const gchar * const * dir = g_get_system_data_dirs();
564 - int f; 607 + int p;
565 608
566 - for(f=0;dir[f] && !datadir;f++) 609 + for(p=0;p<G_N_ELEMENTS(appname) && !datadir;p++)
567 { 610 {
568 - gchar *name = g_build_filename(dir[f],PACKAGE_NAME,NULL);  
569 - if(g_file_test(name,G_FILE_TEST_IS_DIR))  
570 - datadir = name;  
571 - else  
572 - g_free(name);  
573 - } 611 + int f;
574 612
575 - if(!datadir)  
576 - {  
577 - datadir = g_get_current_dir();  
578 - g_warning("Unable to find application datadir, using %s",datadir); 613 + for(f=0;dir[f] && !datadir;f++)
  614 + {
  615 + gchar *name = g_build_filename(dir[f],appname[p],NULL);
  616 + if(g_file_test(name,G_FILE_TEST_IS_DIR))
  617 + datadir = name;
  618 + else
  619 + g_free(name);
  620 + }
579 } 621 }
580 622
581 } 623 }
582 624
583 - result = g_string_new(datadir);  
584 -  
585 -#endif 625 + if(!result)
  626 + {
  627 + result = g_string_new(g_get_current_dir());
  628 + g_warning("Unable to find application datadir, using %s",result->str);
  629 + }
586 630
587 va_start(args, first_element); 631 va_start(args, first_element);
588 632
ui/00default.xml
@@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
37 Extended attributes for 'save' actions: 37 Extended attributes for 'save' actions:
38 38
39 * overwrite='yes' to always overwrite file 39 * overwrite='yes' to always overwrite file
40 - * filename='PATH' to save to a predefined file (no user save dialog) 40 + * filename='PATH' to save to a predefined file whithout user interaction
41 41
42 ---> 42 --->
43 <menuitem action='save' src='all' group='online' label='Save screen' /> 43 <menuitem action='save' src='all' group='online' label='Save screen' />
@@ -45,7 +45,7 @@ @@ -45,7 +45,7 @@
45 <menuitem action='save' src='copy' group='clipboard' label='Save copy' /> 45 <menuitem action='save' src='copy' group='clipboard' label='Save copy' />
46 46
47 <separator/> 47 <separator/>
48 - <menuitem action='print' src='all' key='Print' icon='print' label='Print' /> 48 + <menuitem action='print' src='all' group='online' key='Print' icon='print' label='Print' />
49 <menuitem action='print' src='selected' group='selection' label='Print selected' /> 49 <menuitem action='print' src='selected' group='selection' label='Print selected' />
50 <menuitem action='print' src='copy' group='clipboard' label='Print copy' /> 50 <menuitem action='print' src='copy' group='clipboard' label='Print copy' />
51 <separator/> 51 <separator/>