/[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 328 by twoaday, Fri Sep 25 16:07:38 2009 UTC revision 355 by twoaday, Sat Dec 3 18:59:01 2011 UTC
# Line 46  HWND glob_hwnd;                /* global window handle Line 46  HWND glob_hwnd;                /* global window handle
46  int scard_support = 0;  int scard_support = 0;
47  int debug = 0;  int debug = 0;
48  int gpg_read_only = 0;  int gpg_read_only = 0;
 int emulate_utf8_bug = 0;  
49  char gpgver[3];  char gpgver[3];
50  /* End */  /* End */
51    
52    
53    /* Retrieve the product verion of the given file @fname.
54       Format: MAJOR.MINOR.PATCH1.PATCH2
55       Return value: 0 on success. */
56    int
57    get_file_version (const char *fname, WORD *major, WORD *minor, WORD *patch1, WORD *patch2)
58    {
59        VS_FIXEDFILEINFO *inf;
60        char file[MAX_PATH+1] = {0};
61        LPVOID buf, data;
62        DWORD size;
63        UINT qlen;
64        int err = 0;
65    
66        strncpy (file, fname, MAX_PATH);
67        size = GetFileVersionInfoSize (file, NULL);
68        if (!size)
69            return -1;
70        
71        buf = (LPVOID)new char[size];
72        if (!buf)
73            BUG (NULL);
74        if (!GetFileVersionInfo (file, 0, size, buf)) {
75            err = -1;
76            goto fail;
77        }
78    
79        qlen = 0;
80        VerQueryValue (buf, (char*)"\\", &data, &qlen);
81        if (!qlen) {
82            err = -1;
83            goto fail;
84        }
85        
86        inf = (VS_FIXEDFILEINFO*)data;
87        *major = HIWORD (inf->dwProductVersionMS);
88        *minor = LOWORD (inf->dwProductVersionMS);
89        *patch1 = HIWORD (inf->dwProductVersionLS);
90        *patch2 = LOWORD (inf->dwProductVersionLS);
91    
92    fail:
93        delete [](char*)buf;
94        return err;
95    }
96    
97    
98  /* Load the key cache and rebuild the signature cache. */  /* Load the key cache and rebuild the signature cache. */
99  int  int
100  update_keycache (HWND hwnd)  update_keycache (HWND hwnd)
# Line 324  count_insecure_elgkeys (void) Line 368  count_insecure_elgkeys (void)
368  }  }
369    
370    
371    /* Return 1 if the current OS version is at least Windows XP */
372    static int
373    check_os_version (void)
374    {
375        OSVERSIONINFOA osver;    
376        memset (&osver, 0, sizeof (osver));
377        osver.dwOSVersionInfoSize = sizeof (osver);
378        
379        if (!GetVersionEx (&osver)) {
380            MessageBox (NULL, _("Could not read the OS version."), _("WinPT Error"), MB_ERR);
381            return 0;
382        }
383    
384        if (osver.dwMajorVersion < 5 ||
385            (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 0)) {
386            MessageBox (NULL, _("WinPT requires Windows XP or higher."), _("WinPT Error"), MB_ERR);
387            return 0;
388        }
389        
390        return 1;
391    }
392        
393  /* Main entry point. */  /* Main entry point. */
394  int WINAPI  int WINAPI
395  WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)  WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)
# Line 333  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 399  WinMain (HINSTANCE hinst, HINSTANCE hpre
399      MSG msg;      MSG msg;
400      HWND hwnd = NULL;      HWND hwnd = NULL;
401      WORD ver[3], ptdver[4];      WORD ver[3], ptdver[4];
402      OSVERSIONINFOA osver;      
403      const char *s;      const char *s;
404      int rc, ec, created = 0;      int rc, ec, created = 0;
405      int first_start = 0, start_gpgprefs = 0;      int first_start = 0, start_gpgprefs = 0;
406      int winpt_inst_found = 0;      int winpt_inst_found = 0;
407      int start_manager = 0;          int start_manager = 0;    
408    
409      memset (&osver, 0, sizeof (osver));      if (!check_os_version ())
     osver.dwOSVersionInfoSize = sizeof (osver);  
     if (!GetVersionEx (&osver)) {  
         MessageBox (NULL, _("Could not read the OS version."),  
                     _("WinPT Error"), MB_ERR);  
         return 0;  
     }  
     /*  
     if (osver.dwMajorVersion < 5) {  
         MessageBox (NULL, _("WinPT requires Windows XP or higher."),  
                     _("WinPT Warning"), MB_INFO);  
410          return 0;          return 0;
411      }*/      
           
412      glob_hinst = hinst;      glob_hinst = hinst;
413        
414        /* Allow to shutdown the process, for instance by an installer */
415      if (cmdline && stristr (cmdline, "--stop")) {      if (cmdline && stristr (cmdline, "--stop")) {
416          hwnd = FindWindow ("WinPT", "WinPT");          hwnd = FindWindow ("WinPT", "WinPT");
417          if (hwnd != NULL)          if (hwnd != NULL)
# Line 363  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 420  WinMain (HINSTANCE hinst, HINSTANCE hpre
420      }          }    
421    
422      get_file_version ("winpt.exe", &ver[0], &ver[1], &ver[2], &ver[3]);      get_file_version ("winpt.exe", &ver[0], &ver[1], &ver[2], &ver[3]);
423      ec = get_file_version ("PTD.dll", &ptdver[0], &ptdver[1],        ec = get_file_version ("PTD.dll", &ptdver[0], &ptdver[1], &ptdver[2], &ptdver[3]);
424                                   &ptdver[2], &ptdver[3]);      if (!ec && (ptdver[0] != ver[0] || ptdver[1] != ver[1] || ptdver[2] != ver[2])) {
       
     if (!ec && (ptdver[0] != ver[0] ||  
                 ptdver[1] != ver[1] ||  
                 ptdver[2] != ver[2])) {  
425          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
426                   _("The PTD.dll file has a different version than WinPT.exe\n"                   _("The PTD.dll file has a different version than WinPT.exe\n"
427                     "Please update the PTD.dll to version %d.%d.%d"),                     "Please update the PTD.dll to version %d.%d.%d"),
# Line 376  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 429  WinMain (HINSTANCE hinst, HINSTANCE hpre
429          return 0;          return 0;
430      }      }
431    
     if (gpg_md_selftest ()) {  
         msg_box (GetDesktopWindow (), _("Cryptographic selftest failed."),  
                  _("WinPT Error"), MB_ERR);  
         return 0;  
     }  
   
432      s = gpgme_check_version (NEED_GPGME_VERSION);      s = gpgme_check_version (NEED_GPGME_VERSION);
433      if (!s || !*s) {      if (!s || !*s) {
434          msg_box (GetDesktopWindow (),          msg_box (GetDesktopWindow (),
435                   _("A newer GPGME version is needed; at least "NEED_GPGME_VERSION),                   _("A newer GPGME version is needed; at least "NEED_GPGME_VERSION),
436                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
437          return 0;          return 0;
# Line 528  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 575  WinMain (HINSTANCE hinst, HINSTANCE hpre
575      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));
576      rc = RegisterClass (&wc);      rc = RegisterClass (&wc);
577      if (rc == FALSE) {      if (rc == FALSE) {
578          msg_box (GetDesktopWindow (),          msg_box (GetDesktopWindow (), _("Could not register window class"),
                  _("Could not register window class"),  
579                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
580          free_gnupg_table ();          free_gnupg_table ();
581          return 0;          return 0;
# Line 543  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 589  WinMain (HINSTANCE hinst, HINSTANCE hpre
589                           hinst,                           hinst,
590                           NULL);                           NULL);
591      if (hwnd == NULL) {      if (hwnd == NULL) {
592          msg_box (GetDesktopWindow (),          msg_box (GetDesktopWindow (),
593                   _("Could not create window"),                   _("Could not create window"),
594                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
595          free_gnupg_table ();          free_gnupg_table ();
# Line 597  start: Line 643  start:
643              }              }
644              break;              break;
645    
646            case SETUP_EXISTING:
647                rc = gnupg_import_keypair ();
648                if (rc) {
649                    msg_box (hwnd, winpt_strerror (rc), _("WinPT Error"), MB_ERR);
650                    goto start;
651                }
652                break;
653    
654          case SETUP_CARDGEN:          case SETUP_CARDGEN:
655              rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN,              rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN,
656                                   h, card_keygen_dlg_proc, 0);                                   h, card_keygen_dlg_proc, 0);
# Line 662  start: Line 716  start:
716                              elgamal_warn_dlg_proc, 0);                              elgamal_warn_dlg_proc, 0);
717      }      }
718        
     if (strstr (cmdline, "--emulate-utf8-bug")) {  
         MessageBox (NULL, "Please use this mode only for resetting your passphrase to a non-utf8 form.",  
                     "WinPT Warning", MB_WARN);  
         emulate_utf8_bug = 1;  
     }  
719      if (start_manager)      if (start_manager)
720          PostMessage (hwnd, WM_COMMAND, start_manager, 0);          PostMessage (hwnd, WM_COMMAND, start_manager, 0);
721    

Legend:
Removed from v.328  
changed lines
  Added in v.355

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26