/[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 69 by twoaday, Sat Nov 5 12:28:12 2005 UTC revision 167 by twoaday, Thu Jan 26 10:17:17 2006 UTC
# Line 36  Line 36 
36    
37  #define rc_ok(rc) ((rc) == ERROR_SUCCESS)  #define rc_ok(rc) ((rc) == ERROR_SUCCESS)
38    
39  static gpg_filetype gpg_filetypes[] = {  
     {"GPG Detached Signature", ".sig", 1},  
     {"GPG Encrypted Data",     ".gpg", 2},  
     {"GPG Armored Data",       ".asc", 2},  
     {0}  
 };  
40    
41  struct reg_hotkey_s reg_hotkeys[] = {  struct reg_hotkey_s reg_hotkeys[] = {
42      {"ClipEncrypt", "", 0},      {"ClipEncrypt", "", 0},
# Line 60  winpt_reg_prefs_s reg_prefs; Line 55  winpt_reg_prefs_s reg_prefs;
55  #define WINPT_REG "Software\\WinPT"  #define WINPT_REG "Software\\WinPT"
56    
57    
58    /* Return != 0 if GPG4win is installed. */
59    int
60    is_gpg4win_installed (void)
61    {
62        char *p;
63    
64        p = get_reg_entry_gpg4win (NULL);
65        if (!p)
66            return 0;
67        if (dir_exist_check (p)) {
68            free_if_alloc (p);
69            return 0;
70        }
71        free_if_alloc (p);
72        return -1;
73    }
74    
75    
76    /* Return != 0 if GPGee is installed. */
77    int
78    is_gpgee_installed (void)
79    {
80        HKEY hk;
81        LONG ec;
82    
83        ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\GPGee", 0, KEY_READ, &hk);
84        if (ec == ERROR_SUCCESS) {
85            RegCloseKey (hk);
86            return -1;
87        }
88    
89        return 0;
90    }
91    
92    
93    /* Free all members in the registry preference struct. */
94  void  void
95  free_reg_prefs (void)  free_reg_prefs (void)
96  {  {
# Line 67  free_reg_prefs (void) Line 98  free_reg_prefs (void)
98      free_if_alloc (reg_prefs.kserv_conf);      free_if_alloc (reg_prefs.kserv_conf);
99      free_if_alloc (reg_prefs.homedir);      free_if_alloc (reg_prefs.homedir);
100      memset (&reg_prefs, 0, sizeof reg_prefs);      memset (&reg_prefs, 0, sizeof reg_prefs);
101  } /* free_reg_prefs */  }
102    
103    
104  /* Register the given WinPT filetype. */  /* Register the given WinPT filetype. */
105  static int  static int
106  regist_single_filetype (gpg_filetype *gfile)  regist_single_filetype (gpg_filetype *gfile)
107  {  {
108      char icon[256], prog[256];      char icon[256];
109        char prog[256];
110            
111      memset (&icon, 0, sizeof (icon));      memset (&icon, 0, sizeof (icon));
112      GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);      GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);
113      _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);      _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);
114      return create_file_type (prog, gfile->ext, gfile->descr, icon);      return create_file_type (prog, gfile->ext, gfile->descr, icon);
115  } /* regist_single_filetype */  }
116    
117    
118  /* 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 113  regist_inst_gnupg (int create_mokey) Line 145  regist_inst_gnupg (int create_mokey)
145      }      }
146    
147      return 0;      return 0;
148  } /* regist_inst_gpg */  }
149    
150    
151  /* Install WinPT into the W32 registry, if the entry already  /* Install WinPT into the W32 registry, if the entry already
152     exists the function returns immediately.*/     exists the function returns immediately. @with_ext can be
153       used to register some file types (if 1). @created contains
154       1 if the registry key was created.
155       Return value: 0 on success. */
156  int  int
157  regist_inst_winpt (int with_ext, int * created)  regist_inst_winpt (int with_ext, int *created)
158  {  {    
159      HKEY reg;      HKEY reg;
160      char * p = NULL;      char *p = NULL;
161        char modpath[MAX_PATH+1];
162      int rc, i, id, n = 0;      int rc, i, id, n = 0;
163    
164      if( created )      gpg_filetype gpg_filetypes[] = {
165            {_("GPG Detached Signature"), ".sig", 1},
166            {_("GPG Encrypted Data"),     ".gpg", 2},
167            {_("GPG Armored Data"),       ".asc", 2},
168            {0}
169        };
170    
171        if (created)
172          *created = 0;          *created = 0;
173    
174      p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");      p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");
175      if (p && *p == '1')      if ((p && *p == '1') || is_gpgee_installed ())
176          with_ext = 0;          with_ext = 0;
177      free_if_alloc( p );      free_if_alloc (p);
178    
179      if( with_ext ) {      if (with_ext) {
180          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 "
181                                "be processed with a double click in the explorer.\n"                                "be processed with a double click in the explorer.\n"
182                                "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO );                                "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO);
183          if( id == IDNO ) {          if (id == IDNO) {
184              set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );              set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
185              goto start;              goto start;
186          }          }
187          for( i = 0; gpg_filetypes[i].ext; i++ ) {          for (i = 0; gpg_filetypes[i].ext; i++) {
188              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);
189              if( rc_ok( rc ) ) {              if (rc_ok (rc)) {
190                  RegCloseKey( reg );                  RegCloseKey (reg);
191                  id = log_box( _("WinPT WARNING"), MB_YESNO|MB_INFO,                  id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,
192                                _("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"
193                                  "Do you want to overwrite it?"), gpg_filetypes[i].ext );                                  "Do you want to overwrite it?"), gpg_filetypes[i].ext);
194                  if( id == IDNO )                  if (id == IDNO)
195                      continue;                      continue;
196              }              }
197              regist_single_filetype( &gpg_filetypes[i] );              regist_single_filetype (&gpg_filetypes[i]);
198              n++;              n++;
199          }          }
200      }      }
201                    
202  start:  start:
203      rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg );      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);
204      if( rc_ok( rc ) ) {      if (rc_ok (rc)) {
205          RegCloseKey( reg );          RegCloseKey (reg);
206          rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg );          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);
207          if( !rc_ok( rc ) ) {          if (!rc_ok (rc)) {
208              RegCreateKey( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg );              RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);
209              RegCloseKey( reg );              RegCloseKey (reg);
210          }          }
211          p = get_reg_entry_keyserver ("Default");          p = get_reg_entry_keyserver ("Default");
212          if (!p) {          if (!p) {
# Line 172  start: Line 215  start:
215              set_reg_entry_keyserver ("Default_Port", buf);              set_reg_entry_keyserver ("Default_Port", buf);
216              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);
217          }          }
218          free_if_alloc( p );          free_if_alloc (p);
219          if( n )          if (n)
220              set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );              set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );
221          return 0;          return 0;
222      }      }
223      rc = RegCreateKey( HKEY_CURRENT_USER, WINPT_REG, &reg );      rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);
224      if( !rc_ok( rc ) )      if (!rc_ok (rc))
225          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
226      if( created )      if (created)
227          *created = 1;          *created = 1;
228      RegCloseKey( reg );      RegCloseKey (reg);
229      if( n )      if (n > 0 || is_gpgee_installed ())
230          set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );          set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
231        if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {
232            while (n-- > 0) {
233                if (modpath[n] == '\\') {
234                    modpath[n] = 0;
235                    break;
236                }
237            }
238            set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Install Directory", modpath);
239        }
240      return 0;      return 0;
241  } /* regist_inst_winpt */  }
242    
243    
244  /* Create a new filetype in the W32 registry.  /* Create a new filetype in the W32 registry.
245     We should really care of errors! Otherwise we can damage the registry! */     We should really care of errors! Otherwise we can damage the registry! */
246  int  int
247  create_file_type( const char *exefile, const char *ext, const char *extname, char *iconfile )  create_file_type (const char *exefile, const char *ext,
248                      const char *extname, char *iconfile)
249  {  {
250      int rc;      int rc;
251      HKEY reg = NULL;      HKEY reg = NULL;
# Line 258  expand_path (const char *path) Line 311  expand_path (const char *path)
311          return NULL;          return NULL;
312      len += 1;      len += 1;
313      p = new char[len+1];      p = new char[len+1];
314      if( !p )      if (!p)
315          return NULL;          return NULL;
316      len = ExpandEnvironmentStrings (path, p, len);      len = ExpandEnvironmentStrings (path, p, len);
317      if (!len) {      if (!len) {
# Line 266  expand_path (const char *path) Line 319  expand_path (const char *path)
319          return NULL;          return NULL;
320      }      }
321      return p;      return p;
322  } /* expand_path */  }
323    
324    
325  /* Retrieve a registry entry with the directory given in @dir  /* Retrieve a registry entry with the directory given in @dir
# Line 279  get_reg_entry (HKEY root_key, const char Line 332  get_reg_entry (HKEY root_key, const char
332      char text[384] = {0};      char text[384] = {0};
333      DWORD nbytes, type;      DWORD nbytes, type;
334      HKEY reg_key = NULL;      HKEY reg_key = NULL;
335      char *p = NULL;      char * p = NULL;
336            
337      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);
338      if( !rc_ok( rc ) )      if( !rc_ok( rc ) )
# Line 373  set_reg_entry_mo (const char * value) Line 426  set_reg_entry_mo (const char * value)
426  }  }
427    
428    
429  char *  char*
430  get_reg_entry_gpg (const char *key)  get_reg_entry_gpg (const char *key)
431  {  {
432      return get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key);      char *p;
433        p = get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key);
434        if (!p || strlen (p) == 0) {
435            free_if_alloc (p);
436            return NULL;
437        }
438        return p;
439  }  }
440    
441    
442  char *  /* Return if possible the GPG4Win installation directory concatenated
443  get_reg_entry_mo(void)     with the string in @path if given. */
444    char*
445    get_reg_entry_gpg4win (const char *path)
446    {
447        char *p, *pp;
448        p = get_reg_entry (HKEY_LOCAL_MACHINE,
449                           "Software\\GNU\\GnuPG", "Install Directory");
450        if (!p)
451            return NULL;
452        if (!path)
453            return p;
454        pp = new char[strlen (p) + strlen (path) + 4];
455        if (!pp)
456            BUG (NULL);
457        sprintf (pp, "%s\\%s", p, path);
458        free_if_alloc (p);
459        return pp;
460    }
461    
462        
463    char*
464    get_reg_entry_mo (void)
465  {        {      
466      return get_reg_entry(HKEY_CURRENT_USER,      char *p, *pp;
467                           "Control Panel\\Mingw32\\NLS", "MODir");      const char *lang;
468    
469        p = get_reg_entry (HKEY_CURRENT_USER,
470                           "Control Panel\\Mingw32\\NLS", "MODir");
471        if (p)
472            return p;
473    
474        lang = get_gettext_langid ();
475        if (!lang)    
476            return NULL;    
477        pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8];
478        if (!pp)    
479            BUG (NULL);
480        sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang);
481        p = get_reg_entry_gpg4win (pp);
482        free_if_alloc (pp);
483        return p;
484  }  }
485    
486    
# Line 440  int Line 536  int
536  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)
537  {  {
538      char buf[128];      char buf[128];
539      int rc = 0, i;      size_t i;
540        int rc = 0;
541    
542      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
543          switch (i) {          switch (i) {
# Line 496  set_reg_winpt_prefs (winpt_reg_prefs_s * Line 593  set_reg_winpt_prefs (winpt_reg_prefs_s *
593          if (rc)          if (rc)
594              goto leave;              goto leave;
595      }      }
     if (opt->kserv_conf) {  
         rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig",  
                             opt->kserv_conf);  
         if (rc)  
             goto leave;  
     }  
596    
597      for (i=0; reg_hotkeys[i].reg_entry; i++) {      for (i=0; reg_hotkeys[i].reg_entry; i++) {
598          strcpy (buf, " ");          strcpy (buf, " ");
# Line 549  get_reg_winpt_flag (const char * name) Line 640  get_reg_winpt_flag (const char * name)
640  int  int
641  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)
642  {  {
643      char * val = NULL;      char *val = NULL;
644      int i;      size_t i;
645    
646      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
647          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]);          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]);
# Line 612  get_reg_winpt_prefs (winpt_reg_prefs_s * Line 703  get_reg_winpt_prefs (winpt_reg_prefs_s *
703      if (val && val[0] != ' ')      if (val && val[0] != ' ')
704          opt->backup.path = m_strdup (val);          opt->backup.path = m_strdup (val);
705      free_if_alloc (val);      free_if_alloc (val);
   
     val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig");  
     if (val && val[0] != ' ')  
         opt->kserv_conf = m_strdup (val);  
     free_if_alloc (val);  
706            
707      for (i=0; reg_hotkeys[i].reg_entry; i++) {      for (i=0; reg_hotkeys[i].reg_entry; i++) {
708          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry);          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry);

Legend:
Removed from v.69  
changed lines
  Added in v.167

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26