1 |
/* wptMDSumDlg.cpp |
/* wptMDSumDlg.cpp |
2 |
* Copyright (C) 2003, 2005 Timo Schulz |
* Copyright (C) 2003, 2005, 2006 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 |
|
#ifdef HAVE_CONFIG_H |
21 |
|
#include <config.h> |
22 |
#include <windows.h> |
#endif |
23 |
#include <stdio.h> |
|
24 |
#include "../resource.h" |
#include <windows.h> |
25 |
|
#include <stdio.h> |
26 |
#include "wptTypes.h" |
|
27 |
#include "wptW32API.h" |
#include "resource.h" |
28 |
#include "wptGPG.h" |
#include "wptTypes.h" |
29 |
#include "wptCommonCtl.h" |
#include "wptW32API.h" |
30 |
#include "wptContext.h" |
#include "wptGPG.h" |
31 |
#include "wptNLS.h" |
#include "wptCommonCtl.h" |
32 |
#include "wptErrors.h" |
#include "wptContext.h" |
33 |
|
#include "wptNLS.h" |
34 |
|
#include "wptErrors.h" |
35 |
/* Return a printable digest of the buffer @mdbuf. */ |
|
36 |
static const char* |
|
37 |
printable_digest (byte *mdbuf, size_t n) |
/* Symbolic column IDs. */ |
38 |
{ |
enum md_col_t {COL_MD=0, COL_NAME}; |
39 |
static char mdasc[64]; |
|
40 |
size_t i; |
|
41 |
for (i = 0; i < n; i++) |
/* Return a printable digest of the buffer @mdbuf. */ |
42 |
sprintf (mdasc+2*i, "%02X", mdbuf[i]); |
static const char* |
43 |
return mdasc; |
printable_digest (BYTE *mdbuf, size_t n) |
44 |
} |
{ |
45 |
|
static char mdasc[128]; |
46 |
|
size_t i; |
47 |
/* Dialog box procedure to show and calculate file digests. */ |
|
48 |
BOOL CALLBACK |
for (i = 0; i < n; i++) |
49 |
mdsum_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
sprintf (mdasc+2*i, "%02X", mdbuf[i]); |
50 |
{ |
return mdasc; |
51 |
static listview_ctrl_t lv; |
} |
52 |
static struct md_file_s * md; |
|
53 |
struct listview_column_s cols[] = { |
|
54 |
{0, 264, (char *)_("Digest")}, |
static const char* |
55 |
{1, 128, (char *)_("Name")}, |
id2algo (gpgme_hash_algo_t mdalgo) |
56 |
{0, 0, 0} |
{ |
57 |
}; |
switch (mdalgo) { |
58 |
gpgme_data_t sumlist; |
case GPGME_MD_MD5: return "MD5"; |
59 |
char fname[300], mdasc[64]; |
case GPGME_MD_SHA1: return "SHA1"; |
60 |
byte mdbuf[20]; |
case GPGME_MD_RMD160: return "RMD160"; |
61 |
int i; |
case GPGME_MD_SHA256: return "SHA256"; |
62 |
size_t n; |
default: break; |
63 |
|
} |
64 |
switch( msg ) { |
return ""; |
65 |
case WM_INITDIALOG: |
} |
66 |
md = (md_file_s *)lparam; |
|
67 |
if( !md ) |
|
68 |
BUG( NULL ); |
/* Hash the selected file from the FM listview control in @md. |
69 |
if( listview_new( &lv ) ) |
Add the results to the listview @lv. */ |
70 |
BUG( NULL ); |
static void |
71 |
lv->ctrl = GetDlgItem( dlg, IDC_MDSUM_LIST ); |
hash_selected_files (md_file_s *md, listview_ctrl_t lv) |
72 |
for( i = 0; i < cols[i].width; i++ ) |
{ |
73 |
listview_add_column( lv, &cols[i] ); |
BYTE mdbuf[32]; |
74 |
for( i = 0; i < listview_count_items( md->lv, 0 ); i++ ) { |
char fname[256+1]; |
75 |
if( listview_get_item_state( md->lv, i ) ) { |
int i; |
76 |
listview_get_item_text( md->lv, i, 1, fname, sizeof (fname)-1 ); |
size_t n; |
77 |
if( !gpg_md_hash_file( md->mdalgo, fname, mdbuf, &n ) ) { |
|
78 |
listview_add_item( lv, "" ); |
for (i = 0; i < listview_count_items (md->lv, 0); i++) { |
79 |
listview_add_sub_item( lv, 0, 0, printable_digest( mdbuf, n ) ); |
if (listview_get_item_state (md->lv, i)) { |
80 |
listview_add_sub_item( lv, 0, 1, fname ); |
listview_get_item_text (md->lv, i, 1, fname, sizeof (fname)-1); |
81 |
} |
if (!gpg_md_hash_file (md->mdalgo, fname, mdbuf, &n)) { |
82 |
} |
listview_add_item (lv, ""); |
83 |
} |
listview_add_sub_item (lv, 0, COL_MD, printable_digest (mdbuf, n)); |
84 |
SetForegroundWindow( dlg ); |
listview_add_sub_item (lv, 0, COL_NAME, fname); |
85 |
break; |
} |
86 |
|
} |
87 |
case WM_DESTROY: |
} |
88 |
if( lv ) { |
} |
89 |
listview_release( lv ); |
|
90 |
lv = NULL; |
|
91 |
} |
/* Return 1 if there is a tool available to check the file. |
92 |
break; |
(sha1sum, md5sum). */ |
93 |
|
static int |
94 |
case WM_COMMAND: |
tool_avail (gpgme_hash_algo_t mdalgo) |
95 |
switch (LOWORD (wparam)) { |
{ |
96 |
case IDOK: |
if (mdalgo == GPGME_MD_SHA1 || mdalgo == GPGME_MD_MD5) |
97 |
EndDialog (dlg, TRUE); |
return 1; |
98 |
break; |
return 0; |
99 |
|
} |
100 |
case IDC_MDSUM_COPY: |
|
101 |
if (gpgme_data_new (&sumlist)) |
|
102 |
BUG(0); |
|
103 |
if (md->mdalgo == 3) {/* rmd160 */ |
|
104 |
const char *s = "# warning rmd160sum is not yet available\r\n"; |
/* Dialog box procedure to show and calculate file digests. */ |
105 |
gpgme_data_write (sumlist, s, strlen (s)); |
BOOL CALLBACK |
106 |
} |
mdsum_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
107 |
for (i = 0; i < listview_count_items (lv, 0); i++) { |
{ |
108 |
listview_get_item_text (lv, i, 0, mdasc, DIM (mdasc)-1); |
static listview_ctrl_t lv; |
109 |
listview_get_item_text (lv, i, 1, fname, DIM (fname)-1); |
static struct md_file_s *md; |
110 |
|
struct listview_column_s cols[] = { |
111 |
gpgme_data_write (sumlist, mdasc, strlen (mdasc)); |
{0, 264, (char *)_("Digest")}, |
112 |
gpgme_data_write (sumlist, " ", 1); |
{1, 160, (char *)_("Name")}, |
113 |
gpgme_data_write (sumlist, fname, strlen (fname)); |
{0, 0, 0} |
114 |
gpgme_data_write (sumlist, "\r\n", 2); |
}; |
115 |
} |
gpgme_data_t sumlist; |
116 |
const char *name = get_filename_dlg (dlg, 1, _("Select file to save checksums"), NULL, NULL); |
const char *name, *algname; |
117 |
if (name && *name) { |
char fname[300], mdasc[128]; |
118 |
gpg_data_release_and_set_file (sumlist, name); |
int i; |
119 |
log_box (_("File Manager"), MB_OK, "Checksums successfully saved in '%s'", name); |
|
120 |
} |
switch (msg) { |
121 |
else |
case WM_INITDIALOG: |
122 |
gpgme_data_release (sumlist); |
md = (md_file_s *)lparam; |
123 |
break; |
if (!md) |
124 |
} |
BUG (NULL); |
125 |
break; |
listview_new (&lv, GetDlgItem (dlg, IDC_MDSUM_LIST)); |
126 |
} |
for (i = 0; i < cols[i].width; i++) |
127 |
return FALSE; |
listview_add_column (lv, &cols[i]); |
128 |
} |
hash_selected_files (md, lv); |
129 |
|
SetDlgItemText (dlg, IDC_MDSUM_COPY, _("&Save...")); |
130 |
|
SetDlgItemText (dlg, IDOK, _("&Close")); |
131 |
|
SetDlgItemText (dlg, IDC_MDSUM_TOCLIP, _("Save to clipboard")); |
132 |
|
SetWindowText (dlg, _("Print Message Digest")); |
133 |
|
SetForegroundWindow (dlg); |
134 |
|
break; |
135 |
|
|
136 |
|
case WM_DESTROY: |
137 |
|
if (lv) { |
138 |
|
listview_release (lv); |
139 |
|
lv = NULL; |
140 |
|
} |
141 |
|
break; |
142 |
|
|
143 |
|
case WM_COMMAND: |
144 |
|
switch (LOWORD (wparam)) { |
145 |
|
case IDOK: |
146 |
|
EndDialog (dlg, TRUE); |
147 |
|
break; |
148 |
|
|
149 |
|
case IDCANCEL: |
150 |
|
EndDialog (dlg, FALSE); |
151 |
|
break; |
152 |
|
|
153 |
|
case IDC_MDSUM_COPY: |
154 |
|
algname = id2algo ((gpgme_hash_algo_t)md->mdalgo); |
155 |
|
if (gpgme_data_new (&sumlist)) |
156 |
|
BUG(0); |
157 |
|
if (!tool_avail ((gpgme_hash_algo_t)md->mdalgo)) { |
158 |
|
const char *s; |
159 |
|
|
160 |
|
s = "#warning '"; |
161 |
|
gpgme_data_write (sumlist, s, strlen (s)); |
162 |
|
gpgme_data_write (sumlist, algname, strlen (algname)); |
163 |
|
s = " ' sum is not yet available\r\n"; |
164 |
|
gpgme_data_write (sumlist, s, strlen (s)); |
165 |
|
} |
166 |
|
for (i = 0; i < listview_count_items (lv, 0); i++) { |
167 |
|
listview_get_item_text (lv, i, COL_MD, mdasc, DIM (mdasc)-1); |
168 |
|
listview_get_item_text (lv, i, COL_NAME, fname, DIM (fname)-1); |
169 |
|
|
170 |
|
gpgme_data_write (sumlist, mdasc, strlen (mdasc)); |
171 |
|
gpgme_data_write (sumlist, " ", 1); |
172 |
|
gpgme_data_write (sumlist, fname, strlen (fname)); |
173 |
|
gpgme_data_write (sumlist, "\r\n", 2); |
174 |
|
} |
175 |
|
if (IsDlgButtonChecked (dlg, IDC_MDSUM_TOCLIP)) { |
176 |
|
gpg_data_release_and_set_clipboard (sumlist, 0); |
177 |
|
break; |
178 |
|
} |
179 |
|
_snprintf (fname, sizeof (fname)-1, "%s_sums.txt", algname); |
180 |
|
name = get_filesave_dlg (dlg, _("Select File to Save Checksums"), |
181 |
|
NULL, fname); |
182 |
|
if (name && *name) { |
183 |
|
gpg_data_release_and_set_file (sumlist, name); |
184 |
|
log_box (_("File Manager"), MB_OK, |
185 |
|
_("Checksums successfully saved in '%s'"), name); |
186 |
|
} |
187 |
|
else |
188 |
|
gpgme_data_release (sumlist); |
189 |
|
break; |
190 |
|
} |
191 |
|
break; |
192 |
|
} |
193 |
|
return FALSE; |
194 |
|
} |