/[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 76 by twoaday, Thu Nov 10 14:07:06 2005 UTC revision 172 by twoaday, Mon Jan 30 13:47:35 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    
# Line 406  get_reg_entry_mo (void) Line 452  get_reg_entry_mo (void)
452  {        {      
453      char *p, *pp;      char *p, *pp;
454      const char *lang;      const char *lang;
455        
456      p = get_reg_entry (HKEY_CURRENT_USER,      p = get_reg_entry (HKEY_CURRENT_USER,
457                         "Control Panel\\Mingw32\\NLS", "MODir");                         "Control Panel\\Mingw32\\NLS", "MODir");
458      if (p)      if (p)
459          return p;          return p;
460        
461      lang = get_gettext_langid ();      lang = get_gettext_langid ();
462      if (!lang)      if (!lang)    
463          return NULL;          return NULL;    
464      pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8];      pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8];
465      if (!pp)      if (!pp)    
466          BUG (NULL);          BUG (NULL);
467      sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang);      sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang);
468      p = get_reg_entry_gpg4win (pp);      p = get_reg_entry_gpg4win (pp);
# Line 534  set_reg_winpt_prefs (winpt_reg_prefs_s * Line 580  set_reg_winpt_prefs (winpt_reg_prefs_s *
580          if (rc)          if (rc)
581              goto leave;              goto leave;
582      }      }
     if (opt->kserv_conf) {  
         rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig",  
                             opt->kserv_conf);  
         if (rc)  
             goto leave;  
     }  
583    
584      for (i=0; reg_hotkeys[i].reg_entry; i++) {      for (i=0; reg_hotkeys[i].reg_entry; i++) {
585          strcpy (buf, " ");          strcpy (buf, " ");
# Line 587  get_reg_winpt_flag (const char * name) Line 627  get_reg_winpt_flag (const char * name)
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      size_t i;      size_t i;
632    
633      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
# Line 650  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.76  
changed lines
  Added in v.172

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26