OSDN Git Service

サービス化の下準備途中 IM0033
authoreru <eru01@users.sourceforge.jp>
Tue, 10 Mar 2009 05:56:25 +0000 (05:56 +0000)
committereru <eru01@users.sourceforge.jp>
Tue, 10 Mar 2009 05:56:25 +0000 (05:56 +0000)
Vista(笑)のWindows Defenderがhostsのlocalhostを消すのに対応

PeerCast.root/PeerCast/core/common/channel.cpp
PeerCast.root/PeerCast/core/common/version2.h
PeerCast.root/PeerCast/core/win32/wsys.cpp
PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp
c:/Git/PeerCast.root/PeerCast/core/common/channel.cpp
c:/Git/PeerCast.root/PeerCast/core/common/version2.h
c:/Git/PeerCast.root/PeerCast/core/win32/wsys.cpp
c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp

index fdf4cc4..a49f282 100644 (file)
@@ -3108,7 +3108,7 @@ void ChanMgr::playChannel(ChanInfo &info)
 
        char str[128],fname[256],idStr[128];
 
-       sprintf(str,"http://localhost:%d",servMgr->serverHost.port);
+       sprintf(str,"http://127.0.0.1:%d",servMgr->serverHost.port);
        info.id.toStr(idStr);
 
        PlayList::TYPE type;
index 2a444a5..a12118d 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 = 32;
-static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0032)";
-static const char *PCX_VERSTRING_EX = "v0.1218(IM0032)";
+static const int  PCP_CLIENT_VERSION_EX_NUMBER = 33;
+static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0033)";
+static const char *PCX_VERSTRING_EX = "v0.1218(IM0033)";
 #endif
 
 // ------------------------------------------------
index 65165e9..86f5f8c 100644 (file)
@@ -124,7 +124,7 @@ void WSys::appMsg(long msg, long arg)
 void WSys::callLocalURL(const char *str,int port)
 {
        char cmd[512];
-       sprintf(cmd,"http://localhost:%d/%s",port,str);
+       sprintf(cmd,"http://127.0.0.1:%d/%s",port,str);
        ShellExecute(mainWindow, NULL, cmd, NULL, NULL, SW_SHOWNORMAL);
 }
 
index 6f8c8ac..35d5c79 100644 (file)
@@ -186,6 +186,82 @@ void LOG2(const char *fmt,...)
        va_end(ap);     
 }
 
+// --------------------------------------------------
+void WINAPI ServiceMain(DWORD argc, LPSTR *argv)
+{
+       //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;
+
+       // get current path
+       {
+               TCHAR buf[1024];
+               DWORD ret;
+
+               ret = GetModuleFileName(NULL, buf, sizeof(buf)/sizeof(TCHAR));
+               if (ret)
+               {
+                       exit(-1);
+               }
+               for (int i=_tcslen(buf); i>0; --i)
+               {
+                       if (buf[i] == '\\')
+                       {
+                               buf[i+1] = '\0';
+                               break;
+                       }
+               }
+
+               exePath = buf;
+       }
+
+       iniFileName.set(exePath.cstr());
+       iniFileName.append("\\peercast.ini");
+
+       _chdir(exePath);
+
+       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);
+               }
+       }
+
+       peercastInst->saveSettings();
+       peercastInst->quit();
+}
 
 // --------------------------------------------------
 int WinMainDummy(HINSTANCE hInstance,
@@ -411,8 +487,22 @@ int APIENTRY WinMain(HINSTANCE hInstance,
        _EXCEPTION_POINTERS *lpExcept;
        __try
        {
-               WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
-
+#if 0
+               // switch to service
+               if (lstrlen(lpCmdLine) && strstr(lpCmdLine, "-D") != NULL)
+               {
+                       SERVICE_TABLE_ENTRY svctbl[] = {
+                               {"PeerCast", (LPSERVICE_MAIN_FUNCTION)ServiceMain},
+                               {NULL, NULL}
+                       };
+
+                       if (!StartServiceCtrlDispatcher(svctbl)) 
+                       { 
+                               //SvcReportEvent(TEXT("StartServiceCtrlDispatcher")); 
+                       }
+               } else
+#endif
+                       WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
        } __except(lpExcept = GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER)
        {
                DWORD nParams;
index fdf4cc4..a49f282 100644 (file)
@@ -3108,7 +3108,7 @@ void ChanMgr::playChannel(ChanInfo &info)
 
        char str[128],fname[256],idStr[128];
 
-       sprintf(str,"http://localhost:%d",servMgr->serverHost.port);
+       sprintf(str,"http://127.0.0.1:%d",servMgr->serverHost.port);
        info.id.toStr(idStr);
 
        PlayList::TYPE type;
index 2a444a5..a12118d 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 = 32;
-static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0032)";
-static const char *PCX_VERSTRING_EX = "v0.1218(IM0032)";
+static const int  PCP_CLIENT_VERSION_EX_NUMBER = 33;
+static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0033)";
+static const char *PCX_VERSTRING_EX = "v0.1218(IM0033)";
 #endif
 
 // ------------------------------------------------
index 65165e9..86f5f8c 100644 (file)
@@ -124,7 +124,7 @@ void WSys::appMsg(long msg, long arg)
 void WSys::callLocalURL(const char *str,int port)
 {
        char cmd[512];
-       sprintf(cmd,"http://localhost:%d/%s",port,str);
+       sprintf(cmd,"http://127.0.0.1:%d/%s",port,str);
        ShellExecute(mainWindow, NULL, cmd, NULL, NULL, SW_SHOWNORMAL);
 }
 
index 6f8c8ac..35d5c79 100644 (file)
@@ -186,6 +186,82 @@ void LOG2(const char *fmt,...)
        va_end(ap);     
 }
 
+// --------------------------------------------------
+void WINAPI ServiceMain(DWORD argc, LPSTR *argv)
+{
+       //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;
+
+       // get current path
+       {
+               TCHAR buf[1024];
+               DWORD ret;
+
+               ret = GetModuleFileName(NULL, buf, sizeof(buf)/sizeof(TCHAR));
+               if (ret)
+               {
+                       exit(-1);
+               }
+               for (int i=_tcslen(buf); i>0; --i)
+               {
+                       if (buf[i] == '\\')
+                       {
+                               buf[i+1] = '\0';
+                               break;
+                       }
+               }
+
+               exePath = buf;
+       }
+
+       iniFileName.set(exePath.cstr());
+       iniFileName.append("\\peercast.ini");
+
+       _chdir(exePath);
+
+       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);
+               }
+       }
+
+       peercastInst->saveSettings();
+       peercastInst->quit();
+}
 
 // --------------------------------------------------
 int WinMainDummy(HINSTANCE hInstance,
@@ -411,8 +487,22 @@ int APIENTRY WinMain(HINSTANCE hInstance,
        _EXCEPTION_POINTERS *lpExcept;
        __try
        {
-               WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
-
+#if 0
+               // switch to service
+               if (lstrlen(lpCmdLine) && strstr(lpCmdLine, "-D") != NULL)
+               {
+                       SERVICE_TABLE_ENTRY svctbl[] = {
+                               {"PeerCast", (LPSERVICE_MAIN_FUNCTION)ServiceMain},
+                               {NULL, NULL}
+                       };
+
+                       if (!StartServiceCtrlDispatcher(svctbl)) 
+                       { 
+                               //SvcReportEvent(TEXT("StartServiceCtrlDispatcher")); 
+                       }
+               } else
+#endif
+                       WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
        } __except(lpExcept = GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER)
        {
                DWORD nParams;