/[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 218 by twoaday, Wed May 24 07:53:24 2006 UTC revision 409 by twoaday, Mon Feb 6 19:39:00 2012 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 12  Line 12 
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   * General Public License for more details.   * General Public License for more details.
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
15   */   */
   
16  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
17  #include <config.h>  #include <config.h>
18  #endif  #endif
# Line 37  Line 32 
32    
33  #define rc_ok(rc) ((rc) == ERROR_SUCCESS)  #define rc_ok(rc) ((rc) == ERROR_SUCCESS)
34    
35    /* WinPT registry path. */
36  #define WINPT_REG "Software\\WinPT"  #define WINPT_REG "Software\\WinPT"
37    
38    /* GPG registry path. */
39    #define GPG_REG "Software\\GNU\\GnuPG"
40    
41    #define GPG_MO_REG "Control Panel\\MingW32\\NLS"
42    
43  /* GPG file association context. */  /* GPG file association context. */
44  struct gpg_filetype {      struct gpg_filetype_s {    
45      const char *descr;      const char *descr;  /* description. */
46      const char *ext;      const char *ext;    /* extension. */
47      int nicon;      int nicon;          /* number of the image icon. */
48  };  };
49    typedef struct gpg_filetype_s *gpg_filetype_t;
50    
51  /* Global WinPT registry prefereneces. */  /* Global WinPT registry prefereneces. */
52  winpt_reg_prefs_s reg_prefs;  struct winpt_prefs_s reg_prefs;
53    
54    /* All valid configuration commands. */
55    const char *cfg [] = {
56        NULL,      
57        "CacheTime",
58        "WordWrap",
59        "DefaultExt",
60        "Viewer",
61        "AlwaysTrust",
62        "AutoBackup",
63        "BackupMode",
64        "DisableHotkeys",  
65        "NoCompressMultiMedia",    
66        "Expert",
67        "FMProgressBar",
68        "BackupSecring"
69    };
70    
71  /* Return != 0 if GPG4win is installed. */  /* Return != 0 if GPG4win is installed. */
72  int  int
# Line 69  is_gpg4win_installed (void) Line 87  is_gpg4win_installed (void)
87    
88    
89  /* Return != 0 if GPGee is installed. */  /* Return != 0 if GPGee is installed. */
90  int  static int
91  is_gpgee_installed (void)  is_gpgee_installed (void)
92  {  {
93      HKEY hk;      HKEY hk;
# Line 92  free_reg_prefs (void) Line 110  free_reg_prefs (void)
110      free_if_alloc (reg_prefs.backup.path);      free_if_alloc (reg_prefs.backup.path);
111      free_if_alloc (reg_prefs.kserv_conf);      free_if_alloc (reg_prefs.kserv_conf);
112      free_if_alloc (reg_prefs.homedir);      free_if_alloc (reg_prefs.homedir);
113      memset (&reg_prefs, 0, sizeof reg_prefs);      memset (&reg_prefs, 0, sizeof (reg_prefs));
114  }  }
115    
116    
 /* 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);  
 }  
   
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
119     exists the function returns immediately. */     exists the function returns immediately. */
# Line 118  regist_inst_gnupg (int create_mokey) Line 123  regist_inst_gnupg (int create_mokey)
123      int rc;      int rc;
124      HKEY reg;      HKEY reg;
125    
126      rc = RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", 0, KEY_READ, &reg );        rc = RegOpenKeyEx (HKEY_CURRENT_USER, GPG_REG, 0, KEY_READ, &reg);
127      if( rc_ok( rc ) ) {      if (rc == ERROR_SUCCESS) {
128          RegCloseKey( reg );          RegCloseKey (reg);
129          return 0;                return 0;      
130      }      }
131      rc = RegCreateKey( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", &reg );      rc = RegCreateKey (HKEY_CURRENT_USER, GPG_REG, &reg);
132      if( !rc_ok( rc ) )                if (rc != ERROR_SUCCESS)
133          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
134      RegCloseKey( reg );      RegCloseKey (reg);
135      if( create_mokey ) {  
136          rc = RegOpenKeyEx( HKEY_CURRENT_USER,  "Control Panel\\MingW32\\NLS", 0, KEY_READ, &reg );      if (!create_mokey)
137          if( rc_ok( rc ) ) {          return 0;
138              RegCloseKey( reg );  
139              return 0;        rc = RegOpenKeyEx (HKEY_CURRENT_USER,  GPG_MO_REG, 0, KEY_READ, &reg);
140          }      if (rc == ERROR_SUCCESS) {
141          rc = RegCreateKey( HKEY_CURRENT_USER, "Control Panel\\MingW32\\NLS", &reg );          RegCloseKey (reg);
142          if( !rc_ok( rc ) )          return 0;      
             return WPTERR_REGISTRY;      
         RegCloseKey( reg );  
143      }      }
144        rc = RegCreateKey (HKEY_CURRENT_USER, GPG_MO_REG, &reg);
145        if (rc != ERROR_SUCCESS)
146            return WPTERR_REGISTRY;
147    
148        RegCloseKey (reg);
149      return 0;      return 0;
150  }  }
151    
152    
153    /* Create a new filetype in the W32 registry.
154       We should really care of errors! Otherwise we can damage the registry! */
155    static int
156    create_file_type (const char *exefile, const char *ext,
157                      const char *extname, char *iconfile)
158    {
159        HKEY reg = NULL;
160        char deficon[MAX_PATH+1];
161        char defexec[MAX_PATH+1];
162        char p_exefile[MAX_PATH+1];
163        int rc;
164        
165        rc = RegCreateKey (HKEY_CLASSES_ROOT, ext, &reg);
166        if( rc_ok( rc ) )
167            rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *)extname, strlen( extname ) );
168        if( rc_ok( rc ) )
169            rc = RegCloseKey( reg );
170        if( rc_ok( rc ) )    
171            rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, &reg );
172        if( rc_ok( rc ) )
173            rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *) extname, strlen( extname ) );
174        if( rc_ok( rc ) )
175            rc = RegCloseKey( reg );
176        if( !rc_ok( rc ) ) {
177            rc = WPTERR_REGISTRY;
178            goto leave;
179        }
180        
181        memset( &deficon, 0, sizeof deficon );
182        _snprintf( deficon, DIM (deficon) - 1, "%s\\DefaultIcon", extname );
183        memset( &defexec, 0, sizeof defexec );
184        _snprintf( defexec, DIM (defexec) - 1, "%s\\shell\\open\\command", extname );      
185        memset( &p_exefile, 0, sizeof p_exefile );
186        _snprintf( p_exefile, DIM (p_exefile) - 1, "%s %%1", exefile );
187        
188        rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, &reg );
189        if( rc_ok( rc ) )
190            rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (BYTE *)iconfile, strlen( iconfile ) );
191        if( rc_ok( rc ) )
192            rc = RegCloseKey( reg );
193        if( rc_ok( rc ) )
194            rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, &reg );
195        if( rc_ok( rc ) )
196            rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *)p_exefile, strlen( exefile ) );
197        if( rc_ok( rc ) )
198            rc = RegCloseKey( reg );
199        if( !rc_ok( rc ) ) {
200            rc = WPTERR_REGISTRY;
201            goto leave;    
202        }
203        
204    leave:
205        if (reg)
206            RegCloseKey (reg);
207        return rc;
208    }
209    
210    
211    /* Register the given WinPT filetype. */
212    static int
213    regist_single_filetype (gpg_filetype_t gfile)
214    {
215        char icon[MAX_PATH+1] = {0};
216        char prog[MAX_PATH+1] = {0};
217    
218        if (!GetModuleFileName (glob_hinst, prog, DIM (prog)-1))
219            return WPTERR_REGISTRY;
220        _snprintf (icon, DIM (icon) -1, "%s,%d", prog, gfile->nicon);
221        return create_file_type (prog, gfile->ext, gfile->descr, icon);
222    }
223    
224  /* Install WinPT into the W32 registry, if the entry already  /* Install WinPT into the W32 registry, if the entry already
225     exists the function returns immediately. @with_ext can be     exists the function returns immediately. @with_ext can be
226     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 228  regist_inst_gnupg (int create_mokey)
228     Return value: 0 on success. */     Return value: 0 on success. */
229  int  int
230  regist_inst_winpt (int with_ext, int *created)  regist_inst_winpt (int with_ext, int *created)
231  {      {
232      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[] = {  
233          {_("GPG Detached Signature"), ".sig", 1},          {_("GPG Detached Signature"), ".sig", 1},
234          {_("GPG Encrypted Data"),     ".gpg", 2},          {_("GPG Encrypted Data"),     ".gpg", 2},
235          {_("GPG Armored Data"),       ".asc", 2},          {_("GPG Armored Data"),       ".asc", 2},
236          {0}          {0}
237      };      };
238        HKEY reg;
239        char *p = NULL;
240        char modpath[MAX_PATH+1];
241        int rc, i, id, n;
242    
243      if (created)      if (created)
244          *created = 0;          *created = 0;
245    
246        /* If GPGee is already installed deactivate file extension registering
247           because it is very likely this would overwrite the GPGee settings. */
248      if (is_gpgee_installed ())      if (is_gpgee_installed ())
249          with_ext = 0;          with_ext = 0;
250    
251      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);
252      if (rc_ok (rc)) {      if (rc == ERROR_SUCCESS) {
253          RegCloseKey (reg);          RegCloseKey (reg);
254          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);
255          if (!rc_ok (rc)) {          if (rc != ERROR_SUCCESS) {
256              RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);              rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);
257              RegCloseKey (reg);              if (rc == ERROR_SUCCESS)
258                    RegCloseKey (reg);
259          }          }
260            else
261                RegCloseKey (reg);
262          p = get_reg_entry_keyserver ("Default");          p = get_reg_entry_keyserver ("Default");
263          if (!p) {          if (!p) {
264              char buf[16];              char buf[16];
265              sprintf (buf, "%d", HKP_PORT);  
266                _snprintf (buf, DIM (buf)-1, "%d", HKP_PORT);
267              set_reg_entry_keyserver ("Default_Port", buf);              set_reg_entry_keyserver ("Default_Port", buf);
268              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);
269          }          }
# Line 187  regist_inst_winpt (int with_ext, int *cr Line 271  regist_inst_winpt (int with_ext, int *cr
271          return 0;          return 0;
272      }      }
273      rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);      rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);
274      if (!rc_ok (rc))      if (rc != ERROR_SUCCESS)
275          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
276      if (created)      if (created)
277          *created = 1;          *created = 1;
278      RegCloseKey (reg);      RegCloseKey (reg);
279        /* FIXME: check this part */
280      if (with_ext) {      if (with_ext) {
281          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 "
282                                "be processed with a double click in the explorer.\n"                                "be processed with a double click in the explorer.\n"
# Line 199  regist_inst_winpt (int with_ext, int *cr Line 284  regist_inst_winpt (int with_ext, int *cr
284          if (id == IDYES) {          if (id == IDYES) {
285              for (i = 0; gpg_filetypes[i].ext; i++) {              for (i = 0; gpg_filetypes[i].ext; i++) {
286                  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);
287                  if (rc_ok (rc)) {                  if (rc == ERROR_SUCCESS) {
288                  RegCloseKey (reg);                      RegCloseKey (reg);
289                      id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,                      id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,
290                                    _("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"
291                                      "Do you want to overwrite it?"), gpg_filetypes[i].ext);                                      "Do you want to overwrite it?"), gpg_filetypes[i].ext);
292                      if (id == IDNO)                      if (id == IDNO)
# Line 211  regist_inst_winpt (int with_ext, int *cr Line 296  regist_inst_winpt (int with_ext, int *cr
296              }              }
297          }          }
298      }      }
299      if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {      /* Store the install directory for later use. */
300        n = GetModuleFileName (NULL, modpath, MAX_PATH-1);
301        if (n > 0) {
302          while (n-- > 0) {          while (n-- > 0) {
303              if (modpath[n] == '\\') {              if (modpath[n] == '\\') {
304                  modpath[n] = 0;                  modpath[n] = 0;
305                  break;                  break;
306              }              }
307          }          }
308          set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Install Directory", modpath);          log_debug("storing install directory '%s'", modpath);
309            set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Install Directory", modpath);    
310      }      }
311      return 0;      return 0;
312  }  }
313    
314    
 /* 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;  
 } /* create_file_type */  
   
   
315  /* Expand a string with %foo% entries so that %foo% will  /* Expand a string with %foo% entries so that %foo% will
316     be replaced with its actual value. */     be replaced with its actual value. */
317  static char *  static char*
318  expand_path (const char *path)  expand_path (const char *path)
319  {  {
320      DWORD len;      DWORD len;
# Line 309  expand_path (const char *path) Line 340  expand_path (const char *path)
340     and the key given in @key.     and the key given in @key.
341     Return value is the value or NULL otherwise. */     Return value is the value or NULL otherwise. */
342  char*  char*
343  get_reg_entry (HKEY root_key, const char * dir, const char * key)  get_reg_entry (HKEY root_key, const char *dir, const char *key)
344  {  {
     int rc;  
     char text[384] = {0};  
     DWORD nbytes, type;  
345      HKEY reg_key = NULL;      HKEY reg_key = NULL;
346      char * p = NULL;      char *p = NULL, *pp;    
347            DWORD type = REG_SZ, nbytes = 0;
348        int rc;
349    
350      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);
351      if( !rc_ok( rc ) )      if (rc != ERROR_SUCCESS)
352          goto leave;          goto leave;
353      nbytes = sizeof (text) - 1;      rc = RegQueryValueEx (reg_key, key, NULL, &type, NULL, &nbytes);
354      type = REG_SZ;      if (rc != ERROR_SUCCESS)
       
     rc = RegQueryValueEx (reg_key, key, 0, &type, (BYTE *)&text, &nbytes);  
     if (!rc_ok (rc) || !nbytes)  
355          goto leave;          goto leave;
356            if (!nbytes)
357      if (type == REG_EXPAND_SZ && strchr (text, '%'))          goto leave; /* empty */
358          p = expand_path (text);      p = new char[nbytes+1];
359      else {      if (!p)
360          p = new char[nbytes + 1];          BUG (0);
361          if (!p)      rc = RegQueryValueEx (reg_key, key, NULL, &type, (BYTE*)p,  &nbytes);
362              BUG (0);      if (rc != ERROR_SUCCESS)
363          memcpy (p, text, nbytes);          goto leave;
364          p[nbytes] = '\0';      if (type == REG_EXPAND_SZ && strchr (p, '%')) {
365            pp = p;
366            p = expand_path (pp);
367            free_if_alloc (pp);
368      }      }
369        
370  leave:  leave:
371      if (reg_key)      if (reg_key != NULL)
372          RegCloseKey (reg_key);          RegCloseKey (reg_key);
373      return p;      return p;
374  }  }
# Line 352  int Line 382  int
382  set_reg_entry (HKEY root_key, const char *dir, const char *key,  set_reg_entry (HKEY root_key, const char *dir, const char *key,
383                 const char *value)                 const char *value)
384  {  {
     int rc = 0;  
385      HKEY reg_key;      HKEY reg_key;
386        int rc;
387    
388      rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, &reg_key );      rc = RegOpenKeyEx (root_key, dir, 0, KEY_WRITE, &reg_key);
389      if( !rc_ok( rc ) )      if (rc != ERROR_SUCCESS)
390          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
391      rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) );      rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value));
392      if( !rc_ok( rc ) )      if (rc != ERROR_SUCCESS)
393          rc = WPTERR_REGISTRY;            rc = WPTERR_REGISTRY;  
394      RegCloseKey( reg_key );      RegCloseKey (reg_key);
395      return rc;      return rc;
396  } /* set_reg_entry */  }
397    
398    
399  int  int
400  set_reg_key( HKEY root_key, const char * dir, const char * key,  set_reg_key (HKEY root_key, const char *dir, const char *key,
401               const char * value )               const char *value)
402  {  {    
     int rc = 0;  
403      HKEY reg_key;      HKEY reg_key;
404        int rc;
405            
406      rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, &reg_key );      rc = RegOpenKeyEx (root_key, dir, 0, KEY_WRITE, &reg_key);
407      if( !rc_ok( rc ) )      if (rc != ERROR_SUCCESS)
408          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
409            
410      rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) );            rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value));
411      if( !rc_ok( rc ) ) {              if (rc != ERROR_SUCCESS) {
412          if ( RegCreateKey( root_key, key, &reg_key ) != ERROR_SUCCESS ) {          if (RegCreateKey (root_key, key, &reg_key) != ERROR_SUCCESS) {
413              rc = WPTERR_REGISTRY;              rc = WPTERR_REGISTRY;
414              goto leave;              goto leave;
415          }          }
416          rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) );                    rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value));
417          if ( !rc_ok( rc ) )          if (rc != ERROR_SUCCESS)
418              rc = WPTERR_REGISTRY;              rc = WPTERR_REGISTRY;
419      }      }
420            
421  leave:  leave:
422      RegCloseKey( reg_key );      RegCloseKey (reg_key);
423      return rc;      return rc;
 } /* set_reg_key */  
   
   
 int  
 set_reg_entry_gpg (const char * key, const char * value)  
 {        
     return set_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key, value);  
424  }  }
425    
426    
427  int  int
428  set_reg_entry_mo (const char * value)  set_reg_entry_gpg (const char *key, const char *value)
429  {        {      
430      return set_reg_entry (HKEY_CURRENT_USER, "Control Panel\\Mingw32\\NLS",      return set_reg_entry (HKEY_CURRENT_USER, GPG_REG, key, value);
                           "MODir", value);  
431  }  }
432    
433    
434    
435  char*  char*
436  get_reg_entry_gpg (const char *key)  get_reg_entry_gpg (const char *key)
437  {  {
438      char *p;      char *p;
439      p = get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key);  
440        p = get_reg_entry (HKEY_CURRENT_USER, GPG_REG, key);
441      if (!p || strlen (p) == 0) {      if (!p || strlen (p) == 0) {
442          free_if_alloc (p);          free_if_alloc (p);
443          return NULL;          return NULL;
# Line 427  get_reg_entry_gpg (const char *key) Line 451  get_reg_entry_gpg (const char *key)
451  char*  char*
452  get_reg_entry_gpg4win (const char *path)  get_reg_entry_gpg4win (const char *path)
453  {  {
454        const char *fmt;
455      char *p, *pp;      char *p, *pp;
456      p = get_reg_entry (HKEY_LOCAL_MACHINE,  
457                         "Software\\GNU\\GnuPG", "Install Directory");      p = get_reg_entry (HKEY_LOCAL_MACHINE, GPG_REG, "Install Directory");
458      if (!p)      if (!p)
459          return NULL;          return NULL;
460      if (!path)      if (!path)
461          return p;          return p;
462      pp = new char[strlen (p) + strlen (path) + 4];      fmt = "%s\\%s";
463        pp = new char[strlen (p) + strlen (path) + strlen (fmt) + 1];
464      if (!pp)      if (!pp)
465          BUG (NULL);          BUG (NULL);
466      sprintf (pp, "%s\\%s", p, path);      sprintf (pp, fmt, p, path);
467      free_if_alloc (p);      free_if_alloc (p);
468      return pp;      return pp;
469  }  }
# Line 447  char* Line 473  char*
473  get_reg_entry_mo (void)  get_reg_entry_mo (void)
474  {        {      
475      char *p, *pp;      char *p, *pp;
476        const char *fmt;
477      const char *lang;      const char *lang;
478    
479      p = get_reg_entry (HKEY_CURRENT_USER,      p = get_reg_entry (HKEY_CURRENT_USER, GPG_MO_REG, "MODir");
                        "Control Panel\\Mingw32\\NLS", "MODir");  
480      if (p)      if (p)
481          return p;          return p;
482    
483      lang = get_gettext_langid ();      lang = gettext_get_langid ();
484      if (!lang)      if (!lang)
485          return NULL;          return NULL;
486      pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8];      fmt = "share\\locale\\%s\\LC_MESSAGES";
487        pp = new char[strlen (fmt) + strlen (lang) + 4 + 1];
488      if (!pp)          if (!pp)    
489          BUG (NULL);          BUG (NULL);
490      sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang);      sprintf (pp, fmt, lang);
491      p = get_reg_entry_gpg4win (pp);      p = get_reg_entry_gpg4win (pp);
492      free_if_alloc (pp);      free_if_alloc (pp);
493      return p;      return p;
494  }  }
495    
496    
 /* All valid configuration commands. */  
 static const char *cfg [] = {  
     NULL,        
     "CacheTime",  
     "WordWrap",  
     "DefaultExt",  
     "Viewer",  
     "WipeMode",  
     "AlwaysTrust",  
     "AutoBackup",  
     "BackupMode",  
     "DisableHotkeys",    
     "NoCompressMultiMedia",      
     "Expert",  
     "FMProgressBar",  
 };  
   
   
497  int  int
498  set_reg_winpt_single (int id, int val)  set_reg_winpt_single (int id, int val)
499  {  {
500      char buf[64];      char buf[64];
501      int rc;      int rc;
502    
503      sprintf (buf, "%d", val);      _snprintf (buf, DIM (buf)-1, "%d", val);
504      rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id], buf);      rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id], buf);
505      return rc;      return rc;
506  }  }
# Line 500  set_reg_winpt_single (int id, int val) Line 509  set_reg_winpt_single (int id, int val)
509  int  int
510  get_reg_winpt_single (int id)  get_reg_winpt_single (int id)
511  {  {
512      char * buf = NULL;      char *buf;
513      int val = 0;      int val = 0;
514    
515      buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]);      buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]);
# Line 515  get_reg_winpt_single (int id) Line 524  get_reg_winpt_single (int id)
524    
525  /* Saves the winpt preferences in the registry. */  /* Saves the winpt preferences in the registry. */
526  int  int
527  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)  set_reg_winpt_prefs (winpt_prefs_t opt)
528  {  {
529      char buf[128];      char buf[128];
530      size_t i;      size_t i;
# Line 526  set_reg_winpt_prefs (winpt_reg_prefs_s * Line 535  set_reg_winpt_prefs (winpt_reg_prefs_s *
535          case CFG_CACHETIME:          case CFG_CACHETIME:
536              sprintf (buf, "%d", opt->cache_time);              sprintf (buf, "%d", opt->cache_time);
537              break;              break;
538                
539          case CFG_WORDWRAP:          case CFG_WORDWRAP:
540              sprintf (buf, "%d", opt->word_wrap);              sprintf (buf, "%d", opt->word_wrap);
541              break;              break;
542          case CFG_WIPEMODE:              
             sprintf (buf, "%d", opt->wipe_mode);  
             break;  
543          case CFG_FILEEXT:          case CFG_FILEEXT:
544              sprintf (buf, "%d", opt->default_ext);              sprintf (buf, "%d", opt->default_ext);
545              break;              break;
546                
547          case CFG_NOZIP_MMEDIA:          case CFG_NOZIP_MMEDIA:
548              sprintf (buf, "%d", opt->no_zip_mmedia);              sprintf (buf, "%d", opt->no_zip_mmedia);
549              break;              break;
550                
551          case CFG_VIEWER:          case CFG_VIEWER:
552              sprintf (buf, "%d", opt->use_viewer);              sprintf (buf, "%d", opt->use_viewer);
553              break;              break;
554                
555          case CFG_ALWAYSTRUST:          case CFG_ALWAYSTRUST:
556              sprintf (buf, "%d", opt->always_trust);              sprintf (buf, "%d", opt->always_trust);
557              break;              break;
558    
559          case CFG_AUTOBACKUP:          case CFG_AUTOBACKUP:
560              sprintf (buf, "%d", opt->auto_backup);              sprintf (buf, "%d", opt->auto_backup);
561              break;              break;
562                
563          case CFG_AUTOBAKMODE:          case CFG_AUTOBAKMODE:
564              sprintf (buf, "%d", opt->backup.mode);              sprintf (buf, "%d", opt->backup.mode);
565              break;              break;
566                
567          case CFG_DISHOTKEYS:          case CFG_DISHOTKEYS:
568              sprintf (buf, "%d", opt->no_hotkeys);              sprintf (buf, "%d", opt->no_hotkeys);
569              break;              break;
570                
571          case CFG_EXPERT:          case CFG_EXPERT:
572              sprintf (buf, "%d", opt->expert);              sprintf (buf, "%d", opt->expert);
573              break;              break;
# Line 560  set_reg_winpt_prefs (winpt_reg_prefs_s * Line 575  set_reg_winpt_prefs (winpt_reg_prefs_s *
575          case CFG_FM_PROGRESS:          case CFG_FM_PROGRESS:
576              sprintf (buf, "%d", opt->fm.progress);              sprintf (buf, "%d", opt->fm.progress);
577              break;              break;
578    
579            case CFG_BACKUP_INC_SKR:
580                sprintf (buf, "%d", opt->backup.include_secr);
581                break;
582          }          }
583          rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf);          rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf);
584          if (rc)          if (rc)
# Line 573  set_reg_winpt_prefs (winpt_reg_prefs_s * Line 592  set_reg_winpt_prefs (winpt_reg_prefs_s *
592              goto leave;              goto leave;
593      }      }
594    
595      for (i=0; wpt_hotkeys[i].name; i++) {      for (i=0; wpt_hotkeys[i].name != NULL; i++) {
596          if (wpt_hotkeys[i].enabled) {          if (wpt_hotkeys[i].enabled == 1) {
597              buf[0] = wpt_hotkeys[i].key;              buf[0] = wpt_hotkeys[i].key;
598              buf[1] = 0;              buf[1] = 0;
599          }          }
# Line 596  leave: Line 615  leave:
615    
616    
617  int  int
618  set_reg_winpt_flag (const char * name, int val)  set_reg_winpt_flag (const char *name, int val)
619  {  {
620      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");
621  } /* set_reg_winpt_flag */  }
622    
623    
624  int  int
625  get_reg_winpt_flag (const char * name)  get_reg_winpt_flag (const char *name)
626  {  {
627      char * buf;      char *buf;
628      int flag = 0;      int flag = 0;
629    
630      buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name);      buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name);
631      if (buf && buf[0] == '1')      if (buf && buf[0] == '1')
632          flag = 1;          flag = 1;
633      else if (!buf || buf && buf[0] != '0')      else if (!buf || (buf && buf[0] != '0'))
634          flag = -1;          flag = -1;
635      free_if_alloc (buf);      free_if_alloc (buf);
636      return flag;      return flag;
637  } /* get_reg_winpt_flag */  }
638    
639    
640  /* Retrieve the winpt preferences from the registry. */  /* Retrieve the winpt preferences from the registry. */
641  int  int
642  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)  get_reg_winpt_prefs (winpt_prefs_t opt)
643  {  {
644      char *val = NULL;      char *val = NULL;
645      size_t i;      size_t i;
# Line 633  get_reg_winpt_prefs (winpt_reg_prefs_s * Line 652  get_reg_winpt_prefs (winpt_reg_prefs_s *
652          }          }
653          switch (i) {          switch (i) {
654          case CFG_CACHETIME:          case CFG_CACHETIME:
655              opt->cache_time = atol (val);              opt->cache_time = atoi (val);
656              break;              break;
657          case CFG_WORDWRAP:          case CFG_WORDWRAP:
658              opt->word_wrap = atol (val);              opt->word_wrap = atoi (val);
659              break;              break;
660          case CFG_FILEEXT:          case CFG_FILEEXT:
661              opt->default_ext = atol (val);              opt->default_ext = atoi (val);
662              break;              break;
663          case CFG_NOZIP_MMEDIA:          case CFG_NOZIP_MMEDIA:
664              opt->no_zip_mmedia = atol (val);              opt->no_zip_mmedia = atoi (val);
665              break;              break;
666          case CFG_VIEWER:          case CFG_VIEWER:
667              opt->use_viewer = atol (val);              opt->use_viewer = atoi (val);
             break;  
         case CFG_WIPEMODE:  
             opt->wipe_mode = atol (val);  
668              break;              break;
669          case CFG_DISHOTKEYS:          case CFG_DISHOTKEYS:
670              opt->no_hotkeys = atol (val);              opt->no_hotkeys = atoi (val);
671              break;              break;
672          case CFG_ALWAYSTRUST:          case CFG_ALWAYSTRUST:
673              opt->always_trust = atol (val);              opt->always_trust = atoi (val);
674              break;              break;
675          case CFG_AUTOBACKUP:          case CFG_AUTOBACKUP:
676              opt->auto_backup = atol (val);              opt->auto_backup = atoi (val);
677              break;              break;
678          case CFG_AUTOBAKMODE:          case CFG_AUTOBAKMODE:
679              opt->backup.mode = atol (val);              opt->backup.mode = atoi (val);
680              break;              break;
681          case CFG_EXPERT:          case CFG_EXPERT:
682              opt->expert = atol (val);              opt->expert = atoi (val);
683              break;              break;
684          case CFG_FM_PROGRESS:          case CFG_FM_PROGRESS:
685              opt->fm.progress = atol (val);              opt->fm.progress = atoi (val);
686                break;
687    
688            case CFG_BACKUP_INC_SKR:
689                opt->backup.include_secr = atoi (val);
690              break;              break;
691          }          }
692          free_if_alloc (val);          free_if_alloc (val);
# Line 703  get_reg_entry_keyserver (const char *nam Line 723  get_reg_entry_keyserver (const char *nam
723    
724    
725  int  int
726  set_reg_entry_keyserver (const char * name, const char * val)  set_reg_entry_keyserver (const char *name, const char *val)
727  {  {
728      return set_reg_entry( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val );      return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val);
729  }  }
730    
 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)  
 {  
     if (!prox)  
         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;  
 }  

Legend:
Removed from v.218  
changed lines
  Added in v.409

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26