/[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 117 by twoaday, Thu Dec 8 09:26:32 2005 UTC revision 176 by twoaday, Mon Feb 13 09:38:03 2006 UTC
# Line 36  Line 36 
36    
37  #define rc_ok(rc) ((rc) == ERROR_SUCCESS)  #define rc_ok(rc) ((rc) == ERROR_SUCCESS)
38    
39  static gpg_filetype gpg_filetypes[] = {  #define WINPT_REG "Software\\WinPT"
     {"GPG Detached Signature", ".sig", 1},  
     {"GPG Encrypted Data",     ".gpg", 2},  
     {"GPG Armored Data",       ".asc", 2},  
     {0}  
 };  
   
40    
41  struct reg_hotkey_s reg_hotkeys[] = {  struct reg_hotkey_s reg_hotkeys[] = {
42      {"ClipEncrypt", "", 0},      {"ClipEncrypt", "", 0},
# Line 56  struct reg_hotkey_s reg_hotkeys[] = { Line 50  struct reg_hotkey_s reg_hotkeys[] = {
50      {NULL, "", 0}      {NULL, "", 0}
51  };  };
52    
53    /* Global WinPT registry prefereneces. */
54  winpt_reg_prefs_s reg_prefs;  winpt_reg_prefs_s reg_prefs;
55    
56  #define WINPT_REG "Software\\WinPT"  
57    /* Return != 0 if GPG4win is installed. */
58    int
59    is_gpg4win_installed (void)
60    {
61        char *p;
62    
63        p = get_reg_entry_gpg4win (NULL);
64        if (!p)
65            return 0;
66        if (dir_exist_check (p)) {
67            free_if_alloc (p);
68            return 0;
69        }
70        free_if_alloc (p);
71        return -1;
72    }
73    
74    
75  /* Return != 0 if GPGee is installed. */  /* Return != 0 if GPGee is installed. */
# Line 93  free_reg_prefs (void) Line 104  free_reg_prefs (void)
104  static int  static int
105  regist_single_filetype (gpg_filetype *gfile)  regist_single_filetype (gpg_filetype *gfile)
106  {  {
107      char icon[256], prog[256];      char icon[256];
108        char prog[256];
109            
110      memset (&icon, 0, sizeof (icon));      memset (&icon, 0, sizeof (icon));
111      GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);      GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);
# Line 132  regist_inst_gnupg (int create_mokey) Line 144  regist_inst_gnupg (int create_mokey)
144      }      }
145    
146      return 0;      return 0;
147  } /* regist_inst_gpg */  }
148    
149    
150  /* Install WinPT into the W32 registry, if the entry already  /* Install WinPT into the W32 registry, if the entry already
# Line 142  regist_inst_gnupg (int create_mokey) Line 154  regist_inst_gnupg (int create_mokey)
154     Return value: 0 on success. */     Return value: 0 on success. */
155  int  int
156  regist_inst_winpt (int with_ext, int *created)  regist_inst_winpt (int with_ext, int *created)
157  {  {    
158      HKEY reg;      HKEY reg;
159      char *p = NULL;      char *p = NULL;
160      char modpath[MAX_PATH+1];      char modpath[MAX_PATH+1];
161      int rc, i, id, n = 0;      int rc, i, id, n;
162    
163        gpg_filetype gpg_filetypes[] = {
164            {_("GPG Detached Signature"), ".sig", 1},
165            {_("GPG Encrypted Data"),     ".gpg", 2},
166            {_("GPG Armored Data"),       ".asc", 2},
167            {0}
168        };
169    
170      if (created)      if (created)
171          *created = 0;          *created = 0;
172        if (is_gpgee_installed ())
     p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");  
     if ((p && *p == '1') || is_gpgee_installed ())  
173          with_ext = 0;          with_ext = 0;
     free_if_alloc (p);  
174    
     if (with_ext) {  
         id = msg_box (NULL, _("WinPT can register some GPG file types for you so they can "  
                               "be processed with a double click in the explorer.\n"  
                               "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO);  
         if (id == IDNO) {  
             set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");  
             goto start;  
         }  
         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:  
175      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);
176      if (rc_ok (rc)) {      if (rc_ok (rc)) {
177          RegCloseKey (reg);          RegCloseKey (reg);
178          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);
179          if( !rc_ok (rc)) {          if (!rc_ok (rc)) {
180              RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);              RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);
181              RegCloseKey (reg);              RegCloseKey (reg);
182          }          }
# Line 196  start: Line 188  start:
188              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);
189          }          }
190          free_if_alloc (p);          free_if_alloc (p);
         if (n)  
             set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");  
191          return 0;          return 0;
192      }      }
193      rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);      rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);
# Line 206  start: Line 196  start:
196      if (created)      if (created)
197          *created = 1;          *created = 1;
198      RegCloseKey (reg);      RegCloseKey (reg);
199      if (n)      if (with_ext) {
200          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 "
201                                  "be processed with a double click in the explorer.\n"
202                                  "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO);
203            if (id == IDYES) {
204                for (i = 0; gpg_filetypes[i].ext; i++) {
205                    rc = RegOpenKeyEx (HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, &reg);
206                    if (rc_ok (rc)) {
207                    RegCloseKey (reg);
208                        id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,
209                                      _("It seems there was already a '%s' file type registered by another application.\n"
210                                        "Do you want to overwrite it?"), gpg_filetypes[i].ext);
211                        if (id == IDNO)
212                            continue;
213                    }
214                    regist_single_filetype (&gpg_filetypes[i]);
215                }
216            }
217        }
218      if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {      if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {
219          while (n-- > 0) {          while (n-- > 0) {
220              if (modpath[n] == '\\') {              if (modpath[n] == '\\') {
# Line 224  start: Line 231  start:
231  /* Create a new filetype in the W32 registry.  /* Create a new filetype in the W32 registry.
232     We should really care of errors! Otherwise we can damage the registry! */     We should really care of errors! Otherwise we can damage the registry! */
233  int  int
234  create_file_type( const char *exefile, const char *ext, const char *extname, char *iconfile )  create_file_type (const char *exefile, const char *ext,
235                      const char *extname, char *iconfile)
236  {  {
237      int rc;      int rc;
238      HKEY reg = NULL;      HKEY reg = NULL;
# Line 290  expand_path (const char *path) Line 298  expand_path (const char *path)
298          return NULL;          return NULL;
299      len += 1;      len += 1;
300      p = new char[len+1];      p = new char[len+1];
301      if( !p )      if (!p)
302          return NULL;          return NULL;
303      len = ExpandEnvironmentStrings (path, p, len);      len = ExpandEnvironmentStrings (path, p, len);
304      if (!len) {      if (!len) {
# Line 298  expand_path (const char *path) Line 306  expand_path (const char *path)
306          return NULL;          return NULL;
307      }      }
308      return p;      return p;
309  } /* expand_path */  }
310    
311    
312  /* Retrieve a registry entry with the directory given in @dir  /* Retrieve a registry entry with the directory given in @dir
# Line 311  get_reg_entry (HKEY root_key, const char Line 319  get_reg_entry (HKEY root_key, const char
319      char text[384] = {0};      char text[384] = {0};
320      DWORD nbytes, type;      DWORD nbytes, type;
321      HKEY reg_key = NULL;      HKEY reg_key = NULL;
322      char *p = NULL;      char * p = NULL;
323            
324      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);
325      if( !rc_ok( rc ) )      if( !rc_ok( rc ) )
# Line 397  set_reg_entry_gpg (const char * key, con Line 405  set_reg_entry_gpg (const char * key, con
405  }  }
406    
407    
   
   
408  int  int
409  set_reg_entry_mo (const char * value)  set_reg_entry_mo (const char * value)
410  {        {      
# Line 407  set_reg_entry_mo (const char * value) Line 413  set_reg_entry_mo (const char * value)
413  }  }
414    
415    
416  char *  char*
417  get_reg_entry_gpg (const char *key)  get_reg_entry_gpg (const char *key)
418  {  {
419      return get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key);      char *p;
420        p = get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key);
421        if (!p || strlen (p) == 0) {
422            free_if_alloc (p);
423            return NULL;
424        }
425        return p;
426  }  }
427    
428    
# Line 460  get_reg_entry_mo (void) Line 472  get_reg_entry_mo (void)
472    
473    
474  /* All valid configuration commands. */  /* All valid configuration commands. */
475  static const char * cfg [] = {  static const char *cfg [] = {
476          NULL,      NULL,      
477          "CacheTime",      "CacheTime",
478          "WordWrap",      "WordWrap",
479          "FastMode",      "FastMode",
480          "Viewer",      "Viewer",
481          "KeylistMode",      "WipeMode",
482          "WipeMode",      "AlwaysTrust",
483          "AlwaysTrust",      "AutoBackup",
484          "AutoBackup",      "BackupMode",
485          "BackupMode",      "DisableHotkeys",  
486          "DisableHotkeys",            "NoCompressMultiMedia",    
487          "NoCompressMultiMedia",      "Expert",
488          "Expert",      "FMProgressBar",
489          "FMProgressBar",  };
     };  
490    
491    
492  int  int
# Line 493  set_reg_winpt_single (int id, int val) Line 504  set_reg_winpt_single (int id, int val)
504  int  int
505  get_reg_winpt_single (int id)  get_reg_winpt_single (int id)
506  {  {
507      char *buf = NULL;      char * buf = NULL;
508      int val = 0;      int val = 0;
509    
510      buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]);      buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]);
# Line 534  set_reg_winpt_prefs (winpt_reg_prefs_s * Line 545  set_reg_winpt_prefs (winpt_reg_prefs_s *
545          case CFG_VIEWER:          case CFG_VIEWER:
546              sprintf (buf, "%d", opt->use_viewer);              sprintf (buf, "%d", opt->use_viewer);
547              break;              break;
         case CFG_KEYLISTMODE:  
             sprintf (buf, "%d", opt->keylist_mode);  
             break;  
548          case CFG_ALWAYSTRUST:          case CFG_ALWAYSTRUST:
549              sprintf (buf, "%d", opt->always_trust);              sprintf (buf, "%d", opt->always_trust);
550              break;              break;
# Line 568  set_reg_winpt_prefs (winpt_reg_prefs_s * Line 576  set_reg_winpt_prefs (winpt_reg_prefs_s *
576          if (rc)          if (rc)
577              goto leave;              goto leave;
578      }      }
     if (opt->kserv_conf) {  
         rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig",  
                             opt->kserv_conf);  
         if (rc)  
             goto leave;  
     }  
579    
580      for (i=0; reg_hotkeys[i].reg_entry; i++) {      for (i=0; reg_hotkeys[i].reg_entry; i++) {
581          strcpy (buf, " ");          strcpy (buf, " ");
# Line 651  get_reg_winpt_prefs (winpt_reg_prefs_s * Line 653  get_reg_winpt_prefs (winpt_reg_prefs_s *
653          case CFG_VIEWER:          case CFG_VIEWER:
654              opt->use_viewer = atol (val);              opt->use_viewer = atol (val);
655              break;              break;
         case CFG_KEYLISTMODE:  
             opt->keylist_mode = atol (val);  
             break;  
656          case CFG_WIPEMODE:          case CFG_WIPEMODE:
657              opt->wipe_mode = atol (val);              opt->wipe_mode = atol (val);
658              break;              break;
# Line 684  get_reg_winpt_prefs (winpt_reg_prefs_s * Line 683  get_reg_winpt_prefs (winpt_reg_prefs_s *
683      if (val && val[0] != ' ')      if (val && val[0] != ' ')
684          opt->backup.path = m_strdup (val);          opt->backup.path = m_strdup (val);
685      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);  
686            
687      for (i=0; reg_hotkeys[i].reg_entry; i++) {      for (i=0; reg_hotkeys[i].reg_entry; i++) {
688          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry);          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry);

Legend:
Removed from v.117  
changed lines
  Added in v.176

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26