22 |
* check_armor_type: we should check the whole file and not only the first line! |
* check_armor_type: we should check the whole file and not only the first line! |
23 |
*/ |
*/ |
24 |
|
|
|
#ifdef HAVE_CONFIG_H |
|
|
#include <config.h> |
|
|
#endif |
|
|
|
|
|
#include <sys/types.h> |
|
25 |
#include <sys/types.h> |
#include <sys/types.h> |
26 |
#include <windows.h> |
#include <windows.h> |
27 |
#include <commdlg.h> |
#include <commdlg.h> |
28 |
#include <io.h> |
#include <io.h> |
29 |
|
#include <stdio.h> |
30 |
|
|
31 |
#include "../resource.h" |
#include "../resource.h" |
32 |
#include "wptTypes.h" |
#include "wptTypes.h" |
69 |
|
|
70 |
|
|
71 |
/* Check if the drive given by @fname is a floppy disc. |
/* Check if the drive given by @fname is a floppy disc. |
72 |
Return value: 1 for success. */ |
Return value: -1 for success. */ |
73 |
static int |
static int |
74 |
is_floppy_disc (const char * fname) |
is_floppy_disc (const char *fname) |
75 |
{ |
{ |
76 |
char drv[32] = {0}; |
char drv[32] = {0}; |
77 |
|
int max = sizeof (drv)-1; |
78 |
int i=0; |
int i=0; |
79 |
|
|
80 |
if (!strstr (fname, ":\\")) |
if (!strstr (fname, ":\\")) |
81 |
return 0; |
return 0; |
82 |
|
|
83 |
while (fname && *fname && *fname != '\\') |
while (fname && *fname && *fname != '\\' && i < max) |
84 |
drv[i++] = *fname++; |
drv[i++] = *fname++; |
85 |
drv[i++] = '\\'; |
drv[i++] = '\\'; |
86 |
drv[i++] = '\0'; |
drv[i++] = '\0'; |
93 |
|
|
94 |
/* Ask the user to overwrite file @fname. |
/* Ask the user to overwrite file @fname. |
95 |
Return value: 0 for cancel. */ |
Return value: 0 for cancel. */ |
96 |
int |
static int |
97 |
overwrite_file (const char *fname) |
overwrite_file (const char *fname) |
98 |
{ |
{ |
99 |
int id; |
int id; |
112 |
static void |
static void |
113 |
remove_crit_file_attrs (const char *fname, int force) |
remove_crit_file_attrs (const char *fname, int force) |
114 |
{ |
{ |
115 |
u32 f_attr; |
u32 fattr; |
116 |
int id; |
int id = 0; |
117 |
|
|
118 |
if (file_exist_check (fname)) |
if (file_exist_check (fname)) |
119 |
return; /* Does not exist */ |
return; /* Does not exist */ |
120 |
|
|
121 |
f_attr = GetFileAttributes (fname); |
fattr = GetFileAttributes (fname); |
122 |
if ((f_attr & FILE_ATTRIBUTE_READONLY) && force) |
if ((fattr & FILE_ATTRIBUTE_READONLY) && force) |
123 |
SetFileAttributes (fname, FILE_ATTRIBUTE_NORMAL); |
id = IDYES; |
124 |
else if (f_attr & FILE_ATTRIBUTE_READONLY) { |
else if (fattr & FILE_ATTRIBUTE_READONLY) |
125 |
id = log_box (_("File Manager"), MB_YESNO, |
id = log_box (_("File Manager"), MB_YESNO, |
126 |
_("\"%s\" has read-only attribute.\n" |
_("\"%s\" has read-only attribute.\n" |
127 |
"Set attribute to normal?"), fname); |
"Set attribute to normal?"), fname); |
128 |
if (id == IDYES) |
if (id == IDYES) { |
129 |
SetFileAttributes (fname, FILE_ATTRIBUTE_NORMAL); |
if (!SetFileAttributes (fname, FILE_ATTRIBUTE_NORMAL)) |
130 |
|
msg_box (NULL, _("Could not reset file attribute to normal."), |
131 |
|
_("File Manager"), MB_ERR); |
132 |
} |
} |
133 |
} |
} |
134 |
|
|
135 |
|
|
136 |
static int inline |
/* Return 1 if the given path @fname is a directory, 0 otherwise. */ |
137 |
|
static int |
138 |
is_directory (const char *fname) |
is_directory (const char *fname) |
139 |
{ |
{ |
140 |
return GetFileAttributes (fname) & FILE_ATTRIBUTE_DIRECTORY? 1 : 0; |
return GetFileAttributes (fname) & FILE_ATTRIBUTE_DIRECTORY? 1 : 0; |
141 |
} |
} |
142 |
|
|
143 |
|
|
144 |
static int inline |
/* Return -1 if the given name @name is a valid PGP extension. */ |
145 |
|
static int |
146 |
is_openpgp_ext (const char *name) |
is_openpgp_ext (const char *name) |
147 |
{ |
{ |
148 |
if (strstr (name, ".gpg") || strstr (name, ".asc") |
if (stristr (name, ".gpg") || stristr (name, ".asc") |
149 |
|| strstr (name, ".sig") || strstr (name, ".pgp")) |
|| stristr (name, ".sig") || stristr (name, ".pgp")) |
150 |
return -1; |
return -1; |
151 |
return 0; |
return 0; |
152 |
} |
} |
178 |
p = strrchr (name, '.'); |
p = strrchr (name, '.'); |
179 |
if (!p) |
if (!p) |
180 |
return 0; |
return 0; |
181 |
for (i=0; (val = mm_files[i]); i++) |
for (i=0; (val = mm_files[i]); i++) { |
|
{ |
|
182 |
if (!stricmp (p, val)) |
if (!stricmp (p, val)) |
183 |
return -1; |
return -1; |
184 |
} |
} |
186 |
} |
} |
187 |
|
|
188 |
|
|
189 |
|
/* Return a GPG file extension which depends on the operation |
190 |
|
mode in @ctx and the sig mode @sigmode. */ |
191 |
const char* |
const char* |
192 |
file_get_extension (gpgme_ctx_t ctx, gpgme_sig_mode_t sigmode) |
file_get_extension (gpgme_ctx_t ctx, gpgme_sig_mode_t sigmode) |
193 |
{ |
{ |
201 |
} |
} |
202 |
|
|
203 |
|
|
204 |
|
/* Quote a file to avoid shell problems with spaces in the files. */ |
205 |
char* |
char* |
206 |
fm_quote_file (const char * name) |
fm_quote_file (const char * name) |
207 |
{ |
{ |
216 |
_snprintf (p, len, "\"%s\"", name); |
_snprintf (p, len, "\"%s\"", name); |
217 |
|
|
218 |
return p; |
return p; |
219 |
} /* fm_quote_file */ |
} |
220 |
|
|
221 |
|
|
222 |
|
|
274 |
{ |
{ |
275 |
gpg_iobuf_t inp; |
gpg_iobuf_t inp; |
276 |
armor_filter_context_t afx; |
armor_filter_context_t afx; |
277 |
PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt); |
PACKET *pkt; |
|
int i = 0, rc = 0; |
|
278 |
const char *s = NULL; |
const char *s = NULL; |
279 |
|
int i = 0, rc = 0; |
280 |
|
|
281 |
if (r_type) |
if (r_type) |
282 |
*r_type = PGP_NONE; |
*r_type = PGP_NONE; |
283 |
if (!fname) { |
if (!fname) { |
284 |
safe_free (pkt); |
log_debug ("fm_get_file_type: !fname\r\n"); |
285 |
return NULL; |
return NULL; |
286 |
} |
} |
287 |
|
|
291 |
inp = gpg_iobuf_open (fname); |
inp = gpg_iobuf_open (fname); |
292 |
if (!inp) { |
if (!inp) { |
293 |
const char *s = winpt_strerror (WPTERR_FILE_OPEN); |
const char *s = winpt_strerror (WPTERR_FILE_OPEN); |
294 |
log_box( _("File Manager"), MB_ERR, "\"%s\": %s", fname, s ); |
log_box (_("File Manager"), MB_ERR, "\"%s\": %s", fname, s); |
|
safe_free( pkt ); |
|
295 |
return NULL; |
return NULL; |
296 |
} |
} |
297 |
gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */ |
gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */ |
305 |
memset (&afx, 0, sizeof (afx)); |
memset (&afx, 0, sizeof (afx)); |
306 |
gpg_iobuf_push_filter (inp, gpg_armor_filter, &afx); |
gpg_iobuf_push_filter (inp, gpg_armor_filter, &afx); |
307 |
} |
} |
308 |
|
pkt = (PACKET *)calloc (1, sizeof *pkt); |
309 |
|
if (!pkt) |
310 |
|
BUG (NULL); |
311 |
gpg_init_packet (pkt); |
gpg_init_packet (pkt); |
312 |
while (!(rc = gpg_parse_packet (inp, pkt))) { |
while (!(rc = gpg_parse_packet (inp, pkt))) { |
313 |
switch (pkt->pkttype) { |
switch (pkt->pkttype) { |
398 |
c = new fm_state_s; |
c = new fm_state_s; |
399 |
if (!c) |
if (!c) |
400 |
BUG (0); |
BUG (0); |
401 |
memset (c, 0, sizeof * c); |
memset (c, 0, sizeof *c); |
402 |
rc = gpgme_new (&c->ctx); |
rc = gpgme_new (&c->ctx); |
403 |
if (rc) |
if (rc) |
404 |
BUG (0); |
BUG (0); |
433 |
int i; |
int i; |
434 |
|
|
435 |
memset (name, 0, sizeof (name)); |
memset (name, 0, sizeof (name)); |
436 |
for( i = 0; i < listview_count_items( lv, 0 ); i++ ) |
for (i = 0; i < listview_count_items( lv, 0 ); i++) { |
|
{ |
|
437 |
listview_get_item_text( lv, i, 1, name, sizeof (name) - 1 ); |
listview_get_item_text( lv, i, 1, name, sizeof (name) - 1 ); |
438 |
if( !strcmp( name, file ) ) |
if( !strcmp( name, file ) ) |
439 |
return 1; /* found */ |
return 1; /* found */ |
483 |
if (!is_directory (p)) |
if (!is_directory (p)) |
484 |
fm_set_ftype (lv, p); |
fm_set_ftype (lv, p); |
485 |
free_if_alloc (p); |
free_if_alloc (p); |
|
|
|
486 |
} while (_findnext (hd, &fd) == 0); |
} while (_findnext (hd, &fd) == 0); |
487 |
_findclose (hd); |
_findclose (hd); |
488 |
return 0; |
return 0; |
506 |
else |
else |
507 |
rc = fm_set_ftype (lv, name); |
rc = fm_set_ftype (lv, name); |
508 |
if (rc == -1) |
if (rc == -1) |
509 |
break; |
break; /* XXX: fixme? */ |
510 |
} |
} |
511 |
return rc; |
return rc; |
512 |
} |
} |
513 |
|
|
514 |
|
|
515 |
|
/* Add a single file @name to the list view and before |
516 |
|
figure out the type of it. |
517 |
|
Return value: 0 on success. */ |
518 |
|
static int |
519 |
|
add_single_file (listview_ctrl_t lv, const char *name) |
520 |
|
{ |
521 |
|
const char *type; |
522 |
|
int rc = 0; |
523 |
|
|
524 |
|
type = fm_get_file_type (name, NULL); |
525 |
|
if (!type) |
526 |
|
return WPTERR_FILE_OPEN; |
527 |
|
if (!strcmp (type, "UNKNOWN")) |
528 |
|
type = gnupg_check_file_ext (name, NULL); |
529 |
|
rc = listview_add_item (lv, ""); |
530 |
|
if (!rc) { |
531 |
|
listview_add_sub_item (lv, 0, 0, type); |
532 |
|
listview_add_sub_item (lv, 0, 1, name); |
533 |
|
} |
534 |
|
return rc; |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
|
/* Use the common Open-File-Dialog to allow the user to |
539 |
|
add one ore more selected files to the listview @lv. */ |
540 |
int |
int |
541 |
fm_add_opened_files (listview_ctrl_t lv, HWND dlg) |
fm_add_opened_files (listview_ctrl_t lv, HWND dlg) |
542 |
{ |
{ |
543 |
OPENFILENAME open; |
OPENFILENAME open; |
544 |
const char *type; |
char file[512], name[MAX_PATH+1]; |
545 |
char file[512] = ""; |
char *path = NULL; |
546 |
int rc; |
const char *s; |
547 |
|
int i, len=0, n=0; |
548 |
/* XXX: support to add multiple files. */ |
int rc=0; |
549 |
|
|
550 |
memset (&open, 0, sizeof (open)); |
memset (&open, 0, sizeof (open)); |
551 |
open.lStructSize = sizeof (OPENFILENAME); |
open.lStructSize = sizeof (OPENFILENAME); |
552 |
open.hInstance = glob_hinst; |
open.hInstance = glob_hinst; |
555 |
open.hwndOwner = dlg; |
open.hwndOwner = dlg; |
556 |
open.lpstrFile = file; |
open.lpstrFile = file; |
557 |
open.nMaxFile = sizeof (file) - 1; |
open.nMaxFile = sizeof (file) - 1; |
558 |
open.Flags = 0; |
open.Flags = OFN_ALLOWMULTISELECT|OFN_EXPLORER ; |
559 |
|
|
560 |
if (GetOpenFileName (&open)) { |
memset (file, 0, sizeof file); |
561 |
type = fm_get_file_type (open.lpstrFile, NULL); |
if (!GetOpenFileName (&open)) |
562 |
if (!type) |
return 0; |
563 |
return WPTERR_FILE_OPEN; |
|
564 |
if (!strcmp (type, "UNKNOWN")) |
s = file; |
565 |
type = gnupg_check_file_ext (open.lpstrFile, NULL); |
len = sizeof (file)-1; |
566 |
rc = listview_add_item (lv, ""); |
for (;;) { |
567 |
if (!rc) { |
if (len < 2 || (*s == '\0' && *(s+1) == '\0')) |
568 |
listview_add_sub_item (lv, 0, 0, type); |
break; |
569 |
listview_add_sub_item (lv, 0, 1, open.lpstrFile); |
memset (name, 0, sizeof (name)); |
570 |
} |
for (i=0; len > 0; len--, i++) { |
571 |
|
if (*s == '\0') { |
572 |
|
name[i] = *s++; |
573 |
|
break; |
574 |
|
} |
575 |
|
name[i] = *s++; |
576 |
|
} |
577 |
|
if (n == 0) |
578 |
|
path = strdup (name); |
579 |
|
else { |
580 |
|
char *p = make_filename (path, name, NULL); |
581 |
|
rc = add_single_file (lv, p); |
582 |
|
free (p); |
583 |
|
} |
584 |
|
n++; |
585 |
} |
} |
586 |
|
if (n == 1) /* single file selected. */ |
587 |
|
rc = add_single_file (lv, path); |
588 |
|
if (path) |
589 |
|
free (path); |
590 |
return rc; |
return rc; |
591 |
} |
} |
592 |
|
|
1243 |
if (is_openpgp_ext (c->output)) |
if (is_openpgp_ext (c->output)) |
1244 |
c->output[strlen (c->output)-4] = '\0'; |
c->output[strlen (c->output)-4] = '\0'; |
1245 |
else { |
else { |
1246 |
const char *s = get_filesave_dlg (c->dlg, _("Choose Filename for Output"), |
const char *s; |
1247 |
NULL, NULL); |
s = get_filesave_dlg (c->dlg, _("Choose Filename for Output"), |
1248 |
|
NULL, NULL); |
1249 |
if (s) { |
if (s) { |
1250 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1251 |
c->output = m_strdup (s); |
c->output = m_strdup (s); |
1306 |
sigres = gpgme_op_verify_result (ctx); |
sigres = gpgme_op_verify_result (ctx); |
1307 |
if (sigres && sigres->signatures) |
if (sigres && sigres->signatures) |
1308 |
show_verify_result (sigres); |
show_verify_result (sigres); |
|
|
|
1309 |
|
|
1310 |
leave: |
leave: |
1311 |
if (in) |
if (in) |