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

Diff of /trunk/Src/wptErrors.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 271 by twoaday, Sun Nov 5 08:57:45 2006 UTC revision 278 by twoaday, Mon Jan 15 22:02:04 2007 UTC
# Line 32  Line 32 
32  #include "wptGPG.h"  #include "wptGPG.h"
33  #include "wptNLS.h"  #include "wptNLS.h"
34    
35    static FILE *log_fp = NULL;
36    
37  static char *  
38  gpg_strerror( int errid )  /* Return a GPG specific error message. */
39    static char*
40    gpg_strerror (int errid)
41  {  {
42      static char buf[512];      static char buf[2*MAX_PATH+1];
43      char * path = NULL;      char *path;
44    
45      path = get_gnupg_path();      path = get_gnupg_path ();
46      if( !path )      if (!path)
47          BUG( NULL );          BUG (NULL);
48      switch( errid ) {      switch (errid) {
49      case WPTERR_GPG_EXEFILE:      case WPTERR_GPG_EXEFILE:
50          _snprintf( buf, sizeof buf - 1, _("Could not locate GPG.exe in %s."), path );            _snprintf (buf, DIM (buf) - 1,
51                        _("Could not locate GPG.exe in %s."), path);
52          break;          break;
53      case WPTERR_GPG_OPT_KEYRINGS:      case WPTERR_GPG_OPT_KEYRINGS:
54      case WPTERR_GPG_KEYRINGS:      case WPTERR_GPG_KEYRINGS:
55          _snprintf( buf, sizeof buf - 1,          _snprintf (buf, DIM (buf) - 1,
56                     _("Could not find keyring entries in the config file in %s "                     _("Could not find keyring entries in the config file in %s "
57                       "or the file does NOT exist."), path );                       "or the file does NOT exist."), path);
58          break;          break;
59      }      }
60      free_if_alloc( path );      free_if_alloc (path);
61      return buf;      return buf;
62  } /* gpg_strerror */  }
63    
64    
65  static void  static void
# Line 66  w32_fmt_msg (char *buf, size_t buflen) Line 70  w32_fmt_msg (char *buf, size_t buflen)
70                     buf, buflen, NULL);                     buf, buflen, NULL);
71  }  }
72    
73    
74  /* Return an error specific message.  /* Return an error specific message.
75     If there is a translation available, it returns the translated text. */     If there is a translation available, it returns the translated text. */
76  const char*  const char*
# Line 73  winpt_strerror (int errid) Line 78  winpt_strerror (int errid)
78  {        {      
79      static char buf[256];      static char buf[256];
80                    
81      switch( errid ) {      switch (errid) {
82      case -1: w32_fmt_msg (buf, 255); return buf;      case -1: w32_fmt_msg (buf, DIM (buf)-1); return buf;
83      case WPTERR_GENERAL: return _("General error occured");      case WPTERR_GENERAL: return _("General error occured");
84      case WPTERR_FILE_OPEN: return _("Could not open file");      case WPTERR_FILE_OPEN: return _("Could not open file");
85      case WPTERR_FILE_CREAT: return _("Could not create file");      case WPTERR_FILE_CREAT: return _("Could not create file");
# Line 91  winpt_strerror (int errid) Line 96  winpt_strerror (int errid)
96      case WPTERR_CLIP_ISEMPTY: return _("There is no text in the Clipboard");      case WPTERR_CLIP_ISEMPTY: return _("There is no text in the Clipboard");
97      case WPTERR_CLIP_SECURED: return _("The Clipboard already contains GPG data");      case WPTERR_CLIP_SECURED: return _("The Clipboard already contains GPG data");
98      case WPTERR_CLIP: return _("General Clipboard error");      case WPTERR_CLIP: return _("General Clipboard error");
99      case WPTERR_REGISTRY: sprintf (buf, "%s", _("Registry error: "));      case WPTERR_REGISTRY: _snprintf (buf, DIM (buf)-1, "%s", _("Registry error: "));
100                            w32_fmt_msg (buf + strlen (buf), 128);                            w32_fmt_msg (buf + strlen (buf), DIM (buf)/2);
101                            return buf;                            return buf;
102      case WPTERR_WINSOCK_INIT: return _("Could not startup Winsock 2 interface");      case WPTERR_WINSOCK_INIT: return _("Could not startup Winsock 2 interface");
103      case WPTERR_WINSOCK_RESOLVE: return _("Could not resolve hostname");      case WPTERR_WINSOCK_RESOLVE: return _("Could not resolve hostname");
104      case WPTERR_WINSOCK_SOCKET: return _("Could not create new socket");      case WPTERR_WINSOCK_SOCKET: return _("Could not create new socket");
# Line 101  winpt_strerror (int errid) Line 106  winpt_strerror (int errid)
106      case WPTERR_WINSOCK_SENDKEY: return _("Could not send the key to the keyserver");      case WPTERR_WINSOCK_SENDKEY: return _("Could not send the key to the keyserver");
107      case WPTERR_WINSOCK_RECVKEY: return _("Could not receive the key from the keyserver");      case WPTERR_WINSOCK_RECVKEY: return _("Could not receive the key from the keyserver");
108      case WPTERR_WINSOCK_TIMEOUT: return _("Socket timed out, no data");      case WPTERR_WINSOCK_TIMEOUT: return _("Socket timed out, no data");
109      case WPTERR_WINSOCK_PROXY: return _("Could not forward request to proxy");        case WPTERR_WINSOCK_PROXY: return _("Could not forward request to proxy");
110      case WPTERR_KEYSERVER_NOTFOUND: return _("Keyserver returned: no matching keys in database");      case WPTERR_KEYSERVER_NOTFOUND: return _("Keyserver returned: no matching keys in database");
111      case WPTERR_HOTKEY: sprintf (buf, "%s", _("Could not register hotkey: "));      case WPTERR_HOTKEY: _snprintf (buf, DIM (buf)-1, "%s", _("Could not register hotkey: "));
112                          w32_fmt_msg (buf + strlen (buf), 128);                          w32_fmt_msg (buf + strlen (buf), DIM (buf)/2);
113                          return buf;                          return buf;
114      case WPTERR_DIR_OPEN: return _("Could not open directory");      case WPTERR_DIR_OPEN: return _("Could not open directory");
115      case WPTERR_DIR_CREAT: return _("Could not create directory");      case WPTERR_DIR_CREAT: return _("Could not create directory");
# Line 124  winpt_strerror (int errid) Line 129  winpt_strerror (int errid)
129      case WPTERR_CDISK_OPEN: return _("Could not  open volume");      case WPTERR_CDISK_OPEN: return _("Could not  open volume");
130      case WPTERR_CDISK_BUSY: return _("Drive that belongs to the volume is busy");      case WPTERR_CDISK_BUSY: return _("Drive that belongs to the volume is busy");
131      case WPTERR_CDISK_QUERY: return _("Could not query volume information");      case WPTERR_CDISK_QUERY: return _("Could not query volume information");
132           */          */
133      default: _snprintf (buf, sizeof (buf) - 1, _("Unknown error=%d"), errid); return buf;      default: _snprintf (buf, DIM (buf) - 1,
134                            _("Unknown error=%d"), errid); return buf;
135      }      }
136    
137      return NULL;      return NULL;
138  } /* winpt_strerror */  }
139    
140    
141    /* Display a message box with the last system error. */
142  void  void
143  winpt_errmsg (const char * name, int is_file)  winpt_errmsg (const char *name, int is_file)
144  {        {      
145      TCHAR buf[500], head[500];      TCHAR buf[500], head[500];
146      DWORD last_err;      DWORD last_err;
# Line 153  winpt_errmsg (const char * name, int is_ Line 160  winpt_errmsg (const char * name, int is_
160  }  }
161    
162    
163    /* Show debug message. */
 /* This function is used to cleanup static debug resources. */  
 void  
 debug_end (void)  
 {  
 }  
   
   
   
164  void  void
165  debug_box( const char *msg, const char *file, int line )  debug_box (const char *msg, const char *file, int line)
166  {  {
167  #if _DEBUG      #if _DEBUG
168      char output[4096];      char output[4096];
169    
170      memset( output, 0, sizeof output );      memset( output, 0, sizeof output );
171      _snprintf( output, sizeof output -1,      _snprintf( output, sizeof output -1,
172          "WinPT DBG:\n \"%s\", file %s, line %d\n", msg, file, line );            "WinPT DBG:\n \"%s\", file %s, line %d\n", msg, file, line );  
173      MessageBox( NULL, output, PGM_NAME, MB_OK | MB_ICONERROR );      MessageBox( NULL, output, PGM_NAME, MB_OK | MB_ICONERROR );
174  #endif      #endif
175  } /* debug_box */  }
176    
177    
178  void  void
179  debug_f( const char *msg, const char *file, int line )  debug_f (const char *msg, const char *file, int line)
180  {  {
181  #if _DEBUG      #if _DEBUG
182      FILE *fp;      log_debug ("DBG:\n \"%s\", file %s, line %d\n", msg, file, line);
183      char temp_path[ 1024 ];      #endif
184      char output[ 4096 ];  }
   
     GetTempPath( sizeof temp_path - 1, temp_path );      
     strcat( temp_path, "\\WinPT.DEBUG" );        
     fp = fopen( temp_path, "a+b" );      
     if( !fp )  
         return;  
     memset( output, 0, sizeof output );  
     _snprintf( output, sizeof output -1,  
                "WinPT DBG:\n \"%s\", file %s, line %d\n", msg, file, line );  
     fwrite( output, 1, strlen( output ), fp );  
     fflush( fp );  
     fclose( fp );  
 #endif  
 } /* debug_f */  
185    
186    
187    /* Log a message into the log file. */
188  void  void
189  log_debug (const char *format, ...)  log_debug (const char *format, ...)
190  {  {    
191      FILE *fp;      char tmpdir[384];
     char temp_path[384];  
192      va_list arg_ptr;      va_list arg_ptr;
193    
194      if (!debug)      if (!debug)
195          return;          return;
196    
197      GetTempPath (sizeof temp_path - 1, temp_path);      if (log_fp == NULL) {
198      strcat (temp_path, "\\WinPT.LOG");          GetTempPath (sizeof (tmpdir) - 32, tmpdir);
199      fp = fopen (temp_path, "a+b");          strcat (tmpdir, "\\WinPT.LOG");
200      if (!fp)          log_fp = fopen (tmpdir, "a+b");
201          return;          if (!log_fp)
202                return;
203        }
204      va_start (arg_ptr, format);      va_start (arg_ptr, format);
205      vfprintf (fp, format, arg_ptr);      vfprintf (log_fp, format, arg_ptr);
206      va_end (arg_ptr);      va_end (arg_ptr);
207      fflush (fp);      fflush (log_fp);
     fclose (fp);  
208  }  }
209    
210    
211    /* Cleanup */
212    void
213    debug_end (void)
214    {
215        if (log_fp != NULL)
216            fclose (log_fp);
217    }
218    
219    
220    /* Emulate an MessageBox with variable input. */
221  int  int
222  printf_box (const char *title, int style, const char *format, ...)  printf_box (const char *title, int style, const char *format, ...)
223  {  {
224      va_list arg_ptr;      va_list arg_ptr;
225      char log[8192];      char log[4096];
226      int id;      int id;
227    
228      va_start (arg_ptr, format);      va_start (arg_ptr, format);
229      _vsnprintf (log, sizeof (log)-1, format, arg_ptr);          _vsnprintf (log, sizeof (log)-1, format, arg_ptr);    
230      id = msg_box (NULL, log, title? title : "Log Output", style);      id = msg_box (NULL, log, title, style);
231      va_end( arg_ptr );      va_end (arg_ptr);
232    
233      return id;      return id;
234  }  }
   

Legend:
Removed from v.271  
changed lines
  Added in v.278

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26