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

Annotation of /trunk/Src/wptMDSumDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 3642 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26