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

Contents of /trunk/Src/wptErrors.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 271 - (show annotations)
Sun Nov 5 08:57:45 2006 UTC (18 years, 3 months ago) by twoaday
File size: 7664 byte(s)


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26