/[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 68 by twoaday, Sat Nov 5 12:00:55 2005 UTC revision 128 by twoaday, Mon Dec 19 13:05:59 2005 UTC
# Line 43  static gpg_filetype gpg_filetypes[] = { Line 43  static gpg_filetype gpg_filetypes[] = {
43      {0}      {0}
44  };  };
45    
46    
47  struct reg_hotkey_s reg_hotkeys[] = {  struct reg_hotkey_s reg_hotkeys[] = {
48      {"ClipEncrypt", NULL, 0},      {"ClipEncrypt", "", 0},
49      {"ClipDecrypt", NULL, 0},      {"ClipDecrypt", "", 0},
50      {"ClipSign",    NULL, 0},      {"ClipSign",    "", 0},
51      {"ClipSignEnc", NULL, 0},      {"ClipSignEnc", "", 0},
52      {"CwsEncrypt",  NULL, 0},      {"CwsEncrypt",  "", 0},
53      {"CwsDecrypt",  NULL, 0},      {"CwsDecrypt",  "", 0},
54      {"CwsSign",     NULL, 0},      {"CwsSign",     "", 0},
55      {"CwsSignEnc",  NULL, 0},      {"CwsSignEnc",  "", 0},
56      {NULL, NULL, 0}      {NULL, "", 0}
57  };  };
58    
59  winpt_reg_prefs_s reg_prefs;  winpt_reg_prefs_s reg_prefs;
# Line 60  winpt_reg_prefs_s reg_prefs; Line 61  winpt_reg_prefs_s reg_prefs;
61  #define WINPT_REG "Software\\WinPT"  #define WINPT_REG "Software\\WinPT"
62    
63    
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. */
83    int
84    is_gpgee_installed (void)
85    {
86        HKEY hk;
87        LONG ec;
88    
89        ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\GPGee", 0, KEY_READ, &hk);
90        if (ec == ERROR_SUCCESS) {
91            RegCloseKey (hk);
92            return -1;
93        }
94    
95        return 0;
96    }
97    
98    
99    /* Free all members in the registry preference struct. */
100  void  void
101  free_reg_prefs (void)  free_reg_prefs (void)
102  {  {
# Line 67  free_reg_prefs (void) Line 104  free_reg_prefs (void)
104      free_if_alloc (reg_prefs.kserv_conf);      free_if_alloc (reg_prefs.kserv_conf);
105      free_if_alloc (reg_prefs.homedir);      free_if_alloc (reg_prefs.homedir);
106      memset (&reg_prefs, 0, sizeof reg_prefs);      memset (&reg_prefs, 0, sizeof reg_prefs);
107  } /* free_reg_prefs */  }
108    
109    
110  /* Register the given WinPT filetype. */  /* Register the given WinPT filetype. */
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);
119      _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);      _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);
120      return create_file_type (prog, gfile->ext, gfile->descr, icon);      return create_file_type (prog, gfile->ext, gfile->descr, icon);
121  } /* regist_single_filetype */  }
122    
123    
124  /* 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 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
158     exists the function returns immediately.*/     exists the function returns immediately. @with_ext can be
159       used to register some file types (if 1). @created contains
160       1 if the registry key was created.
161       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];
168      int rc, i, id, n = 0;      int rc, i, id, n = 0;
169    
170      if( created )      if (created)
171          *created = 0;          *created = 0;
172    
173      p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");      p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");
174      if (p && *p == '1')      if ((p && *p == '1') || is_gpgee_installed ())
175          with_ext = 0;          with_ext = 0;
176      free_if_alloc( p );      free_if_alloc (p);
177    
178      if( with_ext ) {      if (with_ext) {
179          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 "
180                                "be processed with a double click in the explorer.\n"                                "be processed with a double click in the explorer.\n"
181                                "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO );                                "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO);
182          if( id == IDNO ) {          if (id == IDNO) {
183              set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );              set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
184              goto start;              goto start;
185          }          }
186          for( i = 0; gpg_filetypes[i].ext; i++ ) {          for (i = 0; gpg_filetypes[i].ext; i++) {
187              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);
188              if( rc_ok( rc ) ) {              if (rc_ok (rc)) {
189                  RegCloseKey( reg );                  RegCloseKey (reg);
190                  id = log_box( _("WinPT WARNING"), MB_YESNO|MB_INFO,                  id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,
191                                _("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"
192                                  "Do you want to overwrite it?"), gpg_filetypes[i].ext );                                  "Do you want to overwrite it?"), gpg_filetypes[i].ext);
193                  if( id == IDNO )                  if (id == IDNO)
194                      continue;                      continue;
195              }              }
196              regist_single_filetype( &gpg_filetypes[i] );              regist_single_filetype (&gpg_filetypes[i]);
197              n++;              n++;
198          }          }
199      }      }
200                    
201  start:  start:
202      rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg );      rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);
203      if( rc_ok( rc ) ) {      if (rc_ok (rc)) {
204          RegCloseKey( reg );          RegCloseKey (reg);
205          rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg );          rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);
206          if( !rc_ok( rc ) ) {          if( !rc_ok (rc)) {
207              RegCreateKey( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg );              RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);
208              RegCloseKey( reg );              RegCloseKey (reg);
209          }          }
210          p = get_reg_entry_keyserver ("Default");          p = get_reg_entry_keyserver ("Default");
211          if (!p) {          if (!p) {
# Line 172  start: Line 214  start:
214              set_reg_entry_keyserver ("Default_Port", buf);              set_reg_entry_keyserver ("Default_Port", buf);
215              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);              set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);
216          }          }
217          free_if_alloc( p );          free_if_alloc (p);
218          if( n )          if (n)
219              set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );              set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );
220          return 0;          return 0;
221      }      }
222      rc = RegCreateKey( HKEY_CURRENT_USER, WINPT_REG, &reg );      rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);
223      if( !rc_ok( rc ) )      if (!rc_ok (rc))
224          return WPTERR_REGISTRY;          return WPTERR_REGISTRY;
225      if( created )      if (created)
226          *created = 1;          *created = 1;
227      RegCloseKey( reg );      RegCloseKey (reg);
228      if( n )      if (n)
229          set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );          set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
230        if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {
231            while (n-- > 0) {
232                if (modpath[n] == '\\') {
233                    modpath[n] = 0;
234                    break;
235                }
236            }
237            set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Install Directory", modpath);
238        }
239      return 0;      return 0;
240  } /* regist_inst_winpt */  }
241    
242    
243  /* Create a new filetype in the W32 registry.  /* Create a new filetype in the W32 registry.
244     We should really care of errors! Otherwise we can damage the registry! */     We should really care of errors! Otherwise we can damage the registry! */
245  int  int
246  create_file_type( const char *exefile, const char *ext, const char *extname, char *iconfile )  create_file_type (const char *exefile, const char *ext,
247                      const char *extname, char *iconfile)
248  {  {
249      int rc;      int rc;
250      HKEY reg = NULL;      HKEY reg = NULL;
# Line 258  expand_path (const char *path) Line 310  expand_path (const char *path)
310          return NULL;          return NULL;
311      len += 1;      len += 1;
312      p = new char[len+1];      p = new char[len+1];
313      if( !p )      if (!p)
314          return NULL;          return NULL;
315      len = ExpandEnvironmentStrings (path, p, len);      len = ExpandEnvironmentStrings (path, p, len);
316      if (!len) {      if (!len) {
# Line 266  expand_path (const char *path) Line 318  expand_path (const char *path)
318          return NULL;          return NULL;
319      }      }
320      return p;      return p;
321  } /* expand_path */  }
322    
323    
324  /* Retrieve a registry entry with the directory given in @dir  /* Retrieve a registry entry with the directory given in @dir
# Line 277  get_reg_entry (HKEY root_key, const char Line 329  get_reg_entry (HKEY root_key, const char
329  {  {
330      int rc;      int rc;
331      char text[384] = {0};      char text[384] = {0};
332      DWORD nbytes, type, n1 = 0;      DWORD nbytes, type;
333      HKEY reg_key = NULL;      HKEY reg_key = NULL;
334      char * p = NULL, * tmp = NULL;      char * p = NULL;
335            
336      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);      rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);
337      if( !rc_ok( rc ) )      if( !rc_ok( rc ) )
# Line 380  get_reg_entry_gpg (const char *key) Line 432  get_reg_entry_gpg (const char *key)
432  }  }
433    
434    
435  char *  /* Return if possible the GPG4Win installation directory concatenated
436  get_reg_entry_mo(void)     with the string in @path if given. */
437    char*
438    get_reg_entry_gpg4win (const char *path)
439    {
440        char *p, *pp;
441        p = get_reg_entry (HKEY_LOCAL_MACHINE,
442                           "Software\\GNU\\GnuPG", "Install Directory");
443        if (!p)
444            return NULL;
445        if (!path)
446            return p;
447        pp = new char[strlen (p) + strlen (path) + 4];
448        if (!pp)
449            BUG (NULL);
450        sprintf (pp, "%s\\%s", p, path);
451        free_if_alloc (p);
452        return pp;
453    }
454    
455        
456    char*
457    get_reg_entry_mo (void)
458  {        {      
459      return get_reg_entry(HKEY_CURRENT_USER,      char *p, *pp;
460                           "Control Panel\\Mingw32\\NLS", "MODir");      const char *lang;
461    
462        p = get_reg_entry (HKEY_CURRENT_USER,
463                           "Control Panel\\Mingw32\\NLS", "MODir");
464        if (p)
465            return p;
466    
467        lang = get_gettext_langid ();
468        if (!lang)    
469            return NULL;    
470        pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8];
471        if (!pp)    
472            BUG (NULL);
473        sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang);
474        p = get_reg_entry_gpg4win (pp);
475        free_if_alloc (pp);
476        return p;
477  }  }
478    
479    
# Line 440  int Line 529  int
529  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)  set_reg_winpt_prefs (winpt_reg_prefs_s * opt)
530  {  {
531      char buf[128];      char buf[128];
532      int rc = 0, i;      size_t i;
533        int rc = 0;
534    
535      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
536          switch (i) {          switch (i) {
# Line 549  get_reg_winpt_flag (const char * name) Line 639  get_reg_winpt_flag (const char * name)
639  int  int
640  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)  get_reg_winpt_prefs (winpt_reg_prefs_s * opt)
641  {  {
642      char * val = NULL;      char *val = NULL;
643      int i;      size_t i;
644    
645      for (i=1; i < DIM (cfg); i++) {      for (i=1; i < DIM (cfg); i++) {
646          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]);          val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]);

Legend:
Removed from v.68  
changed lines
  Added in v.128

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26