/[winpt]/trunk/Src/WinPT.cpp
ViewVC logotype

Diff of /trunk/Src/WinPT.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 135 by twoaday, Mon Jan 9 09:50:55 2006 UTC revision 168 by twoaday, Fri Jan 27 10:08:10 2006 UTC
# Line 22  Line 22 
22  #endif  #endif
23    
24  #include <windows.h>  #include <windows.h>
25    #include <shlobj.h>
26    
27  #include "resource.h"  #include "resource.h"
28  #include "wptTypes.h"  #include "wptTypes.h"
# Line 40  Line 41 
41  #include "wptCardEdit.h"  #include "wptCardEdit.h"
42  #include "wptCrypto.h"  #include "wptCrypto.h"
43    
 #define MIN_GPG_VER   "1.4.2"            /* Minimal GPG version. */  
 #define MIN_GPGME_VER NEED_GPGME_VERSION /* Minimal GPGME version. */  
   
44    
45  HINSTANCE glob_hinst;   /* global instance for the dialogs */  HINSTANCE glob_hinst;   /* global instance for the dialogs */
46  HWND glob_hwnd;         /* global window handle for the dialogs */  HWND glob_hwnd;         /* global window handle for the dialogs */
47  HWND activ_hwnd;  HWND activ_hwnd;
 LOCK mo_file;  
48  int scard_support = 0;  int scard_support = 0;
49  int debug = 0;  int debug = 0;
50  int mobile = 0;  int mobile = 0;
# Line 96  static void Line 93  static void
93  load_gettext (int prev_inst)  load_gettext (int prev_inst)
94  {  {
95      char *nls = NULL;      char *nls = NULL;
     char *file = NULL;  
96    
97      nls = get_gettext_lang ();      nls = get_gettext_lang ();
98      if (nls) {      if (nls != NULL) {
99          set_gettext_file ("winpt", nls);          set_gettext_file ("winpt", nls);
         file = make_filename (nls, "winpt", "mo");  
         if (!file_exist_check (nls) && init_file_lock (&mo_file, file))  {  
             if (!prev_inst)  
                 msg_box (NULL, _("Could not initizalize file lock.\n"  
                                  "Native Language Support"),  
                          _("WinPT Error"), MB_ERR);  
         }  
100          free_if_alloc (nls);          free_if_alloc (nls);
         free_if_alloc (file);  
101      }      }
102  }  }
103    
104    
105    /* Return true if the GPG environment is useable. */
106    static bool
107    gpg_prefs_ok (void)
108    {
109        char *p;
110    
111        p = get_reg_entry_gpg4win ("gpg.exe");
112        if (!p || file_exist_check (p) != 0) {
113            free_if_alloc (p);
114            p = get_reg_entry_gpg ("gpgProgram");
115            if (!p || file_exist_check (p) != 0) {
116                free_if_alloc (p);
117                return false;
118            }
119        }
120        free_if_alloc (p);
121        p = get_reg_entry_gpg4win (NULL);    
122        if (!p || dir_exist_check (p) != 0) {
123            free_if_alloc (p);
124            p = get_reg_entry_gpg ("HomeDir");
125            if (!p || dir_exist_check (p) != 0) {
126                free_if_alloc (p);
127                return false;
128            }
129        }
130        free_if_alloc (p);
131        return true;
132    }
133    
134    
135    
136  /* Load the GPG environment. On the first start, some  /* Load the GPG environment. On the first start, some
137     checks are performed to find out in what state GPG is.     checks are performed to find out in what state GPG is.
138     Return value: 0  everything OK.     Return value: 0  everything OK.
# Line 134  load_gpg_env (void) Line 153  load_gpg_env (void)
153          return (1);          return (1);
154      }      }
155      free_if_alloc (p);      free_if_alloc (p);
156      p = multi_gnupg_path (0);  
157        p = get_reg_entry_gpg ("HomeDir");
158        if (!p || dir_exist_check (p) != 0) {
159            free_if_alloc (p);
160            p = multi_gnupg_path (0);
161        }
162      if (p && dir_exist_check (p)) {      if (p && dir_exist_check (p)) {
163          memset (&sec_attr, 0, sizeof (sec_attr));          memset (&sec_attr, 0, sizeof (sec_attr));
164          sec_attr.nLength = sizeof (sec_attr);          sec_attr.nLength = sizeof (sec_attr);
# Line 215  get_prog_part (const char * fname, int u Line 239  get_prog_part (const char * fname, int u
239  static bool  static bool
240  check_crypto_engine (void)  check_crypto_engine (void)
241  {  {
242      int ma=1, mi=4, pa=2; /* GPG 1.4.2 */      int ma=0, mi=0, pa=0;
243      int rc;      int rc;
244    
245      rc = check_gnupg_engine (&ma, &mi, &pa);      rc = check_gnupg_engine (NEED_GPG_VERSION, &ma, &mi, &pa);
246      if (rc == -1) {      if (rc == -1) {
247          msg_box (NULL, _("Could not read GnuPG version."),          msg_box (NULL, _("Could not read GnuPG version."),
248                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
# Line 227  check_crypto_engine (void) Line 251  check_crypto_engine (void)
251      else if (rc) {      else if (rc) {
252          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
253                   _("Sorry, you need a newer GPG version.\n"                   _("Sorry, you need a newer GPG version.\n"
254                     "GPG version %d.%d.%d required GPG version "MIN_GPG_VER),                     "GPG version %d.%d.%d required GPG version "NEED_GPG_VERSION),
255                     ma, mi, pa);                     ma, mi, pa);
256          return false;          return false;
257      }      }
# Line 247  check_crypto_engine (void) Line 271  check_crypto_engine (void)
271  static int  static int
272  load_keyserver_conf (int quiet)  load_keyserver_conf (int quiet)
273  {  {
274        char *buf;
275      const char *t;      const char *t;
276      int rc;      int rc;
277    
278      if (reg_prefs.kserv_conf)      /* Create $APPDATA\winpt if needed. */
279          t = reg_prefs.kserv_conf;      buf = make_special_filename (CSIDL_APPDATA, "winpt", NULL);
280      else if (!file_exist_check (get_prog_part ("keyserver.conf", 0)))      if (buf && dir_exist_check (buf) && !CreateDirectory (buf, NULL)) {
281            MessageBox (NULL, _("Failed to create WinPT directory"),
282                        _("Keyserver"), MB_ERR);
283            free_if_alloc (buf);
284            return -1;
285        }
286        free_if_alloc (buf);
287    
288        /* Check for $APPDATA\winpt\keyserver.conf */
289        buf = make_special_filename (CSIDL_APPDATA, "winpt\\keyserver.conf", NULL);
290    
291        if (!file_exist_check (get_prog_part ("keyserver.conf", 0)))
292          t = get_prog_part ("keyserver.conf", 0);          t = get_prog_part ("keyserver.conf", 0);
293      else      else
294          t = "keyserver.conf";          t = "keyserver.conf";
295        if (file_exist_check (t) == 0 && file_exist_check (buf) != 0) {
296            //log_box (_("Keyserver"), MB_INFO,
297            //       _("keyserver.conf will be copied to \"%s\"\r\n"), buf);
298            if (!CopyFile (t, buf, FALSE)) {
299                MessageBox (NULL, _("Failed to copy the keyserver.conf"),
300                            _("Keyserver"), MB_ERR);
301                free_if_alloc (buf);
302                return -1;
303            }
304            t = buf;
305        }
306        else
307            t = buf;
308        
309      rc = kserver_load_conf (t);      rc = kserver_load_conf (t);
310      if (rc && !quiet)      if (rc && !quiet)
311          msg_box (NULL, winpt_strerror (rc), _("Keyserver"), MB_ERR);          msg_box (NULL, winpt_strerror (rc), _("Keyserver"), MB_ERR);
312        else {
313            free_if_alloc (reg_prefs.kserv_conf);
314            reg_prefs.kserv_conf = m_strdup (t);
315        }
316        free_if_alloc (buf);
317      return rc;      return rc;
318  }  }
319    
# Line 361  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 416  WinMain (HINSTANCE hinst, HINSTANCE hpre
416          return 0;          return 0;
417      }      }
418    
419      s = gpgme_check_version (MIN_GPGME_VER);      s = gpgme_check_version (NEED_GPGME_VERSION);
420      if (!s || !*s) {      if (!s || !*s) {
421          msg_box (NULL, _("A newer GPGME version is needed; at least "MIN_GPGME_VER),          msg_box (NULL, _("A newer GPGME version is needed; at least "NEED_GPGME_VERSION),
422                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
423          return 0;          return 0;
424      }      }
# Line 400  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 455  WinMain (HINSTANCE hinst, HINSTANCE hpre
455              hotkeys_modify ();              hotkeys_modify ();
456          gnupg_load_config ();          gnupg_load_config ();
457      }      }
458        else { /* default settings. */
459            reg_prefs.keylist_mode = 1;
460        }
461    
462      if (is_gpg4win_installed ())      if (is_gpg4win_installed ())
463          load_gpg_env (); /* XXX: check return code. */          load_gpg_env (); /* XXX: check return code. */
# Line 412  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 470  WinMain (HINSTANCE hinst, HINSTANCE hpre
470                   winpt_strerror (rc));                   winpt_strerror (rc));
471          s = get_fileopen_dlg (GetActiveWindow (),          s = get_fileopen_dlg (GetActiveWindow (),
472                                _("Select GPG Public Keyring"),                                _("Select GPG Public Keyring"),
473                                _("GPG Keyrings (*.gpg)\0*.gpg\0\0"),                                "GPG Keyrings (*.gpg)\0*.gpg\0\0",
474                                NULL);                                NULL);
475          if (s != NULL) {          if (s != NULL) {
476              size_t n;              size_t n;
# Line 571  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 629  WinMain (HINSTANCE hinst, HINSTANCE hpre
629      }      }
630    
631      if (first_start) {      if (first_start) {
         struct first_start_s fs;  
632          struct genkey_s c;          struct genkey_s c;
633            int choice;
634          HWND h;          HWND h;
635  start:  start:
636          h = GetDesktopWindow ();          h = GetDesktopWindow ();
637          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h,          if (!gpg_prefs_ok ())
638                DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h,
639                              gpgprefs_dlg_proc, 0);                              gpgprefs_dlg_proc, 0);
640          DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h,          choice = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h,
641                          first_run_dlg_proc, (LPARAM)&fs);                                   first_run_dlg_proc, 0);
642          switch (fs.choice) {          switch (choice) {
643          case SETUP_KEYGEN:          case SETUP_KEYGEN:
644              c.interactive = 1;              c.interactive = 1;
645              c.first_start = 1;              c.first_start = 1;
# Line 598  start: Line 657  start:
657              }              }
658              break;              break;
659    
660          case -1: /* Cancel/Abort. */          case 0: /* Cancel/Abort. */
661            default:
662              DestroyWindow (hwnd);              DestroyWindow (hwnd);
663              free_gnupg_table ();              free_gnupg_table ();
664              return 0;              return 0;
665          }          }
666          update_keycache (hwnd);          update_keycache (hwnd);
667          check_crypto_engine ();          if (!check_crypto_engine ()) {
668                DestroyWindow (hwnd);
669                free_gnupg_table ();
670                return 0;
671            }
672      }      }
673      else {      else {
674          gpg_keycache_t c;          gpg_keycache_t c;

Legend:
Removed from v.135  
changed lines
  Added in v.168

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26