void Reset() { m_dir.clear(); }
- // add another file to the report: the file must already exist, its name is
- // relative to GetDirectory()
+ // add another file to the report: the file must already exist, its name
+ // can be either absolute in which case it is copied to the debug report
+ // directory or relative to GetDirectory()
//
// description is shown to the user in the report summary
- virtual void AddFile(const wxString& name, const wxString& description);
+ virtual void AddFile(const wxString& filename, const wxString& description);
// convenience function: write the given text to a file with the given name
// and then add it to the report (the difference with AddFile() is that the
// file will be created by this function and doesn't have to already exist)
- bool AddText(const wxString& name,
+ bool AddText(const wxString& filename,
const wxString& text,
const wxString& description);
// custom debug reporting class
// ----------------------------------------------------------------------------
-// this is your custom debug reporter, you will probably want to parse the XML
-// document in OnServerReply() instead of just dumping it as I do
+// this is your custom debug reporter: it will use curl program (which should
+// be available) to upload the crash report to the given URL (which should be
+// set up by you)
class MyDebugReport : public wxDebugReportUpload
{
public:
MyDebugReport() : wxDebugReportUpload
(
- //_T("http://iml2.hitchcock.org/intranet/crashes/wxtest"),
_T("http://your.url.here/"),
_T("report:file"),
_T("action")
}
protected:
+ // this is called with the contents of the server response: you will
+ // probably want to parse the XML document in OnServerReply() instead of
+ // just dumping it as I do
virtual bool OnServerReply(const wxArrayString& reply)
{
if ( reply.IsEmpty() )
report.AddFile(fn.GetFullName(), _T("timestamp of this report"));
+ // can also add an existing file directly, it will be copied
+ // automatically
+#ifdef __WXMSW__
+ report.AddFile(_T("c:\\autoexec.bat"), _T("DOS startup file"));
+#else
+ report.AddFile(_T("/etc/motd"), _T("Message of the day"));
+#endif
+
// calling Show() is not mandatory, but is more polite
if ( wxDebugReportPreviewStd().Show(report) )
{
return _T("wx");
}
-void wxDebugReport::AddFile(const wxString& name, const wxString& description)
+void
+wxDebugReport::AddFile(const wxString& filename, const wxString& description)
{
+ wxString name;
+ wxFileName fn(filename);
+ if ( fn.IsAbsolute() )
+ {
+ // we need to copy the file to the debug report directory: give it the
+ // same name there
+ name = fn.GetFullName();
+ wxCopyFile(fn.GetFullPath(),
+ wxFileName(GetDirectory(), name).GetFullPath());
+ }
+ else // file relative to the report directory
+ {
+ name = filename;
+
+ wxASSERT_MSG( wxFileName(GetDirectory(), name).FileExists(),
+ _T("file should exist in debug report directory") );
+ }
+
m_files.Add(name);
m_descriptions.Add(description);
}
bool
-wxDebugReport::AddText(const wxString& name,
+wxDebugReport::AddText(const wxString& filename,
const wxString& text,
const wxString& description)
{
- wxFileName fn(GetDirectory(), name);
+ wxASSERT_MSG( !wxFileName(filename).IsAbsolute(),
+ _T("filename should be relative to debug report directory") );
+
+ wxFileName fn(GetDirectory(), filename);
wxFFile file(fn.GetFullPath(), _T("w"));
if ( !file.IsOpened() || !file.Write(text) )
return false;
- AddFile(name, description);
+ AddFile(filename, description);
return true;
}