/[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 172 by twoaday, Mon Jan 30 13:47:35 2006 UTC revision 201 by twoaday, Sat Apr 22 18:30:24 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 117  overwrite_file (const char *fname) Line 115  overwrite_file (const char *fname)
115  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 547  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 601  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 639  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 656  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 740  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 811  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 819  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 921  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 942  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 1026  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 1095  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 1156  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 1205  leave: Line 1204  leave:
1204  }  }
1205    
1206    
1207    char* get_pka_status (gpgme_signature_t sig);
1208    
1209    
1210  /* Show the human readable verify result from @sigres. */  /* Show the human readable verify result from @sigres. */
1211  static void  static void
1212  show_verify_result (gpgme_verify_result_t sigres)  show_verify_result (gpgme_verify_result_t sigres)
# Line 1212  show_verify_result (gpgme_verify_result_ Line 1214  show_verify_result (gpgme_verify_result_
1214      gpgme_key_t key=NULL;      gpgme_key_t key=NULL;
1215      gpgme_signature_t sig=sigres->signatures;      gpgme_signature_t sig=sigres->signatures;
1216      const char *s, *keyid;      const char *s, *keyid;
1217      int sigok = 0;      char *uid, *pka_info;
     int type;  
1218      char buf[384];      char buf[384];
1219        int sigok = 0;
1220    
1221      sig = sigres->signatures;      sig = sigres->signatures;
1222      sigok = sig->summary & GPGME_SIGSUM_GREEN;      sigok = sig->summary & GPGME_SIGSUM_GREEN;
1223      s = sigok? _("Good signature") : _("BAD signature");      s = sigok? _("Good signature") : _("BAD signature");
     type = sigok? MB_OK: MB_ICONWARNING|MB_OK;  
1224      keyid = sig->fpr;      keyid = sig->fpr;
1225      if (!keyid)      if (!keyid)
1226          return;          return;
1227        pka_info = get_pka_status (sig);
1228      keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24;      keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24;
1229      get_pubkey (sig->fpr, &key);      get_pubkey (sig->fpr, &key);
1230    
1231        if (key)
1232            uid = utf8_to_native (key->uids->uid);
1233        else
1234            uid = strdup (_("user ID not found"));
1235    
1236      _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"
1237                                      "%s from \"%s\""),                                        "%s from \"%s\"\n%s"),
1238                  strtimestamp (sig->timestamp),                  strtimestamp (sig->timestamp),
1239                  get_key_pubalgo (sig->pubkey_algo),                  get_key_pubalgo (sig->pubkey_algo),
1240                  keyid, s, key? key->uids->uid : _("user ID not found"));                  keyid, s, uid, pka_info? pka_info : "");
1241      msg_box (NULL, buf, _("Decrypt Verify"), type);      msg_box (NULL, buf, _("Decrypt Verify"), sigok? MB_OK: MB_ICONWARNING|MB_OK);
1242        free_if_alloc (pka_info);
1243        safe_free (uid);
1244  }  }
1245    
1246    
# Line 1255  secret_key_available (gpgme_recipient_t Line 1264  secret_key_available (gpgme_recipient_t
1264  }  }
1265    
1266    
1267    /* If the decrypt result contains the original file name,
1268       we use it instead of the artificial "output - .gpg" string. */
1269    static int
1270    restore_original_name (const char *output, const char *file_name)
1271    {
1272        char *dir;
1273        char *orig;
1274        int rc = 0;
1275    
1276        dir = strrchr (output, '\\');
1277        if (!dir)
1278            orig = strdup (file_name);
1279        else {
1280            orig = (char*)calloc (1, strlen (file_name)+ 1 +
1281                                     strlen (output)+1);
1282            if (!orig)
1283                BUG (0);
1284            memcpy (orig, output, (dir-output)+1);
1285            strcat (orig, file_name);
1286        }
1287        if (overwrite_file (orig)) {
1288            DeleteFile (orig);
1289            if (!MoveFile (output, orig))
1290                rc = -1;
1291        }
1292        safe_free (orig);
1293        return rc;
1294    }
1295    
1296    
1297  /* Decrypt the file @name. */  /* Decrypt the file @name. */
1298  int  int
1299  fm_decrypt (fm_state_t c, const char *name)  fm_decrypt (fm_state_t c, const char *name)
# Line 1263  fm_decrypt (fm_state_t c, const char *na Line 1302  fm_decrypt (fm_state_t c, const char *na
1302      gpgme_ctx_t ctx = c->ctx;          gpgme_ctx_t ctx = c->ctx;    
1303      gpgme_decrypt_result_t res;      gpgme_decrypt_result_t res;
1304      gpgme_verify_result_t sigres;      gpgme_verify_result_t sigres;
1305      file_data_t in =NULL, out=NULL;      file_data_t in = NULL, out = NULL;
1306      int rc = 0;      int rc = 0;
1307            
1308      if (!c->init_cb || !c->cache_cb) {      if (!c->init_cb || !c->cache_cb) {
# Line 1273  fm_decrypt (fm_state_t c, const char *na Line 1312  fm_decrypt (fm_state_t c, const char *na
1312      }      }
1313            
1314      c->output = m_strdup (name);      c->output = m_strdup (name);
     if (!c->output)  
         BUG (0);  
1315      if (is_openpgp_ext (c->output))      if (is_openpgp_ext (c->output))
1316          c->output[strlen (c->output)-4] = '\0';          c->output[strlen (c->output)-4] = '\0';
1317      else {      else {
# Line 1284  fm_decrypt (fm_state_t c, const char *na Line 1321  fm_decrypt (fm_state_t c, const char *na
1321          if (s) {          if (s) {
1322              free_if_alloc (c->output);              free_if_alloc (c->output);
1323              c->output = m_strdup (s);              c->output = m_strdup (s);
             if (!c->output)  
                 BUG (NULL);  
1324          }          }
1325      }      }
1326    
# Line 1319  fm_decrypt (fm_state_t c, const char *na Line 1354  fm_decrypt (fm_state_t c, const char *na
1354          char *p = get_key_userid (keyid+8);          char *p = get_key_userid (keyid+8);
1355          gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo;          gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo;
1356                    
1357          log_box( _("Decryption"), MB_ERR,          log_box (_("Decryption"), MB_ERR,
1358                   _("Encrypted with %s key, ID %s.%s\n"                   _("Encrypted with %s key, ID %s.%s\n"
1359                     "Decryption failed: secret key not available."),                     "Decryption failed: secret key not available."),
1360                     get_key_pubalgo (pkalgo), keyid+8, p);                     get_key_pubalgo (pkalgo), keyid+8, p);
# Line 1336  fm_decrypt (fm_state_t c, const char *na Line 1371  fm_decrypt (fm_state_t c, const char *na
1371          log_box ("Decrypt", MB_ERR,          log_box ("Decrypt", MB_ERR,
1372                   _("Decryption failed.\n%s: does not exist."), c->output);                   _("Decryption failed.\n%s: does not exist."), c->output);
1373          rc = WPTERR_GENERAL;          rc = WPTERR_GENERAL;
1374            goto leave;
1375        }
1376        else if (res && res->file_name) {
1377            char *file = strrchr (c->output, '\\');
1378            int id = log_box (_("Decrypt"), MB_QUEST_ASK,
1379                              _("The original file name is '%s'.\n\n"
1380                                "Do you want to use this instead of '%s'?"),
1381                                res->file_name, file? file+1 : c->output);
1382            if (id == IDYES) {
1383                /* before we can move the file, it needs to be closed first. */
1384                gpg_file_data_release (out);
1385                out = NULL;
1386                restore_original_name (c->output, res->file_name);
1387            }
1388      }      }
       
1389      sigres = gpgme_op_verify_result (ctx);      sigres = gpgme_op_verify_result (ctx);
1390      if (sigres && sigres->signatures)      if (sigres && sigres->signatures)
1391          show_verify_result (sigres);          show_verify_result (sigres);    
1392            
1393  leave:  leave:
1394      if (in)      if (in)
# Line 1521  get_output_file (fm_state_t c, const cha Line 1569  get_output_file (fm_state_t c, const cha
1569      else      else
1570          title = _("Selected Output File");          title = _("Selected Output File");
1571    
1572      if (strstr (name, ".sig")      if (stristr (name, ".sig") ||
1573          || strstr (name, ".asc")          stristr (name, ".asc") ||
1574          || strstr (name, ".gpg")) {          stristr (name, ".gpg")) {
1575          _snprintf (fname, sizeof (fname) - 1, "%s", name);          _snprintf (fname, sizeof (fname) - 1, "%s", name);
1576          fname[strlen (fname) - 4] = '\0';          fname[strlen (fname) - 4] = '\0';
1577          if (file_exist_check (fname) == 0 && detached)            if (file_exist_check (fname) == 0 && detached)  
# Line 1545  get_output_file (fm_state_t c, const cha Line 1593  get_output_file (fm_state_t c, const cha
1593      if (file) {          if (file) {    
1594          free_if_alloc (c->output);              free_if_alloc (c->output);    
1595          c->output = m_strdup (file);          c->output = m_strdup (file);
         if (!c->output)  
             BUG (NULL);  
1596      }      }
1597      else {      else {
1598          msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR);          msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR);
# Line 1555  get_output_file (fm_state_t c, const cha Line 1601  get_output_file (fm_state_t c, const cha
1601      if (detached)      if (detached)
1602          c->sigmode = GPGME_SIG_MODE_DETACH;          c->sigmode = GPGME_SIG_MODE_DETACH;
1603      else {      else {
1604          if (strstr (name, ".asc"))          if (stristr (name, ".asc"))
1605              c->sigmode = GPGME_SIG_MODE_CLEAR;              c->sigmode = GPGME_SIG_MODE_CLEAR;
1606          else          else
1607              c->sigmode = GPGME_SIG_MODE_NORMAL;              c->sigmode = GPGME_SIG_MODE_NORMAL;
# Line 1577  fm_verify (fm_state_t c, int detached, c Line 1623  fm_verify (fm_state_t c, int detached, c
1623      file_data_t in=NULL, out=NULL;      file_data_t in=NULL, out=NULL;
1624      int rc = 0;      int rc = 0;
1625    
1626      if (strstr (name, ".sig"))      if (stristr (name, ".sig"))
1627          detached = 1;          detached = 1;
1628    
1629      if (get_output_file (c, name, detached))      if (get_output_file (c, name, detached))
# Line 1585  fm_verify (fm_state_t c, int detached, c Line 1631  fm_verify (fm_state_t c, int detached, c
1631    
1632      memset (&log, 0, sizeof (log));      memset (&log, 0, sizeof (log));
1633      log.file = m_strdup (name);      log.file = m_strdup (name);
     if (!log.file)  
         BUG (NULL);  
1634      file_verify_create_dlg ();      file_verify_create_dlg ();
1635    
1636      err = gpg_file_data_new (name, F_DATA_READ, &in);      err = gpg_file_data_new (name, F_DATA_READ, &in);
# Line 1640  fm_import (fm_state_t c, const char *nam Line 1684  fm_import (fm_state_t c, const char *nam
1684    
1685      free_if_alloc (c->output);      free_if_alloc (c->output);
1686      c->output = m_strdup (name);      c->output = m_strdup (name);
     if (!c->output)  
         BUG (NULL);  
1687    
1688      err = gpg_file_data_new (name, F_DATA_READ, &keydata);      err = gpg_file_data_new (name, F_DATA_READ, &keydata);
1689      if (err)      if (err)
# Line 1675  leave: Line 1717  leave:
1717  /* Export the selected keys from the File Manager to a file. */  /* Export the selected keys from the File Manager to a file. */
1718  int  int
1719  fm_export (fm_state_t c)  fm_export (fm_state_t c)
1720  {  {    
     int rc = 0;  
1721      gpgme_ctx_t ctx = c->ctx;      gpgme_ctx_t ctx = c->ctx;
1722      gpgme_error_t err;      gpgme_error_t err;
1723      gpgme_key_t *rset = c->recp;      gpgme_key_t *rset = c->recp;
1724      file_data_t keydata = NULL;      file_data_t keydata = NULL;
1725      const char *name;      const char *name;
1726      char *p = NULL, *patt = NULL;      char *p = NULL, *patt = NULL;
1727        int rc = 0;
1728    
1729      if (!rset || !rset[0]) {      if (!rset || !rset[0]) {
1730          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 1717  fm_export (fm_state_t c) Line 1759  fm_export (fm_state_t c)
1759  leave:  leave:
1760      if (keydata)      if (keydata)
1761          gpg_file_data_release (keydata);          gpg_file_data_release (keydata);
1762      if (patt)      safe_free (patt);
         free (patt);  
1763      free_if_alloc (p);      free_if_alloc (p);
1764      return rc;      return rc;
1765  }  }
# Line 1775  fm_parse_command_line (char *cmdl) Line 1816  fm_parse_command_line (char *cmdl)
1816    
1817          case PGP_SIG:          case PGP_SIG:
1818          case PGP_CLEARSIG:          case PGP_CLEARSIG:
             file_verify_use_event ();  
1819              if (type == PGP_SIG)                  if (type == PGP_SIG)    
1820                  detached = 1;                  detached = 1;
1821              fm_verify (ctx, detached, fn);              fm_verify (ctx, detached, fn);
# Line 1812  int Line 1852  int
1852  fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv)  fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv)
1853  {  {
1854      PK_FILE_LIST list=NULL;      PK_FILE_LIST list=NULL;
1855      const char *outfile;      const char *outfile, *ext;
1856      char *out_enc;      char *out_enc;
1857      int nitems = listview_count_items (lv, 0);      int nitems;
1858      int i, idx = -1;      int i, idx = -1;
1859      int rc;      int rc;
1860    
1861        nitems = listview_count_items (lv, 0);
1862      if (!nitems) {      if (!nitems) {
1863          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"),
1864                   _("File Manager"), MB_ERR);                   _("File Manager"), MB_ERR);
# Line 1847  fm_encrypt_into_zip (fm_state_t ctx, lis Line 1888  fm_encrypt_into_zip (fm_state_t ctx, lis
1888      if (rc)      if (rc)
1889          return rc;          return rc;
1890    
1891      out_enc = make_filename (NULL, outfile, "gpg");      ext = file_get_extension (ctx->ctx, ctx->sigmode)+1;
1892        out_enc = make_filename (NULL, outfile, ext);
1893      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);
1894      free_if_alloc (out_enc);      free_if_alloc (out_enc);
1895    
# Line 1922  fm_cmp_cb (LPARAM first, LPARAM second, Line 1964  fm_cmp_cb (LPARAM first, LPARAM second,
1964      const char *a = 0;      const char *a = 0;
1965      const char *b = 0;      const char *b = 0;
1966    
1967      switch( (int)sortby ) {      switch ((int)sortby) {
1968      case FM_SORT_STAT:      case FM_SORT_STAT:
1969          break;          break;
1970      case FM_SORT_NAME:      case FM_SORT_NAME:
# Line 1938  fm_cmp_cb (LPARAM first, LPARAM second, Line 1980  fm_cmp_cb (LPARAM first, LPARAM second,
1980  int  int
1981  fm_sort (listview_ctrl_t lv, int sortby)  fm_sort (listview_ctrl_t lv, int sortby)
1982  {  {
1983      return listview_sort_items( lv, sortby, fm_cmp_cb );      return listview_sort_items (lv, sortby, fm_cmp_cb);
1984  }  }
1985    
1986    

Legend:
Removed from v.172  
changed lines
  Added in v.201

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26