/
GnucleusDoc.cpp
507 lines (373 loc) · 13.2 KB
/
GnucleusDoc.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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
/********************************************************************************
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 "Gnucleus.h"
#include "PrefsEx.h"
#include "EvolverDlg.h"
#include "AutCore.h"
#include "AutPrefs.h"
#include "AutNetwork.h"
#include "AutCache.h"
#include "AutMeta.h"
#include "AutShare.h"
#include "AutSearch.h"
#include "AutDownload.h"
#include "AutUpload.h"
#include "AutUpdate.h"
#include "AutChat.h"
#include "AutNetworkSink.h"
#include "AutShareSink.h"
#include "AutSearchSink.h"
#include "AutDownloadSink.h"
#include "AutUploadSink.h"
#include "AutUpdateSink.h"
#include "AutChatSink.h"
#include "ChatControl.h"
#include "ChatServer.h"
#include "ChatPrefs.h"
#include "ViewConnect.h"
#include "ViewShare.h"
#include "ViewSearch.h"
#include "ViewTransfers.h"
#include "ViewStatistics.h"
#include "ViewChat.h"
#include "NetSetup.h"
#include <afxctl.h>
#include "GnucleusDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CGnucleusDoc, CDocument)
BEGIN_MESSAGE_MAP(CGnucleusDoc, CDocument)
//{{AFX_MSG_MAP(CGnucleusDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CGnucleusDoc::CGnucleusDoc()
{
}
CGnucleusDoc::CGnucleusDoc(CGnucleusApp* pApp)
{
m_pApp = pApp;
m_pViewConnect = NULL;
m_pViewShare = NULL;
m_pViewTransfers = NULL;
m_pViewChat = NULL;
// Mark if XP
OSVERSIONINFO osv;
osv.dwOSVersionInfoSize = sizeof(osv);
GetVersionEx(&osv);
m_RunningXP = (osv.dwMajorVersion == 5 && osv.dwMinorVersion == 1);
// Load main core
ConnectCore();
// Get Gnucleus version info from resource file
m_GnuVersion = GetVersionInfo();
m_autCore->SetClientName("Gnucleus");
m_autCore->SetClientVersion(m_GnuVersion);
m_autCore->SetClientCode("GNUC");
m_RunPath = m_autCore->GetRunPath();
// Load Meta data schemas
m_autMeta->LoadSchemaDir(m_RunPath + "\\Schemas");
// Load preferences
m_autPrefs->LoadConfig( m_RunPath + "Data\\GnuConfig.ini");
m_autPrefs->LoadBlocked( m_RunPath + "Data\\GnuBlocked.net");
// Load Gnuc specific prefs
m_pPrefsEx = new CPrefsEx;
m_pPrefsEx->LoadPrefsEx( m_RunPath + "Data\\GnuConfigEx.ini");
// Load node caches
m_autCache->LoadCache(m_RunPath + "Data\\GnuCache.net");
// Load web caches
//m_autCache->LoadWebCache(m_RunPath + "Data\\WebCache.net");
if(!m_autCache->GetWebCacheSize())
{
// HARDCODED: a few default caches, sites down
//m_autCache->AddWebCache("http://www.zero-g.net/gcache/gcache.php");
//m_autCache->AddWebCache("http://www.gnucleus.net/gcache/gcache.php");
}
// Load update servers and check for update
//m_autUpdate->AddServer("http://gnucleus.gnutelliums.com:80/update2/update.xml");
m_autUpdate->AddServer("http://www.gnucleus.com/update2/update.xml");
m_autUpdate->Check();
// Load Chat
m_pChat = new CChatControl(this);
// Display LAN setup dialog
if(m_autPrefs->GetLanMode())
{
m_autNetwork->LanModeOn();
m_autCache->LoadWebCache(m_RunPath + "Data\\LanWebCache.net");
if( !(m_pApp->m_Min && !m_autPrefs->GetLanName().IsEmpty()) )
{
CNetSetup NetSetup(this);
NetSetup.DoModal();
}
}
// Start connecting
if(m_pPrefsEx->m_AutoConnect)
{
if(m_pPrefsEx->m_ConnectGnutella)
m_autCore->Connect2(NETWORK_GNUTELLA);
if(m_pPrefsEx->m_ConnectG2)
m_autCore->Connect2(NETWORK_G2);
m_pChat->m_AutoConnect = true;
}
if(m_pPrefsEx->m_ForceGnuUltra)
m_autNetwork->ForceUltrapeer2(true, NETWORK_GNUTELLA);
if(m_pPrefsEx->m_ForceG2Hub)
m_autNetwork->ForceUltrapeer2(true, NETWORK_G2);
// this tries the centralized cache for gnucleus
m_autCache->AddWebCache("http://gcache.c0re.net/");
m_autCache->TryWebCache("gnutella");
// Connect to chat
if(m_autPrefs->GetLanMode() && m_pChat->m_pPrefs->m_InternalIRC)
m_pChat->GetConnect();
m_pDiagEvolve = NULL;
m_nLastPref = PREF_LOCAL;
}
void CGnucleusDoc::ConnectCore()
{
m_autCore = new CAutCore;
if(!m_autCore->CreateDispatch("GnucCOM.Core"))
{
AfxMessageBox("Could not load GnucDNA");
return;
}
// Make sure version of core is same or newer than what we built with
CString CoreVersion = m_autCore->GetCoreVersion();
CoreVersion.Remove('.');
CString BuildVersion = BUILD_CORE_VERSION;
BuildVersion.Remove('.');
if(atoi(CoreVersion) < atoi(BuildVersion))
{
AfxMessageBox("GnucDNA " + CString(BUILD_CORE_VERSION) + " or higher needed, please update");
return;
}
// Attach prefs object
m_autPrefs = new CAutPrefs;
m_autPrefs->AttachDispatch( m_autCore->GetIPrefs(), false );
// Attach network object
m_autNetwork = new CAutNetwork;
m_autNetwork->AttachDispatch( m_autCore->GetINetwork(), false );
// Attach cache object
m_autCache = new CAutCache;
m_autCache->AttachDispatch( m_autCore->GetICache(), false );
// Attach meta object
m_autMeta = new CAutMeta;
m_autMeta->AttachDispatch( m_autCore->GetIMeta(), false );
// Attach share object
m_autShare = new CAutShare;
m_autShare->AttachDispatch( m_autCore->GetIShare(), false );
// Attach share object
m_autSearch = new CAutSearch;
m_autSearch->AttachDispatch( m_autCore->GetISearch(), false );
// Attach download object
m_autDownload = new CAutDownload;
m_autDownload->AttachDispatch( m_autCore->GetIDownload(), false );
// Attach upload object
m_autUpload = new CAutUpload;
m_autUpload->AttachDispatch( m_autCore->GetIUpload(), false );
// Attach update object
m_autUpdate = new CAutUpdate;
m_autUpdate->AttachDispatch( m_autCore->GetIUpdate(), false );
// Attach chat object
m_autChat = new CAutChat;
m_autChat->AttachDispatch( m_autCore->GetIChat(), false );
// Network event object and establish a connection between source and sink.
m_autNetworkSink = new CAutNetworkSink(this);
AfxConnectionAdvise(m_autNetwork->m_lpDispatch, IID_INetworkEvent, m_autNetworkSink->GetIDispatch(false), false, &m_NetEventCookie);
// Share event object and establish a connection between source and sink.
m_autShareSink = new CAutShareSink(this);
AfxConnectionAdvise(m_autShare->m_lpDispatch, IID_IShareEvent, m_autShareSink->GetIDispatch(false), false, &m_ShareEventCookie);
// Share event object and establish a connection between source and sink.
m_autSearchSink = new CAutSearchSink(this);
AfxConnectionAdvise(m_autSearch->m_lpDispatch, IID_ISearchEvent, m_autSearchSink->GetIDispatch(false), false, &m_SearchEventCookie);
// Download event object and establish a connection between source and sink.
m_autDownloadSink = new CAutDownloadSink(this);
AfxConnectionAdvise(m_autDownload->m_lpDispatch, IID_IDownloadEvent, m_autDownloadSink->GetIDispatch(false), false, &m_DownloadEventCookie);
// Upload event object and establish a connection between source and sink.
m_autUploadSink = new CAutUploadSink(this);
AfxConnectionAdvise(m_autUpload->m_lpDispatch, IID_IUploadEvent, m_autUploadSink->GetIDispatch(false), false, &m_UploadEventCookie);
// Update event object and establish a connection between source and sink.
m_autUpdateSink = new CAutUpdateSink(this);
AfxConnectionAdvise(m_autUpdate->m_lpDispatch, IID_IUpdateEvent, m_autUpdateSink->GetIDispatch(false), false, &m_UpdateEventCookie);
// Chat event object and establish a connection between source and sink.
m_autChatSink = new CAutChatSink(this);
AfxConnectionAdvise(m_autChat->m_lpDispatch, IID_IChatEvent, m_autChatSink->GetIDispatch(false), false, &m_ChatEventCookie);
}
void CGnucleusDoc::DisconnectCore()
{
AfxConnectionUnadvise(m_autChat->m_lpDispatch, IID_IChatEvent, m_autChatSink->GetIDispatch(false), false, m_ChatEventCookie);
delete m_autChatSink;
m_autChatSink = NULL;
AfxConnectionUnadvise(m_autUpdate->m_lpDispatch, IID_IUpdateEvent, m_autUpdateSink->GetIDispatch(false), false, m_UpdateEventCookie);
delete m_autUpdateSink;
m_autUpdateSink = NULL;
AfxConnectionUnadvise(m_autUpload->m_lpDispatch, IID_IUploadEvent, m_autUploadSink->GetIDispatch(false), false, m_UploadEventCookie);
delete m_autUploadSink;
m_autUploadSink = NULL;
AfxConnectionUnadvise(m_autDownload->m_lpDispatch, IID_IDownloadEvent, m_autDownloadSink->GetIDispatch(false), false, m_DownloadEventCookie);
delete m_autDownloadSink;
m_autDownloadSink = NULL;
AfxConnectionUnadvise(m_autSearch->m_lpDispatch, IID_ISearchEvent, m_autSearchSink->GetIDispatch(false), false, m_SearchEventCookie);
delete m_autSearchSink;
m_autSearchSink = NULL;
AfxConnectionUnadvise(m_autShare->m_lpDispatch, IID_IShareEvent, m_autShareSink->GetIDispatch(false), false, m_ShareEventCookie);
delete m_autShareSink;
m_autShareSink = NULL;
AfxConnectionUnadvise(m_autNetwork->m_lpDispatch, IID_INetworkEvent, m_autNetworkSink->GetIDispatch(false), false, m_NetEventCookie);
delete m_autNetworkSink;
m_autNetworkSink = NULL;
delete m_autChat;
m_autChat = NULL;
delete m_autUpdate;
m_autUpdate = NULL;
delete m_autUpload;
m_autUpload = NULL;
delete m_autDownload;
m_autDownload = NULL;
delete m_autSearch;
m_autSearch = NULL;
delete m_autShare;
m_autShare = NULL;
delete m_autMeta;
m_autMeta = NULL;
delete m_autCache;
m_autCache = NULL;
delete m_autNetwork;
m_autNetwork = NULL;
delete m_autPrefs;
m_autPrefs = NULL;
delete m_autCore;
m_autCore = NULL;
}
CGnucleusDoc::~CGnucleusDoc()
{
m_pPrefsEx->SavePrefsEx(m_RunPath + "Data\\GnuConfigEx.ini");
// Save preferences
m_autPrefs->SaveConfig( m_RunPath + "Data\\GnuConfig.ini");
m_autPrefs->SaveBlocked(m_RunPath + "Data\\GnuBlocked.net");
// Save node caches
m_autCache->SaveCache(m_RunPath + "Data\\GnuCache.net");
// Save web caches
/*if(m_autPrefs->GetLanMode())
m_autCache->SaveWebCache(m_RunPath + "Data\\LanWebCache.net");
else
{
if(!m_autCache->GetWebCacheSize())
{
// HARDCODED: a few default caches
//m_autCache->AddWebCache("http://www.zero-g.net/gcache/gcache.php");
//m_autCache->AddWebCache("http://www.gnucleus.net/gcache/gcache.php");
}
m_autCache->SaveWebCache(m_RunPath + "Data\\WebCache.net");
}*/
delete m_pPrefsEx;
m_pPrefsEx = NULL;
delete m_pChat;
m_pChat = NULL;
DisconnectCore();
TRACE0("*** CGnucleusDoc Deconstructing\n");
}
/////////////////////////////////////////////////////////////////////////////
// CGnucleusDoc serialization
void CGnucleusDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CGnucleusDoc diagnostics
#ifdef _DEBUG
void CGnucleusDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CGnucleusDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGnucleusDoc commands
CString CGnucleusDoc::ResolveIP(IP HostIP)
{
/*hostent* pHostent;
pHostent = (LPHOSTENT) m_pComm->m_HostEnt;
pHostent = gethostbyaddr((char*) &HostIP.S_addr, sizeof(HostIP), AF_INET);
if(pHostent)
{
CString HostName( pHostent->h_name);
return HostName;
}*/
return IPtoStr(HostIP);
}
FullIcon CGnucleusDoc::GetIconIndex(const CString& file)
{
FullIcon Icon;
Icon.Index = GetIconIndexFromName(file);
Icon.Type = GetIconDescFromName(file);
return Icon;
}
void CGnucleusDoc::DisplayEvolver()
{
if(m_pDiagEvolve == NULL)
{
m_pDiagEvolve = new CEvolverDlg(AfxGetApp()->GetMainWnd());
m_pDiagEvolve->m_pDoc = this;
m_pDiagEvolve->m_autUpdate = m_autUpdate;
m_pDiagEvolve->Create(IDD_EVOLVE_MAIN, AfxGetApp()->m_pMainWnd);
}
m_pDiagEvolve->ShowWindow(SW_SHOW);
m_pDiagEvolve->BringWindowToTop();
}
/////////////////////////////////////////////////////////////////////////////
// CGnucleusDoc GetVersionInfo
CString CGnucleusDoc::GetVersionInfo(void)
{
char szAppName[_MAX_PATH];
DWORD dwHandle, dwSize;
CString version = "9.9.9.9";
if( GetModuleFileName(AfxGetInstanceHandle(), szAppName, sizeof(szAppName)) )
{
dwHandle = 0;
dwSize = GetFileVersionInfoSize(szAppName, &dwHandle);
if( dwSize != 0L )
{
UINT uVerInfoSize;
LPVOID lpStr;
LPVOID lpVerInfo = new BYTE[dwSize];
if( GetFileVersionInfo(szAppName, NULL, dwSize, lpVerInfo) )
{
if( VerQueryValue(lpVerInfo, "\\StringFileInfo\\040904B0\\ProductVersion", &lpStr, &uVerInfoSize) )
version = reinterpret_cast<char *>(lpStr);
}
delete[] lpVerInfo;
}
}
return version;
}