/[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 220 by twoaday, Tue May 30 15:31:49 2006 UTC revision 226 by twoaday, Mon Jun 12 13:40:21 2006 UTC
# Line 149  is_directory (const char *fname) Line 149  is_directory (const char *fname)
149  int  int
150  is_openpgp_ext (const char *name)  is_openpgp_ext (const char *name)
151  {  {
152      if (stristr (name, ".gpg") || stristr (name, ".asc")      if (stristr (name, ".gpg") ||
153          || stristr (name, ".sig") || stristr (name, ".pgp"))          stristr (name, ".asc") ||
154            stristr (name, ".sig") ||
155            stristr (name, ".pgp"))
156          return -1;          return -1;
157      return 0;      return 0;
158  }  }
# Line 438  fm_state_release (fm_state_t c) Line 440  fm_state_release (fm_state_t c)
440  }  }
441    
442    
443    /* Check if file @file is already in the list (view). */
444  static int  static int
445  fm_check_for_entry( listview_ctrl_t lv, const char *file )  fm_check_for_entry (listview_ctrl_t lv, const char *file)
446  {  {
447      char name[512];      char name[512];
448      int i;      int i;
449    
450      memset (name, 0, sizeof (name));      memset (name, 0, sizeof (name));
451      for (i = 0; i < listview_count_items( lv, 0 ); i++) {      for (i = 0; i < listview_count_items (lv, 0); i++) {
452          listview_get_item_text( lv, i, 1, name, sizeof (name) - 1 );          listview_get_item_text (lv, i, FM_COL_NAME, name, sizeof (name) - 1);
453          if( !strcmp( name, file ) )          if (!strcmp( name, file))
454              return 1; /* found */                    return 1; /* found */      
455      }      }
456    
# Line 470  fm_set_ftype (listview_ctrl_t lv, const Line 473  fm_set_ftype (listview_ctrl_t lv, const
473      rc = listview_add_item (lv, " ");      rc = listview_add_item (lv, " ");
474      if (rc)      if (rc)
475          return -1;          return -1;
476      listview_add_sub_item (lv, 0, 0, type);      listview_add_sub_item (lv, 0, FM_COL_STAT, type);
477      listview_add_sub_item (lv, 0, 1, name);      listview_add_sub_item (lv, 0, FM_COL_NAME, name);
478      return 0;      return 0;
479  }  }
480    
# Line 481  static int Line 484  static int
484  fm_add_dir_files (listview_ctrl_t lv, char *path)  fm_add_dir_files (listview_ctrl_t lv, char *path)
485  {  {
486      struct _finddata_t fd;      struct _finddata_t fd;
487      char * p;      char *p;
488      long hd;      long hd;
489    
490      strcat (path, "\\*");      strcat (path, "\\*");
491      hd = _findfirst (path, &fd);      hd = _findfirst (path, &fd);
492      do {      do {
493          p = new char [(strlen (path) + strlen (fd.name))+1];          p = new char [strlen (path) + strlen (fd.name)+1];
494          if (!p)          if (!p)
495              BUG (0);              BUG (0);
496          memcpy (p, path, strlen (path)-1);          memcpy (p, path, strlen (path)-1);
# Line 544  add_single_file (listview_ctrl_t lv, con Line 547  add_single_file (listview_ctrl_t lv, con
547          type = gnupg_check_file_ext (name, NULL);          type = gnupg_check_file_ext (name, NULL);
548      rc = listview_add_item (lv, "");      rc = listview_add_item (lv, "");
549      if (!rc) {      if (!rc) {
550          listview_add_sub_item (lv, 0, 0, type);          listview_add_sub_item (lv, 0, FM_COL_STAT, type);
551          listview_add_sub_item (lv, 0, 1, name);          listview_add_sub_item (lv, 0, FM_COL_NAME, name);
552      }      }
553      return rc;      return rc;
554  }  }
# Line 577  fm_add_opened_files (listview_ctrl_t lv, Line 580  fm_add_opened_files (listview_ctrl_t lv,
580      if (!GetOpenFileName (&open))      if (!GetOpenFileName (&open))
581          return 0;          return 0;
582    
583        /* It is possible that multiple files are returned
584           and then they are separated by \0 chars. */
585      s = file;      s = file;
586      len = sizeof (file)-1;      len = sizeof (file)-1;
587      for (;;) {      for (;;) {
# Line 591  fm_add_opened_files (listview_ctrl_t lv, Line 596  fm_add_opened_files (listview_ctrl_t lv,
596              name[i] = *s++;              name[i] = *s++;
597          }          }
598          if (n == 0)          if (n == 0)
599              path = strdup (name);              path = m_strdup (name);
600          else {          else {
601              char *p = make_filename (path, name, NULL);              char *p = make_filename (path, name, NULL);
602              rc = add_single_file (lv, p);              rc = add_single_file (lv, p);
603              safe_free (p);              free_if_alloc (p);
604          }          }
605          n++;          n++;
606      }      }
607      if (n == 1) /* single file selected. */      if (n == 1) /* single file selected. */
608          rc = add_single_file (lv, path);          rc = add_single_file (lv, path);
609      safe_free (path);      free_if_alloc (path);
610      return rc;      return rc;
611  }  }
612    
# Line 636  fm_assume_onepass_sig (const char *fname Line 641  fm_assume_onepass_sig (const char *fname
641              check = 1;                check = 1;  
642          gpg_free_packet (pkt);          gpg_free_packet (pkt);
643          gpg_iobuf_close (fp);          gpg_iobuf_close (fp);
644          remove (tmpfile);          DeleteFile (tmpfile);
645      }      }
646      /* XXX: implement it for real files */      /* XXX: implement it for real files */
647      safe_free (pkt);      safe_free (pkt);
# Line 698  fm_check_file_type (listview_ctrl_t lv, Line 703  fm_check_file_type (listview_ctrl_t lv,
703          break;          break;
704                    
705      case FM_DECRYPT:      case FM_DECRYPT:
706          if (!strcmp (status, "DATA")          if (!strcmp (status, "DATA") ||
707              || !strcmp (status, "ENCRYPTED")              !strcmp (status, "ENCRYPTED") ||
708              || !strcmp (status, "SYMKEYENC")              !strcmp (status, "SYMKEYENC") ||
709              || !strcmp (status, "ARMORED"))              !strcmp (status, "ARMORED"))
710              rc = 1;              rc = 1;
711          break;          break;
712                    
# Line 790  fm_clearsign_8bit (listview_ctrl_t lv, f Line 795  fm_clearsign_8bit (listview_ctrl_t lv, f
795    
796      if (ctx->sigmode != GPGME_SIG_MODE_CLEAR)      if (ctx->sigmode != GPGME_SIG_MODE_CLEAR)
797          return 0;          return 0;
798      listview_get_item_text (lv, -1, 1, name, sizeof (name)-1);      listview_get_item_text (lv, -1, FM_COL_NAME, name, sizeof (name)-1);
799      if (stristr (name, ".TXT"))      if (stristr (name, ".TXT"))
800          return 0;          return 0;
801      f = fopen (name, "rb");      f = fopen (name, "rb");
802      if (!f)      if (!f)
803          return -1; /* should never happen */          return -1; /* should never happen */
804      n = fread (buf, 1, 32, f);      n = fread (buf, 1, 32, f);
805        fclose (f);
806      for (i = 0; i < n; i++) {      for (i = 0; i < n; i++) {
807          if (buf[i] == 0x00 || buf[i] > 170)          if (buf[i] == 0x00 || buf[i] > 170)
808              cnt++;              cnt++;
809      }      }
     fclose (f);  
810      if (!cnt)      if (!cnt)
811          return 0;          return 0;
812      n = -1;      n = -1;
# Line 1013  fm_list (const char *name, HWND dlg) Line 1018  fm_list (const char *name, HWND dlg)
1018  static int  static int
1019  ask_filename (fm_state_t c, const char *msg, char **dst)  ask_filename (fm_state_t c, const char *msg, char **dst)
1020  {  {
1021      const char * s;      const char *s;
1022    
1023      s = get_filesave_dlg (c->dlg, msg, NULL, NULL);      s = get_filesave_dlg (c->dlg, msg, NULL, NULL);
1024      if (!s)      if (!s)
# Line 1048  fm_encrypt (fm_state_t c, const char *na Line 1053  fm_encrypt (fm_state_t c, const char *na
1053      strcat (c->output, ext);      strcat (c->output, ext);
1054            
1055      if (!overwrite_file (c->output)) {      if (!overwrite_file (c->output)) {
1056          rc = ask_filename (c, _("Enter filename for encrypted file"), NULL);          rc = ask_filename (c, _("Enter Filename for Encrypted File"), NULL);
1057          if (rc)          if (rc)
1058              goto leave;              goto leave;
1059      }      }
# Line 1146  fm_sym_encrypt (fm_state_t c, const char Line 1151  fm_sym_encrypt (fm_state_t c, const char
1151      gpgme_error_t err;          gpgme_error_t err;    
1152      file_data_t in=NULL, out=NULL;      file_data_t in=NULL, out=NULL;
1153      int rc = 0, cancel = 0;      int rc = 0, cancel = 0;
1154      char ext[5], * pass;          char ext[5], *pass;    
1155            
1156      pass = request_passphrase2 (_("Symmetric"), 0, &cancel);      pass = request_passphrase2 (_("Symmetric Encryption"), 0, &cancel);
1157      if (cancel) {      if (cancel) {
1158          c->cancel = 1;          c->cancel = 1;
1159          return 0;          return 0;
1160      }      }
1161            
1162      /* XXX gpgme_control (ctx, GPGME_CTRL_CIPHER, -1);*/      /* XXX: a convenient feature could be to select the preferred
1163                symmetric algorithm. */
1164      c->output = new char[strlen (name) + 5 + 1];      c->output = new char[strlen (name) + 5 + 1];
1165      if (!c->output)      if (!c->output)
1166          BUG (0);          BUG (0);
# Line 1167  fm_sym_encrypt (fm_state_t c, const char Line 1173  fm_sym_encrypt (fm_state_t c, const char
1173          goto leave;              goto leave;    
1174      }      }
1175    
1176      gpgme_set_passphrase_cb (ctx, sym_passphrase_cb, pass);          gpgme_set_passphrase_cb (ctx, sym_passphrase_cb, pass);
   
1177      err = gpg_file_data_new (name, 1, &in);      err = gpg_file_data_new (name, 1, &in);
1178      if (err)      if (err)
1179          goto leave;          goto leave;
# Line 1286  fm_decrypt (fm_state_t c, const char *na Line 1291  fm_decrypt (fm_state_t c, const char *na
1291      }      }
1292    
1293      if (overwrite_file (c->output) == 0) {      if (overwrite_file (c->output) == 0) {
1294          rc = ask_filename (c, _("Please enter filename for plaintext file"), NULL);          rc = ask_filename (c, _("Enter Filename for Plaintext File"), NULL);
1295          if (rc)          if (rc)
1296              goto leave;              goto leave;
1297      }      }
# Line 1397  fm_sign (fm_state_t c, const char * name Line 1402  fm_sign (fm_state_t c, const char * name
1402      strcat (c->output, ext);      strcat (c->output, ext);
1403            
1404      if (!overwrite_file (c->output)) {      if (!overwrite_file (c->output)) {
1405          rc = ask_filename (c, _("Enter filename for signed file"), NULL);          rc = ask_filename (c, _("Enter Filename for Signed File"), NULL);
1406          if (rc)          if (rc)
1407              goto leave;              goto leave;
1408      }      }
# Line 1462  verify_pasted (listview_ctrl_t lv, fm_st Line 1467  verify_pasted (listview_ctrl_t lv, fm_st
1467      char file[256], *fname = NULL;      char file[256], *fname = NULL;
1468      int del_end = 0;      int del_end = 0;
1469    
1470      listview_get_item_text (lv, pos, 0, stat, sizeof (stat)-1);      listview_get_item_text (lv, pos, FM_COL_STAT, stat, sizeof (stat)-1);
1471      listview_get_item_text (lv, pos, 1, file, sizeof (file)-1);      listview_get_item_text (lv, pos, FM_COL_NAME, file, sizeof (file)-1);
1472      if (strcmp (stat, "UNKNOWN"))      if (strcmp (stat, "UNKNOWN"))
1473          return 0;          return 0;
1474      fname = make_filename (NULL, file, "asc");      fname = make_filename (NULL, file, "asc");
1475      if (file_exist_check (fname) != 0) {      if (file_exist_check (fname) != 0) {
1476          fp = fopen (fname, "wb");          fp = fopen (fname, "wb");
1477          if (fp == NULL) {          if (fp == NULL) {
1478              log_box (_("File Manager"), MB_ERR, "could not create '%s'", fname);              log_box (_("File Manager"), MB_ERR, "Could not create '%s'", fname);
1479              free_if_alloc (fname);              free_if_alloc (fname);
1480              return WPTERR_GENERAL;              return WPTERR_GENERAL;
1481          }          }
# Line 1480  verify_pasted (listview_ctrl_t lv, fm_st Line 1485  verify_pasted (listview_ctrl_t lv, fm_st
1485      }      }
1486      fm_verify (ctx, 1, fname);      fm_verify (ctx, 1, fname);
1487      if (del_end)      if (del_end)
1488          remove (fname);          DeleteFile (fname);
1489      free_if_alloc (fname);      free_if_alloc (fname);
1490      return 0;      return 0;
1491  }  }
# Line 1537  get_output_file (fm_state_t c, const cha Line 1542  get_output_file (fm_state_t c, const cha
1542      else      else
1543          title = _("Selected Output File");          title = _("Selected Output File");
1544    
1545      if (stristr (name, ".sig") ||      if (is_openpgp_ext (name)) {
         stristr (name, ".asc") ||  
         stristr (name, ".gpg") ||  
         stristr (name, ".pgp")) {  
1546          _snprintf (fname, sizeof (fname) - 1, "%s", name);          _snprintf (fname, sizeof (fname) - 1, "%s", name);
1547          fname[strlen (fname) - 4] = '\0';          fname[strlen (fname) - 4] = '\0';
1548          if (file_exist_check (fname) == 0 && detached)            if (file_exist_check (fname) == 0 && detached)  
# Line 1696  fm_export (fm_state_t c) Line 1698  fm_export (fm_state_t c)
1698      int rc = 0;      int rc = 0;
1699    
1700      if (!rset || !rset[0]) {      if (!rset || !rset[0]) {
1701          msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR);          msg_box (c->dlg, _("No key was selected for export."),
1702                     _("Export"), MB_ERR);
1703          rc = WPTERR_GENERAL;          rc = WPTERR_GENERAL;
1704          goto leave;          goto leave;
1705      }      }
# Line 1876  fm_encrypt_directory (fm_state_t c, cons Line 1879  fm_encrypt_directory (fm_state_t c, cons
1879      PK_FILE_LIST list = NULL;      PK_FILE_LIST list = NULL;
1880      WIN32_FIND_DATA findbuf;      WIN32_FIND_DATA findbuf;
1881      HANDLE hd;      HANDLE hd;
1882      const char * s;      const char *s;
1883      char * patt = NULL, * p;      char *patt = NULL, *p;
1884      int rc = 0;      int rc = 0;
1885            
1886      if (!is_directory (name))      if (!is_directory (name))
# Line 1892  fm_encrypt_directory (fm_state_t c, cons Line 1895  fm_encrypt_directory (fm_state_t c, cons
1895          free_if_alloc (patt);          free_if_alloc (patt);
1896          return WPTERR_GENERAL;          return WPTERR_GENERAL;
1897      }      }
1898      if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) {      if (strcmp (findbuf.cFileName, ".") && strcmp (findbuf.cFileName, "..")) {
1899          p = make_filename( name, findbuf.cFileName, NULL );          p = make_filename (name, findbuf.cFileName, NULL);
1900          pk_list_add( &list, p );          pk_list_add (&list, p);
1901          free_if_alloc( p );          free_if_alloc (p);
1902      }      }
1903      while( FindNextFile( hd, &findbuf ) ) {      while( FindNextFile( hd, &findbuf ) ) {
1904          if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) {          if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) {
# Line 1907  fm_encrypt_directory (fm_state_t c, cons Line 1910  fm_encrypt_directory (fm_state_t c, cons
1910      s = get_filesave_dlg (c->dlg, _("Choose a Name for the Archive"),      s = get_filesave_dlg (c->dlg, _("Choose a Name for the Archive"),
1911                            NULL, default_dirname (name));                            NULL, default_dirname (name));
1912      if( !s ) {      if( !s ) {
1913          msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR );          msg_box (c->dlg, _("Invalid archive name. Exit."),
1914                     _("Encrypt Directory"), MB_ERR);
1915          rc = -1;          rc = -1;
1916          goto leave;          goto leave;
1917      }      }
1918    
1919      rc = pk_archiv_create( list, s );      rc = pk_archiv_create (list, s);
1920      if( rc )      if( rc )
1921          msg_box( c->dlg, _("Could not create zip archive."), _("Encrypt Directory"), MB_ERR );          msg_box (c->dlg, _("Could not create zip archive."),
1922                     _("Encrypt Directory"), MB_ERR);
1923      else {      else {
1924          fm_encrypt( c, s, 0 );          fm_encrypt (c, s, 0);
1925          remove( s );          DeleteFile (s);
1926      }      }
1927  leave:  leave:
1928      FindClose (hd);      FindClose (hd);
1929      pk_list_free( list );      pk_list_free (list);
1930      free_if_alloc( patt );      free_if_alloc (patt);
1931      return rc;      return rc;
1932  }  }
1933    
# Line 1930  leave: Line 1935  leave:
1935  static int CALLBACK  static int CALLBACK
1936  fm_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)  fm_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)
1937  {  {
1938      const char *a = 0;      const char *a = "";
1939      const char *b = 0;      const char *b = "";
1940    
1941      switch ((int)sortby) {      switch ((int)sortby) {
1942      case FM_SORT_STAT:      case FM_SORT_STAT:

Legend:
Removed from v.220  
changed lines
  Added in v.226

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26