/[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 104 by twoaday, Wed Nov 23 12:16:55 2005 UTC revision 105 by twoaday, Wed Nov 30 10:22:00 2005 UTC
# Line 272  leave: Line 272  leave:
272    
273  /* Extract file type from @fname. If @r_type is valid,  /* Extract file type from @fname. If @r_type is valid,
274     it contains the PGP type on success. */     it contains the PGP type on success. */
275  static const char *  static const char*
276  fm_get_file_type (const char *fname, int *r_type)  fm_get_file_type (const char *fname, int *r_type)
277  {          {        
278      gpg_iobuf_t inp;      gpg_iobuf_t inp;
279      armor_filter_context_t afx;      armor_filter_context_t afx;
280      PACKET *pkt;      PACKET *pkt;
281      const char *s = NULL;      const char *s = NULL;
282        size_t count = 0, compr = 0;
283      int rc = 0;      int rc = 0;
284    
     /* XXX: if the text was created with gpg --sign and armored  
             there is no way to differ between an encrypted text  
             and a one-pass signature. */  
285      if (r_type)      if (r_type)
286          *r_type = PGP_NONE;          *r_type = PGP_NONE;
287      if (!fname) {      if (!fname) {
# Line 340  fm_get_file_type (const char *fname, int Line 338  fm_get_file_type (const char *fname, int
338              if (r_type) *r_type = PGP_SECKEY;              if (r_type) *r_type = PGP_SECKEY;
339              break;              break;
340    
341            case PKT_COMPRESSED:
342                /* If we only find 1 packet and it is compressed,
343                   we assume a compress one-pass signature. */
344                if (count != 0)
345                    break;
346                s = "SIGNED";   rc = -2;
347                compr = 1;
348                break;
349    
350          default:          default:
351              break;              break;
352          }          }
353            count++;
354          gpg_free_packet (pkt);          gpg_free_packet (pkt);
355          gpg_init_packet (pkt);          gpg_init_packet (pkt);
356          if (rc == -2)          if (rc == -2)
# Line 354  fm_get_file_type (const char *fname, int Line 362  fm_get_file_type (const char *fname, int
362          s = fm_check_armor_type (fname, r_type);          s = fm_check_armor_type (fname, r_type);
363      if (!s)      if (!s)
364          s = "UNKNOWN";          s = "UNKNOWN";
365      if (!strcmp (s, "SIGNED")      if (!strcmp (s, "SIGNED") && !compr
366          && strcmp (fm_check_armor_type (fname, r_type), "SIGNED-CLEAR ")) {          && strcmp (fm_check_armor_type (fname, r_type), "SIGNED-CLEAR ")) {
367          if (r_type) *r_type = PGP_SIG;          if (r_type) *r_type = PGP_SIG;
368          s = "SIGNED-DETACH";          s = "SIGNED-DETACH";
# Line 363  fm_get_file_type (const char *fname, int Line 371  fm_get_file_type (const char *fname, int
371  }  }
372    
373    
374    /* Build the File Manager list view control. */
375  int  int
376  fm_build (listview_ctrl_t *lv, HWND ctrl)  fm_build (listview_ctrl_t *lv, HWND ctrl)
377  {  {
378      int i, rc = 0;      int i, rc = 0;
379      listview_ctrl_t c;      listview_ctrl_t c;
380      struct listview_column_s col[] =      struct listview_column_s col[] = {
     {  
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);
388      if( rc )      if (rc)
389          BUG( NULL );          BUG (NULL);
390      c->ctrl = ctrl;      c->ctrl = ctrl;
391      for ( i = 0; col[i].width; i++ )      for (i = 0; col[i].width; i++)
392          listview_add_column( c, &col[i] );          listview_add_column (c, &col[i]);
393      listview_set_ext_style( c );      listview_set_ext_style (c);
394      if( lv )      if (lv)
395          *lv = c;          *lv = c;
396      return 0;      return 0;
397  } /* fm_build */  }
398    
399    
400    /* Release the File Manager listview control. */
401  void  void
402  fm_delete( listview_ctrl_t lv )  fm_delete (listview_ctrl_t lv)
403  {  {
404      if( lv ) {      if (lv) {
405          listview_release( lv );          listview_release(lv);  
406      }      }
407  } /* fm_delete */  }
408    
409    
410  int  int
# Line 424  fm_state_release (fm_state_t c) Line 433  fm_state_release (fm_state_t c)
433  {  {
434      if (!c)      if (!c)
435          return;          return;
     if (c->recp)  
         free (c->recp);  
436      if (c->ctx) {      if (c->ctx) {
437          gpgme_release (c->ctx);          gpgme_release (c->ctx);
438          c->ctx = NULL;            c->ctx = NULL;  
439      }      }
440        safe_free (c->recp);
441      free_if_alloc (c->opaque);      free_if_alloc (c->opaque);
442      free_if_alloc (c->output);      free_if_alloc (c->output);
443      delete c; c = NULL;          delete c; c = NULL;    
# Line 859  fm_parse_files (listview_ctrl_t lv, HWND Line 867  fm_parse_files (listview_ctrl_t lv, HWND
867      case FM_SIGNENCRYPT:      case FM_SIGNENCRYPT:
868          if (fm_cmd == FM_SIGNENCRYPT)          if (fm_cmd == FM_SIGNENCRYPT)
869              ctx->req_signer = 1;              ctx->req_signer = 1;
870          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_ENCRYPT, ctx->dlg,          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_ENCRYPT,
871                          file_encrypt_dlg_proc, (LPARAM)ctx);                          ctx->dlg, file_encrypt_dlg_proc, (LPARAM)ctx);
872          if (ctx->cancel == 1) {          if (ctx->cancel == 1) {
873              rc = WPTERR_GENERAL;              rc = WPTERR_GENERAL;
874              goto leave;              goto leave;
875          }          }
876          break;          break;
# Line 1038  fm_encrypt (fm_state_t c, const char *na Line 1046  fm_encrypt (fm_state_t c, const char *na
1046          BUG (0);          BUG (0);
1047      strcpy (ext, file_get_extension (ctx, c->sigmode));      strcpy (ext, file_get_extension (ctx, c->sigmode));
1048      strcpy (c->output, name);      strcpy (c->output, name);
1049      strcat (c->output, ext);              strcat (c->output, ext);
1050            
1051      if (!overwrite_file (c->output)) {      if (!overwrite_file (c->output)) {
1052          rc = ask_filename (c, _("Enter filename for encrypted file"), NULL);          rc = ask_filename (c, _("Enter filename for encrypted file"), NULL);
# Line 1046  fm_encrypt (fm_state_t c, const char *na Line 1054  fm_encrypt (fm_state_t c, const char *na
1054              goto leave;              goto leave;
1055      }      }
1056    
1057      err = gpg_file_data_new (name, 1, &in);      err = gpg_file_data_new (name, F_DATA_READ, &in);
1058      if (err)      if (err)
1059          goto leave;          goto leave;
1060      err = gpg_file_data_new (c->output, 0, &out);      remove_crit_file_attrs (c->output, 0);
1061        err = gpg_file_data_new (c->output, F_DATA_WRITE, &out);
1062      if (err)      if (err)
1063          goto leave;          goto leave;
1064    
# Line 1060  fm_encrypt (fm_state_t c, const char *na Line 1069  fm_encrypt (fm_state_t c, const char *na
1069      }      }
1070      */      */
1071            
1072      /* XXX      /* XXX: disable compression for multi-media files.
1073      no_compr = is_multi_media (name);      no_compr = is_multi_media (name);
1074      gpgme_control (ctx, GPGME_CTRL_NO_COMPR, no_compr);      gpgme_control (ctx, GPGME_CTRL_NO_COMPR, no_compr);
1075      */      */
# Line 1189  leave: Line 1198  leave:
1198          gpg_file_data_release (out);          gpg_file_data_release (out);
1199      sfree_if_alloc (pass);      sfree_if_alloc (pass);
1200      return rc;      return rc;
1201  } /* fm_sym_encrypt */  }
1202    
1203    
1204  /* Show the human readable verify result from @sigres. */  /* Show the human readable verify result from @sigres. */
# Line 1207  show_verify_result (gpgme_verify_result_ Line 1216  show_verify_result (gpgme_verify_result_
1216      sigok = sig->summary & GPGME_SIGSUM_GREEN;      sigok = sig->summary & GPGME_SIGSUM_GREEN;
1217      s = sigok? _("Good signature") : _("BAD signature");      s = sigok? _("Good signature") : _("BAD signature");
1218      type = sigok? MB_OK: MB_ICONWARNING|MB_OK;      type = sigok? MB_OK: MB_ICONWARNING|MB_OK;
1219      keyid = sig->fpr;        keyid = sig->fpr;
1220      if (!keyid)      if (!keyid)
1221          return;          return;
1222    
1223      keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24;      keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24;
1224      get_pubkey (sig->fpr, &key);      get_pubkey (sig->fpr, &key);
1225      _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"
1226                                      "%s from \"%s\"",                                      "%s from \"%s\""),
1227                  strtimestamp (sig->timestamp), get_key_pubalgo (sig->pubkey_algo),                  strtimestamp (sig->timestamp),
1228                    get_key_pubalgo (sig->pubkey_algo),
1229                  keyid, s, key? key->uids->uid : _("user ID not found"));                  keyid, s, key? key->uids->uid : _("user ID not found"));
1230      msg_box (NULL, buf, _("Decrypt Verify"), type);      msg_box (NULL, buf, _("Decrypt Verify"), type);
1231  }  }
# Line 1228  secret_key_available (gpgme_recipient_t Line 1238  secret_key_available (gpgme_recipient_t
1238      gpgme_recipient_t r;      gpgme_recipient_t r;
1239      gpgme_key_t key;      gpgme_key_t key;
1240    
1241      for (r=rset; r; r = r->next) {            for (r=rset; r; r = r->next) {
1242          if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY)          if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY)
1243              continue;              continue;
1244          else {          else {
# Line 1279  fm_decrypt (fm_state_t c, const char *na Line 1289  fm_decrypt (fm_state_t c, const char *na
1289          rc = ask_filename (c, _("Please enter filename for plaintext file"), NULL);          rc = ask_filename (c, _("Please enter filename for plaintext file"), NULL);
1290          if (rc)          if (rc)
1291              goto leave;              goto leave;
1292      }          }
   
     remove_crit_file_attrs (c->output, 0);  
1293    
1294      err = gpg_file_data_new (name, 1, &in);      err = gpg_file_data_new (name, F_DATA_READ, &in);
1295      if (err)      if (err)
1296          goto leave;          goto leave;
1297      err = gpg_file_data_new (c->output, 0, &out);      remove_crit_file_attrs (c->output, 0);
1298        err = gpg_file_data_new (c->output, F_DATA_WRITE, &out);
1299      if (err)      if (err)
1300          goto leave;          goto leave;
1301    
# Line 1320  fm_decrypt (fm_state_t c, const char *na Line 1329  fm_decrypt (fm_state_t c, const char *na
1329          goto leave;          goto leave;
1330      }      }
1331      if (file_exist_check (c->output)) {      if (file_exist_check (c->output)) {
1332          log_box ("Decrypt", MB_ERR, _("Decryption failed.\n%s: does not exist."), c->output);          log_box ("Decrypt", MB_ERR,
1333                     _("Decryption failed.\n%s: does not exist."), c->output);
1334          rc = WPTERR_GENERAL;          rc = WPTERR_GENERAL;
1335      }      }
1336            
# Line 1339  leave: Line 1349  leave:
1349    
1350  int  int
1351  fm_sign (fm_state_t c, const char * name)  fm_sign (fm_state_t c, const char * name)
1352  {        {
     int rc = 0;  
1353      gpgme_ctx_t ctx = c->ctx;      gpgme_ctx_t ctx = c->ctx;
1354      gpgme_error_t err;      gpgme_error_t err;
1355      file_data_t in=NULL, out=NULL;      file_data_t in=NULL, out=NULL;
1356      char ext[5];      char ext[5];
1357        int rc = 0;
1358    
1359      if (!c->init_cb || !c->cache_cb) {      if (!c->init_cb || !c->cache_cb) {
1360          set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_SIGN, c->dlg, _("Signing") );          set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_SIGN, c->dlg, _("Signing"));
1361          c->init_cb = 1;          c->init_cb = 1;
1362      }      }
1363            
1364      free_if_alloc (c->output);      free_if_alloc (c->output);
1365      c->output = new char[strlen (name) + 5 + 1];      c->output = new char[strlen (name) + 5 + 1];
1366      if( !c->output)      if (!c->output)
1367          BUG( NULL );          BUG (NULL);
1368      strcpy (ext, file_get_extension (ctx, c->sigmode));      strcpy (ext, file_get_extension (ctx, c->sigmode));
1369      strcpy (c->output, name);      strcpy (c->output, name);
1370      strcat (c->output, ext);      strcat (c->output, ext);
# Line 1364  fm_sign (fm_state_t c, const char * name Line 1374  fm_sign (fm_state_t c, const char * name
1374          if (rc)          if (rc)
1375              goto leave;              goto leave;
1376      }      }
1377      remove_crit_file_attrs (c->output, 0);      
1378        err = gpg_file_data_new (name, F_DATA_READ, &in);
     err = gpg_file_data_new (name, 1, &in);  
1379      if (err)      if (err)
1380          goto leave;          goto leave;
1381      err = gpg_file_data_new (c->output, 0, &out);      remove_crit_file_attrs (c->output, 0);
1382        err = gpg_file_data_new (c->output, F_DATA_WRITE, &out);
1383      if (err)      if (err)
1384          goto leave;          goto leave;
1385    
1386      op_begin ();      op_begin ();
1387      err = gpgme_op_sign (ctx, in->dat, out->dat, c->sigmode);      err = gpgme_op_sign (ctx, in->dat, out->dat, c->sigmode);
1388      op_end ();      op_end ();
1389      if( !c->cache_cb )      if (!c->cache_cb)
1390          release_gpg_passphrase_cb (&c->pass_cb);          release_gpg_passphrase_cb (&c->pass_cb);
1391      if( c->pass_cb.cancel ) {      if (c->pass_cb.cancel) {
1392          rc = WPTERR_GENERAL;          rc = WPTERR_GENERAL;
1393          goto leave;          goto leave;
1394      }      }
1395      if( err ) {      if (err) {
1396          msg_box( c->dlg, gpgme_strerror( err ), _("Sign"), MB_ERR );          msg_box (c->dlg, gpgme_strerror (err), _("Sign"), MB_ERR);
1397          rc = WPTERR_GENERAL;          rc = WPTERR_GENERAL;
1398          goto leave;              goto leave;    
1399      }      }
# Line 1397  leave: Line 1407  leave:
1407  }  }
1408    
1409    
1410  static int  static void
1411  fm_add_sig_stat (file_sig_ctx_t log)  fm_add_sig_stat (file_sig_ctx_t log)
1412  {  {
1413      gpgme_key_t key;          gpgme_key_t key;    
# Line 1417  fm_add_sig_stat (file_sig_ctx_t log) Line 1427  fm_add_sig_stat (file_sig_ctx_t log)
1427          log->use_uid = 1;          log->use_uid = 1;
1428      }      }
1429      file_verify_add_state (log);      file_verify_add_state (log);
     return 0;  
1430  }  }
1431    
1432    
1433    /* Verify a detached signature from the clipboard. */  
1434  static int  static int
1435  verify_pasted (listview_ctrl_t lv, fm_state_t ctx, const char * dat,  verify_pasted (listview_ctrl_t lv, fm_state_t ctx,
1436                 int i, HWND dlg)                 const char *dat, int pos, HWND dlg)
1437  {  {
1438      FILE * fp;      FILE *fp;
1439      char stat[32];      char stat[32];
1440      char file[256], * fname = NULL;      char file[256], *fname = NULL;
1441      int del_end=0;      int del_end = 0;
1442    
1443      listview_get_item_text (lv, i, 0, stat, sizeof (stat)-1);      listview_get_item_text (lv, pos, 0, stat, sizeof (stat)-1);
1444      listview_get_item_text (lv, i, 1, file, sizeof (file)-1);      listview_get_item_text (lv, pos, 1, file, sizeof (file)-1);
1445      if (strcmp (stat, "UNKNOWN"))      if (strcmp (stat, "UNKNOWN"))
1446          return 0;          return 0;
1447      fname = make_filename (NULL, file, "asc");      fname = make_filename (NULL, file, "asc");
# Line 1440  verify_pasted (listview_ctrl_t lv, fm_st Line 1450  verify_pasted (listview_ctrl_t lv, fm_st
1450          if (fp == NULL) {          if (fp == NULL) {
1451              log_box (_("File Manager"), MB_ERR, "could not create '%s'", fname);              log_box (_("File Manager"), MB_ERR, "could not create '%s'", fname);
1452              free_if_alloc (fname);              free_if_alloc (fname);
1453              return WPTERR_GENERAL;                    return WPTERR_GENERAL;
1454          }                }
1455          fwrite (dat, 1, strlen (dat), fp);          fwrite (dat, 1, strlen (dat), fp);
1456          fclose (fp);          fclose (fp);
1457          del_end = 1;          del_end = 1;
# Line 1454  verify_pasted (listview_ctrl_t lv, fm_st Line 1464  verify_pasted (listview_ctrl_t lv, fm_st
1464  }  }
1465    
1466    
1467    /* Figure out if the clipboard contains a detached signature. */
1468  int  int
1469  fm_verify_pasted_detsig (listview_ctrl_t lv, HWND dlg)  fm_verify_pasted_detsig (listview_ctrl_t lv, HWND dlg)
1470  {  {
# Line 1471  fm_verify_pasted_detsig (listview_ctrl_t Line 1482  fm_verify_pasted_detsig (listview_ctrl_t
1482      /* XXX find a way to filter out bad signatures or just ignore all in      /* XXX find a way to filter out bad signatures or just ignore all in
1483             this case */             this case */
1484      fm_state_new (&ctx);      fm_state_new (&ctx);
1485      if ((i=listview_get_curr_pos (lv)) != -1) {      i = listview_get_curr_pos (lv);
1486        if (i= -1) {
1487          verify_pasted (lv, ctx, dat, i, dlg);          verify_pasted (lv, ctx, dat, i, dlg);
1488          fnd = 1;          fnd = 1;
1489      }      }
# Line 1503  get_output_file (fm_state_t c, const cha Line 1515  get_output_file (fm_state_t c, const cha
1515      else      else
1516          title = _("Selected Output File");          title = _("Selected Output File");
1517    
1518      if (strstr (name, ".sig") || strstr (name, ".asc") || strstr (name, ".gpg")) {      if (strstr (name, ".sig")
1519            || strstr (name, ".asc")
1520            || strstr (name, ".gpg")) {
1521          _snprintf (fname, sizeof (fname) - 1, "%s", name);          _snprintf (fname, sizeof (fname) - 1, "%s", name);
1522          fname[strlen (fname) - 4] = '\0';          fname[strlen (fname) - 4] = '\0';
1523          if (file_exist_check (fname) == 0 && detached)            if (file_exist_check (fname) == 0 && detached)  
# Line 1569  fm_verify (fm_state_t c, int detached, c Line 1583  fm_verify (fm_state_t c, int detached, c
1583          BUG (NULL);          BUG (NULL);
1584      file_verify_create_dlg ();      file_verify_create_dlg ();
1585    
1586      err = gpg_file_data_new (name, 1, &in);      err = gpg_file_data_new (name, F_DATA_READ, &in);
1587      if (err)      if (err)
1588          goto leave;          goto leave;
1589      err = gpg_file_data_new (c->output, detached? 1 : 0, &out);      err = gpg_file_data_new (c->output,
1590                                 detached? F_DATA_READ : F_DATA_WRITE, &out);
1591      if (err)      if (err)
1592          goto leave;          goto leave;
1593    
# Line 1601  leave: Line 1616  leave:
1616          gpg_file_data_release (in);          gpg_file_data_release (in);
1617      if (out)      if (out)
1618          gpg_file_data_release (out);          gpg_file_data_release (out);
1619      if (log.file)      free_if_alloc (log.file);
         delete []log.file;  
1620      return rc;      return rc;
1621  }  }
1622    
1623    
1624    /* Import the keys from the file @name.
1625       Return value: 0 on success. */
1626  int  int
1627  fm_import (fm_state_t c, const char *name)  fm_import (fm_state_t c, const char *name)
1628  {  {
# Line 1621  fm_import (fm_state_t c, const char *nam Line 1637  fm_import (fm_state_t c, const char *nam
1637      if (!c->output)      if (!c->output)
1638          BUG (NULL);          BUG (NULL);
1639    
1640      err = gpg_file_data_new (name, 1, &keydata);      err = gpg_file_data_new (name, F_DATA_READ, &keydata);
1641      if (err)      if (err)
1642          goto leave;          goto leave;
1643    
# Line 1637  fm_import (fm_state_t c, const char *nam Line 1653  fm_import (fm_state_t c, const char *nam
1653      res = gpgme_op_import_result (ctx);      res = gpgme_op_import_result (ctx);
1654      print_import_status (res);      print_import_status (res);
1655      if (res->no_user_id > 0) {      if (res->no_user_id > 0) {
1656          msg_box (c->dlg, _("Key without a self signature was dectected!\n"                msg_box (c->dlg, _("Key without a self signature was dectected!\n"
1657                             "(This key is NOT usable for encryption, etc)\n"                             "(This key is NOT usable for encryption, etc)\n"
1658                             "\n"                             "\n"
1659                             "Cannot import these key(s)!"), _("Import"), MB_INFO);                             "Cannot import these key(s)!"), _("Import"), MB_INFO);
# Line 1647  leave: Line 1663  leave:
1663      if (keydata)      if (keydata)
1664          gpg_file_data_release (keydata);          gpg_file_data_release (keydata);
1665      return rc;      return rc;
1666  } /* fm_import */  }
1667    
1668    
1669    /* Generate a user friendly file name based on the key @k. */
1670    static char*
1671    gen_key_outname (gpgme_key_t k)
1672    {
1673        char *p;
1674        size_t i;
1675    
1676        p = new char[strlen (k->uids->name)+1+8];
1677        if (!p)    
1678            BUG (NULL);
1679        sprintf (p, "%s.asc", k->uids->name);
1680        for (i=0; i < strlen (p); i++) {
1681            if (p[i] == ' ')
1682                p[i] = '_';
1683        }
1684        return p;
1685    }
1686    
1687    
1688  /* Export the selected keys from the File Manager to a file. */  /* Export the selected keys from the File Manager to a file. */
# Line 1668  fm_export (fm_state_t c) Line 1703  fm_export (fm_state_t c)
1703          goto leave;          goto leave;
1704      }      }
1705    
1706      if (rset[1] == NULL) { /* count == 1*/      if (rset[1] == NULL) /* count == 1*/
1707          gpgme_key_t k = rset[0];          p = gen_key_outname (rset[0]);
         const char *s = k->uids->name;  
         p = new char[strlen (s)+1+8];  
         if (!p)  
             BUG (NULL);  
         strcpy (p, s );  
         strcat (p, ".asc");  
     }  
1708    
1709      name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"),      name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"),
1710                               NULL, p? p : NULL);                               NULL, p? p : NULL);
                               
1711      if (!name)      if (!name)
1712          name = "keys.gpg";          name = "keys.gpg";
1713    
1714      patt = gpg_keylist_to_pattern (rset, c->n_recp);      patt = gpg_keylist_to_pattern (rset, c->n_recp);
1715    
1716      err = gpg_file_data_new (name, 0, &keydata);      err = gpg_file_data_new (name, F_DATA_WRITE, &keydata);
1717      if (err)      if (err)
1718          goto leave;          goto leave;
1719    
# Line 1706  leave: Line 1733  leave:
1733      if (patt)      if (patt)
1734          free (patt);          free (patt);
1735      free_if_alloc (p);      free_if_alloc (p);
           
1736      return rc;      return rc;
1737  }  }
1738    
# Line 1781  fm_parse_command_line (char *cmdl) Line 1807  fm_parse_command_line (char *cmdl)
1807  }  }
1808    
1809    
1810    /* Extract the last folder name from @name. */
1811  const char*  const char*
1812  default_dirname (const char *name)  default_dirname (const char *name)
1813  {  {
1814      char * p = strrchr( name, '\\' );      char *p = strrchr (name, '\\');
1815      if( !p )      if (!p)
1816          return NULL;          return NULL;
1817      return p+1;      return p+1;
1818  } /* default_dirname */  }
1819    
1820    
1821  /* Store all selected files from @lv in a zip archive  /* Store all selected files from @lv in a zip archive
# Line 1807  fm_encrypt_into_zip (fm_state_t ctx, lis Line 1834  fm_encrypt_into_zip (fm_state_t ctx, lis
1834      if (!nitems) {      if (!nitems) {
1835          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"),
1836                   _("File Manager"), MB_ERR);                   _("File Manager"), MB_ERR);
1837          return -1;          return WPTERR_GENERAL;
1838      }      }
1839    
1840      outfile = get_filesave_dlg (NULL, _("Choose File Name for Output"),      outfile = get_filesave_dlg (ctx->dlg, _("Choose File Name for Output"),
1841                                  NULL, "encrypted_files.zip");                                  NULL, "Encrypted_Files.zip");
1842      if (!outfile)      if (!outfile)
1843          return -1;          return WPTERR_GENERAL;
1844    
1845      for (i=0; i < nitems; i++) {      for (i=0; i < nitems; i++) {
1846          char name[300];          char name[300];
# Line 1846  fm_encrypt_into_zip (fm_state_t ctx, lis Line 1873  fm_encrypt_into_zip (fm_state_t ctx, lis
1873    
1874    
1875  int  int
1876  fm_encrypt_directory( fm_state_t c, const char * name )  fm_encrypt_directory (fm_state_t c, const char *name)
1877  {  {
1878      PK_FILE_LIST list = NULL;      PK_FILE_LIST list = NULL;
1879      WIN32_FIND_DATA findbuf;      WIN32_FIND_DATA findbuf;
# Line 1855  fm_encrypt_directory( fm_state_t c, cons Line 1882  fm_encrypt_directory( fm_state_t c, cons
1882      char * patt = NULL, * p;      char * patt = NULL, * p;
1883      int rc = 0;      int rc = 0;
1884            
1885      if( !is_directory( name ) )          if (!is_directory (name))
1886          return -1;          return -1;
1887      patt = new char[strlen( name ) + 4];      patt = new char[strlen (name) + 4];
1888      if( !patt )      if (!patt)
1889          BUG( NULL );          BUG (NULL);
1890      strcpy( patt, name );      strcpy (patt, name);
1891      strcat( patt, "\\*" );      strcat (patt, "\\*");
1892      hd = FindFirstFile( patt, &findbuf );          hd = FindFirstFile (patt, &findbuf);
1893      if( !hd ) {      if (!hd) {
1894          free_if_alloc( patt );            free_if_alloc (patt);
1895          return -1;                return WPTERR_GENERAL;
1896      }      }
1897      if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) {      if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) {
1898          p = make_filename( name, findbuf.cFileName, NULL );          p = make_filename( name, findbuf.cFileName, NULL );
# Line 1879  fm_encrypt_directory( fm_state_t c, cons Line 1906  fm_encrypt_directory( fm_state_t c, cons
1906              free_if_alloc( p );              free_if_alloc( p );
1907          }          }
1908      }      }
1909      s = get_filesave_dlg( c->dlg, _("Choose a Name for the Archive"),      s = get_filesave_dlg (c->dlg, _("Choose a Name for the Archive"),
1910                            NULL, default_dirname( name ) );                            NULL, default_dirname (name));
1911      if( !s ) {      if( !s ) {
1912          msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR );          msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR );
1913          rc = -1;          rc = -1;
# Line 1899  leave: Line 1926  leave:
1926      pk_list_free( list );      pk_list_free( list );
1927      free_if_alloc( patt );      free_if_alloc( patt );
1928      return rc;      return rc;
1929  } /* fm_encrypt_directory */  }
1930    
1931    
1932  static int CALLBACK  static int CALLBACK
1933  fm_cmp_cb( LPARAM first, LPARAM second, LPARAM sortby )  fm_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)
1934  {  {
1935      const char * a = 0, * b = 0;      const char *a = 0;
1936        const char *b = 0;
1937    
1938      switch( (int)sortby ) {      switch( (int)sortby ) {
1939      case FM_SORT_STAT:      case FM_SORT_STAT:
# Line 1915  fm_cmp_cb( LPARAM first, LPARAM second, Line 1943  fm_cmp_cb( LPARAM first, LPARAM second,
1943      case FM_SORT_OP:      case FM_SORT_OP:
1944          break;          break;
1945      }      }
1946      return stricmp( a, b );      return stricmp (a, b);
1947  } /* fm_cmp_cb */  }
1948                    
1949    
1950    /* Sort the list items from @lv with the mode given by @sortby. */
1951  int  int
1952  fm_sort( listview_ctrl_t lv, int sortby )  fm_sort (listview_ctrl_t lv, int sortby)
1953  {  {
1954      return listview_sort_items( lv, sortby, fm_cmp_cb );      return listview_sort_items( lv, sortby, fm_cmp_cb );
1955  } /* fm_sort */  }
1956    
1957    
1958    /* Start the 'print md' dialog. Pass over the listview control
1959       @lv and the digest algo @mdalgo. */
1960  void  void
1961  fm_print_md( listview_ctrl_t lv, HWND dlg, int mdalgo )  fm_print_md (listview_ctrl_t lv, HWND dlg, int mdalgo)
1962  {  {
1963      struct md_file_s mdctx;      struct md_file_s mdctx;
1964    
1965      if( listview_count_items( lv, 0 ) == 0 )      if (listview_count_items (lv, 0) == 0)
1966          return;          return;
1967      memset (&mdctx, 0, sizeof (mdctx));      memset (&mdctx, 0, sizeof (mdctx));
1968      mdctx.lv = lv;      mdctx.lv = lv;
1969      mdctx.mdalgo = mdalgo;      mdctx.mdalgo = mdalgo;
1970      DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_FILE_MDSUM, dlg,      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_MDSUM, dlg,
1971                      mdsum_dlg_proc, (LPARAM)&mdctx );                      mdsum_dlg_proc, (LPARAM)&mdctx);
1972  } /* fm_print_md */  }
1973    
1974    
1975  /* Send the selected file in @lv via MAPI to a mail recipient. */  /* Send the selected file in @lv via MAPI to a mail recipient. */

Legend:
Removed from v.104  
changed lines
  Added in v.105

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26