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

Diff of /trunk/Src/wptMDSumDlg.cpp

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

revision 35 by twoaday, Mon Oct 24 08:03:48 2005 UTC revision 36 by werner, Thu Oct 27 15:25:13 2005 UTC
# Line 1  Line 1 
1  /* wptMDSumDlg.cpp  /* wptMDSumDlg.cpp
2   *      Copyright (C) 2003, 2005 Timo Schulz   *      Copyright (C) 2003, 2005 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
6   * WinPT is free software; you can redistribute it and/or modify   * WinPT is free software; you can redistribute it and/or modify
7   * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
8   * the Free Software Foundation; either version 2 of the License, or   * the Free Software Foundation; either version 2 of the License, or
9   * (at your option) any later version.   * (at your option) any later version.
10   *   *
11   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.   * GNU General Public License for more details.
15   *   *
16   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
20    
21    
22  #include <windows.h>  #ifdef HAVE_CONFIG_H
23  #include <stdio.h>  #include <config.h>
24  #include "../resource.h"  #endif
25    
26  #include "wptTypes.h"  #include <windows.h>
27  #include "wptW32API.h"  #include <windows.h>
28  #include "wptGPG.h"  #include <stdio.h>
29  #include "wptCommonCtl.h"  #include "../resource.h"
30  #include "wptContext.h"  
31  #include "wptNLS.h"  #include "wptTypes.h"
32  #include "wptErrors.h"  #include "wptW32API.h"
33    #include "wptGPG.h"
34    #include "wptCommonCtl.h"
35  /* Return a printable digest of the buffer @mdbuf. */  #include "wptContext.h"
36  static const char*  #include "wptNLS.h"
37  printable_digest (byte *mdbuf, size_t n)  #include "wptErrors.h"
38  {  
39      static char mdasc[64];  
40      size_t i;  /* Return a printable digest of the buffer @mdbuf. */
41      for (i = 0; i < n; i++)  static const char*
42          sprintf (mdasc+2*i, "%02X", mdbuf[i]);  printable_digest (byte *mdbuf, size_t n)
43      return mdasc;  {
44  }      static char mdasc[64];
45        size_t i;
46        for (i = 0; i < n; i++)
47  /* Dialog box procedure to show and calculate file digests. */          sprintf (mdasc+2*i, "%02X", mdbuf[i]);
48  BOOL CALLBACK      return mdasc;
49  mdsum_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  }
50  {  
51      static listview_ctrl_t lv;  
52      static struct md_file_s * md;  /* Dialog box procedure to show and calculate file digests. */
53      struct listview_column_s cols[] = {  BOOL CALLBACK
54          {0, 264, (char *)_("Digest")},  mdsum_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
55          {1, 128, (char *)_("Name")},  {
56          {0, 0, 0}      static listview_ctrl_t lv;
57      };      static struct md_file_s * md;
58      gpgme_data_t sumlist;      struct listview_column_s cols[] = {
59      char fname[300], mdasc[64];          {0, 264, (char *)_("Digest")},
60      byte mdbuf[20];          {1, 128, (char *)_("Name")},
61      int i;          {0, 0, 0}
62      size_t n;      };
63        gpgme_data_t sumlist;
64      switch( msg ) {      char fname[300], mdasc[64];
65      case WM_INITDIALOG:      byte mdbuf[20];
66          md = (md_file_s *)lparam;      int i;
67          if( !md )      size_t n;
68              BUG( NULL );          
69          if( listview_new( &lv ) )      switch( msg ) {
70              BUG( NULL );      case WM_INITDIALOG:
71          lv->ctrl = GetDlgItem( dlg, IDC_MDSUM_LIST );          md = (md_file_s *)lparam;
72          for( i = 0; i < cols[i].width; i++ )          if( !md )
73              listview_add_column( lv, &cols[i] );              BUG( NULL );        
74          for( i = 0; i < listview_count_items( md->lv, 0 ); i++ ) {          if( listview_new( &lv ) )
75              if( listview_get_item_state( md->lv, i ) ) {              BUG( NULL );
76                  listview_get_item_text( md->lv, i, 1, fname, sizeof (fname)-1 );          lv->ctrl = GetDlgItem( dlg, IDC_MDSUM_LIST );
77                  if( !gpg_md_hash_file( md->mdalgo, fname, mdbuf, &n ) ) {          for( i = 0; i < cols[i].width; i++ )
78                      listview_add_item( lv, "" );              listview_add_column( lv, &cols[i] );
79                      listview_add_sub_item( lv, 0, 0, printable_digest( mdbuf, n ) );          for( i = 0; i < listview_count_items( md->lv, 0 ); i++ ) {
80                      listview_add_sub_item( lv, 0, 1, fname );              if( listview_get_item_state( md->lv, i ) ) {
81                  }                  listview_get_item_text( md->lv, i, 1, fname, sizeof (fname)-1 );
82              }                  if( !gpg_md_hash_file( md->mdalgo, fname, mdbuf, &n ) ) {
83          }                      listview_add_item( lv, "" );
84          SetForegroundWindow( dlg );                      listview_add_sub_item( lv, 0, 0, printable_digest( mdbuf, n ) );
85          break;                      listview_add_sub_item( lv, 0, 1, fname );
86                    }
87      case WM_DESTROY:              }
88          if( lv ) {          }
89              listview_release( lv );          SetForegroundWindow( dlg );
90              lv = NULL;          break;
91          }  
92          break;      case WM_DESTROY:
93            if( lv ) {
94      case WM_COMMAND:              listview_release( lv );
95          switch (LOWORD (wparam)) {              lv = NULL;
96          case IDOK:          }
97              EndDialog (dlg, TRUE);          break;
98              break;  
99        case WM_COMMAND:
100          case IDC_MDSUM_COPY:          switch (LOWORD (wparam)) {
101              if (gpgme_data_new (&sumlist))          case IDOK:
102                  BUG(0);              EndDialog (dlg, TRUE);
103              if (md->mdalgo == 3) {/* rmd160 */              break;
104                  const char *s = "# warning rmd160sum is not yet available\r\n";  
105                  gpgme_data_write (sumlist, s, strlen (s));          case IDC_MDSUM_COPY:
106              }              if (gpgme_data_new (&sumlist))
107              for (i = 0; i < listview_count_items (lv, 0); i++) {                  BUG(0);
108                  listview_get_item_text (lv, i, 0, mdasc, DIM (mdasc)-1);              if (md->mdalgo == 3) {/* rmd160 */
109                  listview_get_item_text (lv, i, 1, fname, DIM (fname)-1);                  const char *s = "# warning rmd160sum is not yet available\r\n";
110                                    gpgme_data_write (sumlist, s, strlen (s));
111                  gpgme_data_write (sumlist, mdasc, strlen (mdasc));              }
112                  gpgme_data_write (sumlist, " ", 1);              for (i = 0; i < listview_count_items (lv, 0); i++) {
113                  gpgme_data_write (sumlist, fname, strlen (fname));                  listview_get_item_text (lv, i, 0, mdasc, DIM (mdasc)-1);
114                  gpgme_data_write (sumlist, "\r\n", 2);                  listview_get_item_text (lv, i, 1, fname, DIM (fname)-1);
115              }                  
116              const char *name = get_filename_dlg (dlg, 1, _("Select file to save checksums"), NULL, NULL);                  gpgme_data_write (sumlist, mdasc, strlen (mdasc));
117              if (name && *name) {                  gpgme_data_write (sumlist, " ", 1);
118                  gpg_data_release_and_set_file (sumlist, name);                  gpgme_data_write (sumlist, fname, strlen (fname));
119                  log_box (_("File Manager"), MB_OK, "Checksums successfully saved in '%s'", name);                  gpgme_data_write (sumlist, "\r\n", 2);
120              }              }
121              else              const char *name = get_filename_dlg (dlg, 1, _("Select file to save checksums"), NULL, NULL);
122                  gpgme_data_release (sumlist);              if (name && *name) {
123              break;                  gpg_data_release_and_set_file (sumlist, name);
124          }                  log_box (_("File Manager"), MB_OK, "Checksums successfully saved in '%s'", name);
125          break;              }
126      }              else
127      return FALSE;                  gpgme_data_release (sumlist);
128  }              break;
129            }
130            break;
131        }
132        return FALSE;
133    }

Legend:
Removed from v.35  
changed lines
  Added in v.36

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26