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

Contents of /trunk/Src/wptErrors.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (show annotations)
Sat Oct 8 10:43:08 2005 UTC (19 years, 4 months ago) by twoaday
File size: 7909 byte(s)
Bug fixes to correct some problems introduced by
the MyGPGME to GPGME port.

1 /* wptErrors.cpp - Error management
2 * Copyright (C) 2000-2004 Timo Schulz
3 *
4 * This file is part of WinPT.
5 *
6 * WinPT is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (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 GNU
14 * 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 #include <windows.h>
22 #include <stdio.h>
23
24 #include "wptErrors.h"
25 #include "wptTypes.h"
26 #include "wptW32API.h"
27 #include "wptVersion.h"
28 #include "wptGPG.h"
29 #include "wptNLS.h"
30
31
32 static char *
33 gpg_strerror( int errid )
34 {
35 static char buf[512];
36 char * path = NULL;
37
38 path = get_gnupg_path();
39 if( !path )
40 BUG( NULL );
41 switch( errid ) {
42 case WPTERR_GPG_EXEFILE:
43 _snprintf( buf, sizeof buf - 1, _("Could not locate GPG.exe in %s."), path );
44 break;
45 case WPTERR_GPG_OPT_KEYRINGS:
46 case WPTERR_GPG_KEYRINGS:
47 _snprintf( buf, sizeof buf - 1,
48 _("Could not find keyring entries into the options file in %s "
49 "or the file does NOT exist."), path );
50 break;
51 }
52 free_if_alloc( path );
53 return buf;
54 } /* gpg_strerror */
55
56
57 static void
58 w32_fmt_msg (char *buf, size_t buflen)
59 {
60 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError (),
61 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
62 buf, buflen, NULL);
63 }
64
65 /* Return an error specific message.
66 If there is a translation available, it returns the translated text. */
67 const char*
68 winpt_strerror (int errid)
69 {
70 static char buf[256];
71
72 switch( errid ) {
73 case WPTERR_GENERAL: return _("General error occured");
74 case WPTERR_FILE_OPEN: return _("Could not open file");
75 case WPTERR_FILE_CREAT: return _("Could not create file");
76 case WPTERR_FILE_READ: return _("Could not read file");
77 case WPTERR_FILE_WRITE: return _("Could not write file");
78 case WPTERR_FILE_CLOSE: return _("Could not close file");
79 case WPTERR_FILE_EXIST: return _("File does not exist");
80 case WPTERR_FILE_REMOVE: return _("Could not delete file");
81 case WPTERR_CLIP_OPEN: return _("Could not open Clipboard");
82 case WPTERR_CLIP_CLOSE: return _("Could not close Clipboard");
83 case WPTERR_CLIP_EMPTY: return _("Could not empty Clipboard");
84 case WPTERR_CLIP_SET: return _("Could not set Clipboard data");
85 case WPTERR_CLIP_GET: return _("Could not get Clipboard data");
86 case WPTERR_CLIP_ISEMPTY: return _("There is no text in the Clipboard");
87 case WPTERR_CLIP_SECURED: return _("The Clipboard already contains GPG data");
88 case WPTERR_CLIP: return _("General Clipboard error");
89 case WPTERR_REGISTRY: sprintf (buf, "%s", _("Registry error: "));
90 w32_fmt_msg (buf + strlen (buf), 128);
91 break;
92 case WPTERR_WINSOCK_INIT: return _("Could not startup Winsock 2 interface");
93 case WPTERR_WINSOCK_RESOLVE: return _("Could not resolve hostname");
94 case WPTERR_WINSOCK_SOCKET: return _("Could not create new socket");
95 case WPTERR_WINSOCK_CONNECT: return _("Could not connect to the host");
96 case WPTERR_WINSOCK_SENDKEY: return _("Could not send the key to the keyserver");
97 case WPTERR_WINSOCK_RECVKEY: return _("Could not receive the key from the keyserver");
98 case WPTERR_WINSOCK_TIMEOUT: return _("Socket timed out, no data");
99 case WPTERR_KEYSERVER_NOTFOUND: return _("Keyserver returned: no matching keys in database");
100 case WPTERR_HOTKEY: sprintf (buf, "%s", _("Could not register hotkey: "));
101 w32_fmt_msg (buf + strlen (buf), 128);
102 break;
103 case WPTERR_DIR_OPEN: return _("Could not open directory");
104 case WPTERR_DIR_CREAT: return _("Could not create directory");
105 case WPTERR_CURR_WND: return _("Could not extract data from the current window");
106 case WPTERR_CONFIG_FILE: return _("Could not load config file");
107 case WPTERR_GPG_EXEFILE:
108 case WPTERR_GPG_OPT_KEYRINGS:
109 case WPTERR_GPG_KEYRINGS: return gpg_strerror (errid);
110 case WPTERR_NOCARD: return _("There is no card in the reader");
111 case WPTERR_NOREADER: return _("There was no reader found");
112 case WPTERR_NOPGPCARD: return _("This is not an OpenPGP card");
113 case WPTERR_CDISK_LOCK: return _("Could not lock or unlock volume");
114 case WPTERR_CDISK_MOUNT: return _("Could not mount volume");
115 case WPTERR_CDISK_UMOUNT: return _("Could not unmount volume");
116 case WPTERR_CDISK_OPEN: return _("Could not open volume");
117 case WPTERR_CDISK_BUSY: return _("Drive that belongs to the volume is busy");
118 case WPTERR_CDISK_QUERY: return _("Could not query volume information");
119 default: _snprintf (buf, sizeof (buf) - 1, _("Unknown error=%d"), errid); return buf;
120 }
121
122 return NULL;
123 } /* winpt_strerror */
124
125
126 void
127 winpt_errmsg (const char * name, int is_file)
128 {
129 TCHAR buf[500], head[500];
130 DWORD last_err;
131
132 memset (head, 0, sizeof head);
133 last_err = GetLastError ();
134 if (!name)
135 strcpy (head, _("WinPT Error"));
136 else if (is_file)
137 _snprintf (head, DIM (head)-1, "%s: %d", name, last_err);
138 else
139 strncpy (head, name, DIM (head)-1);
140 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, last_err,
141 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
142 buf, DIM (buf)-1, NULL);
143 MessageBox (NULL, buf, head, MB_OK);
144 } /* winpt_errmsg */
145
146
147 void
148 winpt_debug_msg( void )
149 {
150 char output[768], temp[384];
151
152 GetTempPath( sizeof temp -1, temp );
153 _snprintf( output, sizeof output - 1,
154 "The GPGME output file is gpgme.dbg\n"
155 "The WinPT output file is %swinpt.log\n", temp );
156 MessageBox( NULL, output, "WinPT now runs in DEBUG MODE", MB_INFO );
157 } /* winpt_debug_msg */
158
159
160 void
161 debug_box( const char *msg, const char *file, int line )
162 {
163 #if _DEBUG
164 char output[4096];
165
166 memset( output, 0, sizeof output );
167 _snprintf( output, sizeof output -1,
168 "WinPT DBG:\n \"%s\", file %s, line %d\n", msg, file, line );
169 MessageBox( NULL, output, PGM_NAME, MB_OK | MB_ICONERROR );
170 #endif
171 } /* debug_box */
172
173
174 void
175 debug_f( const char *msg, const char *file, int line )
176 {
177 #if _DEBUG
178 FILE *fp;
179 char temp_path[ 1024 ];
180 char output[ 4096 ];
181
182 GetTempPath( sizeof temp_path - 1, temp_path );
183 strcat( temp_path, "\\WinPT.DEBUG" );
184 fp = fopen( temp_path, "a+b" );
185 if( !fp )
186 return;
187 memset( output, 0, sizeof output );
188 _snprintf( output, sizeof output -1,
189 "WinPT DBG:\n \"%s\", file %s, line %d\n", msg, file, line );
190 fwrite( output, 1, strlen( output ), fp );
191 fflush( fp );
192 fclose( fp );
193 #endif
194 } /* debug_f */
195
196
197 void
198 log_debug (const char *format, ...)
199 {
200 FILE *fp;
201 char temp_path[384];
202 va_list arg_ptr;
203
204 if (!debug)
205 return;
206
207 GetTempPath (sizeof temp_path - 1, temp_path);
208 strcat (temp_path, "\\WinPT.LOG");
209 fp = fopen (temp_path, "a+b");
210 if (!fp)
211 return;
212 va_start (arg_ptr, format);
213 vfprintf (fp, format, arg_ptr);
214 va_end (arg_ptr);
215 fflush (fp);
216 fclose (fp);
217 }
218
219
220 int
221 log_box (const char *title, int style, const char *format, ...)
222 {
223 va_list arg_ptr;
224 char log[8192];
225 int id;
226
227 va_start (arg_ptr, format);
228 _vsnprintf (log, sizeof (log)-1, format, arg_ptr);
229 id = msg_box (NULL, log, title? title : "Log Output", style);
230 va_end( arg_ptr );
231
232 return id;
233 } /* log_box */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26