1 // ------------------------------------------------
6 // Windows front end GUI, PeerCast core is not dependant on any of this.
7 // Its very messy at the moment, but then again Windows UI always is.
8 // I really don`t like programming win32 UI.. I want my borland back..
10 // (c) 2002 peercast.org
11 // ------------------------------------------------
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 // ------------------------------------------------
23 #define _WIN32_WINNT 0x0500
31 #include "win32/wsys.h"
33 #include "win32/wsocket.h"
46 #include "chkMemoryLeak.h"
47 #define DEBUG_NEW new(__FILE__, __LINE__)
52 bool shownChannels=false;
53 WINDOWPLACEMENT winPlace;
56 using namespace Gdiplus;
60 void APICALL MyPeercastApp ::printLog(LogBuffer::TYPE t, const char *str)
62 /* ADDLOG(str,logID,true,NULL,t);
65 logFile.writeLine(str);
70 void APICALL MyPeercastApp::updateSettings()
75 Gdiplus::Bitmap bmpBack(800,600,PixelFormat24bppRGB);
79 Gdiplus::Image *backImage;
80 Gdiplus::Bitmap *backBmp;
81 Gdiplus::Graphics *backGra;
83 Gdiplus::Image *img_idle;
84 Gdiplus::Image *img_connect;
85 Gdiplus::Image *img_conn_ok;
86 Gdiplus::Image *img_conn_full;
87 Gdiplus::Image *img_conn_over;
88 Gdiplus::Image *img_conn_ok_skip;
89 Gdiplus::Image *img_conn_full_skip;
90 Gdiplus::Image *img_conn_over_skip;
91 Gdiplus::Image *img_error;
92 Gdiplus::Image *img_broad_ok;
93 Gdiplus::Image *img_broad_full;
99 extern HINSTANCE hInst;
104 WLock ChannelDataLock;
106 ChannelData *channelDataTop = NULL;
108 bool gbDispTop = false;
109 bool gbAllOpen = false;
111 THREAD_PROC GetHostName(ThreadInfo *thread){
112 IdData *id = (IdData*)(thread->data);
118 ip = htonl(id->getIpAddr());
120 for (int i=0; i<5 && flg; i++){
121 he = gethostbyaddr((char *)&ip,sizeof(ip),AF_INET);
123 ChannelDataLock.on();
124 ChannelData* cd = channelDataTop;
128 if (cd->setName(id->getServentId(), he->h_name)){
132 cd = cd->getNextData();
136 ChannelDataLock.off();
144 int drawSpeed(Graphics *gra, int posX, int posY){
146 //
\91¬
\93x
\95\
\8e¦
\95\94\82Ì
\94w
\8ci
\82ð
\94\92\82
\82·
\82é
147 SolidBrush b(Color(180,255,255,255));
148 backGra->FillRectangle(&b, posX, posY, 200, 14);
149 //
\83t
\83H
\83\93\83g
\90Ý
\92è
150 Font font(L"
\82l
\82r
\82o
\83S
\83V
\83b
\83N",10);
152 SolidBrush strBrush(Color::Black);
153 //
\95¶
\8e\9a\97ñ
\8dì
\90¬
155 sprintf(tmp, "R:%.1fkbps S:%.1fkbps",
156 BYTES_TO_KBPS(stats.getPerSecond(Stats::BYTESIN)-stats.getPerSecond(Stats::LOCALBYTESIN)),
157 BYTES_TO_KBPS(stats.getPerSecond(Stats::BYTESOUT)-stats.getPerSecond(Stats::LOCALBYTESOUT)));
159 //
\95¶
\8e\9a\95\
\8e¦
\94Í
\88Í
\8ew
\92è
161 format.SetAlignment(StringAlignmentCenter);
162 RectF r((REAL)posX, (REAL)posY, (REAL)200, (REAL)14);
163 //
\95¶
\8e\9a\95`
\89æ
164 gra->DrawString(bstr, -1, &font, r, &format, &strBrush);
171 void MakeBack(HWND hwnd, UINT x, UINT y){
182 backBmp = ::new Bitmap(x,y);
183 backGra = ::new Graphics(backBmp);
185 //
\91S
\82Ä
\94\92\82Å
\93h
\82è
\82Â
\82Ô
\82µ
186 SolidBrush b(Color(255,255,255,255));
187 backGra->FillRectangle(&b, 0, 0, x, y);
189 backWidth = backImage->GetWidth();
190 backHeight = backImage->GetHeight();
192 //
\94w
\8ci
\89æ
\91\9c\82ð
\95`
\89æ
193 for (UINT xx = 0; xx < x/backWidth + 1; xx++){
194 for (UINT yy = 0; yy < y/backHeight + 1; yy++){
196 if (backWidth*(xx+1) > x){
197 width = x % backWidth;
201 if (backHeight*(yy+1) > y){
202 height = y % backHeight;
206 Rect r((INT)backWidth*xx, (INT)backHeight*yy, width, height);
207 backGra->DrawImage(backImage, r, 0, 0, (INT)width, (INT)height, UnitPixel);
215 drawSpeed(backGra, winWidth-205, 5);
217 //
\83`
\83\83\83\93\83l
\83\8b\8fî
\95ñ
\82ð
\95`
\89æ
218 ChannelDataLock.on();
219 ChannelData *cd = channelDataTop;
221 posY = cd->drawChannel(backGra, 20, posY);
222 cd = cd->getNextData();
224 ChannelDataLock.off();
228 void MakeBack(HWND hwnd){
229 MakeBack(hwnd, winWidth, winHeight);
230 ::InvalidateRect(guiWnd, NULL, FALSE);
233 void ChannelData::setData(Channel *c){
236 sjis.convertTo(String::T_SJIS);
238 strncpy(name, sjis, 256);
240 channel_id = c->channel_id;
241 bitRate = c->info.bitrate;
242 lastPlayStart = c->info.lastPlayStart;
244 totalListeners = c->totalListeners();
245 totalRelays = c->totalRelays();
246 localListeners = c->localListeners();
247 localRelays = c->localRelays();
248 stayConnected = c->stayConnected;
250 bTracker = c->sourceHost.tracker;
251 lastSkipTime = c->lastSkipTime;
252 skipCount = c->skipCount;
258 int ChannelData::drawChannel(Graphics *g, int x, int y){
263 //
\88Ê
\92u
\82ð
\95Û
\91¶
269 if (getWidth() == 0){
280 //
\83`
\83\83\83\93\83l
\83\8b\95\
\8e¦
\95\94\82Ì
\94w
\8ci
\82ð
\93h
\82é
283 SolidBrush b(Color(160,49,106,197));
284 g->FillRectangle(&b, x, y, w, 14);
287 SolidBrush b(Color(160,255,255,255));
288 g->FillRectangle(&b, x, y, w, 14);
291 //
\83X
\83e
\81[
\83^
\83X
\95\
\8e¦
292 Gdiplus::Image *img = NULL;
293 unsigned int nowTime = sys->getTime();
294 Channel *ch = chanMgr->findChannelByChannelID(this->channel_id);
295 switch(this->getStatus()){
296 case Channel::S_IDLE:
299 case Channel::S_SEARCHING:
300 case Channel::S_CONNECTING:
303 case Channel::S_RECEIVING:
304 if ((skipCount > 2) && (lastSkipTime + 120 > nowTime)){
306 img = img_conn_ok_skip;
308 if (chDisp.numRelays){
309 img = img_conn_full_skip;
311 img = img_conn_over_skip;
318 if (chDisp.numRelays){
326 case Channel::S_BROADCASTING:
329 case Channel::S_ERROR:
330 // bump
\8e\9e\82É
\83G
\83\89\81[
\82ª
\95\
\8e¦
\82³
\82ê
\82é
\82Ì
\82ð
\96h
\8e~
331 if (ch && ch->bumped)
344 PointF origin(xx, yy);
345 //
\83X
\83e
\81[
\83^
\83X
\95\
\8e¦
\88Ê
\92u
346 Rect img_rect((INT)origin.X, (INT)origin.Y + 1, img ? img->GetWidth() : 12, 12);
347 //
\83X
\83e
\81[
\83^
\83X
\95`
\89æ
349 // att.SetColorKey(Color::White, Color::White, ColorAdjustTypeBitmap);
350 g->DrawImage(img, img_rect, 0, 0, img_rect.Width, 12, UnitPixel, &att);
351 //
\8e\9f\82Ì
\8aî
\93_
352 origin.X += img_rect.Width;
354 //
\83t
\83H
\83\93\83g
\90Ý
\92è
355 Gdiplus::Font font(L"
\82l
\82r
\82o
\83S
\83V
\83b
\83N",10);
357 SolidBrush *strBrush;
358 if (servMgr->getFirewall() == ServMgr::FW_ON){
359 strBrush = ::new SolidBrush(Color::Red);
360 } else if (isTracker() && (getStatus() == Channel::S_RECEIVING)){
361 strBrush = ::new SolidBrush(Color::Green);
365 strBrush = ::new SolidBrush(Color::White);
368 strBrush = ::new SolidBrush(Color::Black);
371 //
\83`
\83\83\83\93\83l
\83\8b\96¼
\95\
\8e¦
372 g->SetTextRenderingHint(TextRenderingHintAntiAlias);
373 _bstr_t bstr1(getName());
374 //
\95¶
\8e\9a\95`
\89æ
\94Í
\88Í
\8ew
\92è
375 RectF r1(origin.X, origin.Y, 120.0f, 13.0f);
377 format.SetAlignment(StringAlignmentNear);
378 g->DrawString(bstr1, -1, &font, r1, &format, strBrush);
379 //
\8e\9f\82Ì
\8aî
\93_
380 origin.X += r1.Width;
382 ////
\8fã
\97¬IP/
\83\8a\83X
\83i
\81[
\90\94/
\83\8a\83\8c\81[
\90\94\95\
\8e¦
384 ////
\82Ò
\82 \82©
\82·
\82Ì
\93®
\8dì
\95×
\8b
\97p
\81B
\83\8a\83\8a\81[
\83X
\83r
\83\8b\83h
\82Å
\82Í
\8c³
\82Ì
\83R
\81[
\83h
\82ð
\8eg
\97p
\82Ì
\8e\96\81B
385 ////
\95¶
\8e\9a\95\
\8e¦
\94Í
\88Í
\82Í
\95\9d220
\82®
\82ç
\82¢
\82Å
\82¨
\82\8b
386 //char tmp[512]; //
\95\
\8e¦
\97p
\83o
\83b
\83t
\83@
387 //char hostip[256]; // IP
\83A
\83h
\83\8c\83X
\83o
\83b
\83t
\83@
388 //chDisp.uphost.toStr(hostip); //
\8fã
\97¬IP
389 //sprintf(tmp, "%d/%d - [%d/%d] - %s",
390 // getTotalListeners(),
392 // getLocalListeners(),
397 //
\83\8a\83X
\83i
\81[
\90\94/
\83\8a\83\8c\81[
\90\94\95\
\8e¦
399 sprintf(tmp, "%d/%d - [%d/%d]", getTotalListeners(), getTotalRelays(), getLocalListeners(), getLocalRelays());
401 //
\95¶
\8e\9a\95\
\8e¦
\94Í
\88Í
\8ew
\92è
402 RectF r2(origin.X, origin.Y, 100.0f, 13.0f);
403 format.SetAlignment(StringAlignmentCenter);
404 g->DrawString(bstr2, -1, &font, r2, &format, strBrush);
405 //
\8e\9f\82Ì
\8aî
\93_
406 origin.X += r2.Width;
410 if (isStayConnected()){
411 f = ::new Font(L"Arial", 9.0f, FontStyleItalic|FontStyleBold, UnitPoint);
413 f = ::new Font(L"Arial", 9.0f);
415 sprintf(tmp, "%dkbps", getBitRate());
417 format.SetAlignment(StringAlignmentFar);
418 //
\95¶
\8e\9a\95\
\8e¦
\94Í
\88Í
\8ew
\92è
419 RectF r3(origin.X, origin.Y, 80.0f, 13.0f);
420 g->DrawString(bstr3, -1, f, r3, &format, strBrush);
421 //
\83t
\83H
\83\93\83g
\8aJ
\95ú
424 //
\8e\9f\82Ì
\8aî
\93_
425 origin.X += r3.Width;
427 //
\83u
\83\89\83V
\8dí
\8f\9c
433 int count = getServentCount();
434 // Servent
\95\
\8e¦
\95\94\82Ì
\94w
\8ci
\82ð
\94\92\82É
\82·
\82é
435 SolidBrush b(Color(160,255,255,255));
436 g->FillRectangle(&b, (INT)origin.X, (INT)origin.Y, 14*count, 14);
441 SolidBrush *serventBrush;
442 if (sd->getInfoFlg()){
443 ChanHit *hit = sd->getChanHit();
444 if (hit->firewalled){
445 SolidBrush bb(Color(180,255,0,0));
446 g->FillRectangle(&bb, (INT)origin.X + 14*index, (INT)origin.Y, 14, 14);
449 //
\83\8a\83\8c\81[
\82n
\82j
450 serventBrush = ::new SolidBrush(Color::Green);
452 //
\83\8a\83\8c\81[
\95s
\89Â
454 //
\83\8a\83\8c\81[
\88ê
\94t
455 serventBrush = ::new SolidBrush(Color::Blue);
457 //
\83\8a\83\8c\81[
\82È
\82µ
458 serventBrush = ::new SolidBrush(Color::Purple);
463 serventBrush = ::new SolidBrush(Color::Black);
466 backGra->FillRectangle(serventBrush, (INT)origin.X + index*14 + 1, (INT)origin.Y + 1, 12, 12);
468 ::delete serventBrush;
469 sd = sd->getNextData();
474 //
\8e\9f\82Ì
\8aî
\93_
477 //
\83T
\83C
\83Y
\82ð
\95Û
\91¶
478 setWidth((int)origin.X - posX);
479 setHeight((int)origin.Y - posY);
481 // ServentData
\95\
\8e¦
484 if (openFlg || sd->getSelected()){
485 sd->drawServent(g, (INT)x+12, (INT)origin.Y);
486 //
\8e\9f\82Ì
\8aî
\93_
489 sd = sd->getNextData();
493 return (int)(origin.Y);
496 bool ChannelData::checkDown(int x,int y){
497 //
\94Í
\88Í
\93à
\83`
\83F
\83b
\83N
500 && (x < posX + getWidth())
502 && (y < posY + getHeight())
509 ServentData *ChannelData::findServentData(int servent_id){
510 ServentData *sv = serventDataTop;
512 if (sv->getServentId() == servent_id){
515 sv = sv->getNextData();
520 void ChannelData::addServentData(ServentData *sd){
521 sd->setNextData(serventDataTop);
525 void ChannelData::deleteDisableServents(){
526 ServentData *sd = serventDataTop;
527 ServentData *prev = NULL;
530 if (!(sd->getEnableFlg())){
531 ServentData *next = sd->getNextData();
533 prev->setNextData(next);
535 serventDataTop = next;
541 sd = sd->getNextData();
546 int ChannelData::getServentCount(){
549 ServentData *sd = serventDataTop;
552 sd = sd->getNextData();
557 bool ChannelData::setName(int servent_id, String name){
558 ServentData *sd = serventDataTop;
560 if (sd->getServentId() == servent_id){
564 sd = sd->getNextData();
569 void ServentData::setData(Servent *s, ChanHit *hit, unsigned int listeners, unsigned int relays, bool f){
570 servent_id = s->servent_id;
573 lastSkipTime = s->lastSkipTime;
576 chanHit.numRelays = hit->numRelays;
577 chanHit.relay = hit->relay;
578 chanHit.firewalled = hit->firewalled;
579 chanHit.version = hit->version;
580 chanHit.version_vp = hit->version_vp;
581 chanHit.version_ex_number = hit->version_ex_number;
582 chanHit.version_ex_prefix[0] = hit->version_ex_prefix[0];
583 chanHit.version_ex_prefix[1] = hit->version_ex_prefix[1];
585 totalListeners = listeners;
586 totalRelays = relays;
591 int ServentData::drawServent(Gdiplus::Graphics *g, int x, int y){
596 //
\88Ê
\92u
\82ð
\95Û
\91¶
600 if (getWidth() == 0){
612 PointF origin(xx, yy);
614 //
\83t
\83H
\83\93\83g
\90Ý
\92è
615 Font font(L"
\82l
\82r
\82o
\83S
\83V
\83b
\83N",9);
617 SolidBrush *strBrush;
618 if (chanHit.firewalled){
619 strBrush = ::new SolidBrush(Color::Red);
623 strBrush = ::new SolidBrush(Color::White);
626 strBrush = ::new SolidBrush(Color::Black);
629 // ServantData
\95\
\8e¦
630 g->SetTextRenderingHint(TextRenderingHintAntiAlias);
631 //
\95¶
\8e\9a\97ñ
\8dì
\90¬
637 if (chanHit.version_ex_number){
638 //
\8ag
\92£
\83o
\81[
\83W
\83\87\83\93
639 sprintf(tmp, "%c%c%04d - %d/%d - %s(%s)",
640 chanHit.version_ex_prefix[0],
641 chanHit.version_ex_prefix[1],
642 chanHit.version_ex_number,
648 } else if (chanHit.version_vp){
649 sprintf(tmp, "VP%04d - %d/%d - %s(%s)",
657 sprintf(tmp, "(-----) - %d/%d - %s(%s)",
665 sprintf(tmp, "(-----) - %d/%d - %s(%s)",
674 //
\83X
\83e
\81[
\83^
\83X
\95\
\8e¦
675 Gdiplus::Image *img = NULL;
676 unsigned int nowTime = sys->getTime();
678 case Servent::S_CONNECTING:
681 case Servent::S_CONNECTED:
682 if (lastSkipTime + 120 > nowTime){
684 img = img_conn_ok_skip;
686 if (chanHit.numRelays){
687 img = img_conn_full_skip;
689 img = img_conn_over_skip;
696 if (chanHit.numRelays){
708 //
\95¶
\8e\9a\95`
\89æ
\94Í
\88Í
\8ew
\92è
709 RectF r1(origin.X + img->GetWidth() + 2, origin.Y, 800.0f, 13.0f);
712 format.SetAlignment(StringAlignmentNear);
713 g->MeasureString(bstr1, -1, &font, r1, &format, &r2);
715 w = (INT)r2.Width + img->GetWidth() + 2;
716 // ServentData
\95\
\8e¦
\95\94\82Ì
\94w
\8ci
\82ð
\93h
\82é
719 SolidBrush b(Color(160,49,106,197));
720 g->FillRectangle(&b, x, y, w, 13);
723 SolidBrush b(Color(160,200,200,200));
724 g->FillRectangle(&b, x, y, w, 13);
727 //
\83X
\83e
\81[
\83^
\83X
\95\
\8e¦
\88Ê
\92u
728 Rect img_rect((INT)origin.X, (INT)origin.Y+1, img ? img->GetWidth() : 12, 12);
729 //
\83X
\83e
\81[
\83^
\83X
\95`
\89æ
731 // att.SetColorKey(Color::White, Color::White, ColorAdjustTypeBitmap);
732 g->DrawImage(img, img_rect, 0, 0, img_rect.Width, 12, UnitPixel, &att);
733 //
\8e\9f\82Ì
\8aî
\93_
736 g->DrawString(bstr1, -1, &font, r2, &format, strBrush);
737 //
\8e\9f\82Ì
\8aî
\93_
738 origin.X += r2.Width;
741 setWidth((int)origin.X-posX);
742 setHeight((int)origin.Y - posY);
748 bool ServentData::checkDown(int x, int y){
751 && (x < posX + getWidth())
753 && (y < posY + getHeight())
761 THREAD_PROC GUIDataUpdate(ThreadInfo *thread){
764 // set GUI thread status to running
765 thread->finish = false;
767 while(thread->active){
768 //
\83`
\83\83\83\93\83l
\83\8b\83f
\81[
\83^
\83\8d\83b
\83N
769 ChannelDataLock.on();
770 //
\83`
\83\83\83\93\83l
\83\8b\83f
\81[
\83^
\82Ì
\8dX
\90V
\83t
\83\89\83O
\82ð
\91S
\82ÄFALSE
\82É
\82·
\82é
771 ChannelData *cd = channelDataTop;
773 // Servent
\82Ì
\8dX
\90V
\83t
\83\89\83O
\82ðFALSE
\82É
\82·
\82é
774 ServentData *sv = cd->getServentDataTop();
776 sv->setEnableFlg(FALSE);
777 sv = sv->getNextData();
779 cd->setEnableFlg(FALSE);
780 cd = cd->getNextData();
783 Channel *c = chanMgr->channel;
784 //
\8c»
\8dÝ
\91¶
\8dÝ
\82·
\82é
\83`
\83\83\83\93\83l
\83\8b\95ª
\83\8b\81[
\83v
786 //
\8aù
\82É
\83`
\83\83\83\93\83l
\83\8b\83f
\81[
\83^
\82ð
\8e\9d\82Á
\82Ä
\82¢
\82é
\82©
788 //
\94
\8c©
\83t
\83\89\83OFALSE
789 bool bFoundFlg = FALSE;
791 if (cd->getChannelId() == c->channel_id){
792 //
\8aù
\82É
\83`
\83\83\83\93\83l
\83\8b\83f
\81[
\83^
\82ª
\82 \82é
\82Ì
\82Å
\81A
\82»
\82Ì
\82Ü
\82Ü
\8dX
\90V
794 //
\8dX
\90V
\83t
\83\89\83OTRUE
795 cd->setEnableFlg(TRUE);
796 //
\94
\8c©
\83t
\83\89\83OTRUE
798 //
\83\8b\81[
\83v
\97£
\92E
801 //
\8c©
\82Â
\82©
\82ç
\82È
\82©
\82Á
\82½
\8fê
\8d\87\81A
\8e\9f\82Ì
\83f
\81[
\83^
\82ð
\83`
\83F
\83b
\83N
802 cd = cd->getNextData();
805 //
\90V
\82µ
\82¢
\83`
\83\83\83\93\83l
\83\8b\82Ì
\8fê
\8d\87\81A
\90V
\8bK
\83f
\81[
\83^
\8dì
\90¬
807 //
\90V
\8bK
\83f
\81[
\83^
\8dì
\90¬
808 cd = ::new ChannelData();
809 //
\83f
\81[
\83^
\8dX
\90V
811 //
\8dX
\90V
\83t
\83\89\83OTRUE
812 cd->setEnableFlg(TRUE);
814 //
\90V
\8bK
\83f
\81[
\83^
\82ð
\83\8a\83X
\83g
\82Ì
\90æ
\93ª
\82É
\93ü
\82ê
\82é
815 cd->setNextData(channelDataTop);
818 //
\8e\9f\82Ì
\83`
\83\83\83\93\83l
\83\8b\82ð
\8eæ
\93¾
822 //
\83`
\83\83\83\93\83l
\83\8b\82ª
\82È
\82
\82È
\82Á
\82Ä
\82¢
\82é
\8fê
\8d\87\82Ì
\8f\88\97\9d
824 ChannelData *prev = NULL;
826 //
\83f
\81[
\83^
\82ð
\8dX
\90V
\82µ
\82È
\82©
\82Á
\82½
\82©
827 if (cd->getEnableFlg() == FALSE){
828 //
\83`
\83\83\83\93\83l
\83\8b\82ª
\82È
\82
\82È
\82Á
\82Ä
\82¢
\82é
\82Ì
\82Å
\8dí
\8f\9c
830 next = cd->getNextData();
832 //
\90æ
\93ª
\82Ì
\83f
\81[
\83^
\82ð
\8dí
\8f\9c
833 channelDataTop = next;
835 //
\93r
\92\86\82Ì
\83f
\81[
\83^
\82ð
\8dí
\8f\9c
836 prev->setNextData(next);
838 //
\8e\9f\82Ì
\83f
\81[
\83^
\82Ö
841 //
\83f
\81[
\83^
\8dX
\90V
\8dÏ
\81F
\8e\9f\82Ì
\83f
\81[
\83^
\82Ö
843 cd = cd->getNextData();
847 Servent *s = servMgr->servents;
851 bool infoFlg = false;
853 bool firewalled = false;
854 unsigned int numRelays = 0;
856 char ver_ex_prefix[2] = {' ', ' '};
857 int ver_ex_number = 0;
858 //
\92¼
\89º
\83z
\83X
\83g
\8fî
\95ñ
\83`
\83F
\83b
\83N
859 unsigned int totalRelays = 0;
860 unsigned int totalListeners = 0;
863 //
\8eó
\90M
\92\86\82©
864 if ((s->type == Servent::T_RELAY) && (s->status == Servent::S_CONNECTED)){
865 //
\83z
\83X
\83g
\8fî
\95ñ
\83\8d\83b
\83N
866 chanMgr->hitlistlock.on();
867 //
\92¼
\89º
\83z
\83X
\83g
\82ª
\8eó
\90M
\82µ
\82Ä
\82¢
\82é
\83`
\83\83\83\93\83l
\83\8b\82Ì
\83z
\83X
\83g
\8fî
\95ñ
\82ð
\8eæ
\93¾
868 chl = chanMgr->findHitListByID(s->chanID);
869 //
\83`
\83\83\83\93\83l
\83\8b\82Ì
\83z
\83X
\83g
\8fî
\95ñ
\82ª
\82 \82é
\82©
871 //
\83`
\83\83\83\93\83l
\83\8b\82Ì
\83z
\83X
\83g
\8fî
\95ñ
\82ª
\82 \82é
\8fê
\8d\87
872 ChanHit *hit = chl->hit;
873 //
\81@
\83`
\83\83\83\93\83l
\83\8b\82Ì
\83z
\83X
\83g
\8fî
\95ñ
\82ð
\91S
\91\96\8d¸
\82µ
\82Ä
875 // ID
\82ª
\93¯
\82¶
\82à
\82Ì
\82Å
\82 \82ê
\82Î
876 if (hit->servent_id == s->servent_id){
877 //
\83g
\81[
\83^
\83\8b\83\8a\83\8c\81[
\82Æ
\83g
\81[
\83^
\83\8b\83\8a\83X
\83i
\81[
\82ð
\89Á
\8eZ
878 totalRelays += hit->numRelays;
879 totalListeners += hit->numListeners;
880 //
\92¼
\89º
\82Å
\82 \82ê
\82Î
881 if (hit->numHops == 1){
882 //
\8fî
\95ñ
\82ð
\88ê
\92U
\95Û
\91¶
884 hitData.relay = hit->relay;
885 hitData.firewalled = hit->firewalled;
886 hitData.numRelays = hit->numRelays;
887 hitData.version_vp = hit->version_vp;
888 hitData.version_ex_prefix[0] = hit->version_ex_prefix[0];
889 hitData.version_ex_prefix[1] = hit->version_ex_prefix[1];
890 hitData.version_ex_number = hit->version_ex_number;
893 //
\8e\9f\82ð
\83`
\83F
\83b
\83N
898 //
\83`
\83\83\83\93\83l
\83\8b\83f
\81[
\83^
\82©
\82çServent
\82ð
\8c\9f\8dõ
899 bool bFoundFlg = FALSE;
902 ServentData *sv = cd->findServentData(s->servent_id);
903 // ServentData
\82ª
\82 \82ê
\82Î
904 if (sv && cd->getChannelId() == s->channel_id){
905 //
\83f
\81[
\83^
\90Ý
\92è
906 sv->setData(s, &hitData, totalListeners, totalRelays, infoFlg);
907 sv->setEnableFlg(TRUE);
911 cd = cd->getNextData();
913 // ServentData
\82ª
\8c©
\82Â
\82©
\82ç
\82È
\82©
\82Á
\82½
\8fê
\8d\87
915 //
\83`
\83\83\83\93\83l
\83\8b\83f
\81[
\83^
\82ð
\92T
\82·
918 //
\83`
\83\83\83\93\83l
\83\8bID
\82ª
\93¯
\82¶
\82©
919 if (cd->getChannelId() == s->channel_id){
920 //
\83f
\81[
\83^
\90Ý
\92è
921 ServentData *sv = ::new ServentData();
922 sv->setData(s, &hitData, totalListeners, totalRelays, infoFlg);
923 sv->setEnableFlg(TRUE);
924 //
\83`
\83\83\83\93\83l
\83\8b\83f
\81[
\83^
\82ÉServentData
\92Ç
\89Á
925 cd->addServentData(sv);
926 //
\83z
\83X
\83g
\96¼
\82ð
\8eæ
\93¾
\82·
\82é
927 IdData *id = ::new IdData(cd->getChannelId(), sv->getServentId(), sv->getHost().ip);
929 t.func = GetHostName;
931 sys->startThread(&t);
932 //
\83\8b\81[
\83v
\8fI
\97¹
935 //
\8e\9f\82Ì
\83f
\81[
\83^
\82Ö
936 cd = cd->getNextData();
939 //
\83z
\83X
\83g
\8fî
\95ñ
\83A
\83\93\83\8d\83b
\83N
940 chanMgr->hitlistlock.off();
945 //
\8dX
\90V
\82µ
\82Ä
\82¢
\82È
\82¢ServentData
\82ð
\8dí
\8f\9c
948 cd->deleteDisableServents();
949 cd = cd->getNextData();
952 //
\83`
\83\83\83\93\83l
\83\8b\83f
\81[
\83^
\83A
\83\93\83\8d\83b
\83N
953 ChannelDataLock.off();
960 // 0.1
\95b
\81~10
\82Å1
\95b
\91Ò
\82¿
969 // set GUI thread status to terminated
970 thread->finish = true;
975 ChannelData *findChannelData(int channel_id){
976 ChannelData *cd = channelDataTop;
979 if (cd->getChannelId() == channel_id){
982 cd = cd->getNextData();
989 void PopupChannelMenu(int channel_id){
991 MENUITEMINFO info, separator;
995 hMenu = CreatePopupMenu();
997 memset(&separator, 0, sizeof(MENUITEMINFO));
998 separator.cbSize = sizeof(MENUITEMINFO);
999 separator.fMask = MIIM_ID | MIIM_TYPE;
1000 separator.fType = MFT_SEPARATOR;
1001 separator.wID = 8000;
1003 memset(&info, 0, sizeof(MENUITEMINFO));
1004 info.cbSize = sizeof(MENUITEMINFO);
1005 info.fMask = MIIM_ID | MIIM_TYPE;
1006 info.fType = MFT_STRING;
1008 ChannelData *cd = findChannelData(channel_id);
1015 info.dwTypeData = "
\90Ø
\92f";
1016 InsertMenuItem(hMenu, -1, true, &info);
1018 InsertMenuItem(hMenu, -1, true, &separator);
1021 info.dwTypeData = "
\8dÄ
\90¶";
1022 InsertMenuItem(hMenu, -1, true, &info);
1024 InsertMenuItem(hMenu, -1, true, &separator);
1027 info.dwTypeData = "
\8dÄ
\90Ú
\91±";
1028 InsertMenuItem(hMenu, -1, true, &info);
1031 info.dwTypeData = "
\83L
\81[
\83v";
1032 InsertMenuItem(hMenu, -1, true, &info);
1034 InsertMenuItem(hMenu, -1, true, &separator);
1036 if (!cd->getOpenFlg()){
1038 info.dwTypeData = "
\92¼
\89º
\95\
\8e¦";
1039 InsertMenuItem(hMenu, -1, true, &info);
1042 info.dwTypeData = "
\92¼
\89º
\89B
\95Á";
1043 InsertMenuItem(hMenu, -1, true, &info);
1047 dwID = TrackPopupMenu(hMenu, TPM_LEFTALIGN|TPM_RETURNCMD, pos.x, pos.y, 0, guiWnd, NULL);
1051 cd = findChannelData(channel_id);
1057 Channel *c = chanMgr->findChannelByChannelID(channel_id);
1064 case 1000: //
\8dÄ
\90¶
1065 chanMgr->playChannel(c->info);
1068 case 1001: //
\90Ø
\92f
1069 c->thread.active = false;
1070 c->thread.finish = true;
1073 case 1002: //
\8dÄ
\90Ú
\91±
1074 //
\92¼
\89º
\82©
\82Â
\8eó
\90M
\92\86\82Å
\82 \82ê
\82Î
\8am
\94F
\83\81\83b
\83Z
\81[
\83W
\95\
\8e¦
1075 if (cd->isTracker() && cd->getStatus() == Channel::S_RECEIVING)
1078 id = MessageBox(guiWnd,
1079 "
\92¼
\89º
\82Å
\82·
\82ª
\8dÄ
\90Ú
\91±
\82µ
\82Ü
\82·
\82©
\81H",
1080 "
\92¼
\89º
\8cx
\8d\90",
1081 MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2);
1089 case 1003: //
\83L
\81[
\83v
1090 if (!c->stayConnected){
1091 c->stayConnected = true;
1093 c->stayConnected = false;
1097 case 1004: //
\92¼
\89º
\95\
\8e¦
1098 cd->setOpenFlg(TRUE);
1102 case 1005: //
\92¼
\89º
\89B
\95Á
1103 cd->setOpenFlg(FALSE);
1109 void PopupServentMenu(int servent_id){
1111 MENUITEMINFO info, separator;
1115 hMenu = CreatePopupMenu();
1117 memset(&separator, 0, sizeof(MENUITEMINFO));
1118 separator.cbSize = sizeof(MENUITEMINFO);
1119 separator.fMask = MIIM_ID | MIIM_TYPE;
1120 separator.fType = MFT_SEPARATOR;
1121 separator.wID = 8000;
1123 memset(&info, 0, sizeof(MENUITEMINFO));
1124 info.cbSize = sizeof(MENUITEMINFO);
1125 info.fMask = MIIM_ID | MIIM_TYPE;
1126 info.fType = MFT_STRING;
1128 ServentData *sd = NULL;
1129 ChannelData *cd = channelDataTop;
1131 sd = cd->findServentData(servent_id);
1135 cd = cd->getNextData();
1138 if (cd == NULL || sd == NULL){
1143 info.dwTypeData = "
\90Ø
\92f";
1144 InsertMenuItem(hMenu, -1, true, &info);
1146 // InsertMenuItem(hMenu, -1, true, &separator);
1149 dwID = TrackPopupMenu(hMenu, TPM_LEFTALIGN|TPM_RETURNCMD, pos.x, pos.y, 0, guiWnd, NULL);
1153 cd = channelDataTop;
1155 sd = cd->findServentData(servent_id);
1159 cd = cd->getNextData();
1162 if (cd == NULL || sd == NULL){
1166 Servent *s = servMgr->findServentByServentID(servent_id);
1173 case 1001: //
\90Ø
\92f
1174 s->thread.active = false;
1180 void PopupOtherMenu(){
1182 MENUITEMINFO info, separator;
1186 hMenu = CreatePopupMenu();
1188 memset(&separator, 0, sizeof(MENUITEMINFO));
1189 separator.cbSize = sizeof(MENUITEMINFO);
1190 separator.fMask = MIIM_ID | MIIM_TYPE;
1191 separator.fType = MFT_SEPARATOR;
1192 separator.wID = 8000;
1194 memset(&info, 0, sizeof(MENUITEMINFO));
1195 info.cbSize = sizeof(MENUITEMINFO);
1196 info.fMask = MIIM_ID | MIIM_TYPE;
1197 info.fType = MFT_STRING;
1201 info.dwTypeData = "
\8dÅ
\91O
\96Ê
\95\
\8e¦";
1202 InsertMenuItem(hMenu, -1, true, &info);
1205 info.dwTypeData = "
\8dÅ
\91O
\96Ê
\89ð
\8f\9c";
1206 InsertMenuItem(hMenu, -1, true, &info);
1209 InsertMenuItem(hMenu, -1, true, &separator);
1213 info.dwTypeData = "
\91S
\92¼
\89º
\93W
\8aJ";
1214 InsertMenuItem(hMenu, -1, true, &info);
1217 info.dwTypeData = "
\91S
\92¼
\89º
\89B
\95Á";
1218 InsertMenuItem(hMenu, -1, true, &info);
1221 InsertMenuItem(hMenu, -1, true, &separator);
1223 if (!servMgr->autoServe){
1225 info.dwTypeData = "
\97L
\8cø";
1226 InsertMenuItem(hMenu, -1, true, &info);
1229 info.dwTypeData = "
\96³
\8cø";
1230 InsertMenuItem(hMenu, -1, true, &info);
1234 dwID = TrackPopupMenu(hMenu, TPM_LEFTALIGN|TPM_RETURNCMD, pos.x, pos.y, 0, guiWnd, NULL);
1238 ChannelData *cd = channelDataTop;
1241 case 1101: //
\8dÅ
\91O
\96Ê
\95\
\8e¦
1243 ::SetWindowPos(guiWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
1246 case 1102: //
\8dÅ
\91O
\96Ê
\89ð
\8f\9c
1248 ::SetWindowPos(guiWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
1251 case 1103: //
\91S
\92¼
\89º
\93W
\8aJ
1254 cd->setOpenFlg(true);
1255 cd = cd->getNextData();
1259 case 1104: //
\91S
\92¼
\89º
\89B
\95Á
1262 cd->setOpenFlg(false);
1263 cd = cd->getNextData();
1267 case 1105: //
\97L
\8cø
1268 servMgr->autoServe = true;
1271 case 1106: //
\96³
\8cø
1272 servMgr->autoServe = false;
1278 void WmCreateProc(HWND hwnd){
1279 //
\8e©
\93®
\8dÅ
\91O
\96Ê
\8b@
\94\
1280 if (servMgr->topmostGui)
1288 _bstr_t bstr("back.jpg");
1289 backImage = ::new Image(bstr);
1291 MakeBack(hwnd, 800, 600);
1293 guiThread.func = GUIDataUpdate;
1294 if (!sys->startThread(&guiThread)){
1295 MessageBox(hwnd,"Unable to start GUI","PeerCast",MB_OK|MB_ICONERROR);
1296 PostMessage(hwnd,WM_DESTROY,0,0);
1299 SetWindowPlacement(hwnd, &winPlace);
1304 ::delete img_connect;
1305 ::delete img_conn_ok;
1306 ::delete img_conn_full;
1307 ::delete img_conn_over;
1308 ::delete img_conn_ok_skip;
1309 ::delete img_conn_full_skip;
1310 ::delete img_conn_over_skip;
1312 ::delete img_broad_ok;
1313 ::delete img_broad_full;
1315 bstr = L"ST_IDLE.bmp";
1316 img_idle = ::new Image(bstr);
1317 bstr = L"ST_CONNECT.bmp";
1318 img_connect = ::new Image(bstr);
1319 bstr = L"ST_CONN_OK.bmp";
1320 img_conn_ok = ::new Image(bstr);
1321 bstr = L"ST_CONN_FULL.bmp";
1322 img_conn_full = ::new Image(bstr);
1323 bstr = L"ST_CONN_OVER.bmp";
1324 img_conn_over = ::new Image(bstr);
1325 bstr = L"ST_CONN_OK_SKIP.bmp";
1326 img_conn_ok_skip = ::new Image(bstr);
1327 bstr = L"ST_CONN_FULL_SKIP.bmp";
1328 img_conn_full_skip = ::new Image(bstr);
1329 bstr = L"ST_CONN_OVER_SKIP.bmp";
1330 img_conn_over_skip = ::new Image(bstr);
1331 bstr = L"ST_ERROR.bmp";
1332 img_error = ::new Image(bstr);
1333 bstr = L"ST_BROAD_OK.bmp";
1334 img_broad_ok = ::new Image(bstr);
1335 bstr = L"ST_BROAD_FULL.bmp";
1336 img_broad_full = ::new Image(bstr);
1339 void WmPaintProc(HWND hwnd){
1345 hdc = BeginPaint(hwnd, &paint);
1346 RECT *rcRect; //
\95`
\89æ
\94Í
\88Í
1347 rcRect = &(paint.rcPaint);
1348 LONG width = rcRect->right - rcRect->left + 1;
1349 LONG height = rcRect->bottom - rcRect->top + 1;
1352 Rect r(rcRect->left, rcRect->top, width, height);
1353 g2.DrawImage(backBmp,r, rcRect->left, rcRect->top, width, height, UnitPixel);
1354 EndPaint(hwnd, &paint);
1359 void WmSizeProc(HWND hwnd, LPARAM lParam){
1360 UINT width = LOWORD(lParam);
1361 UINT height = HIWORD(lParam);
1363 MakeBack(hwnd, width, height);
1367 void WmLButtonDownProc(HWND hwnd, LPARAM lParam){
1369 bool changeFlg = FALSE;
1371 ChannelDataLock.on();
1372 cd = channelDataTop;
1374 int x = LOWORD(lParam);
1375 int y = HIWORD(lParam);
1376 if (cd->checkDown(LOWORD(lParam), HIWORD(lParam))){
1377 if (!(cd->isSelected())){
1380 cd->setSelected(TRUE);
1382 if (cd->isSelected()){
1385 cd->setSelected(FALSE);
1387 int sx = cd->getPosX() + cd->getWidth();
1388 int sy = cd->getPosY();
1390 ServentData *sd = cd->getServentDataTop();
1392 if ( ( (!cd->getOpenFlg())
1393 && (sx + index*14 < x)
1394 && (x < sx + (index+1)*14)
1397 || sd->checkDown(LOWORD(lParam), HIWORD(lParam))
1399 if (!sd->getSelected()){
1402 sd->setSelected(TRUE);
1404 if (sd->getSelected()){
1407 sd->setSelected(FALSE);
1409 sd = sd->getNextData();
1412 cd = cd->getNextData();
1414 ChannelDataLock.off();
1420 void WmLButtonDblclkProc(HWND hwnd, LPARAM lParam){
1422 bool changeFlg = FALSE;
1424 ChannelDataLock.on();
1425 cd = channelDataTop;
1427 int x = LOWORD(lParam);
1428 int y = HIWORD(lParam);
1429 if (cd->checkDown(LOWORD(lParam), HIWORD(lParam))){
1430 if (!(cd->isSelected())){
1433 if (!(cd->getOpenFlg())){
1435 cd->setOpenFlg(TRUE);
1438 cd->setOpenFlg(FALSE);
1440 cd->setSelected(TRUE);
1442 if (cd->isSelected()){
1445 cd->setSelected(FALSE);
1447 /* int sx = cd->getPosX() + cd->getWidth();
1448 int sy = cd->getPosY();
1450 ServentData *sd = cd->getServentDataTop();
1452 if ( ( (!cd->getOpenFlg())
1453 && (sx + index*14 < x)
1454 && (x < sx + (index+1)*14)
1457 || sd->checkDown(LOWORD(lParam), HIWORD(lParam))
1459 if (!sd->getSelected()){
1462 sd->setSelected(TRUE);
1464 if (sd->getSelected()){
1467 sd->setSelected(FALSE);
1469 sd = sd->getNextData();
1472 cd = cd->getNextData();
1474 ChannelDataLock.off();
1480 void WmRButtonDownProc(HWND hwnd, LPARAM lParam){
1482 bool changeFlg = FALSE;
1483 bool channel_selected = FALSE;
1484 bool servent_selected = FALSE;
1488 cd = channelDataTop;
1490 if (cd->checkDown(LOWORD(lParam), HIWORD(lParam))){
1491 if (!(cd->isSelected())){
1494 cd->setSelected(TRUE);
1495 channel_id = cd->getChannelId();
1496 channel_selected = TRUE;
1498 if (cd->isSelected()){
1501 cd->setSelected(FALSE);
1503 ServentData *sd = cd->getServentDataTop();
1505 if (sd->checkDown(LOWORD(lParam), HIWORD(lParam))){
1506 if (!sd->getSelected()){
1509 sd->setSelected(TRUE);
1510 servent_id = sd->getServentId();
1511 servent_selected = TRUE;
1513 if (sd->getSelected()){
1516 sd->setSelected(FALSE);
1518 sd = sd->getNextData();
1520 cd = cd->getNextData();
1526 if (channel_selected){
1527 PopupChannelMenu(channel_id);
1528 } else if (servent_selected){
1529 PopupServentMenu(servent_id);
1535 LRESULT CALLBACK GUIProc (HWND hwnd, UINT message,
1536 WPARAM wParam, LPARAM lParam)
1539 case WM_CREATE: //
\83E
\83B
\83\93\83h
\83E
\8dì
\90¬
1543 case WM_PAINT: //
\95`
\89æ
1547 case WM_SIZE: //
\83T
\83C
\83Y
\95Ï
\8dX
1548 WmSizeProc(hwnd,lParam);
1551 case WM_LBUTTONDOWN: //
\8d¶
\83{
\83^
\83\93\89\9f\82·
1552 WmLButtonDownProc(hwnd,lParam);
1555 case WM_RBUTTONDOWN: //
\89E
\83{
\83^
\83\93\89\9f\82·
1556 WmRButtonDownProc(hwnd,lParam);
1559 case WM_LBUTTONDBLCLK: //
\8d¶
\83_
\83u
\83\8b\83N
\83\8a\83b
\83N
1560 WmLButtonDblclkProc(hwnd,lParam);
1563 case WM_ERASEBKGND: //
\94w
\8ci
\8fÁ
\8b\8e
1564 return TRUE; //
\94w
\8ci
\82Í
\8fÁ
\82³
\82È
\82¢
1568 // ::delete backImage;
1569 // backImage = NULL;
1571 GetWindowPlacement(hwnd, &winPlace);
1573 DestroyWindow( hwnd );
1576 GetWindowPlacement(hwnd, &winPlace);
1578 guiThread.active = false;
1580 // wait until GUI thread terminated,
1581 // and then dispose background image.
1584 if (guiThread.finish)
1597 return (DefWindowProc(hwnd, message, wParam, lParam));