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);
189 // --------------------------------------------------
190 void WINAPI ServiceMain(DWORD argc, LPSTR *argv)
194 //iniFileName.set(".\\peercast.ini");
196 WIN32_FIND_DATA fd; //JP-EX
197 HANDLE hFind; //JP-EX
199 OSVERSIONINFO osInfo; //JP-EX
200 osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
201 GetVersionEx(&osInfo);
202 if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
203 winDistinctionNT = true;
205 winDistinctionNT = false;
207 // off by default now
215 ret = GetModuleFileName(NULL, buf, sizeof(buf)/sizeof(TCHAR));
220 for (int i=_tcslen(buf); i>0; --i)
232 iniFileName.set(exePath.cstr());
233 iniFileName.append("\\peercast.ini");
237 peercastInst = new MyPeercastInst();
238 peercastApp = new MyPeercastApp();
240 peercastInst->init();
242 LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
244 if (peercastApp->clearTemp()) //JP-EX
246 DeleteFile("play.pls");
247 hFind = FindFirstFile("*.asx",&fd);
248 if (hFind != INVALID_HANDLE_VALUE)
252 DeleteFile((char *)&fd.cFileName);
254 while (FindNextFile(hFind,&fd));
260 peercastInst->saveSettings();
261 peercastInst->quit();
264 // --------------------------------------------------
265 int WinMainDummy(HINSTANCE hInstance,
266 HINSTANCE hPrevInstance,
272 ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
281 iniFileName.set(".\\peercast.ini");
283 WIN32_FIND_DATA fd; //JP-EX
284 HANDLE hFind; //JP-EX
286 OSVERSIONINFO osInfo; //JP-EX
287 osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
288 GetVersionEx(&osInfo);
289 if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
290 winDistinctionNT = true;
292 winDistinctionNT = false;
294 // off by default now
297 if (strlen(lpCmdLine) > 0)
300 if ((p = strstr(lpCmdLine,"-inifile"))!=NULL)
301 iniFileName.setFromString(p+8);
303 if (strstr(lpCmdLine,"-zen"))
306 if (strstr(lpCmdLine,"-multi"))
309 if (strstr(lpCmdLine,"-kill"))
312 if ((p = strstr(lpCmdLine,"-url"))!=NULL)
327 strncpy(tmpURL,p,sizeof(tmpURL)-1);
333 exePath = iniFileName;
334 char *s = exePath.cstr();
346 if (strnicmp(tmpURL,"peercast://",11)==0)
348 if (strnicmp(tmpURL+11,"pls/",4)==0)
349 chanURL = tmpURL+11+4;
359 // Initialize global strings
360 //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
361 //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING);
363 strcpy(szTitle,"PeerCast");
364 strcpy(szWindowClass,"PeerCast");
365 strcpy(szWindowClass2,"Main");
369 HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass);
371 if (GetLastError() == ERROR_ALREADY_EXISTS)
373 HWND oldWin = FindWindow(szWindowClass,NULL);
376 //SendMessage(oldWin,WM_SHOWGUI,0,0);
379 SendMessage(oldWin,WM_DESTROY,0,0);
386 copy.dwData = WM_PLAYCHANNEL;
387 copy.cbData = strlen(chanURL)+1; // plus null term
388 copy.lpData = chanURL;
389 SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)©);
392 SendMessage(oldWin,WM_SHOWGUI,0,0);
402 MyRegisterClass(hInstance);
403 MyRegisterClass2(hInstance);
405 // Perform application initialization:
406 if (!InitInstance (hInstance, nCmdShow))
409 peercastInst = new MyPeercastInst();
410 peercastApp = new MyPeercastApp();
412 peercastInst->init();
414 LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
416 if (peercastApp->clearTemp()) //JP-EX
418 DeleteFile("play.pls");
419 hFind = FindFirstFile("*.asx",&fd);
420 if (hFind != INVALID_HANDLE_VALUE)
424 DeleteFile((char *)&fd.cFileName);
426 while (FindNextFile(hFind,&fd));
435 servMgr->procConnectArgs(chanURL,info);
436 chanMgr->findAndPlayChannel(info,false);
439 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE);
441 // setup menu notifes
442 int mask = peercastInst->getNotifyMask();
443 if (mask & ServMgr::NT_PEERCAST)
444 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND);
445 if (mask & ServMgr::NT_BROADCASTERS)
446 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND);
447 if (mask & ServMgr::NT_TRACKINFO)
448 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND);
450 if (servMgr->startWithGui)
455 // Main message loop:
456 while (GetMessage(&msg, NULL, 0, 0))
458 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
460 TranslateMessage(&msg);
461 DispatchMessage(&msg);
465 Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon);
467 peercastInst->saveSettings();
468 peercastInst->quit();
470 Gdiplus::GdiplusShutdown(gdiplusToken);
476 // ---------------------------------------
477 int APIENTRY WinMain(HINSTANCE hInstance,
478 HINSTANCE hPrevInstance,
483 _EXCEPTION_POINTERS *lpExcept;
488 if (lstrlen(lpCmdLine) && strstr(lpCmdLine, "-D") != NULL)
490 SERVICE_TABLE_ENTRY svctbl[] = {
491 {"PeerCast", (LPSERVICE_MAIN_FUNCTION)ServiceMain},
495 if (!StartServiceCtrlDispatcher(svctbl))
497 //SvcReportEvent(TEXT("StartServiceCtrlDispatcher"));
501 WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
502 } __except(lpExcept = GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER)
506 fs.openWriteReplace(".\\dump.txt");
507 fs.writeLine("Exception Point: WinMain");
508 fs.write("Exception: ", 11);
509 switch (lpExcept->ExceptionRecord->ExceptionCode)
511 case EXCEPTION_ACCESS_VIOLATION:
512 fs.writeLine("Access violation");
515 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
516 case EXCEPTION_INT_DIVIDE_BY_ZERO:
517 fs.writeLine("Divide by zero");
520 case EXCEPTION_STACK_OVERFLOW:
521 fs.writeLine("Stack overflow");
525 fs.writeLong(lpExcept->ExceptionRecord->ExceptionCode);
529 fs.writeLineF("Address: %p", lpExcept->ExceptionRecord->ExceptionAddress);
531 fs.writeLine("Additional information:");
532 nParams = lpExcept->ExceptionRecord->NumberParameters;
533 for (unsigned i=0; i<nParams; ++i)
535 fs.writeLineF("%d: %lu", i, lpExcept->ExceptionRecord->ExceptionInformation[i]);
540 fs.openWriteReplace(".\\dump.html");
541 sys->logBuf->dumpHTML(fs);
544 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"
545 "
\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",
546 MB_OK|MB_ICONWARNING);
548 return GetExceptionCode();
558 // FUNCTION: MyRegisterClass()
560 // PURPOSE: Registers the window class.
564 // This function and its usage is only necessary if you want this code
565 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
566 // function that was added to Windows 95. It is important to call this function
567 // so that the application will get 'well formed' small icons associated
570 ATOM MyRegisterClass(HINSTANCE hInstance)
574 wcex.cbSize = sizeof(WNDCLASSEX);
576 wcex.style = CS_HREDRAW | CS_VREDRAW;
577 wcex.lpfnWndProc = (WNDPROC)WndProc;
580 wcex.hInstance = hInstance;
581 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
582 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
583 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
584 // wcex.lpszMenuName = (LPCSTR)IDC_SIMPLE;
585 wcex.lpszMenuName = NULL;
586 wcex.lpszClassName = szWindowClass;
587 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
589 return RegisterClassEx(&wcex);
592 ATOM MyRegisterClass2(HINSTANCE hInstance)
596 wcex.cbSize = sizeof(WNDCLASSEX);
598 wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
599 wcex.lpfnWndProc = (WNDPROC)GUIProc;
602 wcex.hInstance = hInstance;
603 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
604 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
605 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
606 // wcex.lpszMenuName = (LPCSTR)IDC_SIMPLE;
607 wcex.lpszMenuName = NULL;
608 wcex.lpszClassName = szWindowClass2;
609 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
611 return RegisterClassEx(&wcex);
614 //-----------------------------
615 void loadIcons(HINSTANCE hInstance, HWND hWnd)
617 icon1 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL);
618 icon2 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL2);
620 trayIcon.cbSize = sizeof(trayIcon);
621 trayIcon.hWnd = hWnd;
623 trayIcon.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
624 trayIcon.uCallbackMessage = WM_TRAYICON;
625 trayIcon.hIcon = icon1;
626 strcpy(trayIcon.szTip, "PeerCast");
628 Shell_NotifyIcon(NIM_ADD, (NOTIFYICONDATA*)&trayIcon);
630 //ShowWindow(hWnd, nCmdShow);
633 if(!trayMenu) // for PCRaw (tray icon)
634 trayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_TRAYMENU));
635 if(!ltrayMenu) // for PCRaw (tray icon)
636 ltrayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_LTRAYMENU));
641 //-----------------------------
643 // FUNCTION: InitInstance(HANDLE, int)
645 // PURPOSE: Saves instance handle and creates main window
649 // In this function, we save the instance handle in a global variable and
650 // create and display the main program window.
652 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
656 hInst = hInstance; // Store instance handle in our global variable
658 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
659 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
668 g_iTaskbarCreated = RegisterWindowMessage("TaskbarCreated"); // for PCRaw (tray icon)
670 loadIcons(hInstance,hWnd);
672 using namespace Gdiplus;
673 GdiplusStartupInput gdiplusStartupInput;
674 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
678 //-----------------------------
679 //static String trackTitle;
680 //static String channelComment;
682 //-----------------------------
683 void channelPopup(const char *title, const char *msg, bool isPopup = true)
687 if (*title == '\0') return;
693 trayIcon.uFlags = NIF_ICON|NIF_TIP;
694 strncpy(trayIcon.szTip, both.cstr(),sizeof(trayIcon.szTip)-1);
695 trayIcon.szTip[sizeof(trayIcon.szTip)-1]=0;
697 if (isPopup) trayIcon.uFlags |= 16;
698 trayIcon.uTimeoutOrVersion = 10000;
699 strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
700 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
702 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
704 //-----------------------------
705 void clearChannelPopup()
707 trayIcon.uFlags = NIF_ICON|16;
708 trayIcon.uTimeoutOrVersion = 10000;
709 strncpy(trayIcon.szInfo,"",sizeof(trayIcon.szInfo)-1);
710 strncpy(trayIcon.szInfoTitle,"",sizeof(trayIcon.szInfoTitle)-1);
711 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
714 //-----------------------------
723 static PopupEntry *PEList = NULL;
726 static void putPopupEntry(PopupEntry *pe)
734 static PopupEntry *getPopupEntry(GnuID id)
737 PopupEntry *pe = PEList;
738 PopupEntry *prev = NULL;
740 if (id.isSame(pe->id)) {
741 if (prev) prev->next = pe->next;
742 else PEList = pe->next;
754 static PopupEntry *getTopPopupEntry()
756 PopupEntry *p = NULL;
760 PEList = PEList->next;
766 //-----------------------------
767 void APICALL MyPeercastApp::channelStart(ChanInfo *info)
770 // lastPlayID = info->id;
772 // if(!isIndexTxt(info)) // for PCRaw (popup)
773 // clearChannelPopup();
775 PopupEntry *pe = getPopupEntry(info->id);
780 if (!isIndexTxt(info))
785 //-----------------------------
786 void APICALL MyPeercastApp::channelStop(ChanInfo *info)
788 // if (info->id.isSame(lastPlayID))
790 // lastPlayID.clear();
792 // if(!isIndexTxt(info)) // for PCRaw (popup)
793 // clearChannelPopup();
796 PopupEntry *pe = getPopupEntry(info->id);
799 pe = getTopPopupEntry();
803 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
805 String name,track; //JP-Patch
806 name = pe->name; //JP-Patch
807 track = pe->track; //JP-Patch
808 name.convertTo(String::T_SJIS); //JP-Patch
809 track.convertTo(String::T_SJIS); //JP-Patch
811 // channelPopup(info->name.cstr(),trackTitle.cstr());
812 channelPopup(name.cstr(),track.cstr(), false); //JP-Patch
817 //-----------------------------
818 void APICALL MyPeercastApp::channelUpdate(ChanInfo *info)
822 PopupEntry *pe = getPopupEntry(info->id);
826 tmp.append(info->track.artist);
828 tmp.append(info->track.title);
831 if (!tmp.isSame(pe->track))
833 pe->name = info->name;
835 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
838 String name,track; //JP-Patch
839 name = info->name; //JP-Patch
840 track = tmp; //JP-Patch
841 name.convertTo(String::T_SJIS); //JP-Patch
842 track.convertTo(String::T_SJIS); //JP-Patch
843 if(!isIndexTxt(info)) // for PCRaw (popup)
846 // channelPopup(info->name.cstr(),trackTitle.cstr());
847 channelPopup(name.cstr(),track.cstr()); //JP-Patch
850 } else if (!info->comment.isSame(pe->comment))
852 pe->name = info->name;
853 pe->comment = info->comment;
854 if (ServMgr::NT_BROADCASTERS & peercastInst->getNotifyMask())
856 //channelComment = info->comment;
857 String name,comment; //JP-Patch
858 name = info->name; //JP-Patch
859 comment = info->comment; //JP-Patch
860 name.convertTo(String::T_SJIS); //JP-Patch
861 comment.convertTo(String::T_SJIS); //JP-Patch
862 if(!isIndexTxt(info)) // for PCRaw (popup)
865 // channelPopup(info->name.cstr(),channelComment.cstr());
866 channelPopup(name.cstr(),comment.cstr());
871 if (!isIndexTxt(info))
877 //-----------------------------
878 void APICALL MyPeercastApp::notifyMessage(ServMgr::NOTIFY_TYPE type, const char *msg)
880 static bool shownUpgradeAlert=false;
886 if (!shownUpgradeAlert)
888 trayIcon.uFlags = NIF_ICON;
890 if (type == ServMgr::NT_UPGRADE)
892 shownUpgradeAlert = true;
893 trayIcon.hIcon = icon2;
896 trayIcon.hIcon = icon1;
900 if (type == ServMgr::NT_UPGRADE)
904 const char *title="";
908 case ServMgr::NT_UPGRADE:
909 title = "Upgrade alert";
911 case ServMgr::NT_PEERCAST:
912 title = "Message from PeerCast:";
917 if (type & peercastInst->getNotifyMask())
919 trayIcon.uFlags |= 16;
920 trayIcon.uTimeoutOrVersion = 10000;
921 strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
922 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
923 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
926 //-----------------------------
930 void createGUI(HWND hWnd)
933 guiWnd = ::CreateWindow(szWindowClass2,
935 WS_OVERLAPPEDWINDOW & ~(WS_MAXIMIZEBOX) /*| WS_VSCROLL | WS_HSCROLL*/,
945 ShowWindow(guiWnd,SW_SHOWNORMAL);
947 //
\8e©
\93®
\82Å
\8dÅ
\91O
\96Ê
948 if (servMgr->topmostGui)
950 ::SetWindowPos(guiWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
956 // addRelayedChannelsMenu(HMENU m)
959 void addRelayedChannelsMenu(HMENU cm)
961 int cnt = GetMenuItemCount(cm);
962 for(int i=0; i<cnt-3; i++)
963 DeleteMenu(cm,0,MF_BYPOSITION);
965 Channel *c = chanMgr->channel;
970 char str[128],name[64];
971 strncpy(name,c->info.name,32);
973 if (strlen(c->info.name) > 32)
977 sprintf(str,"%s (%d kb/s %s)",name,c->info.bitrate,ChanInfo::getTypeStr(c->info.contentType));
978 //InsertMenu(cm,0,MF_BYPOSITION,RELAY_CMD+i,str);
984 typedef int (*COMPARE_FUNC)(const void *,const void *);
986 static int compareHitLists(ChanHitList **c2, ChanHitList **c1)
988 return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
991 static int compareChannels(Channel **c2, Channel **c1)
993 return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
997 // addAllChannelsMenu(HMENU m)
1000 void addAllChannelsMenu(HMENU cm)
1002 int cnt = GetMenuItemCount(cm);
1003 /* for(int i=0; i<cnt-2; i++)
1004 DeleteMenu(cm,0,MF_BYPOSITION);*/
1006 for(int i=0; i<cnt; i++)
1007 DeleteMenu(cm,0,MF_BYPOSITION);
1009 HMENU yMenu = CreatePopupMenu();
1010 if (!servMgr->rootHost2.isEmpty()){
1011 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES2,servMgr->rootHost2);
1013 if (!servMgr->rootHost.isEmpty()){
1014 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES1,servMgr->rootHost);
1017 InsertMenu(cm,0,MF_BYPOSITION|MF_POPUP,(UINT)yMenu,"
\83C
\83G
\83\8d\81[
\83y
\81[
\83W");
1018 InsertMenu(cm,0,MF_BYPOSITION|MF_SEPARATOR,NULL,NULL);
1019 // add channels to menu
1021 Channel *ch = chanMgr->channel;
1024 char str[128],name[64];
1025 String sjis; //JP-Patch
1026 sjis = ch->info.name; //JP-Patch
1027 sjis.convertTo(String::T_SJIS); //JP-Patch
1028 strncpy(name,sjis.cstr(),32);
1029 //strncpy(name,ch->info.name,32);
1031 //if (strlen(ch->info.name) > 32)
1032 if (strlen(sjis.cstr()) > 32) //JP-Patch
1035 sprintf(str,"%s (%d kb/s %s)",name,ch->info.bitrate,ChanInfo::getTypeStr(ch->info.contentType));
1037 HMENU opMenu = CreatePopupMenu();
1038 InsertMenu(opMenu,0,MF_BYPOSITION,INFO_CMD+numActive,"Info");
1039 if (ch->info.url.isValidURL())
1040 InsertMenu(opMenu,0,MF_BYPOSITION,URL_CMD+numActive,"URL");
1041 InsertMenu(opMenu,0,MF_BYPOSITION,PLAY_CMD+numActive,"Play");
1043 UINT fl = MF_BYPOSITION|MF_POPUP;
1045 fl |= (ch->isPlaying()?MF_CHECKED:0);
1047 InsertMenu(cm,0,fl,(UINT)opMenu,str);
1056 // InsertMenu(cm,0,MF_BYPOSITION,0,"<No channels>");
1065 // flipNotifyPopup(id, flag)
1066 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt)
1068 int mask = peercastInst->getNotifyMask();
1072 CheckMenuItem(trayMenu,id,MF_CHECKED|MF_BYCOMMAND);
1074 CheckMenuItem(trayMenu,id,MF_UNCHECKED|MF_BYCOMMAND);
1076 peercastInst->setNotifyMask(mask);
1077 peercastInst->saveSettings();
1081 static void showHTML(const char *file)
1084 sprintf(url,"%s/%s",servMgr->htmlPath,file);
1086 // sys->callLocalURL(url,servMgr->serverHost.port);
1087 sys->callLocalURL(url, // for PCRaw (url)
1088 (servMgr->allowServer1&Servent::ALLOW_HTML)?(servMgr->serverHost.port):(servMgr->serverHost.port+1));
1091 static ChanInfo getChannelInfo(int index)
1093 Channel *c = chanMgr->findChannelByIndex(index);
1102 // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
1104 // PURPOSE: Processes messages for the main window.
1106 // WM_COMMAND - process the application menu
1107 // WM_PAINT - Paint the main window
1108 // WM_DESTROY - post a quit message and return
1111 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1117 if(message == g_iTaskbarCreated) // for PCRaw (tray icon)
1118 loadIcons(hInst, hWnd);
1128 switch((UINT)lParam)
1130 case WM_LBUTTONDOWN:
1132 SendMessage(hWnd,WM_SHOWMENU,2,0);
1133 SetForegroundWindow(hWnd);
1135 case WM_RBUTTONDOWN:
1137 SendMessage(hWnd,WM_SHOWMENU,1,0);
1138 SetForegroundWindow(hWnd);
1140 case WM_LBUTTONDBLCLK:
1148 COPYDATASTRUCT *pc = (COPYDATASTRUCT *)lParam;
1149 LOG_DEBUG("URL request: %s",pc->lpData);
1150 if (pc->dwData == WM_PLAYCHANNEL)
1153 servMgr->procConnectArgs((char *)pc->lpData,info);
1154 chanMgr->findAndPlayChannel(info,false);
1156 //sys->callLocalURL((const char *)pc->lpData,servMgr->serverHost.port);
1159 case WM_GETPORTNUMBER:
1162 port=servMgr->serverHost.port;
1169 if (servMgr->saveGuiPos){
1170 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1172 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1175 //
\8e©
\93®GUI/
\8dÅ
\91O
\96Ê
\8b@
\94\
1176 if (servMgr->topmostGui)
1178 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_CHECKED|MF_BYCOMMAND);
1181 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_UNCHECKED|MF_BYCOMMAND);
1184 if (servMgr->startWithGui)
1186 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_CHECKED|MF_BYCOMMAND);
1189 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND);
1192 //
\83X
\83N
\83\8a\81[
\83\93\83Z
\81[
\83o
\81[
\97}
\8e~
1193 if (servMgr->preventSS)
1195 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND);
1198 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND);
1201 //
\83o
\81[
\83W
\83\87\83\93\83`
\83F
\83b
\83N
\82Ì
\97L
\96³
1202 if (servMgr->noVersionCheck)
1204 CheckMenuItem(trayMenu, ID_POPUP_NO_VER_CHECK, MF_CHECKED|MF_BYCOMMAND);
1207 CheckMenuItem(trayMenu, ID_POPUP_NO_VER_CHECK, MF_UNCHECKED|MF_BYCOMMAND);
1210 SetForegroundWindow(hWnd);
1211 bool skipMenu=false;
1213 allowTrayMenu = false;
1215 // check for notifications
1216 if (currNotify & ServMgr::NT_UPGRADE)
1218 if (servMgr->downloadURL[0])
1220 if ((sys->getTime()-seenNewVersionTime) > (60*60)) // notify every hour
1222 if (MessageBox(hWnd,"A newer version of PeerCast is available, press OK to upgrade.","PeerCast",MB_OKCANCEL|MB_APPLMODAL|MB_ICONEXCLAMATION) == IDOK)
1223 sys->getURL(servMgr->downloadURL);
1225 seenNewVersionTime=sys->getTime();
1238 SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWnd, 0);
1239 GetCursorPos(&point);
1241 if (point.x < rcWnd.left){
1242 point.x = rcWnd.left;
1243 flg |= TPM_LEFTALIGN;
1245 if (point.x > rcWnd.right){
1246 point.x = rcWnd.right;
1247 flg |= TPM_RIGHTALIGN;
1249 if (point.y < rcWnd.top){
1250 point.y = rcWnd.top;
1251 flg |= TPM_TOPALIGN;
1253 if (point.y > rcWnd.bottom){
1254 point.y = rcWnd.bottom;
1255 flg |= TPM_BOTTOMALIGN;
1258 flg = TPM_RIGHTALIGN;
1264 menu = GetSubMenu(trayMenu,0);
1265 addAllChannelsMenu(GetSubMenu(menu,0));
1266 addRelayedChannelsMenu(GetSubMenu(menu,1));
1269 menu = GetSubMenu(ltrayMenu,0);
1270 addAllChannelsMenu(menu);
1273 if (!TrackPopupMenu(menu,flg,point.x,point.y,0,hWnd,NULL))
1275 LOG_ERROR("Can`t track popup menu: %d",GetLastError());
1277 PostMessage(hWnd,WM_NULL,0,0);
1280 allowTrayMenu = true;
1290 wmId = LOWORD(wParam);
1291 wmEvent = HIWORD(wParam);
1293 if ((wmId >= INFO_CMD) && (wmId < INFO_CMD+MAX_CHANNELS))
1295 int c = wmId - INFO_CMD;
1296 chanInfo = getChannelInfo(c);
1297 chanInfoIsRelayed = false;
1298 if (winDistinctionNT)
1299 DialogBox(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc);
1302 HWND WKDLG; //JP-Patch
1303 WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc); //JP-Patch
1304 ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1308 if ((wmId >= URL_CMD) && (wmId < URL_CMD+MAX_CHANNELS))
1310 int c = wmId - URL_CMD;
1311 chanInfo = getChannelInfo(c);
1312 if (chanInfo.url.isValidURL())
1313 sys->getURL(chanInfo.url);
1316 if ((wmId >= PLAY_CMD) && (wmId < PLAY_CMD+MAX_CHANNELS))
1318 int c = wmId - PLAY_CMD;
1319 chanInfo = getChannelInfo(c);
1320 chanMgr->findAndPlayChannel(chanInfo,false);
1323 if ((wmId >= RELAY_CMD) && (wmId < RELAY_CMD+MAX_CHANNELS))
1325 int c = wmId - RELAY_CMD;
1326 chanInfo = getChannelInfo(c);
1327 chanMgr->findAndPlayChannel(chanInfo,true);
1331 // Parse the menu selections:
1334 case ID_POPUP_SHOWMESSAGES_PEERCAST:
1335 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_PEERCAST,ServMgr::NT_PEERCAST);
1337 case ID_POPUP_SHOWMESSAGES_BROADCASTERS:
1338 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_BROADCASTERS,ServMgr::NT_BROADCASTERS);
1340 case ID_POPUP_SHOWMESSAGES_TRACKINFO:
1341 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_TRACKINFO,ServMgr::NT_TRACKINFO);
1344 case ID_POPUP_ABOUT:
1346 DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
1348 case ID_POPUP_SHOWGUI:
1349 case IDM_SETTINGS_GUI:
1350 case ID_POPUP_ADVANCED_SHOWGUI:
1355 case ID_POPUP_YELLOWPAGES:
1356 sys->getURL("http://yp.peercast.org/");
1358 case ID_POPUP_YELLOWPAGES1:
1359 sprintf(buf, "http://%s",servMgr->rootHost.cstr());
1362 case ID_POPUP_YELLOWPAGES2:
1363 sprintf(buf, "http://%s",servMgr->rootHost2.cstr());
1367 case ID_POPUP_ADVANCED_VIEWLOG:
1368 showHTML("viewlog.html");
1370 case ID_POPUP_ADVANCED_SAVESETTINGS:
1371 servMgr->saveSettings(iniFileName.cstr());
1373 case ID_POPUP_ADVANCED_INFORMATION:
1374 showHTML("index.html");
1376 case ID_FIND_CHANNELS:
1377 case ID_POPUP_ADVANCED_ALLCHANNELS:
1378 case ID_POPUP_UPGRADE:
1379 sys->callLocalURL("admin?cmd=upgrade",servMgr->serverHost.port);
1381 case ID_POPUP_ADVANCED_RELAYEDCHANNELS:
1382 case ID_POPUP_FAVORITES_EDIT:
1383 showHTML("relays.html");
1385 case ID_POPUP_ADVANCED_BROADCAST:
1386 showHTML("broadcast.html");
1388 case ID_POPUP_SETTINGS:
1389 showHTML("settings.html");
1391 case ID_POPUP_CONNECTIONS:
1392 showHTML("connections.html");
1395 sys->getURL("http://www.peercast.org/help.php");
1398 case ID_POPUP_SAVE_GUI_POS:
1399 if (servMgr->saveGuiPos){
1400 servMgr->saveGuiPos = false;
1401 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1403 servMgr->saveGuiPos = true;
1404 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1406 peercastInst->saveSettings();
1409 case ID_POPUP_KEEP_DOWNSTREAMS:
1410 if (servMgr->keepDownstreams){
1411 servMgr->keepDownstreams = false;
1412 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_UNCHECKED|MF_BYCOMMAND);
1414 servMgr->keepDownstreams = true;
1415 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_CHECKED|MF_BYCOMMAND);
1417 //peercastInst->saveSettings();
1420 case ID_POPUP_TOPMOST:
1421 //
\8dÅ
\91O
\96Ê
\95\
\8e¦
1422 if (servMgr->topmostGui)
1424 servMgr->topmostGui = false;
1425 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_UNCHECKED|MF_BYCOMMAND);
1428 servMgr->topmostGui = true;
1429 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_CHECKED|MF_BYCOMMAND);
1431 peercastInst->saveSettings();
1434 case ID_POPUP_START_WITH_GUI:
1435 //
\8bN
\93®
\8e\9e\82ÉGUI
\95\
\8e¦
1436 if (servMgr->startWithGui)
1438 servMgr->startWithGui = false;
1439 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND);
1442 servMgr->startWithGui = true;
1443 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_CHECKED|MF_BYCOMMAND);
1445 peercastInst->saveSettings();
1448 case ID_POPUP_TRAFFIC:
1449 //
\83g
\83\89\83t
\83B
\83b
\83N
\83\82\83j
\83^
\8bN
\93®
1450 if (winDistinctionNT)
1451 DialogBox(hInst, (LPCTSTR)IDD_TRAFFIC, hWnd, (DLGPROC)TrafficDlgProc);
1454 HWND WKDLG; //JP-Patch
1455 WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_TRAFFIC, hWnd, (DLGPROC)TrafficDlgProc); //JP-Patch
1456 ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1460 case ID_POPUP_PREVENT_SS:
1461 //
\83X
\83N
\83\8a\81[
\83\93\83Z
\81[
\83o
\81[
\97}
\8e~
1462 if (servMgr->preventSS)
1464 servMgr->preventSS = false;
1465 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND);
1468 servMgr->preventSS = true;
1469 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND);
1471 peercastInst->saveSettings();
1474 case ID_POPUP_NO_VER_CHECK:
1475 //
\83o
\81[
\83W
\83\87\83\93\83`
\83F
\83b
\83N
\82Ì
\97L
\96³
1476 if (servMgr->noVersionCheck)
1478 servMgr->noVersionCheck = false;
1479 CheckMenuItem(trayMenu, ID_POPUP_NO_VER_CHECK, MF_UNCHECKED|MF_BYCOMMAND);
1482 servMgr->noVersionCheck = true;
1483 CheckMenuItem(trayMenu, ID_POPUP_NO_VER_CHECK, MF_CHECKED|MF_BYCOMMAND);
1485 peercastInst->saveSettings();
1488 case ID_POPUP_EXIT_CONFIRM:
1490 DestroyWindow(hWnd);
1493 return DefWindowProc(hWnd, message, wParam, lParam);
1501 //
\82È
\82ñ
\82©
\83A
\83N
\83e
\83B
\83u
\82¶
\82á
\82È
\82¢
\82Æ
\91\97\82ç
\82ê
\82Ä
\82±
\82È
\82¢
\82ç
\82µ
\82¢
1502 if (servMgr->preventSS && (wParam == SC_SCREENSAVE) && chanMgr->isBroadcasting())
1505 return DefWindowProc(hWnd, message, wParam, lParam);
1509 return DefWindowProc(hWnd, message, wParam, lParam);
1513 // Mesage handler for about box.
1514 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1519 //SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENT);
1520 // SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTJP);
1523 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LPARAM)PCX_AGENTEX); // x64
\91Î
\89\9e
1526 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTVP);
1532 switch (LOWORD(wParam))
1536 EndDialog(hDlg, LOWORD(wParam));
1539 sys->getURL("http://www.peercast.org");
1540 EndDialog(hDlg, LOWORD(wParam));
1551 // Mesage handler for chaninfo box
1552 LRESULT CALLBACK ChanInfoProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1559 //strcpy(str,chanInfo.track.artist.cstr());
1560 strcpy(str,chanInfo.track.artist); //JP-Patch
1562 //strcat(str,chanInfo.track.title.cstr());
1563 strcat(str,chanInfo.track.title);
1564 String name,track,comment,desc,genre; //JP-Patch
1565 name = chanInfo.name; //JP-Patch
1566 track = str; //JP-Patch
1567 comment = chanInfo.comment; //JP-Patch
1568 desc = chanInfo.desc; //JP-Patc
1569 genre = chanInfo.genre; //JP-Patch
1570 name.convertTo(String::T_SJIS); //JP-Patc
1571 track.convertTo(String::T_SJIS); //JP-Patch
1572 comment.convertTo(String::T_SJIS); //JP-Patch
1573 desc.convertTo(String::T_SJIS); //JP-Patch
1574 genre.convertTo(String::T_SJIS); //JP-Patch
1576 //SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)chanInfo.name.cstr());
1577 SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LPARAM)name.cstr()); // x64
\91Î
\89\9e
1578 //SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)name.cstr()); //JP-Patch
1579 //SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)str);
1580 SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LPARAM)track.cstr()); // x64
\91Î
\89\9e
1581 //SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)track.cstr()); //JP-Patch
1582 //SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)chanInfo.comment.cstr());
1583 SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LPARAM)comment.cstr()); // x64
\91Î
\89\9e
1584 //SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)comment.cstr()); //JP-Patch
1585 //SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)chanInfo.desc.cstr());
1586 SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LPARAM)desc.cstr()); // x64
\91Î
\89\9e
1587 //SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)desc.cstr()); //JP-Patch
1588 //SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)chanInfo.genre.cstr());
1589 SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LPARAM)genre.cstr()); // x64
\91Î
\89\9e
1590 //SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)genre.cstr()); //JP-Patch
1592 sprintf(str,"%d kb/s %s",chanInfo.bitrate,ChanInfo::getTypeStr(chanInfo.contentType));
1593 SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LPARAM)str); // x64
\91Î
\89\9e
1594 //SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LONG)str);
1597 if (!chanInfo.url.isValidURL())
1598 EnableWindow(GetDlgItem(hDlg,IDC_CONTACT),false);
1600 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1603 SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LPARAM)ch->getStatusStr()); // x64
\91Î
\89\9e
1604 //SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)ch->getStatusStr());
1605 SendDlgItemMessage(hDlg, IDC_KEEP,BM_SETCHECK, ch->stayConnected, 0);
1607 //
\8c»
\8dÝ
\82Ì
\8cÅ
\97L
\83\8a\83\8c\81[
\8fã
\8cÀ
\90Ý
\92è
\82ð
\95\
\8e¦(0
\82Í
\96³
\8cø)
1608 ::SetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, ch->maxRelays, false);
1611 // index.txt
\82È
\82Ì
\82Å
\96³
\8cø
\82É
1612 ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_MAXRELAYS), false);
1613 ::EnableWindow(::GetDlgItem(hDlg, IDC_APPLY_MAXRELAYS), false);
1617 SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LPARAM)"OK"); // x64
\91Î
\89\9e
1618 //SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)"OK");
1619 EnableWindow(GetDlgItem(hDlg,IDC_KEEP),false);
1626 HWND hDsk = GetDesktopWindow();
1627 GetWindowRect(hDsk,&drect);
1628 GetWindowRect(hDlg,&rect);
1629 GetCursorPos(&point);
1632 size.x = rect.right-rect.left;
1633 size.y = rect.bottom-rect.top;
1635 if (point.x-drect.left < size.x)
1638 pos.x = point.x-size.x;
1640 if (point.y-drect.top < size.y)
1643 pos.y = point.y-size.y;
1645 SetWindowPos(hDlg,HWND_TOPMOST,pos.x,pos.y,size.x,size.y,0);
1652 char str[1024],idstr[64];
1653 chanInfo.id.toStr(idstr);
1655 switch (LOWORD(wParam))
1659 sys->getURL(chanInfo.url);
1664 sprintf(str,"admin?page=chaninfo&id=%s&relay=%d",idstr,chanInfoIsRelayed);
1665 sys->callLocalURL(str,servMgr->serverHost.port);
1670 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1672 ch->stayConnected = SendDlgItemMessage(hDlg, IDC_KEEP,BM_GETCHECK, 0, 0) == BST_CHECKED;;
1679 chanMgr->findAndPlayChannel(chanInfo,false);
1683 case IDC_APPLY_MAXRELAYS:
1685 //
\83`
\83\83\83\93\83l
\83\8b\8cÅ
\97L
\82Ì
\8dÅ
\91å
\83\8a\83\8c\81[
\90\94\82ð
\90Ý
\92è
1689 //
\93ü
\97Í
\92l
\8eæ
\93¾
1690 mr = ::GetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, &bSucc, false);
1694 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1695 if (ch && !isIndexTxt(ch))
1701 MessageBox(hDlg, "
\93ü
\97Í
\92l
\82ª
\95s
\90³
\82Å
\82·
\81B", "Error", MB_OK|MB_ICONERROR|MB_APPLMODAL);
1702 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1704 ::SetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, ch->maxRelays, false);
1712 if (winDistinctionNT)
1715 DestroyWindow(hDlg); //JP-Patch
1719 if (LOWORD(wParam) == WA_INACTIVE)
1720 if (winDistinctionNT)
1723 DestroyWindow(hDlg); //JP-Patch
1734 // control thread (Traffic dialog)
1735 THREAD_PROC trafficDlgUpdate(ThreadInfo *thread)
1737 thread->finish = false;
1739 while (trafficDlg && thread->active)
1741 SendMessage(trafficDlg, WM_UPDATETRAFFIC, 0, 0);
1745 thread->finish = true;
1750 // Dialog procedure (Traffic dialog)
1751 LRESULT CALLBACK TrafficDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1756 //
\8aù
\82É
\8aJ
\82¢
\82Ä
\82é
1757 if (trafficDlg || trafficDlgThread.active)
1759 if (winDistinctionNT)
1762 DestroyWindow(hDlg);
1767 trafficDlgThread.func = trafficDlgUpdate;
1768 if (!sys->startThread(&trafficDlgThread)){
1769 MessageBox(NULL,"Unable to start GUI","PeerCast",MB_OK|MB_ICONERROR);
1770 PostMessage(hDlg,WM_DESTROY,0,0);
1775 case WM_UPDATETRAFFIC:
1777 enum unitSymbol { B, KB, MB, GB };
1778 const unsigned long int unit[] = { 1, 1024, 1024*1024, 1024*1024*1024 };
1779 char suffix[][3] = { "B", "KB", "MB", "GB" };
1780 const int bufsize = 60;
1781 char szUp[bufsize], szDown[bufsize];
1782 unsigned long long int totalDown = stats.getCurrent(Stats::BYTESIN) - stats.getCurrent(Stats::LOCALBYTESIN);
1783 unsigned long long int totalUp = stats.getCurrent(Stats::BYTESOUT) - stats.getCurrent(Stats::LOCALBYTESOUT);
1786 for (int i=GB; i>0; --i)
1788 if (totalUp >= unit[i])
1790 sprintf_s<bufsize>(szUp, "%.2f%s", (double)totalUp/unit[i], suffix[i]);
1795 sprintf_s<bufsize>(szUp, "%d%s", totalUp, suffix[0]);
1799 for (int i=GB; i>0; --i)
1801 if (totalDown >= unit[i])
1803 sprintf_s<bufsize>(szDown, "%.2f%s", (double)totalDown/unit[i], suffix[i]);
1808 sprintf_s<bufsize>(szDown, "%d%s", totalDown, suffix[0]);
1811 SetDlgItemText(hDlg, IDC_STATIC_UP, szUp);
1812 SetDlgItemText(hDlg, IDC_STATIC_DOWN, szDown);
1818 trafficDlgThread.active = false;
1819 if (winDistinctionNT)
1822 DestroyWindow(hDlg);