/[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 2 by twoaday, Mon Jan 31 11:02:21 2005 UTC revision 22 by twoaday, Wed Aug 10 11:33:35 2005 UTC
# Line 17  Line 17 
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
   
20  #include <windows.h>  #include <windows.h>
21    
22  #include "../resource.h"  #include "../resource.h"
# Line 41  HWND activ_hwnd; Line 40  HWND activ_hwnd;
40  LOCK mo_file;  LOCK mo_file;
41  int scard_support = 0;  int scard_support = 0;
42  int debug = 0;  int debug = 0;
43    int mobile = 0;
44  int gpg_read_only = 0;  int gpg_read_only = 0;
45  char gpgver[3];  char gpgver[3];
46    
47    /* Internal IPC */
48    int start_keymanager = 0;
49    
50  static void  static void
51  update_keycache (HWND hwnd)  update_keycache (HWND hwnd)
# Line 127  get_prog_part (const char * fname, int u Line 129  get_prog_part (const char * fname, int u
129              return NULL;              return NULL;
130          strncpy (currdir, cmd, 255);          strncpy (currdir, cmd, 255);
131          j = strlen (currdir);          j = strlen (currdir);
132          while (j--)          while (j--) {
         {        
133              if (currdir[j] == '\\')              if (currdir[j] == '\\')
134                  break;                            break;          
135          }          }
# Line 142  get_prog_part (const char * fname, int u Line 143  get_prog_part (const char * fname, int u
143  static int  static int
144  check_crypto_engine (void)  check_crypto_engine (void)
145  {  {
146      int ma=1, mi=2, pa=4; /* GPG 1.2.4 */      int ma=1, mi=4, pa=0; /* GPG 1.4.0 */
147      int rc;      int rc;
148    
149      rc = check_gnupg_engine (&ma, &mi, &pa);      rc = check_gnupg_engine (&ma, &mi, &pa);
# Line 153  check_crypto_engine (void) Line 154  check_crypto_engine (void)
154      else if (rc) {      else if (rc) {
155          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
156                   _("Sorry, you need a newer GPG version.\n"                   _("Sorry, you need a newer GPG version.\n"
157                     "GPG version %d.%d.%d requred GPG version 1.2.4"),                     "GPG version %d.%d.%d required GPG version 1.4.0"),
158                     ma, mi, pa);                     ma, mi, pa);
159          return rc;          return rc;
160      }      }
161      /* We enable smartcard support for GPG: 1.9.x and >= 1.3.90 */      /* We enable smartcard support for GPG: 1.9.x or >= 1.4.0 */
162      if (ma > 1 || mi >= 9 || mi > 3)      if (ma >= 1 && mi >= 4)
163          scard_support = 1;          scard_support = 1;
164    
165      gpgver[0] = ma;      gpgver[0] = ma;
# Line 187  load_keyserver_conf (int quiet) Line 188  load_keyserver_conf (int quiet)
188  }  }
189    
190    
191    static void
192    enable_mobile_mode (void)
193    {
194        memset (&reg_prefs, 0, sizeof (reg_prefs));
195        reg_prefs.always_trust = 0;
196        reg_prefs.auto_backup = 0;
197        reg_prefs.cache_time = 0;
198        reg_prefs.expert = 0;
199        reg_prefs.keylist_mode = 1;
200        reg_prefs.kserv_conf = m_strdup ("keyserver.conf");
201        reg_prefs.no_zip_mmedia = 1;
202        reg_prefs.use_tmpfiles = 1;
203        reg_prefs.word_wrap = 80;
204        reg_prefs.use_viewer = 0; /* XXX */
205    }
206    
207    char* get_subkey_fingerprint (gpgme_ctx_t ctx, const char *keyid);
208    
209  int WINAPI  int WINAPI
210    #ifndef WINPT_IPC
211  WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)  WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)
212    #else
213    win_main (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)
214    #endif
215  {  {
216      WNDCLASS wc = {0, winpt_main_proc, 0, 0, hinst, 0, 0, 0, 0, PGM_NAME};      WNDCLASS wc = {0, winpt_main_proc, 0, 0, hinst, 0, 0, 0, 0, PGM_NAME};
217      HACCEL accel_tab;      HACCEL accel_tab;
# Line 196  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 219  WinMain (HINSTANCE hinst, HINSTANCE hpre
219      int first_start = 0, start_gpgprefs = 0;      int first_start = 0, start_gpgprefs = 0;
220      const char * s;      const char * s;
221      MSG msg;      MSG msg;
222      HWND hwnd;      HWND hwnd = NULL;
223    
224      glob_hinst = hinst;      glob_hinst = hinst;
225            
# Line 207  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 230  WinMain (HINSTANCE hinst, HINSTANCE hpre
230      gpgme_set_pgm_string ("WinPT "PGM_VERSION);      gpgme_set_pgm_string ("WinPT "PGM_VERSION);
231    
232      s = PTD_get_version ();      s = PTD_get_version ();
233      if (strcmp (s, "0.8.0"))      if (strcmp (s, "0.8.0")) {
     {  
234          log_box (_("Privacy Tray Dynamic (PTD)"), MB_ERR,          log_box (_("Privacy Tray Dynamic (PTD)"), MB_ERR,
235                   _("Please update your PTD.dll to the newest version, "                   _("Please update your PTD.dll to the newest version, "
236                     "the version (%s) you use is too old."), s);                     "the version (%s) you use is too old."), s);
237          return 0;          return 0;
238      }      }
239    
240      if (gpg_md_selftest ())      if (gpg_md_selftest ()) {
     {  
241          msg_box (NULL, _("Cryptographic selftest failed."),          msg_box (NULL, _("Cryptographic selftest failed."),
242                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
243          return 0;          return 0;
244      }      }
245    
246        if (cmdline && stristr (cmdline, "--mobile")) {
247            msg_box (NULL, "WARNING: mobile modus is not fully implemented yet!",
248                     "WinPT", MB_INFO);
249            mobile = 1;
250        }
251    
252      set_default_kserver ();      set_default_kserver ();
253      regist_inst_gnupg (1);  
254      regist_inst_winpt (1, &created);      if (!mobile) {
255      if (!created)          regist_inst_gnupg (1);
256      {          regist_inst_winpt (1, &created);
257        }
258        else {
259            enable_mobile_mode ();
260            /* XXX: ask for GPG path */
261            created = 1; /* Disable registry writing */
262        }
263    
264        if (!created) {
265          memset (&reg_prefs, 0, sizeof (reg_prefs));          memset (&reg_prefs, 0, sizeof (reg_prefs));
266          reg_prefs.use_tmpfiles = 1; /* default */          reg_prefs.use_tmpfiles = 1; /* default */
267            reg_prefs.fm.progress = 0; /* XXX: fix the bug and enable it again */
268          get_reg_winpt_prefs (&reg_prefs);          get_reg_winpt_prefs (&reg_prefs);
269          if (!reg_prefs.no_hotkeys)          if (!reg_prefs.no_hotkeys)
270              hotkeys_modify ();              hotkeys_modify ();
271      }      }
272    
273      rc = gnupg_check_homedir ();      rc = gnupg_check_homedir ();
274      if (rc)      if (rc) {
     {  
275          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
276                   _("GPG home directory is not set correctly.\n"                   _("GPG home directory is not set correctly.\n"
277                     "Please check the GPG registry settings:\n%s."),                     "Please check the GPG registry settings:\n%s."),
# Line 265  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 300  WinMain (HINSTANCE hinst, HINSTANCE hpre
300                  gnupg_check_homedir (); /* change gpgProgram if needed */                  gnupg_check_homedir (); /* change gpgProgram if needed */
301              }              }
302          }          }
303          else          else {
         {  
304              msg_box (NULL, _("GPG home directory could not be determited."),              msg_box (NULL, _("GPG home directory could not be determited."),
305                       _("WinPT Error"), MB_ERR);                       _("WinPT Error"), MB_ERR);
306              goto start;              goto start;
# Line 274  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 308  WinMain (HINSTANCE hinst, HINSTANCE hpre
308      }      }
309    
310      rc = check_gnupg_prog ();      rc = check_gnupg_prog ();
311      if (rc)      if (rc) {
     {  
312          if (msg_box (NULL, _("Could not find the GPG binary (gpg.exe).\n"          if (msg_box (NULL, _("Could not find the GPG binary (gpg.exe).\n"
313                               "Do you want to start the GPG preferences to "                               "Do you want to start the GPG preferences to "
314                               "correct  this problem?"), _("WinPT Error"),                               "correct  this problem?"), _("WinPT Error"),
# Line 333  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 366  WinMain (HINSTANCE hinst, HINSTANCE hpre
366      }      }
367    
368      load_keyserver_conf (cmdline? 1 : 0);      load_keyserver_conf (cmdline? 1 : 0);
369        if (start_keymanager) {
370            dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC,
371                                GetDesktopWindow(), keymanager_dlg_proc, NULL,
372                                _("Key Manager"), IDS_WINPT_KEYMISC);
373            keycache_release ();
374            free_gnupg_table ();
375            return 0;
376        }
377    
378      if (cmdline && (stristr (cmdline, "--keymanager")      if (cmdline && (stristr (cmdline, "--keymanager")
379                  || stristr (cmdline, "--cardmanager"))) {                  || stristr (cmdline, "--cardmanager"))) {
380          update_keycache (GetDesktopWindow ());          update_keycache (GetDesktopWindow ());
381          if (stristr (cmdline, "keymanager"))          if (stristr (cmdline, "keymanager"))
382              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC,              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC,
383                              GetDesktopWindow(), keymanager_dlg_proc, NULL,                              GetDesktopWindow(), keymanager_dlg_proc, NULL,
384                              _("Key Manager"), IDS_WINPT_KEYMISC);                              _("Key Manager"), IDS_WINPT_KEYMISC);  
385          else {          else {
386              gpgme_card_t crd = smartcard_init ();              gpgme_card_t crd = smartcard_init ();
387              if (crd)              if (crd)
# Line 360  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 402  WinMain (HINSTANCE hinst, HINSTANCE hpre
402          return 0;          return 0;
403      }      }
404    
405      /*if (file_exist_check ("loadimage.exe"))      if (cmdline) {
406          PTD_create_loadimage (NULL);*/          if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) {
407                        gpgme_set_debug_mode (1);
408      if (cmdline && stristr (cmdline, "--enable-debug")) {              winpt_debug_msg ();
409          gpgme_set_debug_mode (1);              debug = 1;
410          winpt_debug_msg ();          }
         debug = 1;  
411      }      }
412    
413      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));
# Line 403  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 444  WinMain (HINSTANCE hinst, HINSTANCE hpre
444              return 0;              return 0;
445          }          }
446      }      }
447        
448      if (start_gpgprefs)      if (start_gpgprefs) {
     {  
449          char *ring;          char *ring;
450          size_t size = 0;          size_t size = 0;
451          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,
# Line 417  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 457  WinMain (HINSTANCE hinst, HINSTANCE hpre
457      }      }
458    
459      if (first_start) {      if (first_start) {
460          struct key_wizard_s c, dummy;          struct first_start_s fs;
461            struct genkey_s c;
462            HWND h;
463  start:  start:
464          DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, hwnd,          h = GetDesktopWindow ();
465                          first_run_dlg_proc, (LPARAM)&dummy);          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h,
466          switch (dummy.interactive)                              gpgprefs_dlg_proc, NULL);
467          {          DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h,
468                            first_run_dlg_proc, (LPARAM)&fs);
469            switch (fs.choice) {
470          case SETUP_KEYGEN:          case SETUP_KEYGEN:
471              c.interactive = 1;              c.interactive = 1;
472                c.first_start = 1;
473              rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD,              rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD,
474                                   hwnd, keygen_wizard_dlg_proc, (LPARAM)&c);                                   h, keygen_wizard_dlg_proc, (LPARAM)&c);
475              if (!rc)              if (!rc)
476                  goto start;                  goto start;
             update_keycache (hwnd);  
             check_crypto_engine ();  
477              break;              break;
478    
479          case SETUP_IMPORT:          case SETUP_IMPORT:
# Line 439  start: Line 482  start:
482                  msg_box (hwnd, winpt_strerror (rc), _("WinPT Error"), MB_ERR);                  msg_box (hwnd, winpt_strerror (rc), _("WinPT Error"), MB_ERR);
483                  goto start;                  goto start;
484              }              }
             update_keycache (hwnd);  
             check_crypto_engine ();  
485              break;              break;
486    
         case SETUP_EXISTING:  
             break; /* todo */  
   
487          case -1:          case -1:
488              DestroyWindow (hwnd);              DestroyWindow (hwnd);
489              free_gnupg_table ();              free_gnupg_table ();
490              return 0;              return 0;
491          }          }
492            update_keycache (hwnd);
493            check_crypto_engine ();
494      }      }
495      else {      else {
496          gpgme_keycache_t c;          gpgme_keycache_t c;

Legend:
Removed from v.2  
changed lines
  Added in v.22

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26