Understanding the source code

Problems compiling? Don't understand the source code? Don't know how to code your feature? Post here.

Moderator: Moderators

AstroDog
Posts: 7
Joined: 2003-03-22 10:29

Understanding the source code

Post by AstroDog » 2003-03-22 10:37

Hey! I have gone through the source code to some extent and have made successful changes but I don't understand the overall workings of the code. So my questions is how can I understand it fully? And also where can I learn WTL? Good someone perhaps by a quick example tell me how to for example add a button under the menubar or limit the download speed so that the source is changed if dl-speed is less than let's say 5 kb/s or similar, and perhaps also how to add an option for this in the settingsdialog. Of course clear code would be the best but I can think for myself and a general outline of how this should be written would be sufficient for me. Also I would like a general discussion of DC++-code in general, things that I always have to think about etc... for example locks, what are they? I am pretty familiar with winapi but have never used mfc,atl or wtl. Anyone know any good e-books or books on WTL? Or perhaps a site with a tutorial?

:arrow: Thanks in advance, Martin, Sweden
You live and you die.

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-08 02:46
Location: .pa.us

Post by GargoyleMT » 2003-03-22 14:56

You have so many questions/requests in your message that I can't possibly answer any of them. :P

Well, maybe just one or two...

As for the adding a menu option just take a look. You'll need to add menu entries in WinUtil.cpp, and methods to handle them in MainFrm.cpp/h. Don't forget the strings in the StringDefs.

Take a look at the settings dialogs, they're pretty easy to add.

For changing sources, that'd be an excellent feature, it's been requested. You'll have to add a int setting to the SettingsManager, a string to StringDefs.cpp/h, an entry for the setting in AdvancedPage.cpp. Then comes the actual implementation of the code. You'll need to modify the DownloadManager, I'd probably add a rolling-5 second average speed to the members (if not 30 or minute), to smooth out the measurement. You might not be able to easily determine if there's another source for a given file, so you might have to add some hooks in to the QueueManager.

I hope this helps. Of course, it's only generalities, but if I gave specifics, I'd be writing the feature. ;-)

AstroDog
Posts: 7
Joined: 2003-03-22 10:29

Well you did give me some info =)

Post by AstroDog » 2003-03-22 15:50

Although I really would need a real coded example cause I am so not familiar with all the terminology of hooks and locks but I am confident (yeey =) that I would understand them with just a coded example and a few lines of good tutoring text, hehe. And of course the WTL-book if there exists one. Preferably a free PDF-version cause I have zero cash right now. Not that you care about my financial situation :evil: :P :lol: :shock: 8) :lol: *smileyspamming*

But I will give a go at the changing of dl-source. I did remember seeing something like onTimerSecond already in the DownloadManager I believe so just copy'n'paste'n'modify ehrr.. yea =)
You live and you die.

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-08 02:46
Location: .pa.us

Post by GargoyleMT » 2003-03-22 16:06

Well, if you look at the source and don't understand some of it, I'll gladly explain specifics and write some code to explain. Your initial barrage of questions was overwhelming. :) Just dive in to the source, and come back here if you need some air. It's how I got where I am, which isn't very far. ;-)

I haven't found a good WTL/ATL reference, by the way - even the ATL references in Visual Studio .NET are outdated - referring to 3.1 - and the WTL 7 distribution from MS seems to have no help files. I haven't looked for real books, though. If you dive into the .h files, you'll see that they're just wrappers, mostly, for win32 code [which you seem to be familiar with].

AstroDog
Posts: 7
Joined: 2003-03-22 10:29

Post by AstroDog » 2003-03-22 20:39

Download::Download(QueueItem* qi) throw() : source(qi->getCurrent()->getPath()),
target(qi->getTarget()), tempTarget(qi->getTempTarget()),
comp(NULL), bytesLeft(0), rollbackBuffer(NULL), rollbackSize(0)

someone please explain this code since I don't understand anything of it, with all the : and etc.. Is this basic C++ that I don't know or what?

Thanx, Martin
You live and you die.

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-08 02:46
Location: .pa.us

Post by GargoyleMT » 2003-03-22 21:58

That's one way of initializing member variables in a constructor. It's a little nicer than having it in the function body, imho.

AstroDog
Posts: 7
Joined: 2003-03-22 10:29

Post by AstroDog » 2003-03-23 08:36

So I presume source(qi->getCurrent()->getPath()) would be equivalent of source = qi->getCurrent()->getPath(); or even some method source(qi->getCurrent()->getPath()) but problem is I can't find neither a variable nor a method. So how does that initializing work?

And what is this here below that I see everywhere?
Lock l(cs);

Sorry if i am being a pain =)
You live and you die.

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-08 02:46
Location: .pa.us

Post by GargoyleMT » 2003-03-23 12:43

Look at GETSETREF() and GETSET() - they're macros, and they define a member variable plus functions to get and change it.

Lock l(cs) is about critical sections. Some of the code is not (can not be) designed to be reentrant, and DC++ is multithreaded, so you need to protect certain things with critical sections.

Who is online

Users browsing this forum: Google [Bot] and 0 guests