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:
parent
b6afa1a38a
commit
fdc1aa5209
@ -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);
|
||||
|
||||
|
@ -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) )
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user