-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGnucleus.cpp
404 lines (303 loc) · 8.9 KB
/
Gnucleus.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/********************************************************************************
Gnucleus - An Application for the Gnutella Network
Copyright (C) 2000-2005 John Marshall Group
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
By contributing code you grant John Marshall Group an unlimited, non-exclusive
license to your contribution.
For support, questions, commercial use, etc...
E-Mail: swabby@c0re.net
********************************************************************************/
#include "stdafx.h"
#include "GnucleusDoc.h"
#include "AutPrefs.h"
#include "AutCore.h"
#include "AutDownload.h"
#include "FrameMain.h"
#include "FrameConnect.h"
#include "FrameStatistics.h"
#include "FrameShare.h"
#include "FrameSearch.h"
#include "FrameTransfers.h"
#include "FrameChat.h"
#include "FrameBrowser.h"
#include "ViewConnect.h"
#include "ViewStatistics.h"
#include "ViewShare.h"
#include "ViewSearch.h"
#include "ViewTransfers.h"
#include "ViewChat.h"
#include "ViewBrowser.h"
#include "NetSetup.h"
#include "Gnucleus.h"
#include "afxwin.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CGnucleusApp, CWinApp)
//{{AFX_MSG_MAP(CGnucleusApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
//}}AFX_MSG_MAP
// Standard file based document commands
END_MESSAGE_MAP()
CGnucleusApp::CGnucleusApp()
{
m_pDoc = NULL;
m_pConnectTemplate = NULL;
m_pStatisticsTemplate = NULL;
m_pShareTemplate = NULL;
m_pTransfersTemplate = NULL;
m_pSearchTemplate = NULL;
m_pChatTemplate = NULL;
m_pBrowserTemplate = NULL;
m_Min = false;
}
CGnucleusApp::~CGnucleusApp()
{
TRACE0("*** CGnucleusApp Deconstructing\n");
}
// The one and only CGnucleusApp object
CGnucleusApp theApp;
BOOL CGnucleusApp::InitInstance()
{
// Make sure this thread runs on the first CPU
AssignThreadToCPU(AfxGetThread(), CPU_0);
// Enable tracing if we are in debug mode
#ifdef _DEBUG
::afxTraceEnabled = true;
#endif
// Winsock Init
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return false;
}
// RichEdit Init
if(!AfxInitRichEdit())
{
AfxMessageBox("Could not initialize RTF Control");
return false;
}
// Enable containing controls, activex stuff
AfxEnableControlContainer();
// Enabe the use of OLE/COM objects
if (!AfxOleInit())
{
AfxMessageBox("OLE Init Failed");
return false;
}
// Depreciated Funtions in MFC 5.0
#if _MSC_VER < 1300
#ifdef _AFXDLL
Enable3dControls(); // MFC in a shared DLL
#else
Enable3dControlsStatic(); // MFC static
#endif
#endif
// Seed random generator
srand( (unsigned)time(NULL) );
// Process CommandLine
CMyCmdLineInfo cmdinfo;
cmdinfo.m_App = this;
cmdinfo.m_Minimize = false;
ParseCommandLine(cmdinfo);
m_Min = cmdinfo.m_Minimize;
// Load view templates and main document object
LoadTemplates();
m_pDoc = new CGnucleusDoc(this);
// Check if we can run multiple instances
if(InstanceRunning())
{
ReleaseMutex(m_hMutex);
if(AfxMessageBox("Gnucleus is already running, click Yes to close this instance,\nthen check the tray for Gnucleus already running", MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
return false;
}
// Init the main window
CFrameMain* pMainFrame = new CFrameMain(m_pDoc);
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
{
AfxMessageBox("Could not initialize CMainFrame");
return FALSE;
}
m_pMainWnd = pMainFrame;
// Hide window at start up
if(cmdinfo.m_Minimize)
pMainFrame->ShowWindow(SW_MINIMIZE);
else
{
CString state = AfxGetApp()->GetProfileString("FrameMain", "State", "maximized");
pMainFrame->ShowWindow(state == "maximized" ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL);
}
// Size child windows
SendMessage(m_pMainWnd->m_hWnd, WM_COMMAND, ID_VIEW_CONNECTIONS, NULL);
if(!m_Min)
SendMessage(m_pMainWnd->m_hWnd, WM_COMMAND, ID_WINDOW_CASCADE, NULL);
return true;
}
bool CGnucleusApp::InstanceRunning()
{
m_hMutex = CreateMutex(NULL, false, "Gnucleus_Mutex");
if(m_hMutex)
{
DWORD dwWait = WaitForSingleObject(m_hMutex, 10);
switch(dwWait)
{
case WAIT_OBJECT_0:
break;
case WAIT_TIMEOUT:
return true;
case WAIT_FAILED:
break;
}
}
return false;
}
void CGnucleusApp::LoadTemplates()
{
// Connect window
m_pConnectTemplate = new CMultiDocTemplate(
IDR_CONNECT,
RUNTIME_CLASS(CGnucleusDoc),
RUNTIME_CLASS(CFrameConnect),
RUNTIME_CLASS(CViewConnect));
AddDocTemplate(m_pConnectTemplate);
// Statistics window
m_pStatisticsTemplate = new CMultiDocTemplate(
IDR_STATISTICS,
RUNTIME_CLASS(CGnucleusDoc),
RUNTIME_CLASS(CFrameStatistics),
RUNTIME_CLASS(CViewStatistics));
AddDocTemplate(m_pStatisticsTemplate);
// Share window
m_pShareTemplate = new CMultiDocTemplate(
IDR_SHARE,
RUNTIME_CLASS(CGnucleusDoc),
RUNTIME_CLASS(CFrameShare),
RUNTIME_CLASS(CViewShare));
AddDocTemplate(m_pShareTemplate);
// Transfers window
m_pTransfersTemplate = new CMultiDocTemplate(
IDR_TRANSFERS,
RUNTIME_CLASS(CGnucleusDoc),
RUNTIME_CLASS(CFrameTransfers),
RUNTIME_CLASS(CViewTransfers));
AddDocTemplate(m_pTransfersTemplate);
// Search window
m_pSearchTemplate = new CMultiDocTemplate(
IDR_SEARCH,
RUNTIME_CLASS(CGnucleusDoc),
RUNTIME_CLASS(CFrameSearch),
RUNTIME_CLASS(CViewSearch));
AddDocTemplate(m_pSearchTemplate);
// Chat window
m_pChatTemplate = new CMultiDocTemplate(
IDR_CHAT,
RUNTIME_CLASS(CGnucleusDoc),
RUNTIME_CLASS(CFrameChat),
RUNTIME_CLASS(CViewChat));
AddDocTemplate(m_pChatTemplate);
// Browser window
m_pBrowserTemplate = new CMultiDocTemplate(
IDR_BROWSER,
RUNTIME_CLASS(CGnucleusDoc),
RUNTIME_CLASS(CFrameBrowser),
RUNTIME_CLASS(CViewBrowser));
AddDocTemplate(m_pBrowserTemplate);
}
// Command line processing
void CMyCmdLineInfo::ParseParam(LPCSTR pszParam, BOOL bFlag, BOOL bLast)
{
if (bFlag && stricmp(pszParam, "min") == 0)
m_Minimize = true;
else
CCommandLineInfo::ParseParam (pszParam, bFlag, bLast);
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
CString m_AboutDNA;
CString m_LicenseDNA;
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CButton m_stcVersionFrame;
//}}AFX_DATA
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
protected:
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedOk();
CStatic m_stcVersion;
CStatic m_stcLicenseDNA;
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_STATIC_VERSION, m_stcVersionFrame);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_STATIC_GNUCDNA, m_stcVersion);
DDX_Control(pDX, IDC_STATIC_DNALICENSE, m_stcLicenseDNA);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()
// App command to run the dialog
void CGnucleusApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.m_AboutDNA = "Gnucleus uses GnucDNA version " + m_pDoc->m_autCore->GetCoreVersion();
aboutDlg.m_LicenseDNA = m_pDoc->m_autCore->GetCoreLicense();
// Test download from web
//int DownloadID = m_pDoc->m_autDownload->DownloadFile2("Picture2.jpg", 282152, HASH_SHA1, "3IM67PAFGVWTQZEAGTWKAEM3SYBVG4OF");
//m_pDoc->m_autDownload->AddSource(DownloadID, NETWORK_WEB, "http://www.gnucleus.com/GnucDNA/picture2.jpg");
//m_pDoc->m_autDownload->Proxy(DownloadID, true, "66.123.218.124:80");
aboutDlg.DoModal();
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CGnucleusDoc* pDoc = (CGnucleusDoc*) ((CGnucleusApp*)AfxGetApp())->m_pDoc;
CString Title = "Gnucleus ";
Title += pDoc->m_GnuVersion;
m_stcVersionFrame.SetWindowText(Title);
m_stcVersion.SetWindowText(m_AboutDNA);
m_stcLicenseDNA.SetWindowText(m_LicenseDNA);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CGnucleusApp::PreTranslateMessage(MSG* pMsg)
{
return CWinApp::PreTranslateMessage(pMsg);
}
void CAboutDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
OnOK();
}