-
Notifications
You must be signed in to change notification settings - Fork 0
/
wxMsLog.cpp
203 lines (189 loc) · 6.31 KB
/
wxMsLog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*-----------------------------------------------------------------
* Name: wxMsLog.cpp
* Purpose:
* Author: A. Wiegert
*
* Copyright:
* Licence: wxWidgets license
*---------------------------------------------------------------- */
/*----------------------------------------------------------------
* Standard wxWidgets headers
*---------------------------------------------------------------- */
// Note __VISUALC__ is defined by wxWidgets, not by MSVC IDE
// and thus won't be defined until some wxWidgets headers are included
#if defined( _MSC_VER )
# if defined ( _DEBUG )
// this statement NEEDS to go BEFORE all headers
# define _CRTDBG_MAP_ALLOC
# endif
#endif
#include "wxMsPreProcDefsh.h" // needs to be first
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
/* For all others, include the necessary headers
* (this file is usually all you need because it
* includes almost all "standard" wxWidgets headers) */
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
// ------------------------------------------------------------------
#include "wxMsFrameh.h"
// ------------------------------------------------------------------
// Note __VISUALC__ is defined by wxWidgets, not by MSVC IDE
// and thus won't be defined until some wxWidgets headers are included
#if defined( _MSC_VER )
// only good for MSVC
// this block needs to go AFTER all headers
#include <crtdbg.h>
#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
#endif
#endif
// ------------------------------------------------------------------
void MyFrame::OnOptionsLogClear( wxCommandEvent& WXUNUSED(event) )
{
#if defined( WANT_LOG_WIN )
m_textCtrlLog->Clear();
#endif
}
// ------------------------------------------------------------------
// Note the check mark is added/removed automagically
// see wxOrdo for more details
void MyFrame::OnOptionsLogShow( wxCommandEvent& event )
{
int iSashPos;
wxWindow *pWin1;
bool bShow = m_menuItemLogShow->IsChecked();
// is log window wanted?
g_iniPrefs.data[IE_LOG_WIN_WANTED].dataCurrent.bVal = bShow;
pWin1 = m_splitterMain->GetWindow1();
if( !bShow )
{
m_pLogWindowSave = m_splitterMain->GetWindow2();
iSashPos = m_splitterMain->GetSashPosition();
g_iniPrefs.data[IE_SASH_POS].dataCurrent.lVal = iSashPos;
m_splitterMain->Unsplit();
}
else
{
m_splitterMain->SplitHorizontally( pWin1, m_pLogWindowSave,
g_iniPrefs.data[IE_SASH_POS].dataCurrent.lVal );
}
wxGetApp().m_frame->Layout();
}
// ------------------------------------------------------------------
#if 0 // not used - yet
void MyFrame::OnMenuItemDeleteLogFiles( wxCommandEvent& WXUNUSED( event ) )
{
// bool bRet;
wxString wsCurLog = wxGetApp().m_wsCurLogFileName;
if( ::wxFileExists( wsCurLog ) )
{
// stop passing messages to file
wxGetApp().m_pLogChain->PassMessages( false );
// confirm the 'delete'
int iResult = wxMessageBox(
_("Do you really want to delete ") + wsCurLog + _("?"),
_("Confirm"), wxYES_NO | wxICON_EXCLAMATION );
if( iResult == wxYES )
{
// simply close it.
// Don't reopen it here; wait for user to ask for it.
wxGetApp().m_pAppLog->CloseLog();
}
// this is needed to pass messages to log window
wxGetApp().m_pLogChain->PassMessages( true );
}
// file does not exist
else
{
wxMessageBox( _("File: ") + wsCurLog + _(" does not exist!"),
wxEmptyString, wxOK | wxICON_INFORMATION );
}
}
#include <shlwapi.h>
// ------------------------------------------------------------------
/**
* Open the current log file in the default editor - read-only
*/
void MyFrame::OnMenuItemOpenLogFiles(wxCommandEvent& WXUNUSED(event))
{
wxFileName wfnLogFile( wxGetApp().m_wsCurLogFileName );
if ( !wfnLogFile.FileExists() )
{
wxMessageBox( _("Log file: ") + wxGetApp().m_wsCurLogFileName + _(" does not exist!") +
_("\nYou can enable logging in \"Options->Log\""),
wxEmptyString, wxOK | wxICON_INFORMATION );
}
wxString wsOpen = _T("open");
ShellExecute(
NULL,
wsOpen.wchar_str(),
wxGetApp().m_wsCurLogFileName.c_str(),
NULL,
NULL,
SW_SHOWNORMAL
);
wxLogError( _("Log file open %s: \n"), wxGetApp().m_wsCurLogFileName );
}
#endif
// ------------------------------------------------------------------
bool MyApp::CreateNewLog()
{
#if defined( WANT_LOG_CHAIN )
#if defined( WANT_LOG_LIMIT )
wxString wsLog2BigMsg = _("Old log too large; started new log");
wxFileName wfnLogFile( m_wsCurLogFileName );
// make the limit just less than the attachment limit EMAIL_ATTACHMENT_LIMIT => 5 MB
if ( wfnLogFile.Exists() && (wfnLogFile.GetSize() > EMAIL_ATTACHMENT_LIMIT - 10 * 1024 ) )
{
#if defined( WANT_LOG_ROTATION )
wxFileName wfnOldLog( wfnLogFile);
wxString wsExt;
wsExt.Printf( _T("%s.%ld"), wfnLogFile.GetExt(), g_iniPrefs.data[IE_LOG_ROT_NEXT].dataCurrent.lVal );
wfnOldLog.SetExt( wsExt );
if( (g_iniPrefs.data[IE_LOG_ROT_NEXT].dataCurrent.lVal)++ >= g_iniPrefs.data[IE_LOG_ROT_MAX].dataCurrent.lVal )
g_iniPrefs.data[IE_LOG_ROT_NEXT].dataCurrent.lVal = 0l;
if( ::wxFileExists( wfnOldLog.GetFullPath() ))
wxRemoveFile( wfnOldLog.GetFullPath() );
::wxRenameFile( m_wsCurLogFileName, wfnOldLog.GetFullPath() );
// if ( g_iniPrefs.data[IE_LOG_VERBOSITY].dataCurrent.lVal > 4 )
wxLogMessage( _T("Log Rotation: %s" ), wfnOldLog.GetFullPath() );
#else
::wxRemoveFile( m_wsCurLogFileName ); // remove file and start over
if ( g_iniPrefs.data[IE_LOG_VERBOSITY].dataCurrent.lVal > 4 )
wxLogMessage( wsLog2BigMsg );
#endif
}
#endif
m_pAppLog = new MyFileLog( m_wsCurLogFileName );
if ( m_pAppLog->IsLogFileOK() )
{
m_pLogChain = new wxLogChain(m_pAppLog);
}
else
{
wxString wsMsg;
wsMsg.Printf(
_("Could not initialize the application log (file \"%s\"). \n\nContinue anyway?"),
m_pAppLog->GetLogFileName());
delete m_pAppLog;
if ( g_iniPrefs.data[IE_LOG_VERBOSITY].dataCurrent.lVal > 4 )
{
wxLogMessage( wsMsg );
}
if ( wxMessageBox( wsMsg, _("Error"), wxYES_NO | wxICON_ERROR, NULL) != wxYES )
{
return false;
}
}
#endif
return true;
}
// ------------------------------- eof ------------------------------