1 |
twoaday |
2 |
/* wptMDSumDlg.cpp |
2 |
|
|
* Copyright (C) 2003 Timo Schulz |
3 |
|
|
* |
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 |
|
|
mdsum_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
48 |
|
|
{ |
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 |
|
|
char fname[300], mdasc[64], buf[128]; |
58 |
|
|
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 |
|
|
listview_get_item_text( md->lv, i, 1, fname, sizeof fname-1 ); |
75 |
|
|
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 |
|
|
switch( LOWORD( wparam ) ) { |
94 |
|
|
case IDOK: |
95 |
|
|
EndDialog( dlg, TRUE ); |
96 |
|
|
break; |
97 |
|
|
|
98 |
|
|
case IDC_MDSUM_COPY: |
99 |
|
|
if( gpgme_data_new( &sumlist ) ) |
100 |
|
|
BUG( NULL ); |
101 |
|
|
sprintf( buf, "--- begin %s digest list ---\r\n", |
102 |
|
|
md->mdalgo == 1? "MD5" : md->mdalgo == 2? "SHA-1" : |
103 |
|
|
md->mdalgo == 3? "RIPEMD160" : "UNKNOWN" ); |
104 |
|
|
gpgme_data_write( sumlist, buf, strlen( buf ) ); |
105 |
|
|
for( i = 0; i < listview_count_items( lv, 0 ); i++ ) { |
106 |
|
|
listview_get_item_text( lv, i, 0, mdasc, sizeof mdasc-1 ); |
107 |
|
|
listview_get_item_text( lv, i, 1, fname, sizeof fname-1 ); |
108 |
|
|
|
109 |
|
|
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 |
|
|
} |
114 |
|
|
gpgme_data_write( sumlist, "--- end digest list ---\r\n", 25 ); |
115 |
|
|
gpgme_data_release_and_set_clipboard( sumlist ); |
116 |
|
|
break; |
117 |
|
|
} |
118 |
|
|
break; |
119 |
|
|
} |
120 |
|
|
return FALSE; |
121 |
|
|
} /* mdsum_dlg_proc */ |