From: eru Date: Mon, 18 Aug 2008 13:33:25 +0000 (+0000) Subject: SEH実装(一般保護例外対策) X-Git-Tag: IM0028^0 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;ds=sidebyside;h=0fb421d21251117d91eec0554b0d0ea1df525d33;p=peercast-im%2FPeerCastIM.git SEH実装(一般保護例外対策) --- diff --git a/PeerCast.root/PeerCast/core/common/servmgr.cpp b/PeerCast.root/PeerCast/core/common/servmgr.cpp index f9dc302..4d166cb 100644 --- a/PeerCast.root/PeerCast/core/common/servmgr.cpp +++ b/PeerCast.root/PeerCast/core/common/servmgr.cpp @@ -140,6 +140,7 @@ ServMgr::ServMgr() topmostGui = false; startWithGui = false; + preventSS = false; chanLog=""; @@ -1106,6 +1107,7 @@ void ServMgr::saveSettings(const char *fn) iniFile.writeBoolValue("topmostGui", servMgr->topmostGui); iniFile.writeBoolValue("startWithGui", servMgr->startWithGui); + iniFile.writeBoolValue("preventSS", servMgr->preventSS); #endif int i; @@ -1517,12 +1519,11 @@ void ServMgr::loadSettings(const char *fn) servMgr->guiAntennaNotifyIcon = iniFile.getBoolValue(); else if (iniFile.isName("topmostGui")) - { servMgr->topmostGui = iniFile.getBoolValue(); - } else if (iniFile.isName("startWithGui")) - { + else if (iniFile.isName("startWithGui")) servMgr->startWithGui = iniFile.getBoolValue(); - } + else if (iniFile.isName("preventSS")) + servMgr->preventSS = iniFile.getBoolValue(); #endif // debug diff --git a/PeerCast.root/PeerCast/core/common/servmgr.h b/PeerCast.root/PeerCast/core/common/servmgr.h index 32012f8..0fdae48 100644 --- a/PeerCast.root/PeerCast/core/common/servmgr.h +++ b/PeerCast.root/PeerCast/core/common/servmgr.h @@ -419,6 +419,7 @@ public: bool topmostGui; // Å‘O–Ê bool startWithGui; // ‹N“®Žž‚ÉGUI + bool preventSS; // ƒXƒNƒŠ[ƒ“ƒZ[ƒo[‚ð—}Ž~ int maxRelaysIndexTxt; // for PCRaw (relay) diff --git a/PeerCast.root/PeerCast/core/common/version2.h b/PeerCast.root/PeerCast/core/common/version2.h index d354394..ee7a87f 100644 --- a/PeerCast.root/PeerCast/core/common/version2.h +++ b/PeerCast.root/PeerCast/core/common/version2.h @@ -44,9 +44,9 @@ extern int version_ex; // PP #if 1 /* for VP extend version */ //#define VERSION_EX 1 static const char *PCP_CLIENT_VERSION_EX_PREFIX = "IM"; // 2bytes only -static const int PCP_CLIENT_VERSION_EX_NUMBER = 27; -static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0027-5-2)"; -static const char *PCX_VERSTRING_EX = "v0.1218(IM0027-5-2)"; +static const int PCP_CLIENT_VERSION_EX_NUMBER = 28; +static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0028)"; +static const char *PCX_VERSTRING_EX = "v0.1218(IM0028)"; #endif // ------------------------------------------------ diff --git a/PeerCast.root/PeerCast/ui/win32/memo.txt b/PeerCast.root/PeerCast/ui/win32/memo.txt index 7d504a3..39fb857 100644 --- a/PeerCast.root/PeerCast/ui/win32/memo.txt +++ b/PeerCast.root/PeerCast/ui/win32/memo.txt @@ -3,3 +3,6 @@ EƒŠƒŒ[ãŒÀƒ`ƒFƒbƒN @@bool Channel::isFull(); (channel.cpp) + +E‰º—¬‚Ö‚Ì“]‘— +@@void Servent::sendPCPChannel() diff --git a/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp b/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp index d777ed1..5aa8a83 100644 --- a/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp +++ b/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp @@ -80,6 +80,7 @@ ULONG_PTR gdiplusToken; extern Stats stats; ThreadInfo trafficDlgThread; HWND trafficDlg = NULL; +FileStream fs; // ƒvƒƒgƒ^ƒCƒvéŒ¾ void createGUI(HWND); @@ -178,20 +179,19 @@ HWND chWnd=NULL; void LOG2(const char *fmt,...) { va_list ap; - va_start(ap, fmt); + va_start(ap, fmt); char str[4096]; vsprintf(str,fmt,ap); OutputDebugString(str); - va_end(ap); + va_end(ap); } - -// --------------------------------------- -int APIENTRY WinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) +// -------------------------------------------------- +int WinMainDummy(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) { #ifdef _DEBUG // memory leak check @@ -270,7 +270,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, *end = 0; } - + if (strnicmp(tmpURL,"peercast://",11)==0) { if (strnicmp(tmpURL+11,"pls/",4)==0) @@ -295,13 +295,13 @@ int APIENTRY WinMain(HINSTANCE hInstance, if (!allowMulti) { HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass); - + if (GetLastError() == ERROR_ALREADY_EXISTS) { HWND oldWin = FindWindow(szWindowClass,NULL); if (oldWin) { - //SendMessage(oldWin,WM_SHOWGUI,0,0); + //SendMessage(oldWin,WM_SHOWGUI,0,0); if (killMe) { SendMessage(oldWin,WM_DESTROY,0,0); @@ -326,7 +326,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, if (killMe) return 0; - + MyRegisterClass(hInstance); MyRegisterClass2(hInstance); @@ -390,7 +390,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, } } - Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon); + Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon); peercastInst->saveSettings(); peercastInst->quit(); @@ -401,6 +401,242 @@ int APIENTRY WinMain(HINSTANCE hInstance, } +// --------------------------------------- +int APIENTRY WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) +{ + // SEH handling + __try + { +#if 0 +#ifdef _DEBUG + // memory leak check + ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); +#endif + + char tmpURL[8192]; + tmpURL[0]=0; + char *chanURL=NULL; + + hInst = hInstance; + + version_ex = 1; // PP”ÅŠg’£‹@”\‚𖳌ø‚Ɂ©‘å‰RBƒo[ƒWƒ‡ƒ“•\‹L‚ðEX‚É + + iniFileName.set(".\\peercast.ini"); + + WIN32_FIND_DATA fd; //JP-EX + HANDLE hFind; //JP-EX + + OSVERSIONINFO osInfo; //JP-EX + osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX + GetVersionEx(&osInfo); + if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) + winDistinctionNT = true; + else + winDistinctionNT = false; + + // off by default now + showGUI = false; + + if (strlen(lpCmdLine) > 0) + { + char *p; + if ((p = strstr(lpCmdLine,"-inifile"))!=NULL) + iniFileName.setFromString(p+8); + + if (strstr(lpCmdLine,"-zen")) + showGUI = false; + + if (strstr(lpCmdLine,"-multi")) + allowMulti = true; + + if (strstr(lpCmdLine,"-kill")) + killMe = true; + + if ((p = strstr(lpCmdLine,"-url"))!=NULL) + { + p+=4; + while (*p) + { + if (*p=='"') + { + p++; + break; + } + if (*p != ' ') + break; + p++; + } + if (*p) + strncpy(tmpURL,p,sizeof(tmpURL)-1); + } + } + + // get current path + { + exePath = iniFileName; + char *s = exePath.cstr(); + char *end = NULL; + while (*s) + { + if (*s++ == '\\') + end = s; + } + if (end) + *end = 0; + } + + + if (strnicmp(tmpURL,"peercast://",11)==0) + { + if (strnicmp(tmpURL+11,"pls/",4)==0) + chanURL = tmpURL+11+4; + else + chanURL = tmpURL+11; + showGUI = false; + } + + + MSG msg; + HACCEL hAccelTable; + + // Initialize global strings + //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING); + + strcpy(szTitle,"PeerCast"); + strcpy(szWindowClass,"PeerCast"); + strcpy(szWindowClass2,"Main"); + + if (!allowMulti) + { + HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass); + + if (GetLastError() == ERROR_ALREADY_EXISTS) + { + HWND oldWin = FindWindow(szWindowClass,NULL); + if (oldWin) + { + //SendMessage(oldWin,WM_SHOWGUI,0,0); + if (killMe) + { + SendMessage(oldWin,WM_DESTROY,0,0); + return 0; + } + + if (chanURL) + { + COPYDATASTRUCT copy; + copy.dwData = WM_PLAYCHANNEL; + copy.cbData = strlen(chanURL)+1; // plus null term + copy.lpData = chanURL; + SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)©); + }else{ + if (showGUI) + SendMessage(oldWin,WM_SHOWGUI,0,0); + } + } + return 0; + } + } + + if (killMe) + return 0; + + MyRegisterClass(hInstance); + MyRegisterClass2(hInstance); + + // Perform application initialization: + if (!InitInstance (hInstance, nCmdShow)) + return FALSE; + + peercastInst = new MyPeercastInst(); + peercastApp = new MyPeercastApp(); + + peercastInst->init(); + + LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x"); + + if (peercastApp->clearTemp()) //JP-EX + { + DeleteFile("play.pls"); + hFind = FindFirstFile("*.asx",&fd); + if (hFind != INVALID_HANDLE_VALUE) + { + do + { + DeleteFile((char *)&fd.cFileName); + } + while (FindNextFile(hFind,&fd)); + + FindClose(hFind); + } + } + + if (chanURL) + { + ChanInfo info; + servMgr->procConnectArgs(chanURL,info); + chanMgr->findAndPlayChannel(info,false); + } + + hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE); + + // setup menu notifes + int mask = peercastInst->getNotifyMask(); + if (mask & ServMgr::NT_PEERCAST) + CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND); + if (mask & ServMgr::NT_BROADCASTERS) + CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND); + if (mask & ServMgr::NT_TRACKINFO) + CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND); + + if (servMgr->startWithGui) + { + createGUI((HWND)0); + } + + // Main message loop: + while (GetMessage(&msg, NULL, 0, 0)) + { + if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon); + + peercastInst->saveSettings(); + peercastInst->quit(); + + Gdiplus::GdiplusShutdown(gdiplusToken); + + return msg.wParam; +#endif + WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow); + + } __except(EXCEPTION_EXECUTE_HANDLER) + { + fs.openWriteReplace(".\\dump.html"); + sys->logBuf->dumpHTML(fs); + fs.close(); + + MessageBox(NULL, "ˆê”Ê•ÛŒìˆá”½‚ׁ̈AƒvƒƒOƒ‰ƒ€‚Í‹­§I—¹‚³‚ê‚Ü‚·B\n" + "–â‘è‰ðŒˆ‚Ì‚½‚߂Ƀ_ƒ“ƒvƒf[ƒ^(dump.html)‚ð’ñ‹Ÿ‚µ‚Ä‚­‚¾‚³‚¢B", "SEH", + MB_OK|MB_ICONWARNING); + + return GetExceptionCode(); + } + + // dummy + return 0; +} + + // // FUNCTION: MyRegisterClass() @@ -1037,6 +1273,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND); } + // ƒXƒNƒŠ[ƒ“ƒZ[ƒo[—}Ž~ + if (servMgr->preventSS) + { + CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND); + } else + { + CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND); + } + SetForegroundWindow(hWnd); bool skipMenu=false; @@ -1287,6 +1532,20 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } break; + case ID_POPUP_PREVENT_SS: + // ƒXƒNƒŠ[ƒ“ƒZ[ƒo[—}Ž~ + if (servMgr->preventSS) + { + servMgr->preventSS = false; + CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND); + } else + { + servMgr->preventSS = true; + CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND); + } + peercastInst->saveSettings(); + break; + case ID_POPUP_EXIT_CONFIRM: case IDM_EXIT: DestroyWindow(hWnd); @@ -1298,6 +1557,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_DESTROY: PostQuitMessage(0); break; + + case WM_SYSCOMMAND: + // ‚È‚ñ‚©ƒAƒNƒeƒBƒu‚¶‚á‚È‚¢‚Æ‘—‚ç‚ê‚Ä‚±‚È‚¢‚炵‚¢ + if (servMgr->preventSS && (wParam == SC_SCREENSAVE) && chanMgr->isBroadcasting()) + return 1; + else + return DefWindowProc(hWnd, message, wParam, lParam); + break; + default: return DefWindowProc(hWnd, message, wParam, lParam); } diff --git a/PeerCast.root/PeerCast/ui/win32/simple/Simple.rc b/PeerCast.root/PeerCast/ui/win32/simple/Simple.rc index dd97f4c..a4f2c67 100644 --- a/PeerCast.root/PeerCast/ui/win32/simple/Simple.rc +++ b/PeerCast.root/PeerCast/ui/win32/simple/Simple.rc @@ -113,6 +113,7 @@ BEGIN MENUITEM "ÄÚ‘±Žž‰º—¬ˆÛŽ", ID_POPUP_SHOWGUI, CHECKED MENUITEM "í‚ÉŽè‘O‚É•\Ž¦", ID_POPUP_TOPMOST MENUITEM "‹N“®ŽžAGUI‚ð•\Ž¦", ID_POPUP_START_WITH_GUI + MENUITEM "”zMŽžAScreenSaver‚ð—}Ž~", ID_POPUP_PREVENT_SS, GRAYED END MENUITEM SEPARATOR POPUP "I—¹" diff --git a/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj b/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj index eda2cee..b7d6674 100644 --- a/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj +++ b/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj @@ -158,6 +158,7 @@ AdditionalIncludeDirectories="../../../core,../../../core/common" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" StringPooling="true" + ExceptionHandling="1" RuntimeLibrary="0" EnableFunctionLevelLinking="true" PrecompiledHeaderFile=".\Release/Simple.pch" diff --git a/PeerCast.root/PeerCast/ui/win32/simple/resource.h b/PeerCast.root/PeerCast/ui/win32/simple/resource.h index ae6df11..d6266ab 100644 --- a/PeerCast.root/PeerCast/ui/win32/simple/resource.h +++ b/PeerCast.root/PeerCast/ui/win32/simple/resource.h @@ -108,6 +108,8 @@ #define ID_POPUP_START_WITH_GUI 32830 #define ID_POPUP_32831 32831 #define ID_POPUP_TRAFFIC 32832 +#define ID_32833 32833 +#define ID_POPUP_PREVENT_SS 32834 #define IDC_STATIC -1 // Next default values for new objects @@ -115,7 +117,7 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 144 -#define _APS_NEXT_COMMAND_VALUE 32833 +#define _APS_NEXT_COMMAND_VALUE 32835 #define _APS_NEXT_CONTROL_VALUE 1025 #define _APS_NEXT_SYMED_VALUE 110 #endif diff --git a/c:/Git/PeerCast.root/PeerCast/core/common/servmgr.cpp b/c:/Git/PeerCast.root/PeerCast/core/common/servmgr.cpp index f9dc302..4d166cb 100644 --- a/c:/Git/PeerCast.root/PeerCast/core/common/servmgr.cpp +++ b/c:/Git/PeerCast.root/PeerCast/core/common/servmgr.cpp @@ -140,6 +140,7 @@ ServMgr::ServMgr() topmostGui = false; startWithGui = false; + preventSS = false; chanLog=""; @@ -1106,6 +1107,7 @@ void ServMgr::saveSettings(const char *fn) iniFile.writeBoolValue("topmostGui", servMgr->topmostGui); iniFile.writeBoolValue("startWithGui", servMgr->startWithGui); + iniFile.writeBoolValue("preventSS", servMgr->preventSS); #endif int i; @@ -1517,12 +1519,11 @@ void ServMgr::loadSettings(const char *fn) servMgr->guiAntennaNotifyIcon = iniFile.getBoolValue(); else if (iniFile.isName("topmostGui")) - { servMgr->topmostGui = iniFile.getBoolValue(); - } else if (iniFile.isName("startWithGui")) - { + else if (iniFile.isName("startWithGui")) servMgr->startWithGui = iniFile.getBoolValue(); - } + else if (iniFile.isName("preventSS")) + servMgr->preventSS = iniFile.getBoolValue(); #endif // debug diff --git a/c:/Git/PeerCast.root/PeerCast/core/common/servmgr.h b/c:/Git/PeerCast.root/PeerCast/core/common/servmgr.h index 32012f8..0fdae48 100644 --- a/c:/Git/PeerCast.root/PeerCast/core/common/servmgr.h +++ b/c:/Git/PeerCast.root/PeerCast/core/common/servmgr.h @@ -419,6 +419,7 @@ public: bool topmostGui; // Å‘O–Ê bool startWithGui; // ‹N“®Žž‚ÉGUI + bool preventSS; // ƒXƒNƒŠ[ƒ“ƒZ[ƒo[‚ð—}Ž~ int maxRelaysIndexTxt; // for PCRaw (relay) diff --git a/c:/Git/PeerCast.root/PeerCast/core/common/version2.h b/c:/Git/PeerCast.root/PeerCast/core/common/version2.h index d354394..ee7a87f 100644 --- a/c:/Git/PeerCast.root/PeerCast/core/common/version2.h +++ b/c:/Git/PeerCast.root/PeerCast/core/common/version2.h @@ -44,9 +44,9 @@ extern int version_ex; // PP #if 1 /* for VP extend version */ //#define VERSION_EX 1 static const char *PCP_CLIENT_VERSION_EX_PREFIX = "IM"; // 2bytes only -static const int PCP_CLIENT_VERSION_EX_NUMBER = 27; -static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0027-5-2)"; -static const char *PCX_VERSTRING_EX = "v0.1218(IM0027-5-2)"; +static const int PCP_CLIENT_VERSION_EX_NUMBER = 28; +static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0028)"; +static const char *PCX_VERSTRING_EX = "v0.1218(IM0028)"; #endif // ------------------------------------------------ diff --git a/c:/Git/PeerCast.root/PeerCast/ui/win32/memo.txt b/c:/Git/PeerCast.root/PeerCast/ui/win32/memo.txt index 7d504a3..39fb857 100644 --- a/c:/Git/PeerCast.root/PeerCast/ui/win32/memo.txt +++ b/c:/Git/PeerCast.root/PeerCast/ui/win32/memo.txt @@ -3,3 +3,6 @@ EƒŠƒŒ[ãŒÀƒ`ƒFƒbƒN @@bool Channel::isFull(); (channel.cpp) + +E‰º—¬‚Ö‚Ì“]‘— +@@void Servent::sendPCPChannel() diff --git a/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp b/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp index d777ed1..5aa8a83 100644 --- a/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp +++ b/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp @@ -80,6 +80,7 @@ ULONG_PTR gdiplusToken; extern Stats stats; ThreadInfo trafficDlgThread; HWND trafficDlg = NULL; +FileStream fs; // ƒvƒƒgƒ^ƒCƒvéŒ¾ void createGUI(HWND); @@ -178,20 +179,19 @@ HWND chWnd=NULL; void LOG2(const char *fmt,...) { va_list ap; - va_start(ap, fmt); + va_start(ap, fmt); char str[4096]; vsprintf(str,fmt,ap); OutputDebugString(str); - va_end(ap); + va_end(ap); } - -// --------------------------------------- -int APIENTRY WinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) +// -------------------------------------------------- +int WinMainDummy(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) { #ifdef _DEBUG // memory leak check @@ -270,7 +270,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, *end = 0; } - + if (strnicmp(tmpURL,"peercast://",11)==0) { if (strnicmp(tmpURL+11,"pls/",4)==0) @@ -295,13 +295,13 @@ int APIENTRY WinMain(HINSTANCE hInstance, if (!allowMulti) { HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass); - + if (GetLastError() == ERROR_ALREADY_EXISTS) { HWND oldWin = FindWindow(szWindowClass,NULL); if (oldWin) { - //SendMessage(oldWin,WM_SHOWGUI,0,0); + //SendMessage(oldWin,WM_SHOWGUI,0,0); if (killMe) { SendMessage(oldWin,WM_DESTROY,0,0); @@ -326,7 +326,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, if (killMe) return 0; - + MyRegisterClass(hInstance); MyRegisterClass2(hInstance); @@ -390,7 +390,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, } } - Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon); + Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon); peercastInst->saveSettings(); peercastInst->quit(); @@ -401,6 +401,242 @@ int APIENTRY WinMain(HINSTANCE hInstance, } +// --------------------------------------- +int APIENTRY WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) +{ + // SEH handling + __try + { +#if 0 +#ifdef _DEBUG + // memory leak check + ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); +#endif + + char tmpURL[8192]; + tmpURL[0]=0; + char *chanURL=NULL; + + hInst = hInstance; + + version_ex = 1; // PP”ÅŠg’£‹@”\‚𖳌ø‚Ɂ©‘å‰RBƒo[ƒWƒ‡ƒ“•\‹L‚ðEX‚É + + iniFileName.set(".\\peercast.ini"); + + WIN32_FIND_DATA fd; //JP-EX + HANDLE hFind; //JP-EX + + OSVERSIONINFO osInfo; //JP-EX + osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX + GetVersionEx(&osInfo); + if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) + winDistinctionNT = true; + else + winDistinctionNT = false; + + // off by default now + showGUI = false; + + if (strlen(lpCmdLine) > 0) + { + char *p; + if ((p = strstr(lpCmdLine,"-inifile"))!=NULL) + iniFileName.setFromString(p+8); + + if (strstr(lpCmdLine,"-zen")) + showGUI = false; + + if (strstr(lpCmdLine,"-multi")) + allowMulti = true; + + if (strstr(lpCmdLine,"-kill")) + killMe = true; + + if ((p = strstr(lpCmdLine,"-url"))!=NULL) + { + p+=4; + while (*p) + { + if (*p=='"') + { + p++; + break; + } + if (*p != ' ') + break; + p++; + } + if (*p) + strncpy(tmpURL,p,sizeof(tmpURL)-1); + } + } + + // get current path + { + exePath = iniFileName; + char *s = exePath.cstr(); + char *end = NULL; + while (*s) + { + if (*s++ == '\\') + end = s; + } + if (end) + *end = 0; + } + + + if (strnicmp(tmpURL,"peercast://",11)==0) + { + if (strnicmp(tmpURL+11,"pls/",4)==0) + chanURL = tmpURL+11+4; + else + chanURL = tmpURL+11; + showGUI = false; + } + + + MSG msg; + HACCEL hAccelTable; + + // Initialize global strings + //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING); + + strcpy(szTitle,"PeerCast"); + strcpy(szWindowClass,"PeerCast"); + strcpy(szWindowClass2,"Main"); + + if (!allowMulti) + { + HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass); + + if (GetLastError() == ERROR_ALREADY_EXISTS) + { + HWND oldWin = FindWindow(szWindowClass,NULL); + if (oldWin) + { + //SendMessage(oldWin,WM_SHOWGUI,0,0); + if (killMe) + { + SendMessage(oldWin,WM_DESTROY,0,0); + return 0; + } + + if (chanURL) + { + COPYDATASTRUCT copy; + copy.dwData = WM_PLAYCHANNEL; + copy.cbData = strlen(chanURL)+1; // plus null term + copy.lpData = chanURL; + SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)©); + }else{ + if (showGUI) + SendMessage(oldWin,WM_SHOWGUI,0,0); + } + } + return 0; + } + } + + if (killMe) + return 0; + + MyRegisterClass(hInstance); + MyRegisterClass2(hInstance); + + // Perform application initialization: + if (!InitInstance (hInstance, nCmdShow)) + return FALSE; + + peercastInst = new MyPeercastInst(); + peercastApp = new MyPeercastApp(); + + peercastInst->init(); + + LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x"); + + if (peercastApp->clearTemp()) //JP-EX + { + DeleteFile("play.pls"); + hFind = FindFirstFile("*.asx",&fd); + if (hFind != INVALID_HANDLE_VALUE) + { + do + { + DeleteFile((char *)&fd.cFileName); + } + while (FindNextFile(hFind,&fd)); + + FindClose(hFind); + } + } + + if (chanURL) + { + ChanInfo info; + servMgr->procConnectArgs(chanURL,info); + chanMgr->findAndPlayChannel(info,false); + } + + hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE); + + // setup menu notifes + int mask = peercastInst->getNotifyMask(); + if (mask & ServMgr::NT_PEERCAST) + CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND); + if (mask & ServMgr::NT_BROADCASTERS) + CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND); + if (mask & ServMgr::NT_TRACKINFO) + CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND); + + if (servMgr->startWithGui) + { + createGUI((HWND)0); + } + + // Main message loop: + while (GetMessage(&msg, NULL, 0, 0)) + { + if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon); + + peercastInst->saveSettings(); + peercastInst->quit(); + + Gdiplus::GdiplusShutdown(gdiplusToken); + + return msg.wParam; +#endif + WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow); + + } __except(EXCEPTION_EXECUTE_HANDLER) + { + fs.openWriteReplace(".\\dump.html"); + sys->logBuf->dumpHTML(fs); + fs.close(); + + MessageBox(NULL, "ˆê”Ê•ÛŒìˆá”½‚ׁ̈AƒvƒƒOƒ‰ƒ€‚Í‹­§I—¹‚³‚ê‚Ü‚·B\n" + "–â‘è‰ðŒˆ‚Ì‚½‚߂Ƀ_ƒ“ƒvƒf[ƒ^(dump.html)‚ð’ñ‹Ÿ‚µ‚Ä‚­‚¾‚³‚¢B", "SEH", + MB_OK|MB_ICONWARNING); + + return GetExceptionCode(); + } + + // dummy + return 0; +} + + // // FUNCTION: MyRegisterClass() @@ -1037,6 +1273,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND); } + // ƒXƒNƒŠ[ƒ“ƒZ[ƒo[—}Ž~ + if (servMgr->preventSS) + { + CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND); + } else + { + CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND); + } + SetForegroundWindow(hWnd); bool skipMenu=false; @@ -1287,6 +1532,20 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } break; + case ID_POPUP_PREVENT_SS: + // ƒXƒNƒŠ[ƒ“ƒZ[ƒo[—}Ž~ + if (servMgr->preventSS) + { + servMgr->preventSS = false; + CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND); + } else + { + servMgr->preventSS = true; + CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND); + } + peercastInst->saveSettings(); + break; + case ID_POPUP_EXIT_CONFIRM: case IDM_EXIT: DestroyWindow(hWnd); @@ -1298,6 +1557,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_DESTROY: PostQuitMessage(0); break; + + case WM_SYSCOMMAND: + // ‚È‚ñ‚©ƒAƒNƒeƒBƒu‚¶‚á‚È‚¢‚Æ‘—‚ç‚ê‚Ä‚±‚È‚¢‚炵‚¢ + if (servMgr->preventSS && (wParam == SC_SCREENSAVE) && chanMgr->isBroadcasting()) + return 1; + else + return DefWindowProc(hWnd, message, wParam, lParam); + break; + default: return DefWindowProc(hWnd, message, wParam, lParam); } diff --git a/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.rc b/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.rc index dd97f4c..a4f2c67 100644 --- a/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.rc +++ b/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.rc @@ -113,6 +113,7 @@ BEGIN MENUITEM "ÄÚ‘±Žž‰º—¬ˆÛŽ", ID_POPUP_SHOWGUI, CHECKED MENUITEM "í‚ÉŽè‘O‚É•\Ž¦", ID_POPUP_TOPMOST MENUITEM "‹N“®ŽžAGUI‚ð•\Ž¦", ID_POPUP_START_WITH_GUI + MENUITEM "”zMŽžAScreenSaver‚ð—}Ž~", ID_POPUP_PREVENT_SS, GRAYED END MENUITEM SEPARATOR POPUP "I—¹" diff --git a/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj b/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj index eda2cee..b7d6674 100644 --- a/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj +++ b/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj @@ -158,6 +158,7 @@ AdditionalIncludeDirectories="../../../core,../../../core/common" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" StringPooling="true" + ExceptionHandling="1" RuntimeLibrary="0" EnableFunctionLevelLinking="true" PrecompiledHeaderFile=".\Release/Simple.pch" diff --git a/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/resource.h b/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/resource.h index ae6df11..d6266ab 100644 --- a/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/resource.h +++ b/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/resource.h @@ -108,6 +108,8 @@ #define ID_POPUP_START_WITH_GUI 32830 #define ID_POPUP_32831 32831 #define ID_POPUP_TRAFFIC 32832 +#define ID_32833 32833 +#define ID_POPUP_PREVENT_SS 32834 #define IDC_STATIC -1 // Next default values for new objects @@ -115,7 +117,7 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 144 -#define _APS_NEXT_COMMAND_VALUE 32833 +#define _APS_NEXT_COMMAND_VALUE 32835 #define _APS_NEXT_CONTROL_VALUE 1025 #define _APS_NEXT_SYMED_VALUE 110 #endif