OSDN Git Service

SEH実装(一般保護例外対策) IM0028
authoreru <eru01@users.sourceforge.jp>
Mon, 18 Aug 2008 13:33:25 +0000 (13:33 +0000)
committereru <eru01@users.sourceforge.jp>
Mon, 18 Aug 2008 13:33:25 +0000 (13:33 +0000)
16 files changed:
PeerCast.root/PeerCast/core/common/servmgr.cpp
PeerCast.root/PeerCast/core/common/servmgr.h
PeerCast.root/PeerCast/core/common/version2.h
PeerCast.root/PeerCast/ui/win32/memo.txt
PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp
PeerCast.root/PeerCast/ui/win32/simple/Simple.rc
PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj
PeerCast.root/PeerCast/ui/win32/simple/resource.h
c:/Git/PeerCast.root/PeerCast/core/common/servmgr.cpp
c:/Git/PeerCast.root/PeerCast/core/common/servmgr.h
c:/Git/PeerCast.root/PeerCast/core/common/version2.h
c:/Git/PeerCast.root/PeerCast/ui/win32/memo.txt
c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp
c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.rc
c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj
c:/Git/PeerCast.root/PeerCast/ui/win32/simple/resource.h

index f9dc302..4d166cb 100644 (file)
@@ -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
index 32012f8..0fdae48 100644 (file)
@@ -419,6 +419,7 @@ public:
 
        bool topmostGui; // \8dÅ\91O\96Ê
        bool startWithGui; // \8bN\93®\8e\9e\82ÉGUI
+       bool preventSS; // \83X\83N\83\8a\81[\83\93\83Z\81[\83o\81[\82ð\97}\8e~
 
        int maxRelaysIndexTxt;  // for PCRaw (relay)
 
index d354394..ee7a87f 100644 (file)
@@ -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
 
 // ------------------------------------------------
index 7d504a3..39fb857 100644 (file)
@@ -3,3 +3,6 @@
 
 \81E\83\8a\83\8c\81[\8fã\8cÀ\83`\83F\83b\83N
 \81@\81@bool Channel::isFull(); (channel.cpp)
+
+\81E\89º\97¬\82Ö\82Ì\93]\91\97
+\81@\81@void Servent::sendPCPChannel()
index d777ed1..5aa8a83 100644 (file)
@@ -80,6 +80,7 @@ ULONG_PTR gdiplusToken;
 extern Stats stats;
 ThreadInfo trafficDlgThread;
 HWND trafficDlg = NULL;
+FileStream fs;
 
 // \83v\83\8d\83g\83^\83C\83v\90é\8c¾
 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\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É
+
+               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)&copy);
+                                       }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, "\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"
+                       "\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",
+                       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);
                                }
 
+                               // \83X\83N\83\8a\81[\83\93\83Z\81[\83o\81[\97}\8e~
+                               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:
+                                       // \83X\83N\83\8a\81[\83\93\83Z\81[\83o\81[\97}\8e~
+                                       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:
+                       // \82È\82ñ\82©\83A\83N\83e\83B\83u\82\82á\82È\82¢\82Æ\91\97\82ç\82ê\82Ä\82±\82È\82¢\82ç\82µ\82¢
+                       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);
    }
index dd97f4c..a4f2c67 100644 (file)
@@ -113,6 +113,7 @@ BEGIN
             MENUITEM "\8dÄ\90Ú\91±\8e\9e\89º\97¬\88Û\8e\9d",                    ID_POPUP_SHOWGUI, CHECKED
             MENUITEM "\8fí\82É\8eè\91O\82É\95\\8e¦",                     ID_POPUP_TOPMOST
             MENUITEM "\8bN\93®\8e\9e\81AGUI\82ð\95\\8e¦",                  ID_POPUP_START_WITH_GUI
+            MENUITEM "\94z\90M\8e\9e\81AScreenSaver\82ð\97}\8e~",          ID_POPUP_PREVENT_SS, GRAYED
         END
         MENUITEM SEPARATOR
         POPUP "\8fI\97¹"
index eda2cee..b7d6674 100644 (file)
                                AdditionalIncludeDirectories="../../../core,../../../core/common"
                                PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
                                StringPooling="true"
+                               ExceptionHandling="1"
                                RuntimeLibrary="0"
                                EnableFunctionLevelLinking="true"
                                PrecompiledHeaderFile=".\Release/Simple.pch"
index ae6df11..d6266ab 100644 (file)
 #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
 #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
index f9dc302..4d166cb 100644 (file)
@@ -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
index 32012f8..0fdae48 100644 (file)
@@ -419,6 +419,7 @@ public:
 
        bool topmostGui; // \8dÅ\91O\96Ê
        bool startWithGui; // \8bN\93®\8e\9e\82ÉGUI
+       bool preventSS; // \83X\83N\83\8a\81[\83\93\83Z\81[\83o\81[\82ð\97}\8e~
 
        int maxRelaysIndexTxt;  // for PCRaw (relay)
 
index d354394..ee7a87f 100644 (file)
@@ -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
 
 // ------------------------------------------------
index 7d504a3..39fb857 100644 (file)
@@ -3,3 +3,6 @@
 
 \81E\83\8a\83\8c\81[\8fã\8cÀ\83`\83F\83b\83N
 \81@\81@bool Channel::isFull(); (channel.cpp)
+
+\81E\89º\97¬\82Ö\82Ì\93]\91\97
+\81@\81@void Servent::sendPCPChannel()
index d777ed1..5aa8a83 100644 (file)
@@ -80,6 +80,7 @@ ULONG_PTR gdiplusToken;
 extern Stats stats;
 ThreadInfo trafficDlgThread;
 HWND trafficDlg = NULL;
+FileStream fs;
 
 // \83v\83\8d\83g\83^\83C\83v\90é\8c¾
 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\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É
+
+               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)&copy);
+                                       }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, "\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"
+                       "\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",
+                       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);
                                }
 
+                               // \83X\83N\83\8a\81[\83\93\83Z\81[\83o\81[\97}\8e~
+                               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:
+                                       // \83X\83N\83\8a\81[\83\93\83Z\81[\83o\81[\97}\8e~
+                                       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:
+                       // \82È\82ñ\82©\83A\83N\83e\83B\83u\82\82á\82È\82¢\82Æ\91\97\82ç\82ê\82Ä\82±\82È\82¢\82ç\82µ\82¢
+                       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);
    }
index dd97f4c..a4f2c67 100644 (file)
@@ -113,6 +113,7 @@ BEGIN
             MENUITEM "\8dÄ\90Ú\91±\8e\9e\89º\97¬\88Û\8e\9d",                    ID_POPUP_SHOWGUI, CHECKED
             MENUITEM "\8fí\82É\8eè\91O\82É\95\\8e¦",                     ID_POPUP_TOPMOST
             MENUITEM "\8bN\93®\8e\9e\81AGUI\82ð\95\\8e¦",                  ID_POPUP_START_WITH_GUI
+            MENUITEM "\94z\90M\8e\9e\81AScreenSaver\82ð\97}\8e~",          ID_POPUP_PREVENT_SS, GRAYED
         END
         MENUITEM SEPARATOR
         POPUP "\8fI\97¹"
index eda2cee..b7d6674 100644 (file)
                                AdditionalIncludeDirectories="../../../core,../../../core/common"
                                PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
                                StringPooling="true"
+                               ExceptionHandling="1"
                                RuntimeLibrary="0"
                                EnableFunctionLevelLinking="true"
                                PrecompiledHeaderFile=".\Release/Simple.pch"
index ae6df11..d6266ab 100644 (file)
 #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
 #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