/[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 85 by twoaday, Fri Nov 18 07:20:40 2005 UTC
# Line 44  static gpg_filetype gpg_filetypes[] = { Line 44  static gpg_filetype gpg_filetypes[] = {
44  };  };
45    
46  struct reg_hotkey_s reg_hotkeys[] = {  struct reg_hotkey_s reg_hotkeys[] = {
47      {"ClipEncrypt", NULL, 0},      {"ClipEncrypt", "", 0},
48      {"ClipDecrypt", NULL, 0},      {"ClipDecrypt", "", 0},
49      {"ClipSign",    NULL, 0},      {"ClipSign",    "", 0},
50      {"ClipSignEnc", NULL, 0},      {"ClipSignEnc", "", 0},
51      {"CwsEncrypt",  NULL, 0},      {"CwsEncrypt",  "", 0},
52      {"CwsDecrypt",  NULL, 0},      {"CwsDecrypt",  "", 0},
53      {"CwsSign",     NULL, 0},      {"CwsSign",     "", 0},
54      {"CwsSignEnc",  NULL, 0},      {"CwsSignEnc",  "", 0},
55      {0}      {NULL, "", 0}
56  };  };
57    
58  winpt_reg_prefs_s reg_prefs;  winpt_reg_prefs_s reg_prefs;
# Line 116  regist_inst_gnupg (int create_mokey) Line 116  regist_inst_gnupg (int create_mokey)
116  } /* regist_inst_gpg */  } /* regist_inst_gpg */
117    
118    
119  /* Install WinPT into the W32 registry, if the entry already  /* Install WinPT into the W32 registry, if the entry already
120     exists the function returns immediately.*/     exists the function returns immediately. @with_ext can be
121       used to register some file types (if 1). @created contains
122       1 if the registry key was created.
123       Return value: 0 on success. */
124  int  int
125  regist_inst_winpt (int with_ext, int * created)  regist_inst_winpt (int with_ext, int * created)
126  {  {
127      HKEY reg;      HKEY reg;
128      char * p = NULL;      char *p = NULL;
129        char modpath[MAX_PATH+1];
130      int rc, i, id, n = 0;      int rc, i, id, n = 0;
131    
132      if( created )      if (created)
133          *created = 0;          *created = 0;
134    
135      p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");      p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");
136      if (p && *p == '1')      if (p && *p == '1')
137          with_ext = 0;          with_ext = 0;
138      free_if_alloc( p );      free_if_alloc (p);
139    
140      if( with_ext ) {      if (with_ext) {
141          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 "
142                                "be processed with a double click in the explorer.\n"                                "be processed with a double click in the explorer.\n"
143                                "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO );                                "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO);
144          if( id == IDNO ) {          if (id == IDNO) {
145              set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );              set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
146              goto start;              goto start;
147          }          }
148          for( i = 0; gpg_filetypes[i].ext; i++ ) {          for (i = 0; gpg_filetypes[i].ext; i++) {
149              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);
150              if( rc_ok( rc ) ) {              if (rc_ok (rc)) {
151                  RegCloseKey( reg );                  RegCloseKey (reg);
152                  id = log_box( _("WinPT WARNING"), MB_YESNO|MB_INFO,                  id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,
153                                _("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"
154                                  "Do you want to overwrite it?"), gpg_filetypes[i].ext );                                  "Do you want to overwrite it?"), gpg_filetypes[i].ext);
155                  if( id == IDNO )                  if (id == IDNO)
156                      continue;                      continue;
157              }              }
158              regist_single_filetype( &gpg_filetypes[i] );              regist_single_filetype (&gpg_filetypes[i]);
159              n++;              n++;
160          }          }
161      }      }
162                    
163  start:  start:
164      rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg );      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);
165      if( rc_ok( rc ) ) {      if (rc_ok (rc)) {  
166          RegCloseKey( reg );          RegCloseKey (reg);
167          rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg );          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);
168          if( !rc_ok( rc ) ) {          if (!rc_ok (rc)) {
169              RegCreateKey( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg );              RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);
170              RegCloseKey( reg );              RegCloseKey (reg);
171          }          }
172          p = get_reg_entry_keyserver ("Default");          p = get_reg_entry_keyserver ("Default");
173          if (!p) {          if (!p) {
# Line 172  start: Line 176  start:
176              set_reg_entry_keyserver ("Default_Port", buf);              set_reg_entry_keyserver ("Default_Port", buf);
177              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);
178          }          }
179          free_if_alloc( p );          free_if_alloc (p);
180          if( n )          if (n)
181              set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );              set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
182          return 0;          return 0;
183      }      }
184      rc = RegCreateKey( HKEY_CURRENT_USER, WINPT_REG, &reg );      rc = RegCreateKey(HKEY_CURRENT_USER, WINPT_REG, &reg);
185      if( !rc_ok( rc ) )      if (!rc_ok (rc))
186          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
187      if( created )      if (created)
188          *created = 1;          *created = 1;
189      RegCloseKey( reg );      RegCloseKey (reg);
190      if( n )      if (n)
191          set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );          set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
192        if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {
193            while (n-- > 0) {
194                if (modpath[n] == '\\') {
195                    modpath[n] = 0;
196                    break;
197                }
198            }
199            set_reg_entry (HKEY_CURRENT_USER, WINPT_REG,
200                           "Install Directory", modpath);
201        }
202        
203      return 0;      return 0;
204  } /* regist_inst_winpt */  }
205    
206    
207  /* 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 292  get_reg_entry (HKEY root_key, const char
292  {  {
293      int rc;      int rc;
294      char text[384] = {0};      char text[384] = {0};
295      DWORD nbytes, type, n1 = 0;      DWORD nbytes, type;
296      HKEY reg_key = NULL;      HKEY reg_key = NULL;
297      char * p = NULL, * tmp = NULL;      char *p = NULL;
298            
299      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);
300      if( !rc_ok( rc ) )      if( !rc_ok( rc ) )
# Line 380  get_reg_entry_gpg (const char *key) Line 395  get_reg_entry_gpg (const char *key)
395  }  }
396    
397    
398  char *  /* Return if possible the GPG4Win installation directory concatenated
399  get_reg_entry_mo(void)     with the string in @path if given. */
400    char*
401    get_reg_entry_gpg4win (const char *path)
402    {
403        char *p, *pp;
404        p = get_reg_entry (HKEY_LOCAL_MACHINE,
405                           "Software\\GNU\\GnuPG", "Install Directory");
406        if (!p)
407            return NULL;
408        if (!path)
409            return p;
410        pp = new char[strlen (p) + strlen (path) + 4];
411        if (!pp)
412            BUG (NULL);
413        sprintf (pp, "%s\\%s", p, path);
414        free_if_alloc (p);
415        return pp;
416    }
417    
418        
419    char*
420    get_reg_entry_mo (void)
421  {        {      
422      return get_reg_entry(HKEY_CURRENT_USER,      char *p, *pp;
423                           "Control Panel\\Mingw32\\NLS", "MODir");      const char *lang;
424        
425        p = get_reg_entry (HKEY_CURRENT_USER,
426                           "Control Panel\\Mingw32\\NLS", "MODir");
427        if (p)
428            return p;
429        
430        lang = get_gettext_langid ();
431        if (!lang)
432            return NULL;
433        pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8];
434        if (!pp)
435            BUG (NULL);
436        sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang);
437        p = get_reg_entry_gpg4win (pp);
438        free_if_alloc (pp);
439        return p;
440  }  }
441    
442    
# Line 440  int Line 492  int
492  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)
493  {  {
494      char buf[128];      char buf[128];
495      int rc = 0, i;      size_t i;
496        int rc = 0;
497    
498      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
499          switch (i) {          switch (i) {
# Line 550  int Line 603  int
603  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)
604  {  {
605      char * val = NULL;      char * val = NULL;
606      int i;      size_t i;
607    
608      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
609          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.85

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26