/[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 179 by twoaday, Fri Feb 24 13:12:26 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    /* GPG file association context. */
42    struct gpg_filetype {    
43        const char *descr;
44        const char *ext;
45        int nicon;
46    };
47    
48  struct reg_hotkey_s reg_hotkeys[] = {  struct reg_hotkey_s reg_hotkeys[] = {
49      {"ClipEncrypt", "", 0},      {"ClipEncrypt", "", 0},
# Line 56  struct reg_hotkey_s reg_hotkeys[] = { Line 57  struct reg_hotkey_s reg_hotkeys[] = {
57      {NULL, "", 0}      {NULL, "", 0}
58  };  };
59    
60    /* Global WinPT registry prefereneces. */
61  winpt_reg_prefs_s reg_prefs;  winpt_reg_prefs_s reg_prefs;
62    
63  #define WINPT_REG "Software\\WinPT"  
64    /* Return != 0 if GPG4win is installed. */
65    int
66    is_gpg4win_installed (void)
67    {
68        char *p;
69    
70        p = get_reg_entry_gpg4win (NULL);
71        if (!p)
72            return 0;
73        if (dir_exist_check (p)) {
74            free_if_alloc (p);
75            return 0;
76        }
77        free_if_alloc (p);
78        return -1;
79    }
80    
81    
82  /* Return != 0 if GPGee is installed. */  /* Return != 0 if GPGee is installed. */
# Line 93  free_reg_prefs (void) Line 111  free_reg_prefs (void)
111  static int  static int
112  regist_single_filetype (gpg_filetype *gfile)  regist_single_filetype (gpg_filetype *gfile)
113  {  {
114      char icon[256], prog[256];      char icon[256];
115        char prog[256];
116            
117      memset (&icon, 0, sizeof (icon));      memset (&icon, 0, sizeof (icon));
118      GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);      GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);
# Line 132  regist_inst_gnupg (int create_mokey) Line 151  regist_inst_gnupg (int create_mokey)
151      }      }
152    
153      return 0;      return 0;
154  } /* regist_inst_gpg */  }
155    
156    
157  /* 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 161  regist_inst_gnupg (int create_mokey)
161     Return value: 0 on success. */     Return value: 0 on success. */
162  int  int
163  regist_inst_winpt (int with_ext, int *created)  regist_inst_winpt (int with_ext, int *created)
164  {  {    
165      HKEY reg;      HKEY reg;
166      char *p = NULL;      char *p = NULL;
167      char modpath[MAX_PATH+1];      char modpath[MAX_PATH+1];
168      int rc, i, id, n = 0;      int rc, i, id, n;
169    
170        gpg_filetype gpg_filetypes[] = {
171            {_("GPG Detached Signature"), ".sig", 1},
172            {_("GPG Encrypted Data"),     ".gpg", 2},
173            {_("GPG Armored Data"),       ".asc", 2},
174            {0}
175        };
176    
177      if (created)      if (created)
178          *created = 0;          *created = 0;
179        if (is_gpgee_installed ())
     p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");  
     if ((p && *p == '1') || is_gpgee_installed ())  
180          with_ext = 0;          with_ext = 0;
     free_if_alloc (p);  
181    
     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:  
182      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);
183      if (rc_ok (rc)) {      if (rc_ok (rc)) {
184          RegCloseKey (reg);          RegCloseKey (reg);
185          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);
186          if( !rc_ok (rc)) {          if (!rc_ok (rc)) {
187              RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);              RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);
188              RegCloseKey (reg);              RegCloseKey (reg);
189          }          }
# Line 196  start: Line 195  start:
195              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);
196          }          }
197          free_if_alloc (p);          free_if_alloc (p);
         if (n)  
             set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");  
198          return 0;          return 0;
199      }      }
200      rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);      rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);
# Line 206  start: Line 203  start:
203      if (created)      if (created)
204          *created = 1;          *created = 1;
205      RegCloseKey (reg);      RegCloseKey (reg);
206      if (n)      if (with_ext) {
207          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 "
208                                  "be processed with a double click in the explorer.\n"
209                                  "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO);
210            if (id == IDYES) {
211                for (i = 0; gpg_filetypes[i].ext; i++) {
212                    rc = RegOpenKeyEx (HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, &reg);
213                    if (rc_ok (rc)) {
214                    RegCloseKey (reg);
215                        id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,
216                                      _("It seems there was already a '%s' file type registered by another application.\n"
217                                        "Do you want to overwrite it?"), gpg_filetypes[i].ext);
218                        if (id == IDNO)
219                            continue;
220                    }
221                    regist_single_filetype (&gpg_filetypes[i]);
222                }
223            }
224        }
225      if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {      if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {
226          while (n-- > 0) {          while (n-- > 0) {
227              if (modpath[n] == '\\') {              if (modpath[n] == '\\') {
# Line 224  start: Line 238  start:
238  /* Create a new filetype in the W32 registry.  /* Create a new filetype in the W32 registry.
239     We should really care of errors! Otherwise we can damage the registry! */     We should really care of errors! Otherwise we can damage the registry! */
240  int  int
241  create_file_type( const char *exefile, const char *ext, const char *extname, char *iconfile )  create_file_type (const char *exefile, const char *ext,
242                      const char *extname, char *iconfile)
243  {  {
244      int rc;      int rc;
245      HKEY reg = NULL;      HKEY reg = NULL;
# Line 290  expand_path (const char *path) Line 305  expand_path (const char *path)
305          return NULL;          return NULL;
306      len += 1;      len += 1;
307      p = new char[len+1];      p = new char[len+1];
308      if( !p )      if (!p)
309          return NULL;          return NULL;
310      len = ExpandEnvironmentStrings (path, p, len);      len = ExpandEnvironmentStrings (path, p, len);
311      if (!len) {      if (!len) {
# Line 298  expand_path (const char *path) Line 313  expand_path (const char *path)
313          return NULL;          return NULL;
314      }      }
315      return p;      return p;
316  } /* expand_path */  }
317    
318    
319  /* 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 326  get_reg_entry (HKEY root_key, const char
326      char text[384] = {0};      char text[384] = {0};
327      DWORD nbytes, type;      DWORD nbytes, type;
328      HKEY reg_key = NULL;      HKEY reg_key = NULL;
329      char *p = NULL;      char * p = NULL;
330            
331      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);
332      if( !rc_ok( rc ) )      if( !rc_ok( rc ) )
# Line 397  set_reg_entry_gpg (const char * key, con Line 412  set_reg_entry_gpg (const char * key, con
412  }  }
413    
414    
   
   
415  int  int
416  set_reg_entry_mo (const char * value)  set_reg_entry_mo (const char * value)
417  {        {      
# Line 407  set_reg_entry_mo (const char * value) Line 420  set_reg_entry_mo (const char * value)
420  }  }
421    
422    
423  char *  char*
424  get_reg_entry_gpg (const char *key)  get_reg_entry_gpg (const char *key)
425  {  {
426      return get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key);      char *p;
427        p = get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key);
428        if (!p || strlen (p) == 0) {
429            free_if_alloc (p);
430            return NULL;
431        }
432        return p;
433  }  }
434    
435    
# Line 460  get_reg_entry_mo (void) Line 479  get_reg_entry_mo (void)
479    
480    
481  /* All valid configuration commands. */  /* All valid configuration commands. */
482  static const char * cfg [] = {  static const char *cfg [] = {
483          NULL,      NULL,      
484          "CacheTime",      "CacheTime",
485          "WordWrap",      "WordWrap",
486          "FastMode",      "FastMode",
487          "Viewer",      "Viewer",
488          "KeylistMode",      "WipeMode",
489          "WipeMode",      "AlwaysTrust",
490          "AlwaysTrust",      "AutoBackup",
491          "AutoBackup",      "BackupMode",
492          "BackupMode",      "DisableHotkeys",  
493          "DisableHotkeys",            "NoCompressMultiMedia",    
494          "NoCompressMultiMedia",      "Expert",
495          "Expert",      "FMProgressBar",
496          "FMProgressBar",  };
     };  
497    
498    
499  int  int
# Line 493  set_reg_winpt_single (int id, int val) Line 511  set_reg_winpt_single (int id, int val)
511  int  int
512  get_reg_winpt_single (int id)  get_reg_winpt_single (int id)
513  {  {
514      char *buf = NULL;      char * buf = NULL;
515      int val = 0;      int val = 0;
516    
517      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 552  set_reg_winpt_prefs (winpt_reg_prefs_s *
552          case CFG_VIEWER:          case CFG_VIEWER:
553              sprintf (buf, "%d", opt->use_viewer);              sprintf (buf, "%d", opt->use_viewer);
554              break;              break;
         case CFG_KEYLISTMODE:  
             sprintf (buf, "%d", opt->keylist_mode);  
             break;  
555          case CFG_ALWAYSTRUST:          case CFG_ALWAYSTRUST:
556              sprintf (buf, "%d", opt->always_trust);              sprintf (buf, "%d", opt->always_trust);
557              break;              break;
# Line 568  set_reg_winpt_prefs (winpt_reg_prefs_s * Line 583  set_reg_winpt_prefs (winpt_reg_prefs_s *
583          if (rc)          if (rc)
584              goto leave;              goto leave;
585      }      }
     if (opt->kserv_conf) {  
         rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig",  
                             opt->kserv_conf);  
         if (rc)  
             goto leave;  
     }  
586    
587      for (i=0; reg_hotkeys[i].reg_entry; i++) {      for (i=0; reg_hotkeys[i].reg_entry; i++) {
588          strcpy (buf, " ");          strcpy (buf, " ");
# Line 651  get_reg_winpt_prefs (winpt_reg_prefs_s * Line 660  get_reg_winpt_prefs (winpt_reg_prefs_s *
660          case CFG_VIEWER:          case CFG_VIEWER:
661              opt->use_viewer = atol (val);              opt->use_viewer = atol (val);
662              break;              break;
         case CFG_KEYLISTMODE:  
             opt->keylist_mode = atol (val);  
             break;  
663          case CFG_WIPEMODE:          case CFG_WIPEMODE:
664              opt->wipe_mode = atol (val);              opt->wipe_mode = atol (val);
665              break;              break;
# Line 684  get_reg_winpt_prefs (winpt_reg_prefs_s * Line 690  get_reg_winpt_prefs (winpt_reg_prefs_s *
690      if (val && val[0] != ' ')      if (val && val[0] != ' ')
691          opt->backup.path = m_strdup (val);          opt->backup.path = m_strdup (val);
692      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);  
693            
694      for (i=0; reg_hotkeys[i].reg_entry; i++) {      for (i=0; reg_hotkeys[i].reg_entry; i++) {
695          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.179

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26