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

Diff of /trunk/Src/wptFileManager.cpp

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

revision 129 by twoaday, Fri Dec 30 13:56:10 2005 UTC revision 197 by twoaday, Mon Apr 10 07:38:06 2006 UTC
# Line 1  Line 1 
1  /* wptFileManager.cpp - File Manager routines  /* wptFileManager.cpp - File Manager routines
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-2006 Timo Schulz
3   *      Copyright (C) 2005 g10 Code GmbH   *      Copyright (C) 2005 g10 Code GmbH
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
# Line 18  Line 18 
18   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
19   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20   */   */
 /* TODO:  
  *    check_armor_type: we should check the whole file and not only the first line!  
  */  
21    
22  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
23  #include <config.h>  #include <config.h>
# Line 53  Line 50 
50  #include "wptKeyManager.h"  #include "wptKeyManager.h"
51  #include "openpgp.h"  #include "openpgp.h"
52    
 #define op_begin()  SetCursor (LoadCursor (NULL, IDC_WAIT))  
 #define op_end()    SetCursor (LoadCursor (NULL, IDC_ARROW))  
53    
54  void progress_cleanup (progress_filter_s *pfx);  void progress_cleanup (progress_filter_s *pfx);
55  BOOL CALLBACK file_secdel_confirm_dlg_proc (HWND dlg, UINT msg,  BOOL CALLBACK file_secdel_confirm_dlg_proc (HWND dlg, UINT msg,
# Line 63  char* gpg_keylist_to_pattern (gpgme_key_ Line 58  char* gpg_keylist_to_pattern (gpgme_key_
58  gpgme_error_t sym_passphrase_cb (void *hook, const char *hint, const char *pass_inf,  gpgme_error_t sym_passphrase_cb (void *hook, const char *hint, const char *pass_inf,
59                                   int prev_was_bad, int fd);                                   int prev_was_bad, int fd);
60    
 /*-- wptFileVerifyDlg.cpp --*/  
 void file_verify_add_state (file_sig_ctx_t c);  
 void file_verify_use_event (void);  
 void file_verify_wait (void);  
61    
62  static const char * mm_files[] = {".mov", ".avi", ".mpg", ".mpeg",  /* Symbolic column IDs. */
63    enum {
64        FM_COL_STAT = 0,
65        FM_COL_NAME = 1,
66        FM_COL_OP   = 2
67    };
68    
69    static const char *mm_files[] = {".mov", ".avi", ".mpg", ".mpeg",
70                                    ".mp3", ".wav", ".mid", ".wma",                                    ".mp3", ".wav", ".mid", ".wma",
71                                    ".gif", ".jpg", ".png", ".jpeg", ".dib", 0};                                    ".gif", ".jpg", ".png", ".jpeg", ".dib", 0};
72    
# Line 114  overwrite_file (const char *fname) Line 112  overwrite_file (const char *fname)
112    
113  /* Removes 'critical' attributes from the file @fname.  /* Removes 'critical' attributes from the file @fname.
114     If @force is 1, the user is not asked for permission. */     If @force is 1, the user is not asked for permission. */
115  static void  void
116  remove_crit_file_attrs (const char *fname, int force)  remove_crit_file_attrs (const char *fname, int force)
117  {  {
118      u32 fattr;      DWORD fattr;
119      int id = 0;      int id = 0;
120    
121      if (file_exist_check (fname))      if (file_exist_check (fname))
# Line 227  fm_quote_file (const char * name) Line 225  fm_quote_file (const char * name)
225    
226  /* Check the armor type of the file @fname and return  /* Check the armor type of the file @fname and return
227     a string representation of it. */     a string representation of it. */
228  static const char *  static const char*
229  fm_check_armor_type (const char *fname, int *r_type)  fm_check_armor_type (const char *fname, int *r_type)
230  {  {
231      FILE * fp;      FILE *fp;
232      char header[768], * p;      char header[768], *p;
233            
234      if (r_type)      if (r_type)
235          *r_type = PGP_NONE;          *r_type = PGP_NONE;
# Line 383  fm_build (listview_ctrl_t *lv, HWND ctrl Line 381  fm_build (listview_ctrl_t *lv, HWND ctrl
381          {0,  80, (char *)_("Status") },          {0,  80, (char *)_("Status") },
382          {1, 256, (char *)_("Name") },          {1, 256, (char *)_("Name") },
383          {2, 128, (char *)_("Operation") },          {2, 128, (char *)_("Operation") },
384          {0,   0, NULL }          {0,   0, NULL}  
385      };      };
386                    
387      rc = listview_new (&c);      rc = listview_new (&c);
# Line 413  int Line 411  int
411  fm_state_new (fm_state_t * ctx)  fm_state_new (fm_state_t * ctx)
412  {  {
413      gpgme_error_t rc;      gpgme_error_t rc;
414      fm_state_s * c;      fm_state_s *c;
415    
416      c = new fm_state_s;      c = new fm_state_s;
417      if (!c)      if (!c)
# Line 422  fm_state_new (fm_state_t * ctx) Line 420  fm_state_new (fm_state_t * ctx)
420      rc = gpgme_new (&c->ctx);      rc = gpgme_new (&c->ctx);
421      if (rc)      if (rc)
422          BUG (0);          BUG (0);
     /* XXX rc = gpgme_recipients_new (&c->recp);*/  
     /* XXX gpgme_set_comment (c->ctx, "Generated by WinPT "PGM_VERSION); */  
423      *ctx = c;      *ctx = c;
424      return 0;      return 0;
425  } /* fm_state_new */  }
426    
427    
428  /* Release the FM state handle @c. */  /* Release the FM state handle @c. */
# Line 442  fm_state_release (fm_state_t c) Line 438  fm_state_release (fm_state_t c)
438      safe_free (c->recp);      safe_free (c->recp);
439      free_if_alloc (c->opaque);      free_if_alloc (c->opaque);
440      free_if_alloc (c->output);      free_if_alloc (c->output);
441      delete c; c = NULL;          delete c;
442  }  }
443    
444    
445  static int  static int
446  fm_check_for_entry( listview_ctrl_t lv, const char *file )  fm_check_for_entry( listview_ctrl_t lv, const char *file )
447  {  {
# Line 459  fm_check_for_entry( listview_ctrl_t lv, Line 456  fm_check_for_entry( listview_ctrl_t lv,
456      }      }
457    
458      return 0;      return 0;
459  } /* fm_check_for_entry */  }
460    
461    
462  static int  static int
# Line 483  fm_set_ftype (listview_ctrl_t lv, const Line 480  fm_set_ftype (listview_ctrl_t lv, const
480  }  }
481    
482    
483    /* Add all files from the directory @path to the list view @lv. */
484  static int  static int
485  fm_add_dir_files (listview_ctrl_t lv, char *path)  fm_add_dir_files (listview_ctrl_t lv, char *path)
486  {  {
# Line 529  fm_add_dropped_files (listview_ctrl_t lv Line 527  fm_add_dropped_files (listview_ctrl_t lv
527          if (rc == -1)          if (rc == -1)
528              break; /* XXX: fixme? */              break; /* XXX: fixme? */
529      }      }
530        DragFinish (dd_files);
531      return rc;      return rc;
532  }  }
533    
# Line 546  add_single_file (listview_ctrl_t lv, con Line 545  add_single_file (listview_ctrl_t lv, con
545      if (!type)      if (!type)
546          return WPTERR_FILE_OPEN;          return WPTERR_FILE_OPEN;
547      if (!strcmp (type, "UNKNOWN"))            if (!strcmp (type, "UNKNOWN"))      
548          type = gnupg_check_file_ext (name, NULL);                    type = gnupg_check_file_ext (name, NULL);
549      rc = listview_add_item (lv, "");              rc = listview_add_item (lv, "");
550      if (!rc) {        if (!rc) {
551          listview_add_sub_item (lv, 0, 0, type);          listview_add_sub_item (lv, 0, 0, type);
552          listview_add_sub_item (lv, 0, 1, name);          listview_add_sub_item (lv, 0, 1, name);
553      }      }
# Line 572  fm_add_opened_files (listview_ctrl_t lv, Line 571  fm_add_opened_files (listview_ctrl_t lv,
571      open.lStructSize = sizeof (OPENFILENAME);      open.lStructSize = sizeof (OPENFILENAME);
572      open.hInstance = glob_hinst;      open.hInstance = glob_hinst;
573      open.lpstrTitle = _("File Open");      open.lpstrTitle = _("File Open");
574      open.lpstrFilter = _("All Files (*.*)\0*.*\0\0");      open.lpstrFilter = "All Files (*.*)\0*.*\0\0";
575      open.hwndOwner = dlg;      open.hwndOwner = dlg;
576      open.lpstrFile = file;      open.lpstrFile = file;
577      open.nMaxFile = sizeof (file) - 1;      open.nMaxFile = sizeof (file) - 1;
# Line 600  fm_add_opened_files (listview_ctrl_t lv, Line 599  fm_add_opened_files (listview_ctrl_t lv,
599          else {          else {
600              char *p = make_filename (path, name, NULL);              char *p = make_filename (path, name, NULL);
601              rc = add_single_file (lv, p);              rc = add_single_file (lv, p);
602              free (p);              safe_free (p);
603          }          }
604          n++;          n++;
605      }      }
606      if (n == 1) /* single file selected. */      if (n == 1) /* single file selected. */
607          rc = add_single_file (lv, path);          rc = add_single_file (lv, path);
608      if (path)      safe_free (path);
         free (path);  
609      return rc;      return rc;
610  }  }
611    
612    
613  int  int
614  fm_assume_onepass_sig (const char * fname)  fm_assume_onepass_sig (const char * fname)
615  {  {    
     gpgme_data_t dat;  
616      armor_filter_context_t afx;      armor_filter_context_t afx;
617      gpg_iobuf_t fp;      gpg_iobuf_t fp;
618      PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt);      gpgme_data_t dat;
619        PACKET *pkt;
620        char tmpfile[MAX_PATH+1];
621      int check = 0;      int check = 0;
622    
623        pkt = (PACKET *)calloc (1, sizeof *pkt);
624      if (!fname) {      if (!fname) {
625            get_temp_name (tmpfile, sizeof (tmpfile)-1, "gpgme.tmp");
626          gpg_data_new_from_clipboard (&dat, 0);          gpg_data_new_from_clipboard (&dat, 0);
627          gpg_data_release_and_set_file (dat, "gpgme.tmp");          gpg_data_release_and_set_file (dat, tmpfile);
628    
629          fp = gpg_iobuf_open ("gpgme.tmp");          fp = gpg_iobuf_open (tmpfile);
630          if (!fp)          if (!fp)
631              return 0;              return 0;
632          gpg_iobuf_ioctl (fp, 3, 1, NULL);          gpg_iobuf_ioctl (fp, 3, 1, NULL);
# Line 638  fm_assume_onepass_sig (const char * fnam Line 639  fm_assume_onepass_sig (const char * fnam
639              && pkt->pkttype == PKT_COMPRESSED)              && pkt->pkttype == PKT_COMPRESSED)
640              check = 1;                check = 1;  
641          gpg_free_packet (pkt);          gpg_free_packet (pkt);
         safe_free (pkt);  
642          gpg_iobuf_close (fp);          gpg_iobuf_close (fp);
643          remove ("gpgme.tmp");          remove (tmpfile);
644      }      }
645      /* XXX: implement it for real files */      /* XXX: implement it for real files */
646        safe_free (pkt);
647      return check;      return check;
648  }  }
649    
# Line 655  fm_get_current_pos (listview_ctrl_t lv) Line 656  fm_get_current_pos (listview_ctrl_t lv)
656      items = listview_count_items (lv, 0);      items = listview_count_items (lv, 0);
657      if (!items)      if (!items)
658          return -1;          return -1;
659      else if (items == 1)      else if (items == 1) {
     {  
660          listview_select_one (lv, 0);          listview_select_one (lv, 0);
661          return 0;          return 0;
662      }      }
663      else if (items > 1)      else if (items > 1) {
     {  
664          i = listview_get_curr_pos (lv);          i = listview_get_curr_pos (lv);
665          if (i == -1)          if (i == -1) {
666          {              msg_box (lv->ctrl, _("Please select a file."),
667              msg_box (lv->ctrl, _("Please select a file."), _("File Manager"), MB_ERR);                       _("File Manager"), MB_ERR);
668              return -1;              return -1;
669          }          }
670          return i;          return i;
671      }      }
672    
673      return -1;      return -1;
674  } /* fm_get_current_pos */  }
675    
676    
677  static int  static int
678  fm_check_detached_sig( listview_ctrl_t lv, int pos )  fm_check_detached_sig (listview_ctrl_t lv, int pos)
679  {  {
680      char type[128];      char type[128];
681    
682      listview_get_item_text( lv, pos, 0, type, 127 );      listview_get_item_text (lv, pos, 0, type, sizeof (type)-1);
683      return !strcmp( type, "SIGNED-DETACH" )? 1 : 0;      return !strcmp (type, "SIGNED-DETACH")? 1 : 0;
684  } /* fm_check_detached_sig */  }
685    
686    
687  int  int
# Line 739  fm_check_file_type (listview_ctrl_t lv, Line 738  fm_check_file_type (listview_ctrl_t lv,
738      }      }
739            
740      return rc;      return rc;
741  } /* fm_check_file_type */  }
742    
743    
744  /* Set the file status of the given command @fm_cmd.  /* Set the file status of the given command @fm_cmd.
# Line 810  fm_clearsign_8bit (listview_ctrl_t lv, f Line 809  fm_clearsign_8bit (listview_ctrl_t lv, f
809      if (!cnt)      if (!cnt)
810          return 0;          return 0;
811      n = -1;      n = -1;
812      i = log_box (_("File Manager"), MB_WARN|MB_YESNO,      i = log_box (_("File Manager"), MB_WARN|MB_YESNO,
813                   _("\"%s\" does not seems to be a text file.\n"                   _("\"%s\" does not seems to be a text file.\n"
814                     "Do you really want to clearsign it?"), name);                     "Do you really want to clearsign it?"), name);
815      if (i == IDYES)      if (i == IDYES)
# Line 818  fm_clearsign_8bit (listview_ctrl_t lv, f Line 817  fm_clearsign_8bit (listview_ctrl_t lv, f
817      return n;      return n;
818  }  }
819    
820    
821  int  int
822  fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd)  fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd)
823  {  {
# Line 920  fm_parse_files (listview_ctrl_t lv, HWND Line 920  fm_parse_files (listview_ctrl_t lv, HWND
920          fm_encrypt_into_zip (ctx, lv);          fm_encrypt_into_zip (ctx, lv);
921    
922      for (i = 0; i < listview_count_items (lv, 0); i++) {      for (i = 0; i < listview_count_items (lv, 0); i++) {
923          if( !listview_get_item_state( lv, i ) )          if (!listview_get_item_state (lv, i))
924              continue;              continue;
925          listview_get_item_text(lv, i, 1, fname, sizeof (fname) - 1);          listview_get_item_text (lv, i, 1, fname, sizeof (fname) - 1);
926          if( file_exist_check (fname) && !is_directory (fname)) {          if( file_exist_check (fname) && !is_directory (fname)) {
927              log_box (_("File Manager"), MB_ERR,              log_box (_("File Manager"), MB_ERR,
928                       _("\"%s\" does not exist"), fname);                       _("\"%s\" does not exist"), fname);
# Line 941  fm_parse_files (listview_ctrl_t lv, HWND Line 941  fm_parse_files (listview_ctrl_t lv, HWND
941          case FM_SIGNENCRYPT: rc = fm_encrypt( ctx, fname, 1 ); break;          case FM_SIGNENCRYPT: rc = fm_encrypt( ctx, fname, 1 ); break;
942          case FM_DECRYPT:     rc = fm_decrypt( ctx, fname );    break;          case FM_DECRYPT:     rc = fm_decrypt( ctx, fname );    break;
943          case FM_SIGN:        rc = fm_sign( ctx, fname );       break;          case FM_SIGN:        rc = fm_sign( ctx, fname );       break;
944          case FM_SYMENC:      rc = fm_sym_encrypt( ctx, fname );break;          case FM_SYMENC:      rc = fm_sym_encrypt (ctx, fname); break;
945          case FM_VERIFY:      rc = fm_verify (ctx, sig_detached, fname);break;          case FM_VERIFY:      rc = fm_verify (ctx, sig_detached, fname);break;
946          case FM_IMPORT:          case FM_IMPORT:
947              free_if_alloc (ctx->opaque);              free_if_alloc (ctx->opaque);
948              ctx->opaque = m_strdup (fname);              ctx->opaque = m_strdup (fname);
949              if (!ctx->opaque)              DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg,
950                  BUG (0);                              file_import_dlg_proc, (LPARAM)ctx);
             DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg,  
                            file_import_dlg_proc, (LPARAM)ctx );  
951              if (ctx->cancel == 1)              if (ctx->cancel == 1)
952                  continue;                  continue;
953              rc = fm_import (ctx, fname);              rc = fm_import (ctx, fname);
954              break;              break;
955          }          }
956            if (ctx->cancel == 1) {
957                ctx->cancel = 0;
958                continue;
959            }
960          fm_set_status (lv, i, fm_cmd, ctx->sigmode, !rc, ctx->output);          fm_set_status (lv, i, fm_cmd, ctx->sigmode, !rc, ctx->output);
961          free_if_alloc (ctx->output);          free_if_alloc (ctx->output);
962          progress_cleanup (&pfx);          progress_cleanup (&pfx);
# Line 1025  ask_filename (fm_state_t c, const char * Line 1027  ask_filename (fm_state_t c, const char *
1027          free_if_alloc (*dst);          free_if_alloc (*dst);
1028      free_if_alloc (c->output);      free_if_alloc (c->output);
1029      c->output = m_strdup (s);      c->output = m_strdup (s);
     if (!c->output)  
         BUG (0);  
1030      if (dst)      if (dst)
1031          *dst = fm_quote_file (s);          *dst = fm_quote_file (s);
1032      return 0;      return 0;
# Line 1094  fm_encrypt (fm_state_t c, const char *na Line 1094  fm_encrypt (fm_state_t c, const char *na
1094              gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0);              gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0);
1095              if (sigkey && sigkey->subkeys) {              if (sigkey && sigkey->subkeys) {
1096                  keyid = m_strdup (sigkey->subkeys->keyid);                  keyid = m_strdup (sigkey->subkeys->keyid);
                 if (!keyid)  
                     BUG (NULL);  
1097              }              }
1098          }          }
1099          if (!c->init_cb || !c->cache_cb) {          if (!c->init_cb || !c->cache_cb) {
# Line 1155  fm_sym_encrypt (fm_state_t c, const char Line 1153  fm_sym_encrypt (fm_state_t c, const char
1153      char ext[5], * pass;          char ext[5], * pass;    
1154            
1155      pass = request_passphrase2 (_("Symmetric"), 0, &cancel);      pass = request_passphrase2 (_("Symmetric"), 0, &cancel);
1156      if (cancel)      if (cancel) {
1157            c->cancel = 1;
1158          return 0;          return 0;
1159        }
1160            
1161      /* XXX gpgme_control (ctx, GPGME_CTRL_CIPHER, -1);*/      /* XXX gpgme_control (ctx, GPGME_CTRL_CIPHER, -1);*/
1162      c->output = new char[strlen (name) + 5 + 1];      c->output = new char[strlen (name) + 5 + 1];
# Line 1211  show_verify_result (gpgme_verify_result_ Line 1211  show_verify_result (gpgme_verify_result_
1211      gpgme_key_t key=NULL;      gpgme_key_t key=NULL;
1212      gpgme_signature_t sig=sigres->signatures;      gpgme_signature_t sig=sigres->signatures;
1213      const char *s, *keyid;      const char *s, *keyid;
1214      int sigok = 0;      char *uid;
     int type;  
1215      char buf[384];      char buf[384];
1216        int sigok = 0;
1217    
1218      sig = sigres->signatures;      sig = sigres->signatures;
1219      sigok = sig->summary & GPGME_SIGSUM_GREEN;      sigok = sig->summary & GPGME_SIGSUM_GREEN;
1220      s = sigok? _("Good signature") : _("BAD signature");      s = sigok? _("Good signature") : _("BAD signature");
     type = sigok? MB_OK: MB_ICONWARNING|MB_OK;  
1221      keyid = sig->fpr;      keyid = sig->fpr;
1222      if (!keyid)      if (!keyid)
1223          return;          return;
1224    
1225      keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24;      keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24;
1226      get_pubkey (sig->fpr, &key);      get_pubkey (sig->fpr, &key);
1227    
1228        if (key)
1229            uid = utf8_to_native (key->uids->uid);
1230        else
1231            uid = strdup (_("user ID not found"));
1232    
1233      _snprintf (buf, sizeof (buf)-1, _("Signature made %s using %s key ID %s\n"      _snprintf (buf, sizeof (buf)-1, _("Signature made %s using %s key ID %s\n"
1234                                      "%s from \"%s\""),                                      "%s from \"%s\""),
1235                  strtimestamp (sig->timestamp),                  strtimestamp (sig->timestamp),
1236                  get_key_pubalgo (sig->pubkey_algo),                  get_key_pubalgo (sig->pubkey_algo),
1237                  keyid, s, key? key->uids->uid : _("user ID not found"));                  keyid, s, uid);
1238      msg_box (NULL, buf, _("Decrypt Verify"), type);      msg_box (NULL, buf, _("Decrypt Verify"), sigok? MB_OK: MB_ICONWARNING|MB_OK);
1239        safe_free (uid);
1240  }  }
1241    
1242    
# Line 1254  secret_key_available (gpgme_recipient_t Line 1260  secret_key_available (gpgme_recipient_t
1260  }  }
1261    
1262    
1263    /* If the decrypt result contains the original file name,
1264       we use it instead of the artificial "output - .gpg" string. */
1265    static int
1266    restore_original_name (const char *output, const char *file_name)
1267    {
1268        char *dir;
1269        char *orig;
1270        int rc = 0;
1271    
1272        dir = strrchr (output, '\\');
1273        if (!dir)
1274            orig = strdup (file_name);
1275        else {
1276            orig = (char*)calloc (1, strlen (file_name)+ 1 +
1277                                     strlen (output)+1);
1278            if (!orig)
1279                BUG (0);
1280            memcpy (orig, output, (dir-output)+1);
1281            strcat (orig, file_name);
1282        }
1283        if (overwrite_file (orig)) {
1284            DeleteFile (orig);
1285            if (!MoveFile (output, orig))
1286                rc = -1;
1287        }
1288        safe_free (orig);
1289        return rc;
1290    }
1291    
1292    
1293  /* Decrypt the file @name. */  /* Decrypt the file @name. */
1294  int  int
1295  fm_decrypt (fm_state_t c, const char *name)  fm_decrypt (fm_state_t c, const char *name)
# Line 1262  fm_decrypt (fm_state_t c, const char *na Line 1298  fm_decrypt (fm_state_t c, const char *na
1298      gpgme_ctx_t ctx = c->ctx;          gpgme_ctx_t ctx = c->ctx;    
1299      gpgme_decrypt_result_t res;      gpgme_decrypt_result_t res;
1300      gpgme_verify_result_t sigres;      gpgme_verify_result_t sigres;
1301      file_data_t in =NULL, out=NULL;      file_data_t in = NULL, out = NULL;
1302      int rc = 0;      int rc = 0;
1303            
1304      if (!c->init_cb || !c->cache_cb) {      if (!c->init_cb || !c->cache_cb) {
# Line 1272  fm_decrypt (fm_state_t c, const char *na Line 1308  fm_decrypt (fm_state_t c, const char *na
1308      }      }
1309            
1310      c->output = m_strdup (name);      c->output = m_strdup (name);
     if (!c->output)  
         BUG (0);  
1311      if (is_openpgp_ext (c->output))      if (is_openpgp_ext (c->output))
1312          c->output[strlen (c->output)-4] = '\0';          c->output[strlen (c->output)-4] = '\0';
1313      else {      else {
# Line 1283  fm_decrypt (fm_state_t c, const char *na Line 1317  fm_decrypt (fm_state_t c, const char *na
1317          if (s) {          if (s) {
1318              free_if_alloc (c->output);              free_if_alloc (c->output);
1319              c->output = m_strdup (s);              c->output = m_strdup (s);
             if (!c->output)  
                 BUG (NULL);  
1320          }          }
1321      }      }
1322    
# Line 1318  fm_decrypt (fm_state_t c, const char *na Line 1350  fm_decrypt (fm_state_t c, const char *na
1350          char *p = get_key_userid (keyid+8);          char *p = get_key_userid (keyid+8);
1351          gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo;          gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo;
1352                    
1353          log_box( _("Decryption"), MB_ERR,          log_box (_("Decryption"), MB_ERR,
1354                   _("Encrypted with %s key, ID %s.%s\n"                   _("Encrypted with %s key, ID %s.%s\n"
1355                     "Decryption failed: secret key not available."),                     "Decryption failed: secret key not available."),
1356                     get_key_pubalgo (pkalgo), keyid+8, p);                     get_key_pubalgo (pkalgo), keyid+8, p);
# Line 1335  fm_decrypt (fm_state_t c, const char *na Line 1367  fm_decrypt (fm_state_t c, const char *na
1367          log_box ("Decrypt", MB_ERR,          log_box ("Decrypt", MB_ERR,
1368                   _("Decryption failed.\n%s: does not exist."), c->output);                   _("Decryption failed.\n%s: does not exist."), c->output);
1369          rc = WPTERR_GENERAL;          rc = WPTERR_GENERAL;
1370            goto leave;
1371        }
1372        else if (res && res->file_name) {
1373            char *file = strrchr (c->output, '\\');
1374            int id = log_box (_("Decrypt"), MB_QUEST_ASK,
1375                              _("The original file name is '%s'.\n\n"
1376                                "Do you want to use this instead of '%s'?"),
1377                                res->file_name, file? file+1 : c->output);
1378            if (id == IDYES) {
1379                /* before we can move the file, it needs to be closed first. */
1380                gpg_file_data_release (out);
1381                out = NULL;
1382                restore_original_name (c->output, res->file_name);
1383            }
1384      }      }
       
1385      sigres = gpgme_op_verify_result (ctx);      sigres = gpgme_op_verify_result (ctx);
1386      if (sigres && sigres->signatures)      if (sigres && sigres->signatures)
1387          show_verify_result (sigres);          show_verify_result (sigres);    
1388            
1389  leave:  leave:
1390      if (in)      if (in)
# Line 1520  get_output_file (fm_state_t c, const cha Line 1565  get_output_file (fm_state_t c, const cha
1565      else      else
1566          title = _("Selected Output File");          title = _("Selected Output File");
1567    
1568      if (strstr (name, ".sig")      if (stristr (name, ".sig") ||
1569          || strstr (name, ".asc")          stristr (name, ".asc") ||
1570          || strstr (name, ".gpg")) {          stristr (name, ".gpg")) {
1571          _snprintf (fname, sizeof (fname) - 1, "%s", name);          _snprintf (fname, sizeof (fname) - 1, "%s", name);
1572          fname[strlen (fname) - 4] = '\0';          fname[strlen (fname) - 4] = '\0';
1573          if (file_exist_check (fname) == 0 && detached)            if (file_exist_check (fname) == 0 && detached)  
# Line 1544  get_output_file (fm_state_t c, const cha Line 1589  get_output_file (fm_state_t c, const cha
1589      if (file) {          if (file) {    
1590          free_if_alloc (c->output);              free_if_alloc (c->output);    
1591          c->output = m_strdup (file);          c->output = m_strdup (file);
         if (!c->output)  
             BUG (NULL);  
1592      }      }
1593      else {      else {
1594          msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR);          msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR);
# Line 1554  get_output_file (fm_state_t c, const cha Line 1597  get_output_file (fm_state_t c, const cha
1597      if (detached)      if (detached)
1598          c->sigmode = GPGME_SIG_MODE_DETACH;          c->sigmode = GPGME_SIG_MODE_DETACH;
1599      else {      else {
1600          if (strstr (name, ".asc"))          if (stristr (name, ".asc"))
1601              c->sigmode = GPGME_SIG_MODE_CLEAR;              c->sigmode = GPGME_SIG_MODE_CLEAR;
1602          else          else
1603              c->sigmode = GPGME_SIG_MODE_NORMAL;              c->sigmode = GPGME_SIG_MODE_NORMAL;
# Line 1576  fm_verify (fm_state_t c, int detached, c Line 1619  fm_verify (fm_state_t c, int detached, c
1619      file_data_t in=NULL, out=NULL;      file_data_t in=NULL, out=NULL;
1620      int rc = 0;      int rc = 0;
1621    
1622      if (strstr (name, ".sig"))      if (stristr (name, ".sig"))
1623          detached = 1;          detached = 1;
1624    
1625      if (get_output_file (c, name, detached))      if (get_output_file (c, name, detached))
# Line 1584  fm_verify (fm_state_t c, int detached, c Line 1627  fm_verify (fm_state_t c, int detached, c
1627    
1628      memset (&log, 0, sizeof (log));      memset (&log, 0, sizeof (log));
1629      log.file = m_strdup (name);      log.file = m_strdup (name);
     if (!log.file)  
         BUG (NULL);  
1630      file_verify_create_dlg ();      file_verify_create_dlg ();
1631    
1632      err = gpg_file_data_new (name, F_DATA_READ, &in);      err = gpg_file_data_new (name, F_DATA_READ, &in);
# Line 1639  fm_import (fm_state_t c, const char *nam Line 1680  fm_import (fm_state_t c, const char *nam
1680    
1681      free_if_alloc (c->output);      free_if_alloc (c->output);
1682      c->output = m_strdup (name);      c->output = m_strdup (name);
     if (!c->output)  
         BUG (NULL);  
1683    
1684      err = gpg_file_data_new (name, F_DATA_READ, &keydata);      err = gpg_file_data_new (name, F_DATA_READ, &keydata);
1685      if (err)      if (err)
# Line 1674  leave: Line 1713  leave:
1713  /* Export the selected keys from the File Manager to a file. */  /* Export the selected keys from the File Manager to a file. */
1714  int  int
1715  fm_export (fm_state_t c)  fm_export (fm_state_t c)
1716  {  {    
     int rc = 0;  
1717      gpgme_ctx_t ctx = c->ctx;      gpgme_ctx_t ctx = c->ctx;
1718      gpgme_error_t err;      gpgme_error_t err;
1719      gpgme_key_t *rset = c->recp;      gpgme_key_t *rset = c->recp;
1720      file_data_t keydata = NULL;      file_data_t keydata = NULL;
1721      const char *name;      const char *name;
1722      char *p = NULL, *patt = NULL;      char *p = NULL, *patt = NULL;
1723        int rc = 0;
1724    
1725      if (!rset || !rset[0]) {      if (!rset || !rset[0]) {
1726          msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR);          msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR);
# Line 1716  fm_export (fm_state_t c) Line 1755  fm_export (fm_state_t c)
1755  leave:  leave:
1756      if (keydata)      if (keydata)
1757          gpg_file_data_release (keydata);          gpg_file_data_release (keydata);
1758      if (patt)      safe_free (patt);
         free (patt);  
1759      free_if_alloc (p);      free_if_alloc (p);
1760      return rc;      return rc;
1761  }  }
# Line 1774  fm_parse_command_line (char *cmdl) Line 1812  fm_parse_command_line (char *cmdl)
1812    
1813          case PGP_SIG:          case PGP_SIG:
1814          case PGP_CLEARSIG:          case PGP_CLEARSIG:
             file_verify_use_event ();  
1815              if (type == PGP_SIG)                  if (type == PGP_SIG)    
1816                  detached = 1;                  detached = 1;
1817              fm_verify (ctx, detached, fn);              fm_verify (ctx, detached, fn);
# Line 1811  int Line 1848  int
1848  fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv)  fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv)
1849  {  {
1850      PK_FILE_LIST list=NULL;      PK_FILE_LIST list=NULL;
1851      const char *outfile;      const char *outfile, *ext;
1852      char *out_enc;      char *out_enc;
1853      int nitems = listview_count_items (lv, 0);      int nitems;
1854      int i, idx = -1;      int i, idx = -1;
1855      int rc;      int rc;
1856    
1857        nitems = listview_count_items (lv, 0);
1858      if (!nitems) {      if (!nitems) {
1859          msg_box (NULL, _("Encrypting into a ZIP archive makes sense with multiple files"),          msg_box (NULL, _("Encrypting into a ZIP archive makes sense with multiple files"),
1860                   _("File Manager"), MB_ERR);                   _("File Manager"), MB_ERR);
# Line 1846  fm_encrypt_into_zip (fm_state_t ctx, lis Line 1884  fm_encrypt_into_zip (fm_state_t ctx, lis
1884      if (rc)      if (rc)
1885          return rc;          return rc;
1886    
1887      out_enc = make_filename (NULL, outfile, "gpg");      ext = file_get_extension (ctx->ctx, ctx->sigmode)+1;
1888        out_enc = make_filename (NULL, outfile, ext);
1889      fm_set_status (lv, idx, FM_ENCRYPT, (gpgme_sig_mode_t)0, 1, out_enc);      fm_set_status (lv, idx, FM_ENCRYPT, (gpgme_sig_mode_t)0, 1, out_enc);
1890      free_if_alloc (out_enc);      free_if_alloc (out_enc);
1891    
# Line 1921  fm_cmp_cb (LPARAM first, LPARAM second, Line 1960  fm_cmp_cb (LPARAM first, LPARAM second,
1960      const char *a = 0;      const char *a = 0;
1961      const char *b = 0;      const char *b = 0;
1962    
1963      switch( (int)sortby ) {      switch ((int)sortby) {
1964      case FM_SORT_STAT:      case FM_SORT_STAT:
1965          break;          break;
1966      case FM_SORT_NAME:      case FM_SORT_NAME:
# Line 1937  fm_cmp_cb (LPARAM first, LPARAM second, Line 1976  fm_cmp_cb (LPARAM first, LPARAM second,
1976  int  int
1977  fm_sort (listview_ctrl_t lv, int sortby)  fm_sort (listview_ctrl_t lv, int sortby)
1978  {  {
1979      return listview_sort_items( lv, sortby, fm_cmp_cb );      return listview_sort_items (lv, sortby, fm_cmp_cb);
1980  }  }
1981    
1982    

Legend:
Removed from v.129  
changed lines
  Added in v.197

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26