/[winpt]/trunk/Src/wptRegistry.cpp
ViewVC logotype

Diff of /trunk/Src/wptRegistry.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 48 by werner, Mon Oct 31 21:14:11 2005 UTC revision 117 by twoaday, Thu Dec 8 09:26:32 2005 UTC
# Line 43  static gpg_filetype gpg_filetypes[] = { Line 43  static gpg_filetype gpg_filetypes[] = {
43      {0}      {0}
44  };  };
45    
46    
47  struct reg_hotkey_s reg_hotkeys[] = {  struct reg_hotkey_s reg_hotkeys[] = {
48      {"ClipEncrypt", NULL, 0},      {"ClipEncrypt", "", 0},
49      {"ClipDecrypt", NULL, 0},      {"ClipDecrypt", "", 0},
50      {"ClipSign",    NULL, 0},      {"ClipSign",    "", 0},
51      {"ClipSignEnc", NULL, 0},      {"ClipSignEnc", "", 0},
52      {"CwsEncrypt",  NULL, 0},      {"CwsEncrypt",  "", 0},
53      {"CwsDecrypt",  NULL, 0},      {"CwsDecrypt",  "", 0},
54      {"CwsSign",     NULL, 0},      {"CwsSign",     "", 0},
55      {"CwsSignEnc",  NULL, 0},      {"CwsSignEnc",  "", 0},
56      {0}      {NULL, "", 0}
57  };  };
58    
59  winpt_reg_prefs_s reg_prefs;  winpt_reg_prefs_s reg_prefs;
# Line 60  winpt_reg_prefs_s reg_prefs; Line 61  winpt_reg_prefs_s reg_prefs;
61  #define WINPT_REG "Software\\WinPT"  #define WINPT_REG "Software\\WinPT"
62    
63    
64    /* Return != 0 if GPGee is installed. */
65    int
66    is_gpgee_installed (void)
67    {
68        HKEY hk;
69        LONG ec;
70    
71        ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\GPGee", 0, KEY_READ, &hk);
72        if (ec == ERROR_SUCCESS) {
73            RegCloseKey (hk);
74            return -1;
75        }
76    
77        return 0;
78    }
79    
80    
81    /* Free all members in the registry preference struct. */
82  void  void
83  free_reg_prefs (void)  free_reg_prefs (void)
84  {  {
# Line 67  free_reg_prefs (void) Line 86  free_reg_prefs (void)
86      free_if_alloc (reg_prefs.kserv_conf);      free_if_alloc (reg_prefs.kserv_conf);
87      free_if_alloc (reg_prefs.homedir);      free_if_alloc (reg_prefs.homedir);
88      memset (&reg_prefs, 0, sizeof reg_prefs);      memset (&reg_prefs, 0, sizeof reg_prefs);
89  } /* free_reg_prefs */  }
90    
91    
92  /* Register the given WinPT filetype. */  /* Register the given WinPT filetype. */
# Line 80  regist_single_filetype (gpg_filetype *gf Line 99  regist_single_filetype (gpg_filetype *gf
99      GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);      GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);
100      _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);      _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);
101      return create_file_type (prog, gfile->ext, gfile->descr, icon);      return create_file_type (prog, gfile->ext, gfile->descr, icon);
102  } /* regist_single_filetype */  }
103    
104    
105  /* Install the GPG related into the W32 resgistry, if the entry already  /* Install the GPG related into the W32 resgistry, if the entry already
# Line 117  regist_inst_gnupg (int create_mokey) Line 136  regist_inst_gnupg (int create_mokey)
136    
137    
138  /* Install WinPT into the W32 registry, if the entry already  /* Install WinPT into the W32 registry, if the entry already
139     exists the function returns immediately.*/     exists the function returns immediately. @with_ext can be
140       used to register some file types (if 1). @created contains
141       1 if the registry key was created.
142       Return value: 0 on success. */
143  int  int
144  regist_inst_winpt (int with_ext, int * created)  regist_inst_winpt (int with_ext, int *created)
145  {  {
146      HKEY reg;      HKEY reg;
147      char * p = NULL;      char *p = NULL;
148        char modpath[MAX_PATH+1];
149      int rc, i, id, n = 0;      int rc, i, id, n = 0;
150    
151      if( created )      if (created)
152          *created = 0;          *created = 0;
153    
154      p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");      p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");
155      if (p && *p == '1')      if ((p && *p == '1') || is_gpgee_installed ())
156          with_ext = 0;          with_ext = 0;
157      free_if_alloc( p );      free_if_alloc (p);
158    
159      if( with_ext ) {      if (with_ext) {
160          id = msg_box( NULL, _("WinPT can register some GPG file types for you so they can "          id = msg_box (NULL, _("WinPT can register some GPG file types for you so they can "
161                                "be processed with a double click in the explorer.\n"                                "be processed with a double click in the explorer.\n"
162                                "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO );                                "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO);
163          if( id == IDNO ) {          if (id == IDNO) {
164              set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );              set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
165              goto start;              goto start;
166          }          }
167          for( i = 0; gpg_filetypes[i].ext; i++ ) {          for (i = 0; gpg_filetypes[i].ext; i++) {
168              rc = RegOpenKeyEx( HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, &reg );              rc = RegOpenKeyEx (HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, &reg);
169              if( rc_ok( rc ) ) {              if (rc_ok (rc)) {
170                  RegCloseKey( reg );                  RegCloseKey (reg);
171                  id = log_box( _("WinPT WARNING"), MB_YESNO|MB_INFO,                  id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,
172                                _("It seems there was already a '%s' file type registered by another application.\n"                                _("It seems there was already a '%s' file type registered by another application.\n"
173                                  "Do you want to overwrite it?"), gpg_filetypes[i].ext );                                  "Do you want to overwrite it?"), gpg_filetypes[i].ext);
174                  if( id == IDNO )                  if (id == IDNO)
175                      continue;                      continue;
176              }              }
177              regist_single_filetype( &gpg_filetypes[i] );              regist_single_filetype (&gpg_filetypes[i]);
178              n++;              n++;
179          }          }
180      }      }
181                    
182  start:  start:
183      rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg );      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);
184      if( rc_ok( rc ) ) {      if (rc_ok (rc)) {
185          RegCloseKey( reg );          RegCloseKey (reg);
186          rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg );          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);
187          if( !rc_ok( rc ) ) {          if( !rc_ok (rc)) {
188              RegCreateKey( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg );              RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);
189              RegCloseKey( reg );              RegCloseKey (reg);
190          }          }
191          p = get_reg_entry_keyserver ("Default");          p = get_reg_entry_keyserver ("Default");
192          if (!p) {          if (!p) {
# Line 172  start: Line 195  start:
195              set_reg_entry_keyserver ("Default_Port", buf);              set_reg_entry_keyserver ("Default_Port", buf);
196              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);
197          }          }
198          free_if_alloc( p );          free_if_alloc (p);
199          if( n )          if (n)
200              set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );              set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
201          return 0;          return 0;
202      }      }
203      rc = RegCreateKey( HKEY_CURRENT_USER, WINPT_REG, &reg );      rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);
204      if( !rc_ok( rc ) )      if (!rc_ok (rc))
205          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
206      if( created )      if (created)
207          *created = 1;          *created = 1;
208      RegCloseKey( reg );      RegCloseKey (reg);
209      if( n )      if (n)
210          set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );          set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
211        if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {
212            while (n-- > 0) {
213                if (modpath[n] == '\\') {
214                    modpath[n] = 0;
215                    break;
216                }
217            }
218            set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Install Directory", modpath);
219        }
220      return 0;      return 0;
221  } /* regist_inst_winpt */  }
222    
223    
224  /* Create a new filetype in the W32 registry.  /* Create a new filetype in the W32 registry.
# Line 277  get_reg_entry (HKEY root_key, const char Line 309  get_reg_entry (HKEY root_key, const char
309  {  {
310      int rc;      int rc;
311      char text[384] = {0};      char text[384] = {0};
312      DWORD nbytes, type, n1 = 0;      DWORD nbytes, type;
313      HKEY reg_key = NULL;      HKEY reg_key = NULL;
314      char * p = NULL, * tmp = NULL;      char *p = NULL;
315            
316      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);
317      if( !rc_ok( rc ) )      if( !rc_ok( rc ) )
# Line 365  set_reg_entry_gpg (const char * key, con Line 397  set_reg_entry_gpg (const char * key, con
397  }  }
398    
399    
400    
401    
402  int  int
403  set_reg_entry_mo (const char * value)  set_reg_entry_mo (const char * value)
404  {        {      
# Line 380  get_reg_entry_gpg (const char *key) Line 414  get_reg_entry_gpg (const char *key)
414  }  }
415    
416    
417  char *  /* Return if possible the GPG4Win installation directory concatenated
418  get_reg_entry_mo(void)     with the string in @path if given. */
419    char*
420    get_reg_entry_gpg4win (const char *path)
421    {
422        char *p, *pp;
423        p = get_reg_entry (HKEY_LOCAL_MACHINE,
424                           "Software\\GNU\\GnuPG", "Install Directory");
425        if (!p)
426            return NULL;
427        if (!path)
428            return p;
429        pp = new char[strlen (p) + strlen (path) + 4];
430        if (!pp)
431            BUG (NULL);
432        sprintf (pp, "%s\\%s", p, path);
433        free_if_alloc (p);
434        return pp;
435    }
436    
437        
438    char*
439    get_reg_entry_mo (void)
440  {        {      
441      return get_reg_entry(HKEY_CURRENT_USER,      char *p, *pp;
442                           "Control Panel\\Mingw32\\NLS", "MODir");      const char *lang;
443    
444        p = get_reg_entry (HKEY_CURRENT_USER,
445                           "Control Panel\\Mingw32\\NLS", "MODir");
446        if (p)
447            return p;
448    
449        lang = get_gettext_langid ();
450        if (!lang)    
451            return NULL;    
452        pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8];
453        if (!pp)    
454            BUG (NULL);
455        sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang);
456        p = get_reg_entry_gpg4win (pp);
457        free_if_alloc (pp);
458        return p;
459  }  }
460    
461    
# Line 422  set_reg_winpt_single (int id, int val) Line 493  set_reg_winpt_single (int id, int val)
493  int  int
494  get_reg_winpt_single (int id)  get_reg_winpt_single (int id)
495  {  {
496      char * buf = NULL;      char *buf = NULL;
497      int val = 0;      int val = 0;
498    
499      buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]);      buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]);
# Line 440  int Line 511  int
511  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)
512  {  {
513      char buf[128];      char buf[128];
514      int rc = 0, i;      size_t i;
515        int rc = 0;
516    
517      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
518          switch (i) {          switch (i) {
# Line 549  get_reg_winpt_flag (const char * name) Line 621  get_reg_winpt_flag (const char * name)
621  int  int
622  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)
623  {  {
624      char * val = NULL;      char *val = NULL;
625      int i;      size_t i;
626    
627      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
628          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]);          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]);

Legend:
Removed from v.48  
changed lines
  Added in v.117

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26