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,
416 ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
425 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É
427 iniFileName.set(".\\peercast.ini");
429 WIN32_FIND_DATA fd; //JP-EX
430 HANDLE hFind; //JP-EX
432 OSVERSIONINFO osInfo; //JP-EX
433 osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
434 GetVersionEx(&osInfo);
435 if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
436 winDistinctionNT = true;
438 winDistinctionNT = false;
440 // off by default now
443 if (strlen(lpCmdLine) > 0)
446 if ((p = strstr(lpCmdLine,"-inifile"))!=NULL)
447 iniFileName.setFromString(p+8);
449 if (strstr(lpCmdLine,"-zen"))
452 if (strstr(lpCmdLine,"-multi"))
455 if (strstr(lpCmdLine,"-kill"))
458 if ((p = strstr(lpCmdLine,"-url"))!=NULL)
473 strncpy(tmpURL,p,sizeof(tmpURL)-1);
479 exePath = iniFileName;
480 char *s = exePath.cstr();
492 if (strnicmp(tmpURL,"peercast://",11)==0)
494 if (strnicmp(tmpURL+11,"pls/",4)==0)
495 chanURL = tmpURL+11+4;
505 // Initialize global strings
506 //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
507 //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING);
509 strcpy(szTitle,"PeerCast");
510 strcpy(szWindowClass,"PeerCast");
511 strcpy(szWindowClass2,"Main");
515 HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass);
517 if (GetLastError() == ERROR_ALREADY_EXISTS)
519 HWND oldWin = FindWindow(szWindowClass,NULL);
522 //SendMessage(oldWin,WM_SHOWGUI,0,0);
525 SendMessage(oldWin,WM_DESTROY,0,0);
532 copy.dwData = WM_PLAYCHANNEL;
533 copy.cbData = strlen(chanURL)+1; // plus null term
534 copy.lpData = chanURL;
535 SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)©);
538 SendMessage(oldWin,WM_SHOWGUI,0,0);
548 MyRegisterClass(hInstance);
549 MyRegisterClass2(hInstance);
551 // Perform application initialization:
552 if (!InitInstance (hInstance, nCmdShow))
555 peercastInst = new MyPeercastInst();
556 peercastApp = new MyPeercastApp();
558 peercastInst->init();
560 LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
562 if (peercastApp->clearTemp()) //JP-EX
564 DeleteFile("play.pls");
565 hFind = FindFirstFile("*.asx",&fd);
566 if (hFind != INVALID_HANDLE_VALUE)
570 DeleteFile((char *)&fd.cFileName);
572 while (FindNextFile(hFind,&fd));
581 servMgr->procConnectArgs(chanURL,info);
582 chanMgr->findAndPlayChannel(info,false);
585 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE);
587 // setup menu notifes
588 int mask = peercastInst->getNotifyMask();
589 if (mask & ServMgr::NT_PEERCAST)
590 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND);
591 if (mask & ServMgr::NT_BROADCASTERS)
592 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND);
593 if (mask & ServMgr::NT_TRACKINFO)
594 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND);
596 if (servMgr->startWithGui)
601 // Main message loop:
602 while (GetMessage(&msg, NULL, 0, 0))
604 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
606 TranslateMessage(&msg);
607 DispatchMessage(&msg);
611 Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon);
613 peercastInst->saveSettings();
614 peercastInst->quit();
616 Gdiplus::GdiplusShutdown(gdiplusToken);
620 WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
622 } __except(EXCEPTION_EXECUTE_HANDLER)
624 fs.openWriteReplace(".\\dump.html");
625 sys->logBuf->dumpHTML(fs);
628 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"
629 "
\96â
\91è
\89ð
\8c\88\82Ì
\82½
\82ß
\82É
\83_
\83\93\83v
\83f
\81[
\83^(dump.html)
\82ð
\92ñ
\8b\9f\82µ
\82Ä
\82
\82¾
\82³
\82¢
\81B", "SEH",
630 MB_OK|MB_ICONWARNING);
632 return GetExceptionCode();
642 // FUNCTION: MyRegisterClass()
644 // PURPOSE: Registers the window class.
648 // This function and its usage is only necessary if you want this code
649 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
650 // function that was added to Windows 95. It is important to call this function
651 // so that the application will get 'well formed' small icons associated
654 ATOM MyRegisterClass(HINSTANCE hInstance)
658 wcex.cbSize = sizeof(WNDCLASSEX);
660 wcex.style = CS_HREDRAW | CS_VREDRAW;
661 wcex.lpfnWndProc = (WNDPROC)WndProc;
664 wcex.hInstance = hInstance;
665 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
666 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
667 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
668 // wcex.lpszMenuName = (LPCSTR)IDC_SIMPLE;
669 wcex.lpszMenuName = NULL;
670 wcex.lpszClassName = szWindowClass;
671 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
673 return RegisterClassEx(&wcex);
676 ATOM MyRegisterClass2(HINSTANCE hInstance)
680 wcex.cbSize = sizeof(WNDCLASSEX);
682 wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
683 wcex.lpfnWndProc = (WNDPROC)GUIProc;
686 wcex.hInstance = hInstance;
687 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
688 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
689 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
690 // wcex.lpszMenuName = (LPCSTR)IDC_SIMPLE;
691 wcex.lpszMenuName = NULL;
692 wcex.lpszClassName = szWindowClass2;
693 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
695 return RegisterClassEx(&wcex);
698 //-----------------------------
699 void loadIcons(HINSTANCE hInstance, HWND hWnd)
701 icon1 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL);
702 icon2 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL2);
704 trayIcon.cbSize = sizeof(trayIcon);
705 trayIcon.hWnd = hWnd;
707 trayIcon.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
708 trayIcon.uCallbackMessage = WM_TRAYICON;
709 trayIcon.hIcon = icon1;
710 strcpy(trayIcon.szTip, "PeerCast");
712 Shell_NotifyIcon(NIM_ADD, (NOTIFYICONDATA*)&trayIcon);
714 //ShowWindow(hWnd, nCmdShow);
717 if(!trayMenu) // for PCRaw (tray icon)
718 trayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_TRAYMENU));
719 if(!ltrayMenu) // for PCRaw (tray icon)
720 ltrayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_LTRAYMENU));
725 //-----------------------------
727 // FUNCTION: InitInstance(HANDLE, int)
729 // PURPOSE: Saves instance handle and creates main window
733 // In this function, we save the instance handle in a global variable and
734 // create and display the main program window.
736 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
740 hInst = hInstance; // Store instance handle in our global variable
742 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
743 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
752 g_iTaskbarCreated = RegisterWindowMessage("TaskbarCreated"); // for PCRaw (tray icon)
754 loadIcons(hInstance,hWnd);
756 using namespace Gdiplus;
757 GdiplusStartupInput gdiplusStartupInput;
758 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
762 //-----------------------------
763 //static String trackTitle;
764 //static String channelComment;
766 //-----------------------------
767 void channelPopup(const char *title, const char *msg, bool isPopup = true)
771 if (*title == '\0') return;
777 trayIcon.uFlags = NIF_ICON|NIF_TIP;
778 strncpy(trayIcon.szTip, both.cstr(),sizeof(trayIcon.szTip)-1);
779 trayIcon.szTip[sizeof(trayIcon.szTip)-1]=0;
781 if (isPopup) trayIcon.uFlags |= 16;
782 trayIcon.uTimeoutOrVersion = 10000;
783 strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
784 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
786 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
788 //-----------------------------
789 void clearChannelPopup()
791 trayIcon.uFlags = NIF_ICON|16;
792 trayIcon.uTimeoutOrVersion = 10000;
793 strncpy(trayIcon.szInfo,"",sizeof(trayIcon.szInfo)-1);
794 strncpy(trayIcon.szInfoTitle,"",sizeof(trayIcon.szInfoTitle)-1);
795 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
798 //-----------------------------
807 static PopupEntry *PEList = NULL;
810 static void putPopupEntry(PopupEntry *pe)
818 static PopupEntry *getPopupEntry(GnuID id)
821 PopupEntry *pe = PEList;
822 PopupEntry *prev = NULL;
824 if (id.isSame(pe->id)) {
825 if (prev) prev->next = pe->next;
826 else PEList = pe->next;
838 static PopupEntry *getTopPopupEntry()
840 PopupEntry *p = NULL;
844 PEList = PEList->next;
850 //-----------------------------
851 void APICALL MyPeercastApp::channelStart(ChanInfo *info)
854 // lastPlayID = info->id;
856 // if(!isIndexTxt(info)) // for PCRaw (popup)
857 // clearChannelPopup();
859 PopupEntry *pe = getPopupEntry(info->id);
864 if (!isIndexTxt(info))
869 //-----------------------------
870 void APICALL MyPeercastApp::channelStop(ChanInfo *info)
872 // if (info->id.isSame(lastPlayID))
874 // lastPlayID.clear();
876 // if(!isIndexTxt(info)) // for PCRaw (popup)
877 // clearChannelPopup();
880 PopupEntry *pe = getPopupEntry(info->id);
883 pe = getTopPopupEntry();
887 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
889 String name,track; //JP-Patch
890 name = pe->name; //JP-Patch
891 track = pe->track; //JP-Patch
892 name.convertTo(String::T_SJIS); //JP-Patch
893 track.convertTo(String::T_SJIS); //JP-Patch
895 // channelPopup(info->name.cstr(),trackTitle.cstr());
896 channelPopup(name.cstr(),track.cstr(), false); //JP-Patch
901 //-----------------------------
902 void APICALL MyPeercastApp::channelUpdate(ChanInfo *info)
906 PopupEntry *pe = getPopupEntry(info->id);
910 tmp.append(info->track.artist);
912 tmp.append(info->track.title);
915 if (!tmp.isSame(pe->track))
917 pe->name = info->name;
919 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
922 String name,track; //JP-Patch
923 name = info->name; //JP-Patch
924 track = tmp; //JP-Patch
925 name.convertTo(String::T_SJIS); //JP-Patch
926 track.convertTo(String::T_SJIS); //JP-Patch
927 if(!isIndexTxt(info)) // for PCRaw (popup)
930 // channelPopup(info->name.cstr(),trackTitle.cstr());
931 channelPopup(name.cstr(),track.cstr()); //JP-Patch
934 } else if (!info->comment.isSame(pe->comment))
936 pe->name = info->name;
937 pe->comment = info->comment;
938 if (ServMgr::NT_BROADCASTERS & peercastInst->getNotifyMask())
940 //channelComment = info->comment;
941 String name,comment; //JP-Patch
942 name = info->name; //JP-Patch
943 comment = info->comment; //JP-Patch
944 name.convertTo(String::T_SJIS); //JP-Patch
945 comment.convertTo(String::T_SJIS); //JP-Patch
946 if(!isIndexTxt(info)) // for PCRaw (popup)
949 // channelPopup(info->name.cstr(),channelComment.cstr());
950 channelPopup(name.cstr(),comment.cstr());
955 if (!isIndexTxt(info))
961 //-----------------------------
962 void APICALL MyPeercastApp::notifyMessage(ServMgr::NOTIFY_TYPE type, const char *msg)
964 static bool shownUpgradeAlert=false;
970 if (!shownUpgradeAlert)
972 trayIcon.uFlags = NIF_ICON;
974 if (type == ServMgr::NT_UPGRADE)
976 shownUpgradeAlert = true;
977 trayIcon.hIcon = icon2;
980 trayIcon.hIcon = icon1;
984 if (type == ServMgr::NT_UPGRADE)
988 const char *title="";
992 case ServMgr::NT_UPGRADE:
993 title = "Upgrade alert";
995 case ServMgr::NT_PEERCAST:
996 title = "Message from PeerCast:";
1001 if (type & peercastInst->getNotifyMask())
1003 trayIcon.uFlags |= 16;
1004 trayIcon.uTimeoutOrVersion = 10000;
1005 strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
1006 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
1007 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
1010 //-----------------------------
1014 void createGUI(HWND hWnd)
1017 guiWnd = ::CreateWindow(szWindowClass2,
1019 WS_OVERLAPPEDWINDOW & ~(WS_MAXIMIZEBOX) /*| WS_VSCROLL | WS_HSCROLL*/,
1029 ShowWindow(guiWnd,SW_SHOWNORMAL);
1031 //
\8e©
\93®
\82Å
\8dÅ
\91O
\96Ê
1032 if (servMgr->topmostGui)
1034 ::SetWindowPos(guiWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
1040 // addRelayedChannelsMenu(HMENU m)
1043 void addRelayedChannelsMenu(HMENU cm)
1045 int cnt = GetMenuItemCount(cm);
1046 for(int i=0; i<cnt-3; i++)
1047 DeleteMenu(cm,0,MF_BYPOSITION);
1049 Channel *c = chanMgr->channel;
1054 char str[128],name[64];
1055 strncpy(name,c->info.name,32);
1057 if (strlen(c->info.name) > 32)
1061 sprintf(str,"%s (%d kb/s %s)",name,c->info.bitrate,ChanInfo::getTypeStr(c->info.contentType));
1062 //InsertMenu(cm,0,MF_BYPOSITION,RELAY_CMD+i,str);
1068 typedef int (*COMPARE_FUNC)(const void *,const void *);
1070 static int compareHitLists(ChanHitList **c2, ChanHitList **c1)
1072 return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
1075 static int compareChannels(Channel **c2, Channel **c1)
1077 return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
1081 // addAllChannelsMenu(HMENU m)
1084 void addAllChannelsMenu(HMENU cm)
1086 int cnt = GetMenuItemCount(cm);
1087 /* for(int i=0; i<cnt-2; i++)
1088 DeleteMenu(cm,0,MF_BYPOSITION);*/
1090 for(int i=0; i<cnt; i++)
1091 DeleteMenu(cm,0,MF_BYPOSITION);
1093 HMENU yMenu = CreatePopupMenu();
1094 if (!servMgr->rootHost2.isEmpty()){
1095 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES2,servMgr->rootHost2);
1097 if (!servMgr->rootHost.isEmpty()){
1098 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES1,servMgr->rootHost);
1101 InsertMenu(cm,0,MF_BYPOSITION|MF_POPUP,(UINT)yMenu,"
\83C
\83G
\83\8d\81[
\83y
\81[
\83W");
1102 InsertMenu(cm,0,MF_BYPOSITION|MF_SEPARATOR,NULL,NULL);
1103 // add channels to menu
1105 Channel *ch = chanMgr->channel;
1108 char str[128],name[64];
1109 String sjis; //JP-Patch
1110 sjis = ch->info.name; //JP-Patch
1111 sjis.convertTo(String::T_SJIS); //JP-Patch
1112 strncpy(name,sjis.cstr(),32);
1113 //strncpy(name,ch->info.name,32);
1115 //if (strlen(ch->info.name) > 32)
1116 if (strlen(sjis.cstr()) > 32) //JP-Patch
1119 sprintf(str,"%s (%d kb/s %s)",name,ch->info.bitrate,ChanInfo::getTypeStr(ch->info.contentType));
1121 HMENU opMenu = CreatePopupMenu();
1122 InsertMenu(opMenu,0,MF_BYPOSITION,INFO_CMD+numActive,"Info");
1123 if (ch->info.url.isValidURL())
1124 InsertMenu(opMenu,0,MF_BYPOSITION,URL_CMD+numActive,"URL");
1125 InsertMenu(opMenu,0,MF_BYPOSITION,PLAY_CMD+numActive,"Play");
1127 UINT fl = MF_BYPOSITION|MF_POPUP;
1129 fl |= (ch->isPlaying()?MF_CHECKED:0);
1131 InsertMenu(cm,0,fl,(UINT)opMenu,str);
1140 // InsertMenu(cm,0,MF_BYPOSITION,0,"<No channels>");
1149 // flipNotifyPopup(id, flag)
1150 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt)
1152 int mask = peercastInst->getNotifyMask();
1156 CheckMenuItem(trayMenu,id,MF_CHECKED|MF_BYCOMMAND);
1158 CheckMenuItem(trayMenu,id,MF_UNCHECKED|MF_BYCOMMAND);
1160 peercastInst->setNotifyMask(mask);
1161 peercastInst->saveSettings();
1165 static void showHTML(const char *file)
1168 sprintf(url,"%s/%s",servMgr->htmlPath,file);
1170 // sys->callLocalURL(url,servMgr->serverHost.port);
1171 sys->callLocalURL(url, // for PCRaw (url)
1172 (servMgr->allowServer1&Servent::ALLOW_HTML)?(servMgr->serverHost.port):(servMgr->serverHost.port+1));
1175 static ChanInfo getChannelInfo(int index)
1177 Channel *c = chanMgr->findChannelByIndex(index);
1186 // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
1188 // PURPOSE: Processes messages for the main window.
1190 // WM_COMMAND - process the application menu
1191 // WM_PAINT - Paint the main window
1192 // WM_DESTROY - post a quit message and return
1195 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1201 if(message == g_iTaskbarCreated) // for PCRaw (tray icon)
1202 loadIcons(hInst, hWnd);
1212 switch((UINT)lParam)
1214 case WM_LBUTTONDOWN:
1216 SendMessage(hWnd,WM_SHOWMENU,2,0);
1217 SetForegroundWindow(hWnd);
1219 case WM_RBUTTONDOWN:
1221 SendMessage(hWnd,WM_SHOWMENU,1,0);
1222 SetForegroundWindow(hWnd);
1224 case WM_LBUTTONDBLCLK:
1232 COPYDATASTRUCT *pc = (COPYDATASTRUCT *)lParam;
1233 LOG_DEBUG("URL request: %s",pc->lpData);
1234 if (pc->dwData == WM_PLAYCHANNEL)
1237 servMgr->procConnectArgs((char *)pc->lpData,info);
1238 chanMgr->findAndPlayChannel(info,false);
1240 //sys->callLocalURL((const char *)pc->lpData,servMgr->serverHost.port);
1243 case WM_GETPORTNUMBER:
1246 port=servMgr->serverHost.port;
1253 if (servMgr->saveGuiPos){
1254 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1256 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1259 //
\8e©
\93®GUI/
\8dÅ
\91O
\96Ê
\8b@
\94\
1260 if (servMgr->topmostGui)
1262 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_CHECKED|MF_BYCOMMAND);
1265 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_UNCHECKED|MF_BYCOMMAND);
1268 if (servMgr->startWithGui)
1270 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_CHECKED|MF_BYCOMMAND);
1273 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND);
1276 //
\83X
\83N
\83\8a\81[
\83\93\83Z
\81[
\83o
\81[
\97}
\8e~
1277 if (servMgr->preventSS)
1279 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND);
1282 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND);
1285 SetForegroundWindow(hWnd);
1286 bool skipMenu=false;
1288 allowTrayMenu = false;
1290 // check for notifications
1291 if (currNotify & ServMgr::NT_UPGRADE)
1293 if (servMgr->downloadURL[0])
1295 if ((sys->getTime()-seenNewVersionTime) > (60*60)) // notify every hour
1297 if (MessageBox(hWnd,"A newer version of PeerCast is available, press OK to upgrade.","PeerCast",MB_OKCANCEL|MB_APPLMODAL|MB_ICONEXCLAMATION) == IDOK)
1298 sys->getURL(servMgr->downloadURL);
1300 seenNewVersionTime=sys->getTime();
1313 SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWnd, 0);
1314 GetCursorPos(&point);
1316 if (point.x < rcWnd.left){
1317 point.x = rcWnd.left;
1318 flg |= TPM_LEFTALIGN;
1320 if (point.x > rcWnd.right){
1321 point.x = rcWnd.right;
1322 flg |= TPM_RIGHTALIGN;
1324 if (point.y < rcWnd.top){
1325 point.y = rcWnd.top;
1326 flg |= TPM_TOPALIGN;
1328 if (point.y > rcWnd.bottom){
1329 point.y = rcWnd.bottom;
1330 flg |= TPM_BOTTOMALIGN;
1333 flg = TPM_RIGHTALIGN;
1339 menu = GetSubMenu(trayMenu,0);
1340 addAllChannelsMenu(GetSubMenu(menu,0));
1341 addRelayedChannelsMenu(GetSubMenu(menu,1));
1344 menu = GetSubMenu(ltrayMenu,0);
1345 addAllChannelsMenu(menu);
1348 if (!TrackPopupMenu(menu,flg,point.x,point.y,0,hWnd,NULL))
1350 LOG_ERROR("Can`t track popup menu: %d",GetLastError());
1352 PostMessage(hWnd,WM_NULL,0,0);
1355 allowTrayMenu = true;
1365 wmId = LOWORD(wParam);
1366 wmEvent = HIWORD(wParam);
1368 if ((wmId >= INFO_CMD) && (wmId < INFO_CMD+MAX_CHANNELS))
1370 int c = wmId - INFO_CMD;
1371 chanInfo = getChannelInfo(c);
1372 chanInfoIsRelayed = false;
1373 if (winDistinctionNT)
1374 DialogBox(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc);
1377 HWND WKDLG; //JP-Patch
1378 WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc); //JP-Patch
1379 ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1383 if ((wmId >= URL_CMD) && (wmId < URL_CMD+MAX_CHANNELS))
1385 int c = wmId - URL_CMD;
1386 chanInfo = getChannelInfo(c);
1387 if (chanInfo.url.isValidURL())
1388 sys->getURL(chanInfo.url);
1391 if ((wmId >= PLAY_CMD) && (wmId < PLAY_CMD+MAX_CHANNELS))
1393 int c = wmId - PLAY_CMD;
1394 chanInfo = getChannelInfo(c);
1395 chanMgr->findAndPlayChannel(chanInfo,false);
1398 if ((wmId >= RELAY_CMD) && (wmId < RELAY_CMD+MAX_CHANNELS))
1400 int c = wmId - RELAY_CMD;
1401 chanInfo = getChannelInfo(c);
1402 chanMgr->findAndPlayChannel(chanInfo,true);
1406 // Parse the menu selections:
1409 case ID_POPUP_SHOWMESSAGES_PEERCAST:
1410 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_PEERCAST,ServMgr::NT_PEERCAST);
1412 case ID_POPUP_SHOWMESSAGES_BROADCASTERS:
1413 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_BROADCASTERS,ServMgr::NT_BROADCASTERS);
1415 case ID_POPUP_SHOWMESSAGES_TRACKINFO:
1416 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_TRACKINFO,ServMgr::NT_TRACKINFO);
1419 case ID_POPUP_ABOUT:
1421 DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
1423 case ID_POPUP_SHOWGUI:
1424 case IDM_SETTINGS_GUI:
1425 case ID_POPUP_ADVANCED_SHOWGUI:
1430 case ID_POPUP_YELLOWPAGES:
1431 sys->getURL("http://yp.peercast.org/");
1433 case ID_POPUP_YELLOWPAGES1:
1434 sprintf(buf, "http://%s",servMgr->rootHost.cstr());
1437 case ID_POPUP_YELLOWPAGES2:
1438 sprintf(buf, "http://%s",servMgr->rootHost2.cstr());
1442 case ID_POPUP_ADVANCED_VIEWLOG:
1443 showHTML("viewlog.html");
1445 case ID_POPUP_ADVANCED_SAVESETTINGS:
1446 servMgr->saveSettings(iniFileName.cstr());
1448 case ID_POPUP_ADVANCED_INFORMATION:
1449 showHTML("index.html");
1451 case ID_FIND_CHANNELS:
1452 case ID_POPUP_ADVANCED_ALLCHANNELS:
1453 case ID_POPUP_UPGRADE:
1454 sys->callLocalURL("admin?cmd=upgrade",servMgr->serverHost.port);
1456 case ID_POPUP_ADVANCED_RELAYEDCHANNELS:
1457 case ID_POPUP_FAVORITES_EDIT:
1458 showHTML("relays.html");
1460 case ID_POPUP_ADVANCED_BROADCAST:
1461 showHTML("broadcast.html");
1463 case ID_POPUP_SETTINGS:
1464 showHTML("settings.html");
1466 case ID_POPUP_CONNECTIONS:
1467 showHTML("connections.html");
1470 sys->getURL("http://www.peercast.org/help.php");
1473 case ID_POPUP_SAVE_GUI_POS:
1474 if (servMgr->saveGuiPos){
1475 servMgr->saveGuiPos = false;
1476 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1478 servMgr->saveGuiPos = true;
1479 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1481 peercastInst->saveSettings();
1484 case ID_POPUP_KEEP_DOWNSTREAMS:
1485 if (servMgr->keepDownstreams){
1486 servMgr->keepDownstreams = false;
1487 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_UNCHECKED|MF_BYCOMMAND);
1489 servMgr->keepDownstreams = true;
1490 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_CHECKED|MF_BYCOMMAND);
1492 //peercastInst->saveSettings();
1495 case ID_POPUP_TOPMOST:
1496 //
\8dÅ
\91O
\96Ê
\95\
\8e¦
1497 if (servMgr->topmostGui)
1499 servMgr->topmostGui = false;
1500 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_UNCHECKED|MF_BYCOMMAND);
1503 servMgr->topmostGui = true;
1504 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_CHECKED|MF_BYCOMMAND);
1506 peercastInst->saveSettings();
1509 case ID_POPUP_START_WITH_GUI:
1510 //
\8bN
\93®
\8e\9e\82ÉGUI
\95\
\8e¦
1511 if (servMgr->startWithGui)
1513 servMgr->startWithGui = false;
1514 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND);
1517 servMgr->startWithGui = true;
1518 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_CHECKED|MF_BYCOMMAND);
1520 peercastInst->saveSettings();
1523 case ID_POPUP_TRAFFIC:
1524 //
\83g
\83\89\83t
\83B
\83b
\83N
\83\82\83j
\83^
\8bN
\93®
1525 if (winDistinctionNT)
1526 DialogBox(hInst, (LPCTSTR)IDD_TRAFFIC, hWnd, (DLGPROC)TrafficDlgProc);
1529 HWND WKDLG; //JP-Patch
1530 WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)TrafficDlgProc); //JP-Patch
1531 ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1535 case ID_POPUP_PREVENT_SS:
1536 //
\83X
\83N
\83\8a\81[
\83\93\83Z
\81[
\83o
\81[
\97}
\8e~
1537 if (servMgr->preventSS)
1539 servMgr->preventSS = false;
1540 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND);
1543 servMgr->preventSS = true;
1544 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND);
1546 peercastInst->saveSettings();
1549 case ID_POPUP_EXIT_CONFIRM:
1551 DestroyWindow(hWnd);
1554 return DefWindowProc(hWnd, message, wParam, lParam);
1562 //
\82È
\82ñ
\82©
\83A
\83N
\83e
\83B
\83u
\82¶
\82á
\82È
\82¢
\82Æ
\91\97\82ç
\82ê
\82Ä
\82±
\82È
\82¢
\82ç
\82µ
\82¢
1563 if (servMgr->preventSS && (wParam == SC_SCREENSAVE) && chanMgr->isBroadcasting())
1566 return DefWindowProc(hWnd, message, wParam, lParam);
1570 return DefWindowProc(hWnd, message, wParam, lParam);
1574 // Mesage handler for about box.
1575 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1580 //SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENT);
1581 // SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTJP);
1584 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTEX);
1587 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTVP);
1593 switch (LOWORD(wParam))
1597 EndDialog(hDlg, LOWORD(wParam));
1600 sys->getURL("http://www.peercast.org");
1601 EndDialog(hDlg, LOWORD(wParam));
1612 // Mesage handler for chaninfo box
1613 LRESULT CALLBACK ChanInfoProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1620 //strcpy(str,chanInfo.track.artist.cstr());
1621 strcpy(str,chanInfo.track.artist); //JP-Patch
1623 //strcat(str,chanInfo.track.title.cstr());
1624 strcat(str,chanInfo.track.title);
1625 String name,track,comment,desc,genre; //JP-Patch
1626 name = chanInfo.name; //JP-Patch
1627 track = str; //JP-Patch
1628 comment = chanInfo.comment; //JP-Patch
1629 desc = chanInfo.desc; //JP-Patc
1630 genre = chanInfo.genre; //JP-Patch
1631 name.convertTo(String::T_SJIS); //JP-Patc
1632 track.convertTo(String::T_SJIS); //JP-Patch
1633 comment.convertTo(String::T_SJIS); //JP-Patch
1634 desc.convertTo(String::T_SJIS); //JP-Patch
1635 genre.convertTo(String::T_SJIS); //JP-Patch
1637 //SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)chanInfo.name.cstr());
1638 SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)name.cstr()); //JP-Patch
1639 //SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)str);
1640 SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)track.cstr()); //JP-Patch
1641 //SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)chanInfo.comment.cstr());
1642 SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)comment.cstr()); //JP-Patch
1643 //SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)chanInfo.desc.cstr());
1644 SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)desc.cstr()); //JP-Patch
1645 //SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)chanInfo.genre.cstr());
1646 SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)genre.cstr()); //JP-Patch
1648 sprintf(str,"%d kb/s %s",chanInfo.bitrate,ChanInfo::getTypeStr(chanInfo.contentType));
1649 SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LONG)str);
1652 if (!chanInfo.url.isValidURL())
1653 EnableWindow(GetDlgItem(hDlg,IDC_CONTACT),false);
1655 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1658 SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)ch->getStatusStr());
1659 SendDlgItemMessage(hDlg, IDC_KEEP,BM_SETCHECK, ch->stayConnected, 0);
1661 //
\8c»
\8dÝ
\82Ì
\8cÅ
\97L
\83\8a\83\8c\81[
\8fã
\8cÀ
\90Ý
\92è
\82ð
\95\
\8e¦(0
\82Í
\96³
\8cø)
1662 ::SetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, ch->maxRelays, false);
1665 // index.txt
\82È
\82Ì
\82Å
\96³
\8cø
\82É
1666 ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_MAXRELAYS), false);
1667 ::EnableWindow(::GetDlgItem(hDlg, IDC_APPLY_MAXRELAYS), false);
1671 SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)"OK");
1672 EnableWindow(GetDlgItem(hDlg,IDC_KEEP),false);
1679 HWND hDsk = GetDesktopWindow();
1680 GetWindowRect(hDsk,&drect);
1681 GetWindowRect(hDlg,&rect);
1682 GetCursorPos(&point);
1685 size.x = rect.right-rect.left;
1686 size.y = rect.bottom-rect.top;
1688 if (point.x-drect.left < size.x)
1691 pos.x = point.x-size.x;
1693 if (point.y-drect.top < size.y)
1696 pos.y = point.y-size.y;
1698 SetWindowPos(hDlg,HWND_TOPMOST,pos.x,pos.y,size.x,size.y,0);
1705 char str[1024],idstr[64];
1706 chanInfo.id.toStr(idstr);
1708 switch (LOWORD(wParam))
1712 sys->getURL(chanInfo.url);
1717 sprintf(str,"admin?page=chaninfo&id=%s&relay=%d",idstr,chanInfoIsRelayed);
1718 sys->callLocalURL(str,servMgr->serverHost.port);
1723 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1725 ch->stayConnected = SendDlgItemMessage(hDlg, IDC_KEEP,BM_GETCHECK, 0, 0) == BST_CHECKED;;
1732 chanMgr->findAndPlayChannel(chanInfo,false);
1736 case IDC_APPLY_MAXRELAYS:
1738 //
\83`
\83\83\83\93\83l
\83\8b\8cÅ
\97L
\82Ì
\8dÅ
\91å
\83\8a\83\8c\81[
\90\94\82ð
\90Ý
\92è
1742 //
\93ü
\97Í
\92l
\8eæ
\93¾
1743 mr = ::GetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, &bSucc, false);
1747 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1748 if (ch && !isIndexTxt(ch))
1754 MessageBox(hDlg, "
\93ü
\97Í
\92l
\82ª
\95s
\90³
\82Å
\82·
\81B", "Error", MB_OK|MB_ICONERROR|MB_APPLMODAL);
1755 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1757 ::SetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, ch->maxRelays, false);
1765 if (winDistinctionNT)
1768 DestroyWindow(hDlg); //JP-Patch
1772 if (LOWORD(wParam) == WA_INACTIVE)
1773 if (winDistinctionNT)
1776 DestroyWindow(hDlg); //JP-Patch
1787 // control thread (Traffic dialog)
1788 THREAD_PROC trafficDlgUpdate(ThreadInfo *thread)
1790 thread->finish = false;
1792 while (trafficDlg && thread->active)
1794 SendMessage(trafficDlg, WM_UPDATETRAFFIC, 0, 0);
1798 thread->finish = true;
1803 // Dialog procedure (Traffic dialog)
1804 LRESULT CALLBACK TrafficDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1809 //
\8aù
\82É
\8aJ
\82¢
\82Ä
\82é
1810 if (trafficDlg || trafficDlgThread.active)
1812 if (winDistinctionNT)
1815 DestroyWindow(hDlg);
1820 trafficDlgThread.func = trafficDlgUpdate;
1821 if (!sys->startThread(&trafficDlgThread)){
1822 MessageBox(NULL,"Unable to start GUI","PeerCast",MB_OK|MB_ICONERROR);
1823 PostMessage(hDlg,WM_DESTROY,0,0);
1828 case WM_UPDATETRAFFIC:
1830 enum unitSymbol { B, KB, MB, GB };
1831 const unsigned long int unit[] = { 1, 1024, 1024*1024, 1024*1024*1024 };
1832 char suffix[][3] = { "B", "KB", "MB", "GB" };
1833 const int bufsize = 60;
1834 char szUp[bufsize], szDown[bufsize];
1835 unsigned long long int totalDown = stats.getCurrent(Stats::BYTESIN) - stats.getCurrent(Stats::LOCALBYTESIN);
1836 unsigned long long int totalUp = stats.getCurrent(Stats::BYTESOUT) - stats.getCurrent(Stats::LOCALBYTESOUT);
1839 for (int i=GB; i>0; --i)
1841 if (totalUp >= unit[i])
1843 sprintf_s<bufsize>(szUp, "%.2f%s", (double)totalUp/unit[i], suffix[i]);
1848 sprintf_s<bufsize>(szUp, "%d%s", totalUp, suffix[0]);
1852 for (int i=GB; i>0; --i)
1854 if (totalDown >= unit[i])
1856 sprintf_s<bufsize>(szDown, "%.2f%s", (double)totalDown/unit[i], suffix[i]);
1861 sprintf_s<bufsize>(szDown, "%d%s", totalDown, suffix[0]);
1864 SetDlgItemText(hDlg, IDC_STATIC_UP, szUp);
1865 SetDlgItemText(hDlg, IDC_STATIC_DOWN, szDown);
1871 trafficDlgThread.active = false;
1872 if (winDistinctionNT)
1875 DestroyWindow(hDlg);