1 // ------------------------------------------------
6 // Simple tray icon interface to PeerCast, mostly win32 related stuff.
8 // (c) 2002 peercast.org
9 // ------------------------------------------------
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 // ------------------------------------------------
29 #include "win32/wsys.h"
38 #include "chkMemoryLeak.h"
39 #define DEBUG_NEW new(__FILE__, __LINE__)
43 #define MAX_LOADSTRING 100
46 #define RELAY_CMD 8000
50 #define MAX_CHANNELS 999
55 void loadIcons(HINSTANCE hInstance, HWND hWnd);
58 UINT g_iTaskbarCreated = ~0; // for PCRaw (tray icon)
62 static int currNotify=0;
66 static HMENU trayMenu = NULL,ltrayMenu = NULL; // for PCRaw (tray icon)
68 bool allowMulti=false;
70 bool allowTrayMenu=true;
71 static bool winDistinctionNT=false;
72 int seenNewVersionTime=0;
75 bool chanInfoIsRelayed;
78 ULONG_PTR gdiplusToken;
81 ThreadInfo trafficDlgThread;
82 HWND trafficDlg = NULL;
85 //
\83v
\83\8d\83g
\83^
\83C
\83v
\90é
\8c¾
87 LRESULT CALLBACK TrafficDlgProc(HWND, UINT, WPARAM, LPARAM);
89 // ---------------------------------
90 Sys * APICALL MyPeercastInst::createSys()
92 return new WSys(mainWnd);
94 // ---------------------------------
95 const char * APICALL MyPeercastApp ::getIniFilename()
97 return iniFileName.cstr();
100 // ---------------------------------
101 const char *APICALL MyPeercastApp ::getClientTypeOS()
106 // ---------------------------------
107 const char * APICALL MyPeercastApp::getPath()
109 return exePath.cstr();
112 // --------------------------------- JP-EX
113 void APICALL MyPeercastApp ::openLogFile()
115 logFile.openWriteReplace("log.txt");
117 // --------------------------------- JP-EX
118 void APICALL MyPeercastApp ::getDirectory()
120 char path_buffer[256],drive[32],dir[128];
121 GetModuleFileName(NULL,path_buffer,255);
122 _splitpath(path_buffer,drive,dir,NULL,NULL);
123 sprintf(servMgr->modulePath,"%s%s",drive,dir);
125 // --------------------------------- JP-EX
126 bool APICALL MyPeercastApp ::clearTemp()
128 if (servMgr->clearPLS)
135 class NOTIFYICONDATA2
138 DWORD cbSize; // DWORD
142 UINT uCallbackMessage; // UINT
143 HICON hIcon; // HICON
144 char szTip[128]; // char[128]
145 DWORD dwState; // DWORD
146 DWORD dwStateMask; // DWORD
147 char szInfo[256]; // char[256]
148 UINT uTimeoutOrVersion; // UINT
149 char szInfoTitle[64]; // char[64]
150 DWORD dwInfoFlags; // DWORD
151 //GUID guidItem; > IE 6
154 NOTIFYICONDATA2 trayIcon;
158 HINSTANCE hInst; // current instance
159 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
160 TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
161 TCHAR szWindowClass2[MAX_LOADSTRING]; // The title bar text
163 // Foward declarations of functions included in this code module:
164 ATOM MyRegisterClass(HINSTANCE hInstance);
165 ATOM MyRegisterClass2(HINSTANCE hInstance);
166 ATOM MyRegisterClass3(HINSTANCE hInstance);
167 BOOL InitInstance(HINSTANCE, int);
168 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
169 LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
170 LRESULT CALLBACK ChanInfoProc(HWND, UINT, WPARAM, LPARAM);
172 void setTrayIcon(int type, const char *,const char *,bool);
173 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt);
178 // --------------------------------------------------
179 void LOG2(const char *fmt,...)
184 vsprintf(str,fmt,ap);
185 OutputDebugString(str);
190 // --------------------------------------------------
191 int WinMainDummy(HINSTANCE hInstance,
192 HINSTANCE hPrevInstance,
198 ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
207 version_ex = 1; // PP
\94Å
\8ag
\92£
\8b@
\94\
\82ð
\96³
\8cø
\82É
\81©
\91å
\89R
\81B
\83o
\81[
\83W
\83\87\83\93\95\
\8bL
\82ðEX
\82É
209 iniFileName.set(".\\peercast.ini");
211 WIN32_FIND_DATA fd; //JP-EX
212 HANDLE hFind; //JP-EX
214 OSVERSIONINFO osInfo; //JP-EX
215 osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
216 GetVersionEx(&osInfo);
217 if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
218 winDistinctionNT = true;
220 winDistinctionNT = false;
222 // off by default now
225 if (strlen(lpCmdLine) > 0)
228 if ((p = strstr(lpCmdLine,"-inifile"))!=NULL)
229 iniFileName.setFromString(p+8);
231 if (strstr(lpCmdLine,"-zen"))
234 if (strstr(lpCmdLine,"-multi"))
237 if (strstr(lpCmdLine,"-kill"))
240 if ((p = strstr(lpCmdLine,"-url"))!=NULL)
255 strncpy(tmpURL,p,sizeof(tmpURL)-1);
261 exePath = iniFileName;
262 char *s = exePath.cstr();
274 if (strnicmp(tmpURL,"peercast://",11)==0)
276 if (strnicmp(tmpURL+11,"pls/",4)==0)
277 chanURL = tmpURL+11+4;
287 // Initialize global strings
288 //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
289 //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING);
291 strcpy(szTitle,"PeerCast");
292 strcpy(szWindowClass,"PeerCast");
293 strcpy(szWindowClass2,"Main");
297 HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass);
299 if (GetLastError() == ERROR_ALREADY_EXISTS)
301 HWND oldWin = FindWindow(szWindowClass,NULL);
304 //SendMessage(oldWin,WM_SHOWGUI,0,0);
307 SendMessage(oldWin,WM_DESTROY,0,0);
314 copy.dwData = WM_PLAYCHANNEL;
315 copy.cbData = strlen(chanURL)+1; // plus null term
316 copy.lpData = chanURL;
317 SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)©);
320 SendMessage(oldWin,WM_SHOWGUI,0,0);
330 MyRegisterClass(hInstance);
331 MyRegisterClass2(hInstance);
333 // Perform application initialization:
334 if (!InitInstance (hInstance, nCmdShow))
337 peercastInst = new MyPeercastInst();
338 peercastApp = new MyPeercastApp();
340 peercastInst->init();
342 LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
344 if (peercastApp->clearTemp()) //JP-EX
346 DeleteFile("play.pls");
347 hFind = FindFirstFile("*.asx",&fd);
348 if (hFind != INVALID_HANDLE_VALUE)
352 DeleteFile((char *)&fd.cFileName);
354 while (FindNextFile(hFind,&fd));
363 servMgr->procConnectArgs(chanURL,info);
364 chanMgr->findAndPlayChannel(info,false);
367 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE);
369 // setup menu notifes
370 int mask = peercastInst->getNotifyMask();
371 if (mask & ServMgr::NT_PEERCAST)
372 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND);
373 if (mask & ServMgr::NT_BROADCASTERS)
374 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND);
375 if (mask & ServMgr::NT_TRACKINFO)
376 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND);
378 if (servMgr->startWithGui)
383 // Main message loop:
384 while (GetMessage(&msg, NULL, 0, 0))
386 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
388 TranslateMessage(&msg);
389 DispatchMessage(&msg);
393 Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon);
395 peercastInst->saveSettings();
396 peercastInst->quit();
398 Gdiplus::GdiplusShutdown(gdiplusToken);
404 // ---------------------------------------
405 int APIENTRY WinMain(HINSTANCE hInstance,
406 HINSTANCE hPrevInstance,
411 _EXCEPTION_POINTERS *lpExcept;
414 WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
416 } __except(lpExcept = GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER)
420 fs.openWriteReplace(".\\dump.txt");
421 fs.writeLine("Exception Point: WinMain");
422 fs.write("Exception: ", 11);
423 switch (lpExcept->ExceptionRecord->ExceptionCode)
425 case EXCEPTION_ACCESS_VIOLATION:
426 fs.writeLine("Access violation");
429 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
430 case EXCEPTION_INT_DIVIDE_BY_ZERO:
431 fs.writeLine("Divide by zero");
434 case EXCEPTION_STACK_OVERFLOW:
435 fs.writeLine("Stack overflow");
439 fs.writeLong(lpExcept->ExceptionRecord->ExceptionCode);
443 fs.writeLineF("Address: %p", lpExcept->ExceptionRecord->ExceptionAddress);
445 fs.writeLine("Additional information:");
446 nParams = lpExcept->ExceptionRecord->NumberParameters;
447 for (unsigned i=0; i<nParams; ++i)
449 fs.writeLineF("%d: %lu", i, lpExcept->ExceptionRecord->ExceptionInformation[i]);
454 fs.openWriteReplace(".\\dump.html");
455 sys->logBuf->dumpHTML(fs);
458 MessageBox(NULL, "
\88ê
\94Ê
\95Û
\8cì
\88á
\94½
\82Ì
\88×
\81A
\83v
\83\8d\83O
\83\89\83\80\82Í
\8b
\90§
\8fI
\97¹
\82³
\82ê
\82Ü
\82·
\81B\n"
459 "
\96â
\91è
\89ð
\8c\88\82Ì
\82½
\82ß
\82É
\83_
\83\93\83v
\83f
\81[
\83^(dump.html, dump.txt)
\82ð
\92ñ
\8b\9f\82µ
\82Ä
\82
\82¾
\82³
\82¢
\81B", "SEH",
460 MB_OK|MB_ICONWARNING);
462 return GetExceptionCode();
472 // FUNCTION: MyRegisterClass()
474 // PURPOSE: Registers the window class.
478 // This function and its usage is only necessary if you want this code
479 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
480 // function that was added to Windows 95. It is important to call this function
481 // so that the application will get 'well formed' small icons associated
484 ATOM MyRegisterClass(HINSTANCE hInstance)
488 wcex.cbSize = sizeof(WNDCLASSEX);
490 wcex.style = CS_HREDRAW | CS_VREDRAW;
491 wcex.lpfnWndProc = (WNDPROC)WndProc;
494 wcex.hInstance = hInstance;
495 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
496 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
497 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
498 // wcex.lpszMenuName = (LPCSTR)IDC_SIMPLE;
499 wcex.lpszMenuName = NULL;
500 wcex.lpszClassName = szWindowClass;
501 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
503 return RegisterClassEx(&wcex);
506 ATOM MyRegisterClass2(HINSTANCE hInstance)
510 wcex.cbSize = sizeof(WNDCLASSEX);
512 wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
513 wcex.lpfnWndProc = (WNDPROC)GUIProc;
516 wcex.hInstance = hInstance;
517 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
518 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
519 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
520 // wcex.lpszMenuName = (LPCSTR)IDC_SIMPLE;
521 wcex.lpszMenuName = NULL;
522 wcex.lpszClassName = szWindowClass2;
523 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
525 return RegisterClassEx(&wcex);
528 //-----------------------------
529 void loadIcons(HINSTANCE hInstance, HWND hWnd)
531 icon1 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL);
532 icon2 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL2);
534 trayIcon.cbSize = sizeof(trayIcon);
535 trayIcon.hWnd = hWnd;
537 trayIcon.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
538 trayIcon.uCallbackMessage = WM_TRAYICON;
539 trayIcon.hIcon = icon1;
540 strcpy(trayIcon.szTip, "PeerCast");
542 Shell_NotifyIcon(NIM_ADD, (NOTIFYICONDATA*)&trayIcon);
544 //ShowWindow(hWnd, nCmdShow);
547 if(!trayMenu) // for PCRaw (tray icon)
548 trayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_TRAYMENU));
549 if(!ltrayMenu) // for PCRaw (tray icon)
550 ltrayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_LTRAYMENU));
555 //-----------------------------
557 // FUNCTION: InitInstance(HANDLE, int)
559 // PURPOSE: Saves instance handle and creates main window
563 // In this function, we save the instance handle in a global variable and
564 // create and display the main program window.
566 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
570 hInst = hInstance; // Store instance handle in our global variable
572 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
573 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
582 g_iTaskbarCreated = RegisterWindowMessage("TaskbarCreated"); // for PCRaw (tray icon)
584 loadIcons(hInstance,hWnd);
586 using namespace Gdiplus;
587 GdiplusStartupInput gdiplusStartupInput;
588 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
592 //-----------------------------
593 //static String trackTitle;
594 //static String channelComment;
596 //-----------------------------
597 void channelPopup(const char *title, const char *msg, bool isPopup = true)
601 if (*title == '\0') return;
607 trayIcon.uFlags = NIF_ICON|NIF_TIP;
608 strncpy(trayIcon.szTip, both.cstr(),sizeof(trayIcon.szTip)-1);
609 trayIcon.szTip[sizeof(trayIcon.szTip)-1]=0;
611 if (isPopup) trayIcon.uFlags |= 16;
612 trayIcon.uTimeoutOrVersion = 10000;
613 strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
614 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
616 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
618 //-----------------------------
619 void clearChannelPopup()
621 trayIcon.uFlags = NIF_ICON|16;
622 trayIcon.uTimeoutOrVersion = 10000;
623 strncpy(trayIcon.szInfo,"",sizeof(trayIcon.szInfo)-1);
624 strncpy(trayIcon.szInfoTitle,"",sizeof(trayIcon.szInfoTitle)-1);
625 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
628 //-----------------------------
637 static PopupEntry *PEList = NULL;
640 static void putPopupEntry(PopupEntry *pe)
648 static PopupEntry *getPopupEntry(GnuID id)
651 PopupEntry *pe = PEList;
652 PopupEntry *prev = NULL;
654 if (id.isSame(pe->id)) {
655 if (prev) prev->next = pe->next;
656 else PEList = pe->next;
668 static PopupEntry *getTopPopupEntry()
670 PopupEntry *p = NULL;
674 PEList = PEList->next;
680 //-----------------------------
681 void APICALL MyPeercastApp::channelStart(ChanInfo *info)
684 // lastPlayID = info->id;
686 // if(!isIndexTxt(info)) // for PCRaw (popup)
687 // clearChannelPopup();
689 PopupEntry *pe = getPopupEntry(info->id);
694 if (!isIndexTxt(info))
699 //-----------------------------
700 void APICALL MyPeercastApp::channelStop(ChanInfo *info)
702 // if (info->id.isSame(lastPlayID))
704 // lastPlayID.clear();
706 // if(!isIndexTxt(info)) // for PCRaw (popup)
707 // clearChannelPopup();
710 PopupEntry *pe = getPopupEntry(info->id);
713 pe = getTopPopupEntry();
717 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
719 String name,track; //JP-Patch
720 name = pe->name; //JP-Patch
721 track = pe->track; //JP-Patch
722 name.convertTo(String::T_SJIS); //JP-Patch
723 track.convertTo(String::T_SJIS); //JP-Patch
725 // channelPopup(info->name.cstr(),trackTitle.cstr());
726 channelPopup(name.cstr(),track.cstr(), false); //JP-Patch
731 //-----------------------------
732 void APICALL MyPeercastApp::channelUpdate(ChanInfo *info)
736 PopupEntry *pe = getPopupEntry(info->id);
740 tmp.append(info->track.artist);
742 tmp.append(info->track.title);
745 if (!tmp.isSame(pe->track))
747 pe->name = info->name;
749 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
752 String name,track; //JP-Patch
753 name = info->name; //JP-Patch
754 track = tmp; //JP-Patch
755 name.convertTo(String::T_SJIS); //JP-Patch
756 track.convertTo(String::T_SJIS); //JP-Patch
757 if(!isIndexTxt(info)) // for PCRaw (popup)
760 // channelPopup(info->name.cstr(),trackTitle.cstr());
761 channelPopup(name.cstr(),track.cstr()); //JP-Patch
764 } else if (!info->comment.isSame(pe->comment))
766 pe->name = info->name;
767 pe->comment = info->comment;
768 if (ServMgr::NT_BROADCASTERS & peercastInst->getNotifyMask())
770 //channelComment = info->comment;
771 String name,comment; //JP-Patch
772 name = info->name; //JP-Patch
773 comment = info->comment; //JP-Patch
774 name.convertTo(String::T_SJIS); //JP-Patch
775 comment.convertTo(String::T_SJIS); //JP-Patch
776 if(!isIndexTxt(info)) // for PCRaw (popup)
779 // channelPopup(info->name.cstr(),channelComment.cstr());
780 channelPopup(name.cstr(),comment.cstr());
785 if (!isIndexTxt(info))
791 //-----------------------------
792 void APICALL MyPeercastApp::notifyMessage(ServMgr::NOTIFY_TYPE type, const char *msg)
794 static bool shownUpgradeAlert=false;
800 if (!shownUpgradeAlert)
802 trayIcon.uFlags = NIF_ICON;
804 if (type == ServMgr::NT_UPGRADE)
806 shownUpgradeAlert = true;
807 trayIcon.hIcon = icon2;
810 trayIcon.hIcon = icon1;
814 if (type == ServMgr::NT_UPGRADE)
818 const char *title="";
822 case ServMgr::NT_UPGRADE:
823 title = "Upgrade alert";
825 case ServMgr::NT_PEERCAST:
826 title = "Message from PeerCast:";
831 if (type & peercastInst->getNotifyMask())
833 trayIcon.uFlags |= 16;
834 trayIcon.uTimeoutOrVersion = 10000;
835 strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
836 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
837 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
840 //-----------------------------
844 void createGUI(HWND hWnd)
847 guiWnd = ::CreateWindow(szWindowClass2,
849 WS_OVERLAPPEDWINDOW & ~(WS_MAXIMIZEBOX) /*| WS_VSCROLL | WS_HSCROLL*/,
859 ShowWindow(guiWnd,SW_SHOWNORMAL);
861 //
\8e©
\93®
\82Å
\8dÅ
\91O
\96Ê
862 if (servMgr->topmostGui)
864 ::SetWindowPos(guiWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
870 // addRelayedChannelsMenu(HMENU m)
873 void addRelayedChannelsMenu(HMENU cm)
875 int cnt = GetMenuItemCount(cm);
876 for(int i=0; i<cnt-3; i++)
877 DeleteMenu(cm,0,MF_BYPOSITION);
879 Channel *c = chanMgr->channel;
884 char str[128],name[64];
885 strncpy(name,c->info.name,32);
887 if (strlen(c->info.name) > 32)
891 sprintf(str,"%s (%d kb/s %s)",name,c->info.bitrate,ChanInfo::getTypeStr(c->info.contentType));
892 //InsertMenu(cm,0,MF_BYPOSITION,RELAY_CMD+i,str);
898 typedef int (*COMPARE_FUNC)(const void *,const void *);
900 static int compareHitLists(ChanHitList **c2, ChanHitList **c1)
902 return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
905 static int compareChannels(Channel **c2, Channel **c1)
907 return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
911 // addAllChannelsMenu(HMENU m)
914 void addAllChannelsMenu(HMENU cm)
916 int cnt = GetMenuItemCount(cm);
917 /* for(int i=0; i<cnt-2; i++)
918 DeleteMenu(cm,0,MF_BYPOSITION);*/
920 for(int i=0; i<cnt; i++)
921 DeleteMenu(cm,0,MF_BYPOSITION);
923 HMENU yMenu = CreatePopupMenu();
924 if (!servMgr->rootHost2.isEmpty()){
925 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES2,servMgr->rootHost2);
927 if (!servMgr->rootHost.isEmpty()){
928 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES1,servMgr->rootHost);
931 InsertMenu(cm,0,MF_BYPOSITION|MF_POPUP,(UINT)yMenu,"
\83C
\83G
\83\8d\81[
\83y
\81[
\83W");
932 InsertMenu(cm,0,MF_BYPOSITION|MF_SEPARATOR,NULL,NULL);
933 // add channels to menu
935 Channel *ch = chanMgr->channel;
938 char str[128],name[64];
939 String sjis; //JP-Patch
940 sjis = ch->info.name; //JP-Patch
941 sjis.convertTo(String::T_SJIS); //JP-Patch
942 strncpy(name,sjis.cstr(),32);
943 //strncpy(name,ch->info.name,32);
945 //if (strlen(ch->info.name) > 32)
946 if (strlen(sjis.cstr()) > 32) //JP-Patch
949 sprintf(str,"%s (%d kb/s %s)",name,ch->info.bitrate,ChanInfo::getTypeStr(ch->info.contentType));
951 HMENU opMenu = CreatePopupMenu();
952 InsertMenu(opMenu,0,MF_BYPOSITION,INFO_CMD+numActive,"Info");
953 if (ch->info.url.isValidURL())
954 InsertMenu(opMenu,0,MF_BYPOSITION,URL_CMD+numActive,"URL");
955 InsertMenu(opMenu,0,MF_BYPOSITION,PLAY_CMD+numActive,"Play");
957 UINT fl = MF_BYPOSITION|MF_POPUP;
959 fl |= (ch->isPlaying()?MF_CHECKED:0);
961 InsertMenu(cm,0,fl,(UINT)opMenu,str);
970 // InsertMenu(cm,0,MF_BYPOSITION,0,"<No channels>");
979 // flipNotifyPopup(id, flag)
980 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt)
982 int mask = peercastInst->getNotifyMask();
986 CheckMenuItem(trayMenu,id,MF_CHECKED|MF_BYCOMMAND);
988 CheckMenuItem(trayMenu,id,MF_UNCHECKED|MF_BYCOMMAND);
990 peercastInst->setNotifyMask(mask);
991 peercastInst->saveSettings();
995 static void showHTML(const char *file)
998 sprintf(url,"%s/%s",servMgr->htmlPath,file);
1000 // sys->callLocalURL(url,servMgr->serverHost.port);
1001 sys->callLocalURL(url, // for PCRaw (url)
1002 (servMgr->allowServer1&Servent::ALLOW_HTML)?(servMgr->serverHost.port):(servMgr->serverHost.port+1));
1005 static ChanInfo getChannelInfo(int index)
1007 Channel *c = chanMgr->findChannelByIndex(index);
1016 // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
1018 // PURPOSE: Processes messages for the main window.
1020 // WM_COMMAND - process the application menu
1021 // WM_PAINT - Paint the main window
1022 // WM_DESTROY - post a quit message and return
1025 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1031 if(message == g_iTaskbarCreated) // for PCRaw (tray icon)
1032 loadIcons(hInst, hWnd);
1042 switch((UINT)lParam)
1044 case WM_LBUTTONDOWN:
1046 SendMessage(hWnd,WM_SHOWMENU,2,0);
1047 SetForegroundWindow(hWnd);
1049 case WM_RBUTTONDOWN:
1051 SendMessage(hWnd,WM_SHOWMENU,1,0);
1052 SetForegroundWindow(hWnd);
1054 case WM_LBUTTONDBLCLK:
1062 COPYDATASTRUCT *pc = (COPYDATASTRUCT *)lParam;
1063 LOG_DEBUG("URL request: %s",pc->lpData);
1064 if (pc->dwData == WM_PLAYCHANNEL)
1067 servMgr->procConnectArgs((char *)pc->lpData,info);
1068 chanMgr->findAndPlayChannel(info,false);
1070 //sys->callLocalURL((const char *)pc->lpData,servMgr->serverHost.port);
1073 case WM_GETPORTNUMBER:
1076 port=servMgr->serverHost.port;
1083 if (servMgr->saveGuiPos){
1084 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1086 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1089 //
\8e©
\93®GUI/
\8dÅ
\91O
\96Ê
\8b@
\94\
1090 if (servMgr->topmostGui)
1092 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_CHECKED|MF_BYCOMMAND);
1095 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_UNCHECKED|MF_BYCOMMAND);
1098 if (servMgr->startWithGui)
1100 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_CHECKED|MF_BYCOMMAND);
1103 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND);
1106 //
\83X
\83N
\83\8a\81[
\83\93\83Z
\81[
\83o
\81[
\97}
\8e~
1107 if (servMgr->preventSS)
1109 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND);
1112 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND);
1115 SetForegroundWindow(hWnd);
1116 bool skipMenu=false;
1118 allowTrayMenu = false;
1120 // check for notifications
1121 if (currNotify & ServMgr::NT_UPGRADE)
1123 if (servMgr->downloadURL[0])
1125 if ((sys->getTime()-seenNewVersionTime) > (60*60)) // notify every hour
1127 if (MessageBox(hWnd,"A newer version of PeerCast is available, press OK to upgrade.","PeerCast",MB_OKCANCEL|MB_APPLMODAL|MB_ICONEXCLAMATION) == IDOK)
1128 sys->getURL(servMgr->downloadURL);
1130 seenNewVersionTime=sys->getTime();
1143 SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWnd, 0);
1144 GetCursorPos(&point);
1146 if (point.x < rcWnd.left){
1147 point.x = rcWnd.left;
1148 flg |= TPM_LEFTALIGN;
1150 if (point.x > rcWnd.right){
1151 point.x = rcWnd.right;
1152 flg |= TPM_RIGHTALIGN;
1154 if (point.y < rcWnd.top){
1155 point.y = rcWnd.top;
1156 flg |= TPM_TOPALIGN;
1158 if (point.y > rcWnd.bottom){
1159 point.y = rcWnd.bottom;
1160 flg |= TPM_BOTTOMALIGN;
1163 flg = TPM_RIGHTALIGN;
1169 menu = GetSubMenu(trayMenu,0);
1170 addAllChannelsMenu(GetSubMenu(menu,0));
1171 addRelayedChannelsMenu(GetSubMenu(menu,1));
1174 menu = GetSubMenu(ltrayMenu,0);
1175 addAllChannelsMenu(menu);
1178 if (!TrackPopupMenu(menu,flg,point.x,point.y,0,hWnd,NULL))
1180 LOG_ERROR("Can`t track popup menu: %d",GetLastError());
1182 PostMessage(hWnd,WM_NULL,0,0);
1185 allowTrayMenu = true;
1195 wmId = LOWORD(wParam);
1196 wmEvent = HIWORD(wParam);
1198 if ((wmId >= INFO_CMD) && (wmId < INFO_CMD+MAX_CHANNELS))
1200 int c = wmId - INFO_CMD;
1201 chanInfo = getChannelInfo(c);
1202 chanInfoIsRelayed = false;
1203 if (winDistinctionNT)
1204 DialogBox(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc);
1207 HWND WKDLG; //JP-Patch
1208 WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc); //JP-Patch
1209 ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1213 if ((wmId >= URL_CMD) && (wmId < URL_CMD+MAX_CHANNELS))
1215 int c = wmId - URL_CMD;
1216 chanInfo = getChannelInfo(c);
1217 if (chanInfo.url.isValidURL())
1218 sys->getURL(chanInfo.url);
1221 if ((wmId >= PLAY_CMD) && (wmId < PLAY_CMD+MAX_CHANNELS))
1223 int c = wmId - PLAY_CMD;
1224 chanInfo = getChannelInfo(c);
1225 chanMgr->findAndPlayChannel(chanInfo,false);
1228 if ((wmId >= RELAY_CMD) && (wmId < RELAY_CMD+MAX_CHANNELS))
1230 int c = wmId - RELAY_CMD;
1231 chanInfo = getChannelInfo(c);
1232 chanMgr->findAndPlayChannel(chanInfo,true);
1236 // Parse the menu selections:
1239 case ID_POPUP_SHOWMESSAGES_PEERCAST:
1240 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_PEERCAST,ServMgr::NT_PEERCAST);
1242 case ID_POPUP_SHOWMESSAGES_BROADCASTERS:
1243 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_BROADCASTERS,ServMgr::NT_BROADCASTERS);
1245 case ID_POPUP_SHOWMESSAGES_TRACKINFO:
1246 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_TRACKINFO,ServMgr::NT_TRACKINFO);
1249 case ID_POPUP_ABOUT:
1251 DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
1253 case ID_POPUP_SHOWGUI:
1254 case IDM_SETTINGS_GUI:
1255 case ID_POPUP_ADVANCED_SHOWGUI:
1260 case ID_POPUP_YELLOWPAGES:
1261 sys->getURL("http://yp.peercast.org/");
1263 case ID_POPUP_YELLOWPAGES1:
1264 sprintf(buf, "http://%s",servMgr->rootHost.cstr());
1267 case ID_POPUP_YELLOWPAGES2:
1268 sprintf(buf, "http://%s",servMgr->rootHost2.cstr());
1272 case ID_POPUP_ADVANCED_VIEWLOG:
1273 showHTML("viewlog.html");
1275 case ID_POPUP_ADVANCED_SAVESETTINGS:
1276 servMgr->saveSettings(iniFileName.cstr());
1278 case ID_POPUP_ADVANCED_INFORMATION:
1279 showHTML("index.html");
1281 case ID_FIND_CHANNELS:
1282 case ID_POPUP_ADVANCED_ALLCHANNELS:
1283 case ID_POPUP_UPGRADE:
1284 sys->callLocalURL("admin?cmd=upgrade",servMgr->serverHost.port);
1286 case ID_POPUP_ADVANCED_RELAYEDCHANNELS:
1287 case ID_POPUP_FAVORITES_EDIT:
1288 showHTML("relays.html");
1290 case ID_POPUP_ADVANCED_BROADCAST:
1291 showHTML("broadcast.html");
1293 case ID_POPUP_SETTINGS:
1294 showHTML("settings.html");
1296 case ID_POPUP_CONNECTIONS:
1297 showHTML("connections.html");
1300 sys->getURL("http://www.peercast.org/help.php");
1303 case ID_POPUP_SAVE_GUI_POS:
1304 if (servMgr->saveGuiPos){
1305 servMgr->saveGuiPos = false;
1306 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1308 servMgr->saveGuiPos = true;
1309 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1311 peercastInst->saveSettings();
1314 case ID_POPUP_KEEP_DOWNSTREAMS:
1315 if (servMgr->keepDownstreams){
1316 servMgr->keepDownstreams = false;
1317 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_UNCHECKED|MF_BYCOMMAND);
1319 servMgr->keepDownstreams = true;
1320 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_CHECKED|MF_BYCOMMAND);
1322 //peercastInst->saveSettings();
1325 case ID_POPUP_TOPMOST:
1326 //
\8dÅ
\91O
\96Ê
\95\
\8e¦
1327 if (servMgr->topmostGui)
1329 servMgr->topmostGui = false;
1330 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_UNCHECKED|MF_BYCOMMAND);
1333 servMgr->topmostGui = true;
1334 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_CHECKED|MF_BYCOMMAND);
1336 peercastInst->saveSettings();
1339 case ID_POPUP_START_WITH_GUI:
1340 //
\8bN
\93®
\8e\9e\82ÉGUI
\95\
\8e¦
1341 if (servMgr->startWithGui)
1343 servMgr->startWithGui = false;
1344 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND);
1347 servMgr->startWithGui = true;
1348 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_CHECKED|MF_BYCOMMAND);
1350 peercastInst->saveSettings();
1353 case ID_POPUP_TRAFFIC:
1354 //
\83g
\83\89\83t
\83B
\83b
\83N
\83\82\83j
\83^
\8bN
\93®
1355 if (winDistinctionNT)
1356 DialogBox(hInst, (LPCTSTR)IDD_TRAFFIC, hWnd, (DLGPROC)TrafficDlgProc);
1359 HWND WKDLG; //JP-Patch
1360 WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_TRAFFIC, hWnd, (DLGPROC)TrafficDlgProc); //JP-Patch
1361 ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1365 case ID_POPUP_PREVENT_SS:
1366 //
\83X
\83N
\83\8a\81[
\83\93\83Z
\81[
\83o
\81[
\97}
\8e~
1367 if (servMgr->preventSS)
1369 servMgr->preventSS = false;
1370 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND);
1373 servMgr->preventSS = true;
1374 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND);
1376 peercastInst->saveSettings();
1379 case ID_POPUP_EXIT_CONFIRM:
1381 DestroyWindow(hWnd);
1384 return DefWindowProc(hWnd, message, wParam, lParam);
1392 //
\82È
\82ñ
\82©
\83A
\83N
\83e
\83B
\83u
\82¶
\82á
\82È
\82¢
\82Æ
\91\97\82ç
\82ê
\82Ä
\82±
\82È
\82¢
\82ç
\82µ
\82¢
1393 if (servMgr->preventSS && (wParam == SC_SCREENSAVE) && chanMgr->isBroadcasting())
1396 return DefWindowProc(hWnd, message, wParam, lParam);
1400 return DefWindowProc(hWnd, message, wParam, lParam);
1404 // Mesage handler for about box.
1405 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1410 //SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENT);
1411 // SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTJP);
1414 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LPARAM)PCX_AGENTEX); // x64
\91Î
\89\9e
1417 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTVP);
1423 switch (LOWORD(wParam))
1427 EndDialog(hDlg, LOWORD(wParam));
1430 sys->getURL("http://www.peercast.org");
1431 EndDialog(hDlg, LOWORD(wParam));
1442 // Mesage handler for chaninfo box
1443 LRESULT CALLBACK ChanInfoProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1450 //strcpy(str,chanInfo.track.artist.cstr());
1451 strcpy(str,chanInfo.track.artist); //JP-Patch
1453 //strcat(str,chanInfo.track.title.cstr());
1454 strcat(str,chanInfo.track.title);
1455 String name,track,comment,desc,genre; //JP-Patch
1456 name = chanInfo.name; //JP-Patch
1457 track = str; //JP-Patch
1458 comment = chanInfo.comment; //JP-Patch
1459 desc = chanInfo.desc; //JP-Patc
1460 genre = chanInfo.genre; //JP-Patch
1461 name.convertTo(String::T_SJIS); //JP-Patc
1462 track.convertTo(String::T_SJIS); //JP-Patch
1463 comment.convertTo(String::T_SJIS); //JP-Patch
1464 desc.convertTo(String::T_SJIS); //JP-Patch
1465 genre.convertTo(String::T_SJIS); //JP-Patch
1467 //SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)chanInfo.name.cstr());
1468 SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LPARAM)name.cstr()); // x64
\91Î
\89\9e
1469 //SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)name.cstr()); //JP-Patch
1470 //SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)str);
1471 SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LPARAM)track.cstr()); // x64
\91Î
\89\9e
1472 //SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)track.cstr()); //JP-Patch
1473 //SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)chanInfo.comment.cstr());
1474 SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LPARAM)comment.cstr()); // x64
\91Î
\89\9e
1475 //SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)comment.cstr()); //JP-Patch
1476 //SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)chanInfo.desc.cstr());
1477 SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LPARAM)desc.cstr()); // x64
\91Î
\89\9e
1478 //SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)desc.cstr()); //JP-Patch
1479 //SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)chanInfo.genre.cstr());
1480 SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LPARAM)genre.cstr()); // x64
\91Î
\89\9e
1481 //SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)genre.cstr()); //JP-Patch
1483 sprintf(str,"%d kb/s %s",chanInfo.bitrate,ChanInfo::getTypeStr(chanInfo.contentType));
1484 SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LPARAM)str); // x64
\91Î
\89\9e
1485 //SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LONG)str);
1488 if (!chanInfo.url.isValidURL())
1489 EnableWindow(GetDlgItem(hDlg,IDC_CONTACT),false);
1491 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1494 SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LPARAM)ch->getStatusStr()); // x64
\91Î
\89\9e
1495 //SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)ch->getStatusStr());
1496 SendDlgItemMessage(hDlg, IDC_KEEP,BM_SETCHECK, ch->stayConnected, 0);
1498 //
\8c»
\8dÝ
\82Ì
\8cÅ
\97L
\83\8a\83\8c\81[
\8fã
\8cÀ
\90Ý
\92è
\82ð
\95\
\8e¦(0
\82Í
\96³
\8cø)
1499 ::SetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, ch->maxRelays, false);
1502 // index.txt
\82È
\82Ì
\82Å
\96³
\8cø
\82É
1503 ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_MAXRELAYS), false);
1504 ::EnableWindow(::GetDlgItem(hDlg, IDC_APPLY_MAXRELAYS), false);
1508 SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LPARAM)"OK"); // x64
\91Î
\89\9e
1509 //SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)"OK");
1510 EnableWindow(GetDlgItem(hDlg,IDC_KEEP),false);
1517 HWND hDsk = GetDesktopWindow();
1518 GetWindowRect(hDsk,&drect);
1519 GetWindowRect(hDlg,&rect);
1520 GetCursorPos(&point);
1523 size.x = rect.right-rect.left;
1524 size.y = rect.bottom-rect.top;
1526 if (point.x-drect.left < size.x)
1529 pos.x = point.x-size.x;
1531 if (point.y-drect.top < size.y)
1534 pos.y = point.y-size.y;
1536 SetWindowPos(hDlg,HWND_TOPMOST,pos.x,pos.y,size.x,size.y,0);
1543 char str[1024],idstr[64];
1544 chanInfo.id.toStr(idstr);
1546 switch (LOWORD(wParam))
1550 sys->getURL(chanInfo.url);
1555 sprintf(str,"admin?page=chaninfo&id=%s&relay=%d",idstr,chanInfoIsRelayed);
1556 sys->callLocalURL(str,servMgr->serverHost.port);
1561 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1563 ch->stayConnected = SendDlgItemMessage(hDlg, IDC_KEEP,BM_GETCHECK, 0, 0) == BST_CHECKED;;
1570 chanMgr->findAndPlayChannel(chanInfo,false);
1574 case IDC_APPLY_MAXRELAYS:
1576 //
\83`
\83\83\83\93\83l
\83\8b\8cÅ
\97L
\82Ì
\8dÅ
\91å
\83\8a\83\8c\81[
\90\94\82ð
\90Ý
\92è
1580 //
\93ü
\97Í
\92l
\8eæ
\93¾
1581 mr = ::GetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, &bSucc, false);
1585 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1586 if (ch && !isIndexTxt(ch))
1592 MessageBox(hDlg, "
\93ü
\97Í
\92l
\82ª
\95s
\90³
\82Å
\82·
\81B", "Error", MB_OK|MB_ICONERROR|MB_APPLMODAL);
1593 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1595 ::SetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, ch->maxRelays, false);
1603 if (winDistinctionNT)
1606 DestroyWindow(hDlg); //JP-Patch
1610 if (LOWORD(wParam) == WA_INACTIVE)
1611 if (winDistinctionNT)
1614 DestroyWindow(hDlg); //JP-Patch
1625 // control thread (Traffic dialog)
1626 THREAD_PROC trafficDlgUpdate(ThreadInfo *thread)
1628 thread->finish = false;
1630 while (trafficDlg && thread->active)
1632 SendMessage(trafficDlg, WM_UPDATETRAFFIC, 0, 0);
1636 thread->finish = true;
1641 // Dialog procedure (Traffic dialog)
1642 LRESULT CALLBACK TrafficDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1647 //
\8aù
\82É
\8aJ
\82¢
\82Ä
\82é
1648 if (trafficDlg || trafficDlgThread.active)
1650 if (winDistinctionNT)
1653 DestroyWindow(hDlg);
1658 trafficDlgThread.func = trafficDlgUpdate;
1659 if (!sys->startThread(&trafficDlgThread)){
1660 MessageBox(NULL,"Unable to start GUI","PeerCast",MB_OK|MB_ICONERROR);
1661 PostMessage(hDlg,WM_DESTROY,0,0);
1666 case WM_UPDATETRAFFIC:
1668 enum unitSymbol { B, KB, MB, GB };
1669 const unsigned long int unit[] = { 1, 1024, 1024*1024, 1024*1024*1024 };
1670 char suffix[][3] = { "B", "KB", "MB", "GB" };
1671 const int bufsize = 60;
1672 char szUp[bufsize], szDown[bufsize];
1673 unsigned long long int totalDown = stats.getCurrent(Stats::BYTESIN) - stats.getCurrent(Stats::LOCALBYTESIN);
1674 unsigned long long int totalUp = stats.getCurrent(Stats::BYTESOUT) - stats.getCurrent(Stats::LOCALBYTESOUT);
1677 for (int i=GB; i>0; --i)
1679 if (totalUp >= unit[i])
1681 sprintf_s<bufsize>(szUp, "%.2f%s", (double)totalUp/unit[i], suffix[i]);
1686 sprintf_s<bufsize>(szUp, "%d%s", totalUp, suffix[0]);
1690 for (int i=GB; i>0; --i)
1692 if (totalDown >= unit[i])
1694 sprintf_s<bufsize>(szDown, "%.2f%s", (double)totalDown/unit[i], suffix[i]);
1699 sprintf_s<bufsize>(szDown, "%d%s", totalDown, suffix[0]);
1702 SetDlgItemText(hDlg, IDC_STATIC_UP, szUp);
1703 SetDlgItemText(hDlg, IDC_STATIC_DOWN, szDown);
1709 trafficDlgThread.active = false;
1710 if (winDistinctionNT)
1713 DestroyWindow(hDlg);