/[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 234 by twoaday, Tue Jun 27 10:16:41 2006 UTC
# Line 1  Line 1 
1  /* wptRegistry.cpp - W32 Registry access  /* wptRegistry.cpp - Windows Registry access
2   *      Copyright (C) 2000-2005 Timo Schulz   *      Copyright (C) 2000-2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 33  Line 33 
33  #include "wptTypes.h"  #include "wptTypes.h"
34  #include "wptNLS.h"  #include "wptNLS.h"
35  #include "wptVersion.h"  #include "wptVersion.h"
36    #include "wptHotkey.h"
37    
38  #define rc_ok(rc) ((rc) == ERROR_SUCCESS)  #define rc_ok(rc) ((rc) == ERROR_SUCCESS)
39    
40  static gpg_filetype gpg_filetypes[] = {  #define WINPT_REG "Software\\WinPT"
     {"GPG Detached Signature", ".sig", 1},  
     {"GPG Encrypted Data",     ".gpg", 2},  
     {"GPG Armored Data",       ".asc", 2},  
     {0}  
 };  
41    
42  struct reg_hotkey_s reg_hotkeys[] = {  /* GPG file association context. */
43      {"ClipEncrypt", "", 0},  struct gpg_filetype {    
44      {"ClipDecrypt", "", 0},      const char *descr;
45      {"ClipSign",    "", 0},      const char *ext;
46      {"ClipSignEnc", "", 0},      int nicon;
     {"CwsEncrypt",  "", 0},  
     {"CwsDecrypt",  "", 0},  
     {"CwsSign",     "", 0},  
     {"CwsSignEnc",  "", 0},  
     {NULL, "", 0}  
47  };  };
48    
49    /* Global WinPT registry prefereneces. */
50  winpt_reg_prefs_s reg_prefs;  winpt_reg_prefs_s reg_prefs;
51    
 #define WINPT_REG "Software\\WinPT"  
52    
53    /* Return != 0 if GPG4win is installed. */
54    int
55    is_gpg4win_installed (void)
56    {
57        char *p;
58    
59        p = get_reg_entry_gpg4win (NULL);
60        if (!p)
61            return 0;
62        if (dir_exist_check (p)) {
63            free_if_alloc (p);
64            return 0;
65        }
66        free_if_alloc (p);
67        return -1;
68    }
69    
70    
71    /* Return != 0 if GPGee is installed. */
72    int
73    is_gpgee_installed (void)
74    {
75        HKEY hk;
76        LONG ec;
77    
78        ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\GPGee", 0, KEY_READ, &hk);
79        if (ec == ERROR_SUCCESS) {
80            RegCloseKey (hk);
81            return -1;
82        }
83    
84        return 0;
85    }
86    
87    
88    /* Free all members in the registry preference struct. */
89  void  void
90  free_reg_prefs (void)  free_reg_prefs (void)
91  {  {
# Line 67  free_reg_prefs (void) Line 93  free_reg_prefs (void)
93      free_if_alloc (reg_prefs.kserv_conf);      free_if_alloc (reg_prefs.kserv_conf);
94      free_if_alloc (reg_prefs.homedir);      free_if_alloc (reg_prefs.homedir);
95      memset (&reg_prefs, 0, sizeof reg_prefs);      memset (&reg_prefs, 0, sizeof reg_prefs);
96  } /* free_reg_prefs */  }
97    
98    
99  /* Register the given WinPT filetype. */  /* Register the given WinPT filetype. */
100  static int  static int
101  regist_single_filetype (gpg_filetype *gfile)  regist_single_filetype (gpg_filetype *gfile)
102  {  {
103      char icon[256], prog[256];      char icon[256];
104        char prog[256];
105            
106      memset (&icon, 0, sizeof (icon));      memset (&icon, 0, sizeof (icon));
107      GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);      GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);
108      _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);      _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);
109      return create_file_type (prog, gfile->ext, gfile->descr, icon);      return create_file_type (prog, gfile->ext, gfile->descr, icon);
110  } /* regist_single_filetype */  }
111    
112    
113  /* 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 140  regist_inst_gnupg (int create_mokey)
140      }      }
141    
142      return 0;      return 0;
143  } /* regist_inst_gpg */  }
144    
145    
146  /* Install WinPT into the W32 registry, if the entry already  /* Install WinPT into the W32 registry, if the entry already
147     exists the function returns immediately.*/     exists the function returns immediately. @with_ext can be
148       used to register some file types (if 1). @created contains
149       1 if the registry key was created.
150       Return value: 0 on success. */
151  int  int
152  regist_inst_winpt (int with_ext, int * created)  regist_inst_winpt (int with_ext, int *created)
153  {  {    
154      HKEY reg;      HKEY reg;
155      char * p = NULL;      char *p = NULL;
156      int rc, i, id, n = 0;      char modpath[MAX_PATH+1];
157        int rc, i, id, n;
158    
159      if( created )      gpg_filetype gpg_filetypes[] = {
160          *created = 0;          {_("GPG Detached Signature"), ".sig", 1},
161            {_("GPG Encrypted Data"),     ".gpg", 2},
162            {_("GPG Armored Data"),       ".asc", 2},
163            {0}
164        };
165    
166      p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");      if (created)
167      if (p && *p == '1')          *created = 0;
168        if (is_gpgee_installed ())
169          with_ext = 0;          with_ext = 0;
     free_if_alloc( p );  
170    
171      if( with_ext ) {      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);
172          id = msg_box( NULL, _("WinPT can register some GPG file types for you so they can "      if (rc_ok (rc)) {
173                                "be processed with a double click in the explorer.\n"          RegCloseKey (reg);
174                                "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO );          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);
175          if( id == IDNO ) {          if (!rc_ok (rc)) {
176              set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );              RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);
177              goto start;              RegCloseKey (reg);
         }  
         for( i = 0; gpg_filetypes[i].ext; i++ ) {  
             rc = RegOpenKeyEx( HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, &reg );  
             if( rc_ok( rc ) ) {  
                 RegCloseKey( reg );  
                 id = log_box( _("WinPT WARNING"), MB_YESNO|MB_INFO,  
                               _("It seems there was already a '%s' file type registered by another application.\n"  
                                 "Do you want to overwrite it?"), gpg_filetypes[i].ext );  
                 if( id == IDNO )  
                     continue;  
             }  
             regist_single_filetype( &gpg_filetypes[i] );  
             n++;  
         }  
     }  
           
 start:  
     rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg );  
     if( rc_ok( rc ) ) {  
         RegCloseKey( reg );  
         rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg );  
         if( !rc_ok( rc ) ) {  
             RegCreateKey( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg );  
             RegCloseKey( reg );  
178          }          }
179          p = get_reg_entry_keyserver ("Default");          p = get_reg_entry_keyserver ("Default");
180          if (!p) {          if (!p) {
# Line 172  start: Line 183  start:
183              set_reg_entry_keyserver ("Default_Port", buf);              set_reg_entry_keyserver ("Default_Port", buf);
184              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);
185          }          }
186          free_if_alloc( p );          free_if_alloc (p);
         if( n )  
             set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );  
187          return 0;          return 0;
188      }      }
189      rc = RegCreateKey( HKEY_CURRENT_USER, WINPT_REG, &reg );      rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);
190      if( !rc_ok( rc ) )      if (!rc_ok (rc))
191          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
192      if( created )      if (created)
193          *created = 1;          *created = 1;
194      RegCloseKey( reg );      RegCloseKey (reg);
195      if( n )      if (with_ext) {
196          set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );          id = msg_box (NULL, _("WinPT can register some GPG file types for you so they can "
197                                  "be processed with a double click in the explorer.\n"
198                                  "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO);
199            if (id == IDYES) {
200                for (i = 0; gpg_filetypes[i].ext; i++) {
201                    rc = RegOpenKeyEx (HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, &reg);
202                    if (rc_ok (rc)) {
203                    RegCloseKey (reg);
204                        id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,
205                                      _("It seems there was already a '%s' file type registered by another application.\n"
206                                        "Do you want to overwrite it?"), gpg_filetypes[i].ext);
207                        if (id == IDNO)
208                            continue;
209                    }
210                    regist_single_filetype (&gpg_filetypes[i]);
211                }
212            }
213        }
214        if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {
215            while (n-- > 0) {
216                if (modpath[n] == '\\') {
217                    modpath[n] = 0;
218                    break;
219                }
220            }
221            set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Install Directory", modpath);
222        }
223      return 0;      return 0;
224  } /* regist_inst_winpt */  }
225    
226    
227  /* Create a new filetype in the W32 registry.  /* Create a new filetype in the W32 registry.
228     We should really care of errors! Otherwise we can damage the registry! */     We should really care of errors! Otherwise we can damage the registry! */
229  int  int
230  create_file_type( const char *exefile, const char *ext, const char *extname, char *iconfile )  create_file_type (const char *exefile, const char *ext,
231                      const char *extname, char *iconfile)
232  {  {
233      int rc;      int rc;
234      HKEY reg = NULL;      HKEY reg = NULL;
# Line 201  create_file_type( const char *exefile, c Line 237  create_file_type( const char *exefile, c
237            
238      rc = RegCreateKey( HKEY_CLASSES_ROOT, ext, &reg );      rc = RegCreateKey( HKEY_CLASSES_ROOT, ext, &reg );
239      if( rc_ok( rc ) )      if( rc_ok( rc ) )
240          rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)extname, strlen( extname ) );          rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *)extname, strlen( extname ) );
241      if( rc_ok( rc ) )      if( rc_ok( rc ) )
242          rc = RegCloseKey( reg );          rc = RegCloseKey( reg );
243      if( rc_ok( rc ) )          if( rc_ok( rc ) )    
244          rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, &reg );          rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, &reg );
245      if( rc_ok( rc ) )      if( rc_ok( rc ) )
246          rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *) extname, strlen( extname ) );          rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *) extname, strlen( extname ) );
247      if( rc_ok( rc ) )      if( rc_ok( rc ) )
248          rc = RegCloseKey( reg );          rc = RegCloseKey( reg );
249      if( !rc_ok( rc ) ) {      if( !rc_ok( rc ) ) {
# Line 224  create_file_type( const char *exefile, c Line 260  create_file_type( const char *exefile, c
260            
261      rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, &reg );      rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, &reg );
262      if( rc_ok( rc ) )      if( rc_ok( rc ) )
263          rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (byte *)iconfile, strlen( iconfile ) );          rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (BYTE *)iconfile, strlen( iconfile ) );
264      if( rc_ok( rc ) )      if( rc_ok( rc ) )
265          rc = RegCloseKey( reg );          rc = RegCloseKey( reg );
266      if( rc_ok( rc ) )      if( rc_ok( rc ) )
267          rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, &reg );          rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, &reg );
268      if( rc_ok( rc ) )      if( rc_ok( rc ) )
269          rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)p_exefile, strlen( exefile ) );          rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *)p_exefile, strlen( exefile ) );
270      if( rc_ok( rc ) )      if( rc_ok( rc ) )
271          rc = RegCloseKey( reg );          rc = RegCloseKey( reg );
272      if( !rc_ok( rc ) ) {      if( !rc_ok( rc ) ) {
# Line 242  leave: Line 278  leave:
278      if( reg )      if( reg )
279          RegCloseKey( reg );          RegCloseKey( reg );
280      return rc;      return rc;
281  } /* create_file_type */  }
282    
283    
284  /* Expand a string with %foo% entries so that %foo% will  /* Expand a string with %foo% entries so that %foo% will
# Line 258  expand_path (const char *path) Line 294  expand_path (const char *path)
294          return NULL;          return NULL;
295      len += 1;      len += 1;
296      p = new char[len+1];      p = new char[len+1];
297      if( !p )      if (!p)
298          return NULL;          return NULL;
299      len = ExpandEnvironmentStrings (path, p, len);      len = ExpandEnvironmentStrings (path, p, len);
300      if (!len) {      if (!len) {
# Line 266  expand_path (const char *path) Line 302  expand_path (const char *path)
302          return NULL;          return NULL;
303      }      }
304      return p;      return p;
305  } /* expand_path */  }
306    
307    
308  /* 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 315  get_reg_entry (HKEY root_key, const char
315      char text[384] = {0};      char text[384] = {0};
316      DWORD nbytes, type;      DWORD nbytes, type;
317      HKEY reg_key = NULL;      HKEY reg_key = NULL;
318      char *p = NULL;      char * p = NULL;
319            
320      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);
321      if( !rc_ok( rc ) )      if( !rc_ok( rc ) )
# Line 327  set_reg_entry (HKEY root_key, const char Line 363  set_reg_entry (HKEY root_key, const char
363          rc = WPTERR_REGISTRY;            rc = WPTERR_REGISTRY;  
364      RegCloseKey( reg_key );      RegCloseKey( reg_key );
365      return rc;      return rc;
366  } /* set_reg_entry */  }
367    
368    
369  int  int
# Line 355  set_reg_key( HKEY root_key, const char * Line 391  set_reg_key( HKEY root_key, const char *
391  leave:  leave:
392      RegCloseKey( reg_key );      RegCloseKey( reg_key );
393      return rc;      return rc;
394  } /* set_reg_key */  }
395    
396    
397  int  int
# Line 373  set_reg_entry_mo (const char * value) Line 409  set_reg_entry_mo (const char * value)
409  }  }
410    
411    
412  char *  char*
413  get_reg_entry_gpg (const char *key)  get_reg_entry_gpg (const char *key)
414  {  {
415      return get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key);      char *p;
416        p = get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key);
417        if (!p || strlen (p) == 0) {
418            free_if_alloc (p);
419            return NULL;
420        }
421        return p;
422  }  }
423    
424    
425  char *  /* Return if possible the GPG4Win installation directory concatenated
426  get_reg_entry_mo(void)     with the string in @path if given. */
427    char*
428    get_reg_entry_gpg4win (const char *path)
429    {
430        char *p, *pp;
431        p = get_reg_entry (HKEY_LOCAL_MACHINE,
432                           "Software\\GNU\\GnuPG", "Install Directory");
433        if (!p)
434            return NULL;
435        if (!path)
436            return p;
437        pp = new char[strlen (p) + strlen (path) + 4];
438        if (!pp)
439            BUG (NULL);
440        sprintf (pp, "%s\\%s", p, path);
441        free_if_alloc (p);
442        return pp;
443    }
444    
445        
446    char*
447    get_reg_entry_mo (void)
448  {        {      
449      return get_reg_entry(HKEY_CURRENT_USER,      char *p, *pp;
450                           "Control Panel\\Mingw32\\NLS", "MODir");      const char *lang;
451    
452        p = get_reg_entry (HKEY_CURRENT_USER,
453                           "Control Panel\\Mingw32\\NLS", "MODir");
454        if (p)
455            return p;
456    
457        lang = get_gettext_langid ();
458        if (!lang)
459            return NULL;
460        pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8];
461        if (!pp)    
462            BUG (NULL);
463        sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang);
464        p = get_reg_entry_gpg4win (pp);
465        free_if_alloc (pp);
466        return p;
467  }  }
468    
469    
470  /* All valid configuration commands. */  /* All valid configuration commands. */
471  static const char * cfg [] = {  static const char *cfg [] = {
472          NULL,      NULL,      
473          "CacheTime",      "CacheTime",
474          "WordWrap",      "WordWrap",
475          "FastMode",      "DefaultExt",
476          "Viewer",      "Viewer",
477          "KeylistMode",      "WipeMode",
478          "WipeMode",      "AlwaysTrust",
479          "AlwaysTrust",      "AutoBackup",
480          "AutoBackup",      "BackupMode",
481          "BackupMode",      "DisableHotkeys",  
482          "DisableHotkeys",            "NoCompressMultiMedia",    
483          "NoCompressMultiMedia",      "Expert",
484          "Expert",      "FMProgressBar",
485          "FMProgressBar",      "BackupSecring"
486      };  };
487    
488    
489  int  int
# Line 422  set_reg_winpt_single (int id, int val) Line 501  set_reg_winpt_single (int id, int val)
501  int  int
502  get_reg_winpt_single (int id)  get_reg_winpt_single (int id)
503  {  {
504      char * buf = NULL;      char *buf;
505      int val = 0;      int val = 0;
506    
507      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 519  int
519  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)
520  {  {
521      char buf[128];      char buf[128];
522      int rc = 0, i;      size_t i;
523        int rc = 0;
524    
525      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
526          switch (i) {          switch (i) {
# Line 453  set_reg_winpt_prefs (winpt_reg_prefs_s * Line 533  set_reg_winpt_prefs (winpt_reg_prefs_s *
533          case CFG_WIPEMODE:          case CFG_WIPEMODE:
534              sprintf (buf, "%d", opt->wipe_mode);              sprintf (buf, "%d", opt->wipe_mode);
535              break;              break;
536          case CFG_FASTMODE:          case CFG_FILEEXT:
537              sprintf (buf, "%d", opt->use_tmpfiles);              sprintf (buf, "%d", opt->default_ext);
538              break;              break;
539          case CFG_NOZIP_MMEDIA:          case CFG_NOZIP_MMEDIA:
540              sprintf (buf, "%d", opt->no_zip_mmedia);              sprintf (buf, "%d", opt->no_zip_mmedia);
# Line 462  set_reg_winpt_prefs (winpt_reg_prefs_s * Line 542  set_reg_winpt_prefs (winpt_reg_prefs_s *
542          case CFG_VIEWER:          case CFG_VIEWER:
543              sprintf (buf, "%d", opt->use_viewer);              sprintf (buf, "%d", opt->use_viewer);
544              break;              break;
         case CFG_KEYLISTMODE:  
             sprintf (buf, "%d", opt->keylist_mode);  
             break;  
545          case CFG_ALWAYSTRUST:          case CFG_ALWAYSTRUST:
546              sprintf (buf, "%d", opt->always_trust);              sprintf (buf, "%d", opt->always_trust);
547              break;              break;
# Line 484  set_reg_winpt_prefs (winpt_reg_prefs_s * Line 561  set_reg_winpt_prefs (winpt_reg_prefs_s *
561          case CFG_FM_PROGRESS:          case CFG_FM_PROGRESS:
562              sprintf (buf, "%d", opt->fm.progress);              sprintf (buf, "%d", opt->fm.progress);
563              break;              break;
564    
565            case CFG_BACKUP_INC_SKR:
566                sprintf (buf, "%d", opt->backup.include_secr);
567                break;
568          }          }
569          rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf);          rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf);
570          if (rc)          if (rc)
# Line 496  set_reg_winpt_prefs (winpt_reg_prefs_s * Line 577  set_reg_winpt_prefs (winpt_reg_prefs_s *
577          if (rc)          if (rc)
578              goto leave;              goto leave;
579      }      }
     if (opt->kserv_conf) {  
         rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig",  
                             opt->kserv_conf);  
         if (rc)  
             goto leave;  
     }  
580    
581      for (i=0; reg_hotkeys[i].reg_entry; i++) {      for (i=0; wpt_hotkeys[i].name; i++) {
582          strcpy (buf, " ");          if (wpt_hotkeys[i].enabled) {
583          if (reg_hotkeys[i].enabled)              buf[0] = wpt_hotkeys[i].key;
584              strcpy (buf, reg_hotkeys[i].key);              buf[1] = 0;
585            }
586            else
587                strcpy (buf, " ");
588          rc = set_reg_key (HKEY_CURRENT_USER, WINPT_REG,          rc = set_reg_key (HKEY_CURRENT_USER, WINPT_REG,
589                            reg_hotkeys[i].reg_entry, buf);                            wpt_hotkeys[i].name, buf);
590          if (rc)          if (rc)
591              break;              break;
592      }      }
# Line 526  int Line 604  int
604  set_reg_winpt_flag (const char * name, int val)  set_reg_winpt_flag (const char * name, int val)
605  {  {
606      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");
607  } /* set_reg_winpt_flag */  }
608    
609    
610  int  int
# Line 542  get_reg_winpt_flag (const char * name) Line 620  get_reg_winpt_flag (const char * name)
620          flag = -1;          flag = -1;
621      free_if_alloc (buf);      free_if_alloc (buf);
622      return flag;      return flag;
623  } /* get_reg_winpt_flag */  }
624    
625    
626  /* Retrieve the winpt preferences from the registry. */  /* Retrieve the winpt preferences from the registry. */
627  int  int
628  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)
629  {  {
630      char * val = NULL;      char *val = NULL;
631      int i;      size_t i;
632    
633      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
634          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]);          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]);
# Line 561  get_reg_winpt_prefs (winpt_reg_prefs_s * Line 639  get_reg_winpt_prefs (winpt_reg_prefs_s *
639          switch (i) {          switch (i) {
640          case CFG_CACHETIME:          case CFG_CACHETIME:
641              opt->cache_time = atol (val);              opt->cache_time = atol (val);
             /* We do NOT support passphrase caching for more than an hour.  
              * Perhaps we should allow it, but for now we silently drop this.  
              */  
             if (opt->cache_time > 3600)  
                 opt->cache_time = 3600;  
642              break;              break;
643          case CFG_WORDWRAP:          case CFG_WORDWRAP:
644              opt->word_wrap = atol (val);              opt->word_wrap = atol (val);
645              break;              break;
646          case CFG_FASTMODE:          case CFG_FILEEXT:
647              opt->use_tmpfiles = atol (val);              opt->default_ext = atol (val);
648              break;              break;
649          case CFG_NOZIP_MMEDIA:          case CFG_NOZIP_MMEDIA:
650              opt->no_zip_mmedia = atol (val);              opt->no_zip_mmedia = atol (val);
# Line 579  get_reg_winpt_prefs (winpt_reg_prefs_s * Line 652  get_reg_winpt_prefs (winpt_reg_prefs_s *
652          case CFG_VIEWER:          case CFG_VIEWER:
653              opt->use_viewer = atol (val);              opt->use_viewer = atol (val);
654              break;              break;
         case CFG_KEYLISTMODE:  
             opt->keylist_mode = atol (val);  
             break;  
655          case CFG_WIPEMODE:          case CFG_WIPEMODE:
656              opt->wipe_mode = atol (val);              opt->wipe_mode = atol (val);
657              break;              break;
# Line 600  get_reg_winpt_prefs (winpt_reg_prefs_s * Line 670  get_reg_winpt_prefs (winpt_reg_prefs_s *
670          case CFG_EXPERT:          case CFG_EXPERT:
671              opt->expert = atol (val);              opt->expert = atol (val);
672              break;              break;
   
673          case CFG_FM_PROGRESS:          case CFG_FM_PROGRESS:
674              opt->fm.progress = atol (val);              opt->fm.progress = atol (val);
675              break;              break;
676    
677            case CFG_BACKUP_INC_SKR:
678                opt->backup.include_secr = atol (val);
679                break;
680          }          }
681          free_if_alloc (val);          free_if_alloc (val);
682      }          }    
# Line 612  get_reg_winpt_prefs (winpt_reg_prefs_s * Line 685  get_reg_winpt_prefs (winpt_reg_prefs_s *
685      if (val && val[0] != ' ')      if (val && val[0] != ' ')
686          opt->backup.path = m_strdup (val);          opt->backup.path = m_strdup (val);
687      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);  
688            
689      for (i=0; reg_hotkeys[i].reg_entry; i++) {      for (i=0; wpt_hotkeys[i].name; i++) {
690          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry);          wpt_hotkeys[i].enabled = 0;
691            val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, wpt_hotkeys[i].name);
692          if (val && val[0] != ' ') {          if (val && val[0] != ' ') {
693              reg_hotkeys[i].key[0] = *val;              wpt_hotkeys[i].key = *val;
694              reg_hotkeys[i].enabled = 1;              wpt_hotkeys[i].enabled = 1;
695          }          }
         else  
             reg_hotkeys[i].enabled = 0;  
696          free_if_alloc (val);          free_if_alloc (val);
697      }      }
698      return 0;      return 0;
699  } /* get_reg_winpt_prefs */  }
700    
701    
702  char*  char*
703  get_reg_entry_keyserver (const char *name)  get_reg_entry_keyserver (const char *name)
704  {  {
705      char * p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name);      char *p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name);
706      if (p && !strcmp (p, "")) {      if (p && (!strcmp (p, "") || strlen (p) == 0)) {
707          free_if_alloc (p);          free_if_alloc (p);
708          return NULL;          return NULL;
709      }      }
# Line 644  get_reg_entry_keyserver (const char *nam Line 711  get_reg_entry_keyserver (const char *nam
711  }  }
712    
713    
714    int
715    set_reg_entry_keyserver (const char * name, const char * val)
716    {
717        return set_reg_entry( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val );
718    }
719    
720    static int
721    get_reg_entry_keyserver_int (const char *key)
722    {
723        char *p;
724        int val = 0;
725    
726        p = get_reg_entry_keyserver (key);
727        if (p && *p)
728            val = atoi (p);
729        free_if_alloc (p);
730        return val;
731    }
732    
733    
734  void  void
735  get_reg_proxy_prefs (char ** host, int * port, char ** user, char ** pass)  get_reg_proxy_prefs (keyserver_proxy_t prox)
736  {  {
737      if (host)      if (!prox)
738          *host = get_reg_entry_keyserver ("Host");          return;
739      if (user)      
740          *user = get_reg_entry_keyserver ("User");      free_if_alloc (prox->host);
741      if (pass)      prox->host = get_reg_entry_keyserver ("Host");
742          *pass = get_reg_entry_keyserver ("Pass");      free_if_alloc (prox->user);
743      if (port) {      prox->user = get_reg_entry_keyserver ("User");
744          char * p = get_reg_entry_keyserver ("Port");      free_if_alloc (prox->pass);
745          if (p) {      prox->pass = get_reg_entry_keyserver ("Pass");
746              *port = atol (p);      prox->port = get_reg_entry_keyserver_int ("Port");
747              free_if_alloc (p);  }
         }  
     }  
 } /* get_reg_proxy_prefs */  
748    
749    
750  int  static int
751  set_reg_entry_keyserver( const char * name, const char * val )  set_reg_entry_keyserver_int (const char *key, int val)
752  {  {
753      return set_reg_entry( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val );      char buf[32];
754  } /* set_reg_entry_keyserver */  
755        sprintf (buf, "%d", val);
756        return set_reg_entry_keyserver (key, buf);
757    }
758    
759    
760  int  int
761  set_reg_proxy_prefs( const char * host, int port, const char * user, const char * pass )  set_reg_proxy_prefs (keyserver_proxy_t prox)
762  {  {    
763      int rc;      int rc;
764            
765      rc = set_reg_entry_keyserver( "Host", host? host : "" );      rc = set_reg_entry_keyserver_int ("Proto", prox->proto);
766      if( !rc ) {      if (!rc)
767          char buf[32];          rc = set_reg_entry_keyserver ("Host", prox->host? prox->host : "");
768          sprintf( buf, "%d", port );      if (!rc)
769          rc = set_reg_entry_keyserver( "Port", buf );          rc = set_reg_entry_keyserver_int ("Port", prox->port);
770      }      if (!rc)
771      if( !rc )          rc = set_reg_entry_keyserver ("User", prox->user? prox->user : "");
772          rc = set_reg_entry_keyserver( "User", user? user : "" );      if (!rc)
773      if( !rc )          rc = set_reg_entry_keyserver ("Pass", prox->pass? prox->pass : "");
         rc = set_reg_entry_keyserver( "Pass", pass? pass : "" );  
774      return rc;      return rc;
775  } /* set_reg_proxy_prefs */  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26