/[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 76 by twoaday, Thu Nov 10 14:07:06 2005 UTC revision 77 by twoaday, Mon Nov 14 15:01:01 2005 UTC
# Line 27  Line 27 
27  #endif  #endif
28    
29  #include <sys/types.h>  #include <sys/types.h>
 #include <sys/types.h>  
30  #include <windows.h>  #include <windows.h>
31  #include <commdlg.h>  #include <commdlg.h>
32  #include <io.h>  #include <io.h>
# Line 51  Line 50 
50  #include "wptRegistry.h"  #include "wptRegistry.h"
51  #include "wptImport.h"  #include "wptImport.h"
52  #include "wptCrypto.h"  #include "wptCrypto.h"
   
53  #include "openpgp.h"  #include "openpgp.h"
54    
55  #define op_begin()  SetCursor (LoadCursor (NULL, IDC_WAIT))  #define op_begin()  SetCursor (LoadCursor (NULL, IDC_WAIT))
# Line 282  fm_get_file_type (const char *fname, int Line 280  fm_get_file_type (const char *fname, int
280      armor_filter_context_t afx;      armor_filter_context_t afx;
281      PACKET *pkt;      PACKET *pkt;
282      const char *s = NULL;      const char *s = NULL;
283      int rc=0;      int rc = 0;
284    
285      if (r_type)      if (r_type)
286          *r_type = PGP_NONE;          *r_type = PGP_NONE;
# Line 296  fm_get_file_type (const char *fname, int Line 294  fm_get_file_type (const char *fname, int
294    
295      inp = gpg_iobuf_open (fname);      inp = gpg_iobuf_open (fname);
296      if (!inp) {      if (!inp) {
297          const char *s = winpt_strerror (WPTERR_FILE_OPEN);          const char *err = winpt_strerror (WPTERR_FILE_OPEN);
298          log_box (_("File Manager"), MB_ERR, "\"%s\": %s", fname, s);          log_box (_("File Manager"), MB_ERR, "\"%s\": %s", fname, err);
299          return NULL;          return NULL;
300      }      }
301      gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */      gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */
# Line 504  int Line 502  int
502  fm_add_dropped_files (listview_ctrl_t lv, HDROP dd_files)  fm_add_dropped_files (listview_ctrl_t lv, HDROP dd_files)
503  {  {
504      char name[384+4];      char name[384+4];
505      int nfiles, i;      int nfiles;
506      int rc=0;      int rc = 0;
507        int i;
508            
509      memset (name, 0, sizeof (name));      memset (name, 0, sizeof (name));
510      nfiles = DragQueryFile (dd_files, 0xFFFFFFFF, NULL, 0);      nfiles = DragQueryFile (dd_files, 0xFFFFFFFF, NULL, 0);
# Line 629  fm_assume_onepass_sig (const char * fnam Line 628  fm_assume_onepass_sig (const char * fnam
628          gpg_free_packet (pkt);          gpg_free_packet (pkt);
629          safe_free (pkt);          safe_free (pkt);
630          gpg_iobuf_close (fp);          gpg_iobuf_close (fp);
631          unlink ("gpgme.tmp");          remove ("gpgme.tmp");
632      }      }
633      /* XXX: implement it for real files */      /* XXX: implement it for real files */
634      return check;      return check;
# Line 812  fm_parse_files (listview_ctrl_t lv, HWND Line 811  fm_parse_files (listview_ctrl_t lv, HWND
811            
812      switch (cmd) {      switch (cmd) {
813      case ID_FILEMISC_ENCRYPT: fm_cmd = FM_ENCRYPT; break;      case ID_FILEMISC_ENCRYPT: fm_cmd = FM_ENCRYPT; break;
814        case ID_FILEMISC_ENCRYPT_ZIP:fm_cmd = FM_ENCRYPT_ZIP; break;
815      case ID_FILEMISC_DECRYPT: fm_cmd = FM_DECRYPT; break;      case ID_FILEMISC_DECRYPT: fm_cmd = FM_DECRYPT; break;
816      case ID_FILEMISC_SYMENC:  fm_cmd = FM_SYMENC;  break;      case ID_FILEMISC_SYMENC:  fm_cmd = FM_SYMENC;  break;
817      case ID_FILEMISC_SIGN:    fm_cmd = FM_SIGN;    break;          case ID_FILEMISC_SIGN:    fm_cmd = FM_SIGN;    break;    
# Line 824  fm_parse_files (listview_ctrl_t lv, HWND Line 824  fm_parse_files (listview_ctrl_t lv, HWND
824      }      }
825            
826      if (fm_get_current_pos (lv) == -1)      if (fm_get_current_pos (lv) == -1)
827          return WPTERR_GENERAL;              return WPTERR_GENERAL;
828      rc = fm_state_new (&ctx);      rc = fm_state_new (&ctx);
829      if (rc)      if (rc)
830          BUG (0);          BUG (0);
# Line 845  fm_parse_files (listview_ctrl_t lv, HWND Line 845  fm_parse_files (listview_ctrl_t lv, HWND
845            
846      /* Commands we need before we can perform the main command */      /* Commands we need before we can perform the main command */
847      switch (fm_cmd) {      switch (fm_cmd) {
848        case FM_ENCRYPT_ZIP:
849      case FM_ENCRYPT:      case FM_ENCRYPT:
850      case FM_SIGNENCRYPT:      case FM_SIGNENCRYPT:
851          if (fm_cmd == FM_SIGNENCRYPT)          if (fm_cmd == FM_SIGNENCRYPT)
# Line 891  fm_parse_files (listview_ctrl_t lv, HWND Line 892  fm_parse_files (listview_ctrl_t lv, HWND
892          memset (&confirm, 0, sizeof confirm);          memset (&confirm, 0, sizeof confirm);
893          confirm.lv_files = lv;          confirm.lv_files = lv;
894          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILES_SECDEL, ctx->dlg,          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILES_SECDEL, ctx->dlg,
895                              file_secdel_confirm_dlg_proc, (LPARAM)&confirm);                          file_secdel_confirm_dlg_proc, (LPARAM)&confirm);
896          if (!confirm.yes)          if (!confirm.yes)
897              goto leave;              goto leave;
898      }      }
899            
900      for( i = 0; i < listview_count_items( lv, 0 ); i++ ) {      if (fm_cmd == FM_ENCRYPT_ZIP)
901            fm_encrypt_into_zip (ctx, lv);
902    
903        for (i = 0; i < listview_count_items (lv, 0); i++) {
904          if( !listview_get_item_state( lv, i ) )          if( !listview_get_item_state( lv, i ) )
905              continue;              continue;
906          listview_get_item_text( lv, i, 1, fname, sizeof (fname) - 1 );          listview_get_item_text( lv, i, 1, fname, sizeof (fname) - 1 );
# Line 909  fm_parse_files (listview_ctrl_t lv, HWND Line 913  fm_parse_files (listview_ctrl_t lv, HWND
913          if( !fm_check_file_type( lv, i, fm_cmd ) )          if( !fm_check_file_type( lv, i, fm_cmd ) )
914              continue;              continue;
915          sig_detached = fm_check_detached_sig( lv, i );          sig_detached = fm_check_detached_sig( lv, i );
916          switch( fm_cmd ) {          switch (fm_cmd) {
917          case FM_LIST:        rc = fm_list( fname, dlg );       break;          case FM_LIST:        rc = fm_list( fname, dlg );       break;
918          case FM_WIPE:        rc = fm_wipe( fname );            break;          case FM_WIPE:        rc = fm_wipe( fname );            break;
919          case FM_ENCRYPT:     rc = fm_encrypt( ctx, fname, 0 ); break;          case FM_ENCRYPT:     rc = fm_encrypt( ctx, fname, 0 ); break;
# Line 935  fm_parse_files (listview_ctrl_t lv, HWND Line 939  fm_parse_files (listview_ctrl_t lv, HWND
939          free_if_alloc (ctx->output);          free_if_alloc (ctx->output);
940          progress_cleanup (&pfx);          progress_cleanup (&pfx);
941      }      }
942    
943      if (fm_cmd == FM_WIPE) {      if (fm_cmd == FM_WIPE) {
944          secure_unlink_set_cb (NULL, NULL);          secure_unlink_set_cb (NULL, NULL);
945          progress_cleanup (&pfx2);          progress_cleanup (&pfx2);
# Line 947  fm_parse_files (listview_ctrl_t lv, HWND Line 952  fm_parse_files (listview_ctrl_t lv, HWND
952      /* remove wipe files from the list */      /* remove wipe files from the list */
953      n = listview_count_items (lv, 0);      n = listview_count_items (lv, 0);
954      while (n--) {      while (n--) {
         char status[128];  
955          listview_get_item_text (lv, n, 0, status, sizeof (status) - 1);          listview_get_item_text (lv, n, 0, status, sizeof (status) - 1);
956          if( !strcmp (status, "WIPED"))          if (!strcmp (status, "WIPED"))
957              listview_del_item (lv, n);              listview_del_item (lv, n);
958      }      }
959            
# Line 993  ask_filename (fm_state_t c, const char * Line 997  ask_filename (fm_state_t c, const char *
997  {  {
998      const char * s;      const char * s;
999    
1000      s = get_filename_dlg (c->dlg, FILE_SAVE, msg, NULL, NULL);      s = get_filesave_dlg (c->dlg, msg, NULL, NULL);
1001      if (!s)      if (!s)
1002          return WPTERR_GENERAL;          return WPTERR_GENERAL;
1003    
# Line 1066  fm_encrypt (fm_state_t c, const char *na Line 1070  fm_encrypt (fm_state_t c, const char *na
1070              gpgme_signers_add (ctx, key);              gpgme_signers_add (ctx, key);
1071          }          }
1072          else {          else {
1073              gpgme_key_t key = gpgme_signers_enum (ctx, 0);              gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0);
1074              if (key && key->subkeys) {              if (sigkey && sigkey->subkeys) {
1075                  keyid = m_strdup (key->subkeys->keyid);                  keyid = m_strdup (sigkey->subkeys->keyid);
1076                  if (!keyid)                  if (!keyid)
1077                      BUG (NULL);                      BUG (NULL);
1078              }              }
# Line 1113  leave: Line 1117  leave:
1117          gpg_file_data_release (in);          gpg_file_data_release (in);
1118      if (out)      if (out)
1119          gpg_file_data_release (out);          gpg_file_data_release (out);
1120        free_if_alloc (keyid);
1121      if (!rc && c->wipe)      if (!rc && c->wipe)
1122          secure_unlink (name, WIPE_MODE_SIMPLE);          secure_unlink (name, WIPE_MODE_SIMPLE);
     free_if_alloc (keyid);  
1123      return rc;      return rc;
1124  }  }
1125    
# Line 1435  verify_pasted (listview_ctrl_t lv, fm_st Line 1439  verify_pasted (listview_ctrl_t lv, fm_st
1439      }      }
1440      fm_verify (ctx, 1, fname);      fm_verify (ctx, 1, fname);
1441      if (del_end)      if (del_end)
1442          unlink (fname);          remove (fname);
1443      free_if_alloc (fname);      free_if_alloc (fname);
1444      return 0;      return 0;
1445  }  }
# Line 1665  fm_export (fm_state_t c) Line 1669  fm_export (fm_state_t c)
1669          strcat (p, ".asc");          strcat (p, ".asc");
1670      }      }
1671    
1672      name = get_filename_dlg (c->dlg, FILE_SAVE, _("Choose Name for Key File"),      name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"),
1673                               NULL, p? p : NULL);                               NULL, p? p : NULL);
1674                                                            
1675      if (!name)      if (!name)
# Line 1754  fm_parse_command_line (char *cmdl) Line 1758  fm_parse_command_line (char *cmdl)
1758                  detached = 1;                  detached = 1;
1759              fm_verify (ctx, detached, fn);              fm_verify (ctx, detached, fn);
1760              file_verify_wait ();              file_verify_wait ();
1761              break;              break;
1762                
1763            default:
1764                break;
1765          }          }
1766      }      }
1767    
# Line 1775  default_dirname (const char *name) Line 1782  default_dirname (const char *name)
1782  } /* default_dirname */  } /* default_dirname */
1783    
1784    
1785    /* Store all selected files from @lv in a zip archive
1786       and encrypt the zip archive then.
1787       Return value: 0 on success. */
1788    int
1789    fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv)
1790    {
1791        PK_FILE_LIST list=NULL;
1792        const char *outfile;
1793        char *out_enc;
1794        int nitems = listview_count_items (lv, 0);
1795        int i, idx = -1;
1796        int rc;
1797    
1798        if (!nitems) {
1799            msg_box (NULL, _("Encrypting into a ZIP archive makes sense with multiple files"),
1800                     _("File Manager"), MB_ERR);
1801            return -1;
1802        }
1803    
1804        outfile = get_filesave_dlg (NULL, _("Choose File Name for Output"),
1805                                    NULL, "encrypted_files.zip");
1806        if (!outfile)
1807            return -1;
1808    
1809        for (i=0; i < nitems; i++) {
1810            char name[300];
1811            if (!listview_get_item_state (lv, i))
1812                continue;
1813            if (idx == -1)
1814                idx = i;
1815            listview_get_item_text (lv, i, 1, name, sizeof (name)-1);
1816            pk_list_add (&list, name);
1817        }    
1818    
1819        pk_archiv_create (list, outfile);
1820        pk_list_free (list);
1821    
1822        rc = fm_encrypt (ctx, outfile, 0);
1823        DeleteFile (outfile);
1824        if (rc)
1825            return rc;
1826    
1827        out_enc = make_filename (NULL, outfile, "gpg");
1828        fm_set_status (lv, idx, FM_ENCRYPT, 1, out_enc);
1829        free_if_alloc (out_enc);
1830    
1831        for (i=0; i < nitems; i++) {
1832            if (i != idx && listview_get_item_state (lv, i))
1833                listview_del_item (lv, i);
1834        }
1835        return 0;
1836    }
1837    
1838    
1839  int  int
1840  fm_encrypt_directory( fm_state_t c, const char * name )  fm_encrypt_directory( fm_state_t c, const char * name )
1841  {  {
# Line 1809  fm_encrypt_directory( fm_state_t c, cons Line 1870  fm_encrypt_directory( fm_state_t c, cons
1870              free_if_alloc( p );              free_if_alloc( p );
1871          }          }
1872      }      }
1873      s = get_filename_dlg( c->dlg, FILE_SAVE, _("Choose a Name for the Archive"),      s = get_filesave_dlg( c->dlg, _("Choose a Name for the Archive"),
1874                            NULL, default_dirname( name ) );                            NULL, default_dirname( name ) );
1875      if( !s ) {      if( !s ) {
1876          msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR );          msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR );
# Line 1822  fm_encrypt_directory( fm_state_t c, cons Line 1883  fm_encrypt_directory( fm_state_t c, cons
1883          msg_box( c->dlg, _("Could not create zip archive."), _("Encrypt Directory"), MB_ERR );          msg_box( c->dlg, _("Could not create zip archive."), _("Encrypt Directory"), MB_ERR );
1884      else {      else {
1885          fm_encrypt( c, s, 0 );          fm_encrypt( c, s, 0 );
1886          unlink( s );          remove( s );
1887      }      }
1888  leave:  leave:
1889      FindClose (hd);      FindClose (hd);
# Line 1871  fm_print_md( listview_ctrl_t lv, HWND dl Line 1932  fm_print_md( listview_ctrl_t lv, HWND dl
1932  } /* fm_print_md */  } /* fm_print_md */
1933    
1934    
1935    /* Send the selected file in @lv via MAPI to a mail recipient. */
1936  int  int
1937  fm_send_file (listview_ctrl_t lv)  fm_send_file (listview_ctrl_t lv)
1938  {  {
# Line 1878  fm_send_file (listview_ctrl_t lv) Line 1940  fm_send_file (listview_ctrl_t lv)
1940      int rc;      int rc;
1941    
1942      rc = listview_get_item_text (lv, -1, 1, buf, sizeof (buf)-1);      rc = listview_get_item_text (lv, -1, 1, buf, sizeof (buf)-1);
1943      if (rc == -1)      if (rc != -1)
1944          return 0;          mapi_send_ascfile (buf);
     /*mapi_send_ascfile (buf); XXX */  
1945      return 0;      return 0;
1946  }  }

Legend:
Removed from v.76  
changed lines
  Added in v.77

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26