modified AddFile() to copy file to the debug report directory if its path is absolute

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33492 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2005-04-10 22:37:43 +00:00
parent b6afa1a38a
commit fdc1aa5209
3 changed files with 45 additions and 11 deletions

View File

@ -48,16 +48,17 @@ public:
void Reset() { m_dir.clear(); } void Reset() { m_dir.clear(); }
// add another file to the report: the file must already exist, its name is // add another file to the report: the file must already exist, its name
// relative to GetDirectory() // 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 // 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 // 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 // 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) // 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& text,
const wxString& description); const wxString& description);

View File

@ -31,14 +31,14 @@
// custom debug reporting class // custom debug reporting class
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// this is your custom debug reporter, you will probably want to parse the XML // this is your custom debug reporter: it will use curl program (which should
// document in OnServerReply() instead of just dumping it as I do // be available) to upload the crash report to the given URL (which should be
// set up by you)
class MyDebugReport : public wxDebugReportUpload class MyDebugReport : public wxDebugReportUpload
{ {
public: public:
MyDebugReport() : wxDebugReportUpload MyDebugReport() : wxDebugReportUpload
( (
//_T("http://iml2.hitchcock.org/intranet/crashes/wxtest"),
_T("http://your.url.here/"), _T("http://your.url.here/"),
_T("report:file"), _T("report:file"),
_T("action") _T("action")
@ -47,6 +47,9 @@ public:
} }
protected: 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) virtual bool OnServerReply(const wxArrayString& reply)
{ {
if ( reply.IsEmpty() ) if ( reply.IsEmpty() )
@ -199,6 +202,14 @@ public:
report.AddFile(fn.GetFullName(), _T("timestamp of this report")); 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 // calling Show() is not mandatory, but is more polite
if ( wxDebugReportPreviewStd().Show(report) ) if ( wxDebugReportPreviewStd().Show(report) )
{ {

View File

@ -252,23 +252,45 @@ wxString wxDebugReport::GetReportName() const
return _T("wx"); 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_files.Add(name);
m_descriptions.Add(description); m_descriptions.Add(description);
} }
bool bool
wxDebugReport::AddText(const wxString& name, wxDebugReport::AddText(const wxString& filename,
const wxString& text, const wxString& text,
const wxString& description) 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")); wxFFile file(fn.GetFullPath(), _T("w"));
if ( !file.IsOpened() || !file.Write(text) ) if ( !file.IsOpened() || !file.Write(text) )
return false; return false;
AddFile(name, description); AddFile(filename, description);
return true; return true;
} }