+// ---------------------------------------
+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)©);
+ }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;
+}
+
+