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

Annotation of /trunk/Src/wptMDSumDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 130 - (hide annotations)
Fri Dec 30 14:06:39 2005 UTC (19 years, 2 months ago) by twoaday
File size: 4291 byte(s)
2005-12-29  Timo Schulz  <ts@g10code.com>
  
        * wptKeygenDlg.cpp (keygen_dlg_proc): Request passphrase dynamically.
        (gpg_genkey_params): Simplified.
        * wptPreferencesDlg.cpp (prefs_dlg_proc): Fix problem with mutal
        exclusion of the dialog items.
        * wptAboutDlgs.cpp (about_winpt_dlg_proc): Allow to use ESC to
        quit the dialog.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Likewise.
        * wptMDSumDlg.cpp (mdsum_dlg_proc): Handle WM_SYSCOMMAND.
        (id2algo): New.

Prepare 0.11.4 release.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26