From fdc1aa5209a89ce7ef2f91d6bf3ce7852438fa85 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 10 Apr 2005 22:37:43 +0000 Subject: [PATCH] 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 --- include/wx/debugrpt.h | 9 +++++---- samples/debugrpt/debugrpt.cpp | 17 ++++++++++++++--- src/common/debugrpt.cpp | 30 ++++++++++++++++++++++++++---- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/include/wx/debugrpt.h b/include/wx/debugrpt.h index 0ea5642..aa3787e 100644 --- a/include/wx/debugrpt.h +++ b/include/wx/debugrpt.h @@ -48,16 +48,17 @@ public: 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); diff --git a/samples/debugrpt/debugrpt.cpp b/samples/debugrpt/debugrpt.cpp index cd2e4d5..3d4fd14 100644 --- a/samples/debugrpt/debugrpt.cpp +++ b/samples/debugrpt/debugrpt.cpp @@ -31,14 +31,14 @@ // 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") @@ -47,6 +47,9 @@ public: } 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() ) @@ -199,6 +202,14 @@ public: 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) ) { diff --git a/src/common/debugrpt.cpp b/src/common/debugrpt.cpp index 194b337..7b88cb3 100644 --- a/src/common/debugrpt.cpp +++ b/src/common/debugrpt.cpp @@ -252,23 +252,45 @@ wxString wxDebugReport::GetReportName() const 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; } -- 2.7.4