1
// clamav.cpp : Defines the class behaviors for the application.
5
* Copyright (C) 2004 Nigel Horne <njh@bandsman.co.uk>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
34
static char BASED_CODE THIS_FILE[] = __FILE__;
37
/////////////////////////////////////////////////////////////////////////////
40
BEGIN_MESSAGE_MAP(CClamavApp, CWinApp)
41
//{{AFX_MSG_MAP(CClamavApp)
42
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
43
ON_COMMAND(ID_FILE_NEW, OnFileNew)
44
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
45
ON_COMMAND(ID_SET_OPTIONS, OnSetOptions)
47
// Standard file based document commands
48
// ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
49
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
50
// Standard print setup command
51
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
54
/////////////////////////////////////////////////////////////////////////////
55
// CClamavApp construction
57
CClamavApp::CClamavApp()
59
// TODO: add construction code here,
60
// Place all significant initialization in InitInstance
63
CClamavApp::~CClamavApp()
67
/////////////////////////////////////////////////////////////////////////////
68
// The one and only CClamavApp object
72
/////////////////////////////////////////////////////////////////////////////
73
// CClamavApp initialization
75
BOOL CClamavApp::InitInstance()
77
// Standard initialization
78
// If you are not using these features and wish to reduce the size
79
// of your final executable, you should remove from the following
80
// the specific initialization routines you do not need.
84
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
86
// Register the application's document templates. Document templates
87
// serve as the connection between documents, frame windows and views.
89
CSingleDocTemplate* pDocTemplate;
90
pDocTemplate = new CSingleDocTemplate(
92
RUNTIME_CLASS(CClamavDoc),
93
RUNTIME_CLASS(CMainFrame), // main SDI frame window
94
RUNTIME_CLASS(CClamavView));
95
AddDocTemplate(pDocTemplate);
100
if(WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
101
AfxMessageBox("WSAStartup() failed error code");
106
if (m_lpCmdLine[0] != '\0') {
107
// TODO: add command line processing here
108
// First argument is the server, second is the file to scan
109
// TODO: more rigourous argument checking
110
CString args = CString(m_lpCmdLine);
112
int index = args.Find(' ');
116
CString server = args.Left(index);
117
const CString fileName = args.Mid(index + 1);
120
index = server.Find(':');
122
port = (unsigned short)atoi(server.Mid(index + 1));
123
server = server.Left(index);
128
clamServer = new ClamServer(server, port);
129
} CATCH(CException, c) {
130
AfxMessageBox("Can't establish a connection to " + server);
136
CWinApp::OnFileNew();
138
// TODO: set quarantine directory
140
exit(clamServer->Scan(fileName, 0, (CMainFrame *)AfxGetMainWnd(), m_pMainWnd, TRUE, NULL) == TRUE);
142
// create a new (empty) document
147
afxTraceEnabled = TRUE;
150
options = new COptions();
156
/////////////////////////////////////////////////////////////////////////////
157
// CAboutDlg dialog used for App About
159
class CAboutDlg : public CDialog
165
//{{AFX_DATA(CAboutDlg)
166
enum { IDD = IDD_ABOUTBOX };
171
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
172
//{{AFX_MSG(CAboutDlg)
173
// No message handlers
175
DECLARE_MESSAGE_MAP()
178
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
180
//{{AFX_DATA_INIT(CAboutDlg)
184
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
186
CDialog::DoDataExchange(pDX);
187
//{{AFX_DATA_MAP(CAboutDlg)
191
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
192
//{{AFX_MSG_MAP(CAboutDlg)
193
// No message handlers
197
// App command to run the dialog
198
void CClamavApp::OnAppAbout()
204
/////////////////////////////////////////////////////////////////////////////
205
// CClamavApp commands
207
int CClamavApp::ExitInstance()
209
// TODO: Add your specialized code here and/or call the base class
220
return CWinApp::ExitInstance();
223
void CClamavApp::OnFileNew()
225
CWinApp::OnFileNew();
227
// TODO: Add your command handler code here
229
// Open connection to a different server
235
clamServer = new ClamServer;
236
} CATCH(CException, c) {
243
void CClamavApp::OnFileOpen()
245
// TODO: Add your command handler code here
248
if (!DoPromptFileName(newName, AFX_IDS_OPENFILE,
249
/*OFN_HIDEREADONLY |*/ OFN_FILEMUSTEXIST, TRUE, NULL))
250
return; // open cancelled
252
// OpenDocumentFile(newName);
256
// TODO: More than one scan happen at once but the progress bar gets confused
257
// Need a new scanner class. Create a new instance everytime we scan something
258
// Pass clamServer as a parameter
259
// Scanner *s = new Scanner(clamServer, 0, (CMainFrame *)AfxGetMainWnd(), m_pMainWnd, recursive, options->m_quarantineDir);
261
// AfxMessageBox("No virus found in " + filename);
264
void CClamavApp::Scan(const CString& filename)
266
if(clamServer == NULL)
267
AfxMessageBox("You must connect to a clamd server first");
268
else if(clamServer->Scan(filename, 0, (CMainFrame *)AfxGetMainWnd(), m_pMainWnd, recursive, options->m_quarantineDir))
269
AfxMessageBox("No virus found in " + filename);
272
void CClamavApp::OnSetOptions()
274
// TODO: Add your command handler code here
275
if(options->DoModal() == IDOK)
276
recursive = options->m_recursive;