/[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 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 55  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    
 #define WINPT_REG "Software\\WinPT"  
56    
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. */
76    int
77    is_gpgee_installed (void)
78    {
79        HKEY hk;
80        LONG ec;
81    
82        ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\GPGee", 0, KEY_READ, &hk);
83        if (ec == ERROR_SUCCESS) {
84            RegCloseKey (hk);
85            return -1;
86        }
87    
88        return 0;
89    }
90    
91    
92    /* Free all members in the registry preference struct. */
93  void  void
94  free_reg_prefs (void)  free_reg_prefs (void)
95  {  {
# Line 67  free_reg_prefs (void) Line 97  free_reg_prefs (void)
97      free_if_alloc (reg_prefs.kserv_conf);      free_if_alloc (reg_prefs.kserv_conf);
98      free_if_alloc (reg_prefs.homedir);      free_if_alloc (reg_prefs.homedir);
99      memset (&reg_prefs, 0, sizeof reg_prefs);      memset (&reg_prefs, 0, sizeof reg_prefs);
100  } /* free_reg_prefs */  }
101    
102    
103  /* Register the given WinPT filetype. */  /* Register the given WinPT filetype. */
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);
112      _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);      _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);
113      return create_file_type (prog, gfile->ext, gfile->descr, icon);      return create_file_type (prog, gfile->ext, gfile->descr, icon);
114  } /* regist_single_filetype */  }
115    
116    
117  /* 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 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
151     exists the function returns immediately.*/     exists the function returns immediately. @with_ext can be
152       used to register some file types (if 1). @created contains
153       1 if the registry key was created.
154       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      int rc, i, id, n = 0;      char modpath[MAX_PATH+1];
161        int rc, i, id, n;
162    
163      if( created )      gpg_filetype gpg_filetypes[] = {
164          *created = 0;          {_("GPG Detached Signature"), ".sig", 1},
165            {_("GPG Encrypted Data"),     ".gpg", 2},
166            {_("GPG Armored Data"),       ".asc", 2},
167            {0}
168        };
169    
170      p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");      if (created)
171      if (p && *p == '1')          *created = 0;
172        if (is_gpgee_installed ())
173          with_ext = 0;          with_ext = 0;
     free_if_alloc( p );  
174    
175      if( with_ext ) {      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);
176          id = msg_box( NULL, _("WinPT can register some GPG file types for you so they can "      if (rc_ok (rc)) {
177                                "be processed with a double click in the explorer.\n"          RegCloseKey (reg);
178                                "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO );          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);
179          if( id == IDNO ) {          if (!rc_ok (rc)) {
180              set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );              RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);
181              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 );  
182          }          }
183          p = get_reg_entry_keyserver ("Default");          p = get_reg_entry_keyserver ("Default");
184          if (!p) {          if (!p) {
# Line 172  start: Line 187  start:
187              set_reg_entry_keyserver ("Default_Port", buf);              set_reg_entry_keyserver ("Default_Port", buf);
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);
194      if( !rc_ok( rc ) )      if (!rc_ok (rc))
195          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
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) {
219            while (n-- > 0) {
220                if (modpath[n] == '\\') {
221                    modpath[n] = 0;
222                    break;
223                }
224            }
225            set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Install Directory", modpath);
226        }
227      return 0;      return 0;
228  } /* regist_inst_winpt */  }
229    
230    
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 258  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 266  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 279  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 373  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    
429  char *  /* Return if possible the GPG4Win installation directory concatenated
430  get_reg_entry_mo(void)     with the string in @path if given. */
431    char*
432    get_reg_entry_gpg4win (const char *path)
433    {
434        char *p, *pp;
435        p = get_reg_entry (HKEY_LOCAL_MACHINE,
436                           "Software\\GNU\\GnuPG", "Install Directory");
437        if (!p)
438            return NULL;
439        if (!path)
440            return p;
441        pp = new char[strlen (p) + strlen (path) + 4];
442        if (!pp)
443            BUG (NULL);
444        sprintf (pp, "%s\\%s", p, path);
445        free_if_alloc (p);
446        return pp;
447    }
448    
449        
450    char*
451    get_reg_entry_mo (void)
452  {        {      
453      return get_reg_entry(HKEY_CURRENT_USER,      char *p, *pp;
454                           "Control Panel\\Mingw32\\NLS", "MODir");      const char *lang;
455    
456        p = get_reg_entry (HKEY_CURRENT_USER,
457                           "Control Panel\\Mingw32\\NLS", "MODir");
458        if (p)
459            return p;
460    
461        lang = get_gettext_langid ();
462        if (!lang)    
463            return NULL;    
464        pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8];
465        if (!pp)    
466            BUG (NULL);
467        sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang);
468        p = get_reg_entry_gpg4win (pp);
469        free_if_alloc (pp);
470        return p;
471  }  }
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 440  int Line 522  int
522  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)
523  {  {
524      char buf[128];      char buf[128];
525      int rc = 0, i;      size_t i;
526        int rc = 0;
527    
528      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
529          switch (i) {          switch (i) {
# Line 462  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 496  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 549  get_reg_winpt_flag (const char * name) Line 623  get_reg_winpt_flag (const char * name)
623  int  int
624  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)
625  {  {
626      char * val = NULL;      char *val = NULL;
627      int i;      size_t i;
628    
629      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
630          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]);          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]);
# Line 579  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 612  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.69  
changed lines
  Added in v.176

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26