/[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 222 by twoaday, Thu Jun 1 08:30:46 2006 UTC revision 270 by twoaday, Sat Oct 21 18:08:57 2006 UTC
# Line 17  Line 17 
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19   */   */
   
20  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
21  #include <config.h>  #include <config.h>
22  #endif  #endif
23    
24    /* For the case WinPT will be compiled in mobile mode, we use a wrapper
25       to avoid registry access (read, write) and thus this file will not
26       be used. */
27    #ifndef WINPT_MOBILE
28  #include <windows.h>  #include <windows.h>
29  #include <stdio.h>  #include <stdio.h>
30    
# Line 37  Line 40 
40    
41  #define rc_ok(rc) ((rc) == ERROR_SUCCESS)  #define rc_ok(rc) ((rc) == ERROR_SUCCESS)
42    
43    /* WinPT registry path. */
44  #define WINPT_REG "Software\\WinPT"  #define WINPT_REG "Software\\WinPT"
45    
46    /* GPG registry path. */
47    #define GPG_REG "Software\\GNU\\GnuPG"
48    
49    #define GPG_MO_REG "Control Panel\\MingW32\\NLS"
50    
51  /* GPG file association context. */  /* GPG file association context. */
52  struct gpg_filetype {      struct gpg_filetype_s {    
53      const char *descr;      const char *descr;  /* description. */
54      const char *ext;      const char *ext;    /* extension. */
55      int nicon;      int nicon;          /* number of the image icon. */
56  };  };
57    typedef struct gpg_filetype_s *gpg_filetype_t;
58    
59  /* Global WinPT registry prefereneces. */  /* Global WinPT registry prefereneces. */
60  winpt_reg_prefs_s reg_prefs;  struct winpt_prefs_s reg_prefs;
61    
62    
63  /* Return != 0 if GPG4win is installed. */  /* Return != 0 if GPG4win is installed. */
# Line 69  is_gpg4win_installed (void) Line 79  is_gpg4win_installed (void)
79    
80    
81  /* Return != 0 if GPGee is installed. */  /* Return != 0 if GPGee is installed. */
82  int  static int
83  is_gpgee_installed (void)  is_gpgee_installed (void)
84  {  {
85      HKEY hk;      HKEY hk;
# Line 96  free_reg_prefs (void) Line 106  free_reg_prefs (void)
106  }  }
107    
108    
 /* Register the given WinPT filetype. */  
 static int  
 regist_single_filetype (gpg_filetype *gfile)  
 {  
     char icon[256];  
     char prog[256];  
       
     memset (&icon, 0, sizeof (icon));  
     GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);  
     _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);  
     return create_file_type (prog, gfile->ext, gfile->descr, icon);  
 }  
   
109    
110  /* Install the GPG related into the W32 resgistry, if the entry already  /* Install the GPG related into the W32 resgistry, if the entry already
111     exists the function returns immediately. */     exists the function returns immediately. */
# Line 118  regist_inst_gnupg (int create_mokey) Line 115  regist_inst_gnupg (int create_mokey)
115      int rc;      int rc;
116      HKEY reg;      HKEY reg;
117    
118      rc = RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", 0, KEY_READ, &reg );        rc = RegOpenKeyEx (HKEY_CURRENT_USER, GPG_REG, 0, KEY_READ, &reg);
119      if( rc_ok( rc ) ) {      if (rc == ERROR_SUCCESS) {
120          RegCloseKey( reg );          RegCloseKey (reg);
121          return 0;                return 0;      
122      }      }
123      rc = RegCreateKey( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", &reg );      rc = RegCreateKey (HKEY_CURRENT_USER, GPG_REG, &reg);
124      if( !rc_ok( rc ) )                if (rc != ERROR_SUCCESS)
125          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
126      RegCloseKey( reg );      RegCloseKey (reg);
127      if( create_mokey ) {  
128          rc = RegOpenKeyEx( HKEY_CURRENT_USER,  "Control Panel\\MingW32\\NLS", 0, KEY_READ, &reg );      if (!create_mokey)
129          if( rc_ok( rc ) ) {          return 0;
130              RegCloseKey( reg );  
131              return 0;        rc = RegOpenKeyEx (HKEY_CURRENT_USER,  GPG_MO_REG, 0, KEY_READ, &reg);
132          }      if (rc == ERROR_SUCCESS) {
133          rc = RegCreateKey( HKEY_CURRENT_USER, "Control Panel\\MingW32\\NLS", &reg );          RegCloseKey (reg);
134          if( !rc_ok( rc ) )          return 0;      
             return WPTERR_REGISTRY;      
         RegCloseKey( reg );  
135      }      }
136        rc = RegCreateKey (HKEY_CURRENT_USER, GPG_MO_REG, &reg);
137        if (rc != ERROR_SUCCESS)
138            return WPTERR_REGISTRY;
139    
140        RegCloseKey (reg);
141      return 0;      return 0;
142  }  }
143    
144    
145    /* Create a new filetype in the W32 registry.
146       We should really care of errors! Otherwise we can damage the registry! */
147    static int
148    create_file_type (const char *exefile, const char *ext,
149                      const char *extname, char *iconfile)
150    {
151        HKEY reg = NULL;
152        char deficon[MAX_PATH+1];
153        char defexec[MAX_PATH+1];
154        char p_exefile[MAX_PATH+1];
155        int rc;
156        
157        rc = RegCreateKey (HKEY_CLASSES_ROOT, ext, &reg);
158        if( rc_ok( rc ) )
159            rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *)extname, strlen( extname ) );
160        if( rc_ok( rc ) )
161            rc = RegCloseKey( reg );
162        if( rc_ok( rc ) )    
163            rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, &reg );
164        if( rc_ok( rc ) )
165            rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *) extname, strlen( extname ) );
166        if( rc_ok( rc ) )
167            rc = RegCloseKey( reg );
168        if( !rc_ok( rc ) ) {
169            rc = WPTERR_REGISTRY;
170            goto leave;
171        }
172        
173        memset( &deficon, 0, sizeof deficon );
174        _snprintf( deficon, sizeof deficon - 1, "%s\\DefaultIcon", extname );
175        memset( &defexec, 0, sizeof defexec );
176        _snprintf( defexec, sizeof defexec - 1, "%s\\shell\\open\\command", extname );      
177        memset( &p_exefile, 0, sizeof p_exefile );
178        _snprintf( p_exefile, sizeof p_exefile - 1, "%s %%1", exefile );
179        
180        rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, &reg );
181        if( rc_ok( rc ) )
182            rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (BYTE *)iconfile, strlen( iconfile ) );
183        if( rc_ok( rc ) )
184            rc = RegCloseKey( reg );
185        if( rc_ok( rc ) )
186            rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, &reg );
187        if( rc_ok( rc ) )
188            rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *)p_exefile, strlen( exefile ) );
189        if( rc_ok( rc ) )
190            rc = RegCloseKey( reg );
191        if( !rc_ok( rc ) ) {
192            rc = WPTERR_REGISTRY;
193            goto leave;    
194        }
195        
196    leave:
197        if (reg)
198            RegCloseKey (reg);
199        return rc;
200    }
201    
202    
203    /* Register the given WinPT filetype. */
204    static int
205    regist_single_filetype (gpg_filetype_t gfile)
206    {
207        char icon[MAX_PATH+1] = {0};
208        char prog[MAX_PATH+1] = {0};
209    
210        if (!GetModuleFileName (glob_hinst, prog, sizeof (prog)-1))
211            return WPTERR_REGISTRY;
212        _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);
213        return create_file_type (prog, gfile->ext, gfile->descr, icon);
214    }
215    
216  /* Install WinPT into the W32 registry, if the entry already  /* Install WinPT into the W32 registry, if the entry already
217     exists the function returns immediately. @with_ext can be     exists the function returns immediately. @with_ext can be
218     used to register some file types (if 1). @created contains     used to register some file types (if 1). @created contains
# Line 150  regist_inst_gnupg (int create_mokey) Line 220  regist_inst_gnupg (int create_mokey)
220     Return value: 0 on success. */     Return value: 0 on success. */
221  int  int
222  regist_inst_winpt (int with_ext, int *created)  regist_inst_winpt (int with_ext, int *created)
223  {      {
224      HKEY reg;      struct gpg_filetype_s gpg_filetypes[] = {
     char *p = NULL;  
     char modpath[MAX_PATH+1];  
     int rc, i, id, n;  
   
     gpg_filetype gpg_filetypes[] = {  
225          {_("GPG Detached Signature"), ".sig", 1},          {_("GPG Detached Signature"), ".sig", 1},
226          {_("GPG Encrypted Data"),     ".gpg", 2},          {_("GPG Encrypted Data"),     ".gpg", 2},
227          {_("GPG Armored Data"),       ".asc", 2},          {_("GPG Armored Data"),       ".asc", 2},
228          {0}          {0}
229      };      };
230        HKEY reg;
231        char *p = NULL;
232        char modpath[MAX_PATH+1];
233        int rc, i, id, n;
234    
235      if (created)      if (created)
236          *created = 0;          *created = 0;
237    
238        /* If GPGee is already installed deactivate file extension registering
239           because it is very likely this would overwrite the GPGee settings. */
240      if (is_gpgee_installed ())      if (is_gpgee_installed ())
241          with_ext = 0;          with_ext = 0;
242    
243      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);
244      if (rc_ok (rc)) {      if (rc == ERROR_SUCCESS) {
245          RegCloseKey (reg);          RegCloseKey (reg);
246          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);
247          if (!rc_ok (rc)) {          if (rc != ERROR_SUCCESS) {
248              RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);              rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);
249              RegCloseKey (reg);              if (rc == ERROR_SUCCESS)
250                    RegCloseKey (reg);
251          }          }
252            else
253                RegCloseKey (reg);
254          p = get_reg_entry_keyserver ("Default");          p = get_reg_entry_keyserver ("Default");
255          if (!p) {          if (!p) {
256              char buf[16];              char buf[16];
257              sprintf (buf, "%d", HKP_PORT);  
258                _snprintf (buf, DIM (buf)-1, "%d", HKP_PORT);
259              set_reg_entry_keyserver ("Default_Port", buf);              set_reg_entry_keyserver ("Default_Port", buf);
260              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);
261          }          }
# Line 187  regist_inst_winpt (int with_ext, int *cr Line 263  regist_inst_winpt (int with_ext, int *cr
263          return 0;          return 0;
264      }      }
265      rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);      rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);
266      if (!rc_ok (rc))      if (rc != ERROR_SUCCESS)
267          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
268      if (created)      if (created)
269          *created = 1;          *created = 1;
# Line 199  regist_inst_winpt (int with_ext, int *cr Line 275  regist_inst_winpt (int with_ext, int *cr
275          if (id == IDYES) {          if (id == IDYES) {
276              for (i = 0; gpg_filetypes[i].ext; i++) {              for (i = 0; gpg_filetypes[i].ext; i++) {
277                  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);
278                  if (rc_ok (rc)) {                  if (rc == ERROR_SUCCESS) {
279                  RegCloseKey (reg);                      RegCloseKey (reg);
280                      id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,                      id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,
281                                    _("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"
282                                      "Do you want to overwrite it?"), gpg_filetypes[i].ext);                                      "Do you want to overwrite it?"), gpg_filetypes[i].ext);
283                      if (id == IDNO)                      if (id == IDNO)
# Line 211  regist_inst_winpt (int with_ext, int *cr Line 287  regist_inst_winpt (int with_ext, int *cr
287              }              }
288          }          }
289      }      }
290        /* Store the install directory for later use. */
291      if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {      if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {
292          while (n-- > 0) {          while (n-- > 0) {
293              if (modpath[n] == '\\') {              if (modpath[n] == '\\') {
# Line 224  regist_inst_winpt (int with_ext, int *cr Line 301  regist_inst_winpt (int with_ext, int *cr
301  }  }
302    
303    
 /* Create a new filetype in the W32 registry.  
    We should really care of errors! Otherwise we can damage the registry! */  
 int  
 create_file_type (const char *exefile, const char *ext,  
                   const char *extname, char *iconfile)  
 {  
     int rc;  
     HKEY reg = NULL;  
     char deficon[256], defexec[256], p_exefile[256];  
       
       
     rc = RegCreateKey( HKEY_CLASSES_ROOT, ext, &reg );  
     if( rc_ok( rc ) )  
         rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)extname, strlen( extname ) );  
     if( rc_ok( rc ) )  
         rc = RegCloseKey( reg );  
     if( rc_ok( rc ) )      
         rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, &reg );  
     if( rc_ok( rc ) )  
         rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *) extname, strlen( extname ) );  
     if( rc_ok( rc ) )  
         rc = RegCloseKey( reg );  
     if( !rc_ok( rc ) ) {  
         rc = WPTERR_REGISTRY;  
         goto leave;  
     }  
       
     memset( &deficon, 0, sizeof deficon );  
     _snprintf( deficon, sizeof deficon - 1, "%s\\DefaultIcon", extname );  
     memset( &defexec, 0, sizeof defexec );  
     _snprintf( defexec, sizeof defexec - 1, "%s\\shell\\open\\command", extname );        
     memset( &p_exefile, 0, sizeof p_exefile );  
     _snprintf( p_exefile, sizeof p_exefile - 1, "%s %%1", exefile );  
       
     rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, &reg );  
     if( rc_ok( rc ) )  
         rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (byte *)iconfile, strlen( iconfile ) );  
     if( rc_ok( rc ) )  
         rc = RegCloseKey( reg );  
     if( rc_ok( rc ) )  
         rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, &reg );  
     if( rc_ok( rc ) )  
         rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)p_exefile, strlen( exefile ) );  
     if( rc_ok( rc ) )  
         rc = RegCloseKey( reg );  
     if( !rc_ok( rc ) ) {  
         rc = WPTERR_REGISTRY;  
         goto leave;      
     }  
       
 leave:  
     if( reg )  
         RegCloseKey( reg );  
     return rc;  
 }  
   
   
304  /* Expand a string with %foo% entries so that %foo% will  /* Expand a string with %foo% entries so that %foo% will
305     be replaced with its actual value. */     be replaced with its actual value. */
306  static char *  static char*
307  expand_path (const char *path)  expand_path (const char *path)
308  {  {
309      DWORD len;      DWORD len;
# Line 309  expand_path (const char *path) Line 329  expand_path (const char *path)
329     and the key given in @key.     and the key given in @key.
330     Return value is the value or NULL otherwise. */     Return value is the value or NULL otherwise. */
331  char*  char*
332  get_reg_entry (HKEY root_key, const char * dir, const char * key)  get_reg_entry (HKEY root_key, const char *dir, const char *key)
333  {  {
     int rc;  
     char text[384] = {0};  
     DWORD nbytes, type;  
334      HKEY reg_key = NULL;      HKEY reg_key = NULL;
335      char * p = NULL;      char *p = NULL, *pp;    
336            DWORD type = REG_SZ, nbytes = 0;
337        int rc;
338    
339      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);
340      if( !rc_ok( rc ) )      if (rc != ERROR_SUCCESS)
341          goto leave;          goto leave;
342      nbytes = sizeof (text) - 1;      rc = RegQueryValueEx (reg_key, key, NULL, &type, NULL, &nbytes);
343      type = REG_SZ;      if (rc != ERROR_SUCCESS)
       
     rc = RegQueryValueEx (reg_key, key, 0, &type, (BYTE *)&text, &nbytes);  
     if (!rc_ok (rc) || !nbytes)  
344          goto leave;          goto leave;
345            if (!nbytes)
346      if (type == REG_EXPAND_SZ && strchr (text, '%'))          goto leave; /* empty */
347          p = expand_path (text);      p = new char[nbytes+1];
348      else {      if (!p)
349          p = new char[nbytes + 1];          BUG (0);
350          if (!p)      rc = RegQueryValueEx (reg_key, key, NULL, &type, (BYTE*)p,  &nbytes);
351              BUG (0);      if (rc != ERROR_SUCCESS)
352          memcpy (p, text, nbytes);          goto leave;
353          p[nbytes] = '\0';      if (type == REG_EXPAND_SZ && strchr (p, '%')) {
354            pp = p;
355            p = expand_path (pp);
356            free_if_alloc (pp);
357      }      }
358        
359  leave:  leave:
360      if (reg_key)      if (reg_key != NULL)
361          RegCloseKey (reg_key);          RegCloseKey (reg_key);
362      return p;      return p;
363  }  }
# Line 352  int Line 371  int
371  set_reg_entry (HKEY root_key, const char *dir, const char *key,  set_reg_entry (HKEY root_key, const char *dir, const char *key,
372                 const char *value)                 const char *value)
373  {  {
     int rc = 0;  
374      HKEY reg_key;      HKEY reg_key;
375        int rc;
376    
377      rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, &reg_key );      rc = RegOpenKeyEx (root_key, dir, 0, KEY_WRITE, &reg_key);
378      if( !rc_ok( rc ) )      if (rc != ERROR_SUCCESS)
379          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
380      rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) );      rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value));
381      if( !rc_ok( rc ) )      if (rc != ERROR_SUCCESS)
382          rc = WPTERR_REGISTRY;            rc = WPTERR_REGISTRY;  
383      RegCloseKey( reg_key );      RegCloseKey (reg_key);
384      return rc;      return rc;
385  }  }
386    
387    
388  int  int
389  set_reg_key( HKEY root_key, const char * dir, const char * key,  set_reg_key (HKEY root_key, const char *dir, const char *key,
390               const char * value )               const char *value)
391  {  {    
     int rc = 0;  
392      HKEY reg_key;      HKEY reg_key;
393        int rc;
394            
395      rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, &reg_key );      rc = RegOpenKeyEx (root_key, dir, 0, KEY_WRITE, &reg_key);
396      if( !rc_ok( rc ) )      if (rc != ERROR_SUCCESS)
397          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
398            
399      rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) );            rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value));
400      if( !rc_ok( rc ) ) {              if (rc != ERROR_SUCCESS) {
401          if ( RegCreateKey( root_key, key, &reg_key ) != ERROR_SUCCESS ) {          if (RegCreateKey (root_key, key, &reg_key) != ERROR_SUCCESS) {
402              rc = WPTERR_REGISTRY;              rc = WPTERR_REGISTRY;
403              goto leave;              goto leave;
404          }          }
405          rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) );                    rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value));
406          if ( !rc_ok( rc ) )          if (rc != ERROR_SUCCESS)
407              rc = WPTERR_REGISTRY;              rc = WPTERR_REGISTRY;
408      }      }
409            
410  leave:  leave:
411      RegCloseKey( reg_key );      RegCloseKey (reg_key);
412      return rc;      return rc;
413  }  }
414    
415    
416  int  int
417  set_reg_entry_gpg (const char * key, const char * value)  set_reg_entry_gpg (const char *key, const char *value)
418  {        {      
419      return set_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key, value);      return set_reg_entry (HKEY_CURRENT_USER, GPG_REG, key, value);
420  }  }
421    
422    
423  int  int
424  set_reg_entry_mo (const char * value)  set_reg_entry_mo (const char *value)
425  {        {      
426      return set_reg_entry (HKEY_CURRENT_USER, "Control Panel\\Mingw32\\NLS",      return set_reg_entry (HKEY_CURRENT_USER, GPG_MO_REG, "MODir", value);
                           "MODir", value);  
427  }  }
428    
429    
# Line 413  char* Line 431  char*
431  get_reg_entry_gpg (const char *key)  get_reg_entry_gpg (const char *key)
432  {  {
433      char *p;      char *p;
434      p = get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key);  
435        p = get_reg_entry (HKEY_CURRENT_USER, GPG_REG, key);
436      if (!p || strlen (p) == 0) {      if (!p || strlen (p) == 0) {
437          free_if_alloc (p);          free_if_alloc (p);
438          return NULL;          return NULL;
# Line 427  get_reg_entry_gpg (const char *key) Line 446  get_reg_entry_gpg (const char *key)
446  char*  char*
447  get_reg_entry_gpg4win (const char *path)  get_reg_entry_gpg4win (const char *path)
448  {  {
449        const char *fmt;
450      char *p, *pp;      char *p, *pp;
451      p = get_reg_entry (HKEY_LOCAL_MACHINE,  
452                         "Software\\GNU\\GnuPG", "Install Directory");      p = get_reg_entry (HKEY_LOCAL_MACHINE, GPG_REG, "Install Directory");
453      if (!p)      if (!p)
454          return NULL;          return NULL;
455      if (!path)      if (!path)
456          return p;          return p;
457      pp = new char[strlen (p) + strlen (path) + 4];      fmt = "%s\\%s";
458        pp = new char[strlen (p) + strlen (path) + strlen (fmt) + 1];
459      if (!pp)      if (!pp)
460          BUG (NULL);          BUG (NULL);
461      sprintf (pp, "%s\\%s", p, path);      sprintf (pp, fmt, p, path);
462      free_if_alloc (p);      free_if_alloc (p);
463      return pp;      return pp;
464  }  }
# Line 447  char* Line 468  char*
468  get_reg_entry_mo (void)  get_reg_entry_mo (void)
469  {        {      
470      char *p, *pp;      char *p, *pp;
471        const char *fmt;
472      const char *lang;      const char *lang;
473    
474      p = get_reg_entry (HKEY_CURRENT_USER,      p = get_reg_entry (HKEY_CURRENT_USER, GPG_MO_REG, "MODir");
                        "Control Panel\\Mingw32\\NLS", "MODir");  
475      if (p)      if (p)
476          return p;          return p;
477    
478      lang = get_gettext_langid ();      lang = get_gettext_langid ();
479      if (!lang)      if (!lang)
480          return NULL;          return NULL;
481      pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8];      fmt = "share\\locale\\%s\\LC_MESSAGES";
482        pp = new char[strlen (fmt) + strlen (lang) + 4 + 1];
483      if (!pp)          if (!pp)    
484          BUG (NULL);          BUG (NULL);
485      sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang);      sprintf (pp, fmt, lang);
486      p = get_reg_entry_gpg4win (pp);      p = get_reg_entry_gpg4win (pp);
487      free_if_alloc (pp);      free_if_alloc (pp);
488      return p;      return p;
489  }  }
490    
491    
 /* All valid configuration commands. */  
 static const char *cfg [] = {  
     NULL,        
     "CacheTime",  
     "WordWrap",  
     "DefaultExt",  
     "Viewer",  
     "WipeMode",  
     "AlwaysTrust",  
     "AutoBackup",  
     "BackupMode",  
     "DisableHotkeys",    
     "NoCompressMultiMedia",      
     "Expert",  
     "FMProgressBar",  
     "BackupSecring"  
 };  
   
   
492  int  int
493  set_reg_winpt_single (int id, int val)  set_reg_winpt_single (int id, int val)
494  {  {
495      char buf[64];      char buf[64];
496      int rc;      int rc;
497    
498      sprintf (buf, "%d", val);      _snprintf (buf, DIM (buf)-1, "%d", val);
499      rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id], buf);      rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id], buf);
500      return rc;      return rc;
501  }  }
# Line 516  get_reg_winpt_single (int id) Line 519  get_reg_winpt_single (int id)
519    
520  /* Saves the winpt preferences in the registry. */  /* Saves the winpt preferences in the registry. */
521  int  int
522  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)  set_reg_winpt_prefs (winpt_prefs_t opt)
523  {  {
524      char buf[128];      char buf[128];
525      size_t i;      size_t i;
# Line 601  leave: Line 604  leave:
604    
605    
606  int  int
607  set_reg_winpt_flag (const char * name, int val)  set_reg_winpt_flag (const char *name, int val)
608  {  {
609      return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name, val? "1" : "0");      return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name, val? "1" : "0");
610  }  }
611    
612    
613  int  int
614  get_reg_winpt_flag (const char * name)  get_reg_winpt_flag (const char *name)
615  {  {
616      char * buf;      char *buf;
617      int flag = 0;      int flag = 0;
618    
619      buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name);      buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name);
# Line 625  get_reg_winpt_flag (const char * name) Line 628  get_reg_winpt_flag (const char * name)
628    
629  /* Retrieve the winpt preferences from the registry. */  /* Retrieve the winpt preferences from the registry. */
630  int  int
631  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)  get_reg_winpt_prefs (winpt_prefs_t opt)
632  {  {
633      char *val = NULL;      char *val = NULL;
634      size_t i;      size_t i;
# Line 638  get_reg_winpt_prefs (winpt_reg_prefs_s * Line 641  get_reg_winpt_prefs (winpt_reg_prefs_s *
641          }          }
642          switch (i) {          switch (i) {
643          case CFG_CACHETIME:          case CFG_CACHETIME:
644              opt->cache_time = atol (val);              opt->cache_time = atoi (val);
645              break;              break;
646          case CFG_WORDWRAP:          case CFG_WORDWRAP:
647              opt->word_wrap = atol (val);              opt->word_wrap = atoi (val);
648              break;              break;
649          case CFG_FILEEXT:          case CFG_FILEEXT:
650              opt->default_ext = atol (val);              opt->default_ext = atoi (val);
651              break;              break;
652          case CFG_NOZIP_MMEDIA:          case CFG_NOZIP_MMEDIA:
653              opt->no_zip_mmedia = atol (val);              opt->no_zip_mmedia = atoi (val);
654              break;              break;
655          case CFG_VIEWER:          case CFG_VIEWER:
656              opt->use_viewer = atol (val);              opt->use_viewer = atoi (val);
657              break;              break;
658          case CFG_WIPEMODE:          case CFG_WIPEMODE:
659              opt->wipe_mode = atol (val);              opt->wipe_mode = atoi (val);
660              break;              break;
661          case CFG_DISHOTKEYS:          case CFG_DISHOTKEYS:
662              opt->no_hotkeys = atol (val);              opt->no_hotkeys = atoi (val);
663              break;              break;
664          case CFG_ALWAYSTRUST:          case CFG_ALWAYSTRUST:
665              opt->always_trust = atol (val);              opt->always_trust = atoi (val);
666              break;              break;
667          case CFG_AUTOBACKUP:          case CFG_AUTOBACKUP:
668              opt->auto_backup = atol (val);              opt->auto_backup = atoi (val);
669              break;              break;
670          case CFG_AUTOBAKMODE:          case CFG_AUTOBAKMODE:
671              opt->backup.mode = atol (val);              opt->backup.mode = atoi (val);
672              break;              break;
673          case CFG_EXPERT:          case CFG_EXPERT:
674              opt->expert = atol (val);              opt->expert = atoi (val);
675              break;              break;
676          case CFG_FM_PROGRESS:          case CFG_FM_PROGRESS:
677              opt->fm.progress = atol (val);              opt->fm.progress = atoi (val);
678              break;              break;
679    
680          case CFG_BACKUP_INC_SKR:          case CFG_BACKUP_INC_SKR:
681              opt->backup.include_secr = atol (val);              opt->backup.include_secr = atoi (val);
682              break;              break;
683          }          }
684          free_if_alloc (val);          free_if_alloc (val);
# Line 712  get_reg_entry_keyserver (const char *nam Line 715  get_reg_entry_keyserver (const char *nam
715    
716    
717  int  int
718  set_reg_entry_keyserver (const char * name, const char * val)  set_reg_entry_keyserver (const char *name, const char *val)
 {  
     return set_reg_entry( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val );  
 }  
   
 static int  
 get_reg_entry_keyserver_int (const char *key)  
 {  
     char *p;  
     int val = 0;  
   
     p = get_reg_entry_keyserver (key);  
     if (p && *p)  
         val = atoi (p);  
     free_if_alloc (p);  
     return val;  
 }  
   
   
 void  
 get_reg_proxy_prefs (keyserver_proxy_t prox)  
719  {  {
720      if (!prox)      return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val);
         return;  
       
     free_if_alloc (prox->host);  
     prox->host = get_reg_entry_keyserver ("Host");  
     free_if_alloc (prox->user);  
     prox->user = get_reg_entry_keyserver ("User");  
     free_if_alloc (prox->pass);  
     prox->pass = get_reg_entry_keyserver ("Pass");  
     prox->port = get_reg_entry_keyserver_int ("Port");  
 }  
   
   
 static int  
 set_reg_entry_keyserver_int (const char *key, int val)  
 {  
     char buf[32];  
   
     sprintf (buf, "%d", val);  
     return set_reg_entry_keyserver (key, buf);  
 }  
   
   
 int  
 set_reg_proxy_prefs (keyserver_proxy_t prox)  
 {      
     int rc;  
       
     rc = set_reg_entry_keyserver_int ("Proto", prox->proto);  
     if (!rc)  
         rc = set_reg_entry_keyserver ("Host", prox->host? prox->host : "");  
     if (!rc)  
         rc = set_reg_entry_keyserver_int ("Port", prox->port);  
     if (!rc)  
         rc = set_reg_entry_keyserver ("User", prox->user? prox->user : "");  
     if (!rc)  
         rc = set_reg_entry_keyserver ("Pass", prox->pass? prox->pass : "");  
     return rc;  
721  }  }
722    #endif

Legend:
Removed from v.222  
changed lines
  Added in v.270

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26