⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prodinstlib.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    {	if (!isspace(*pProdName))	{	    *pCursor = *pProdName;	    pCursor++;	}	pProdName++;    }    *pCursor = 0;    // format the default install path    int nLen = strlen(szTemp) + strlen(szTemp2) + 2; // path sep + null term    szDestDir = new char[nLen];    if (szDestDir)    {	SafeSprintf(szDestDir, nLen, "%s/%s", szTemp, szTemp2);    }    else    {	szDestDir = NULL;    }}BOOLProductInstaller::GetLocalHostName(char*& szHostname){    szHostname = new char[1024];    if(!szHostname)    {        return FALSE;    }    szHostname[0] = '\0';    BOOL bRes = gethostname(szHostname, 1024) == 0;    szHostname[1023] = '\0';    return bRes;}#endif // _WIN32/************************************************************************ * ProductInstaller::BackupIfPresent * * If the named file or directory foo exists, rename it to foo.old. */voidProductInstaller::BackupIfPresent(const char* szFile){    char szCmd[1024];    sprintf (szCmd, "rm -rf %s.old 2>/dev/null", szFile);    System (szCmd);    char szFile2[1024];    sprintf (szFile2, "%s.old", szFile);    rename (szFile, szFile2);}/************************************************************************ * ProductInstaller::ReadInstallerConfigItems * * Read external installer configuration file, setting various defaults * * Note - This is for reading an _installer_ config file, not a product * config file. * * Lines look like: *  DefInstallPath=/some/directory *  AdminUserID=super *  AdminPassword=duper *  AdminPort=4004 *  EncoderUserID=super *  EncoderPassword=super *  EncoderRealm=foo.bar.com.EncoderRealm *  HTTPPort=8081 *  InstallService=0 *  MonitorPassword=red *  MonitorPort=4005 *  PNAPort=4003 *  RTSPPort=4001 */intProductInstaller::ReadInstallerConfigItems(const char*        szFile,                                          const InstCfgItem* pCfg,                                          ConsoleUI*         pCUI){    FILE* fp = fopen (szFile, "r");    if (!fp)    {        return -1;    }    char szName[1024];    char szValue[1024];    char szLine[1024];    char* p = szLine;    char* p2 = szName;    int n=0;    while (fgets (szLine, 1024, fp))    {        // skip leading whitespace        p = szLine;        while (*p == ' ')        {            ++p;        }        // copy the name        p2 = szName;        while (isalnum(*p))        {            *p2 = *p;            ++p;            ++p2;        }        *p2 = '\0';        // skip {whitespace}{equals}{whitespace} sequence        while (*p == ' ' || *p == '\t' || *p == '=')        {            ++p;        }        // copy the value        p2 = szValue;                while (*p && *p != '\n' && *p != '\r')        {            *p2 = *p;            ++p;            ++p2;        }        // skip trailing whitespace        while(p2 > szValue && isspace(*(p2-1)))        {            p2--;        }        *p2 = '\0';        const InstCfgItem* pCfgItem = pCfg;        while (pCfgItem && pCfgItem->szName)        {            if (!strcasecmp(szName, pCfgItem->szName))            {                if (pCUI)                    pCUI->ShowMessage ("      :Config: %s = %s\n",                                      pCfgItem->szName, szValue);                if (pCfgItem->eType == CFG_BOOL ||                     pCfgItem->eType == CFG_INT)                {                    if (pCfgItem->ppValue)                    {                        *(int*)(pCfgItem->ppValue) = atoi(szValue);                    }                }                else if (pCfgItem->eType == CFG_STR)                {                    if ((n = strlen(szValue)) && pCfgItem->ppValue)                    {                        char* pValue = new char[n+1];                        strcpy(pValue, szValue);                        *(pCfgItem->ppValue) = pValue;                    }                }            }            ++pCfgItem;        }    }    fclose(fp);    return 0;}/************************************************************************ * ProductInstaller::SetInstPort */voidProductInstaller::SetInstPort(int nPortID, int nPort){    m_pPorts[nPortID].nPort = nPort;    m_pPorts[nPortID].bSet = TRUE;}/************************************************************************ * ProductInstaller::ValidPort - Checks whether szPort is a valid port  * number and if so, set nPort to its int value. */BOOLProductInstaller::ValidPort(const char* szPort, int& nPort){    // No letters, symbols, etc.    for(const char* p = szPort; *p != '\0'; p++)    {        if(!isdigit(*p))        {            return FALSE;        }    }    nPort = atoi(szPort);    // Make sure it's in a valid range    return (nPort > 0 && nPort <= 0xffff);}/************************************************************************ * ProductInstaller::CheckDupePort - checks if nPort has already been  * selected. Sets szName to the string name of the port (RTSP, HTTP, etc.). * nPortID should be the intended location - it is ignored in the check. */BOOLProductInstaller::CheckDupePort(int nPort, int nPortID, const char*& szName){    for(int i = 0; i < (int)m_ulNumPorts; i++)    {        if(i != nPortID && m_pPorts[i].nPort == nPort && m_pPorts[i].bSet)        {            szName = m_pPorts[i].szName;            return TRUE;        }    }    return FALSE;}/************************************************************************ * ProductInstaller::StartWSA - start winsock */#ifdef _WIN32BOOLProductInstaller::InitWinsock(){    if(!m_bWSAStarted)    {        WSADATA wsadata;        if(WSAStartup(MAKEWORD(1,1), &wsadata) == 0)        {            m_bWSAStarted = TRUE;        }    }    return m_bWSAStarted;}#endif // _WIN32/************************************************************************ * ProductInstaller::PortInUse - checks if nPort is currently in use. */BOOLProductInstaller::PortInUse(int nPort){#ifdef _WIN32    if(!InitWinsock())    {        return FALSE;    }    SOCKET s;#else    int s;#endif // WIN32    s = socket(PF_INET, SOCK_STREAM, 0);#ifdef _WIN32    if(s == INVALID_SOCKET)#else    if(s == -1)#endif // _WIN32    {        return FALSE;    }    BOOL bInUse = FALSE;    sockaddr_in addr;    addr.sin_family = PF_INET;    addr.sin_port = htons(nPort);    addr.sin_addr.s_addr = inet_addr("127.0.0.1");    // Try to bind the port and see if it fails with EADDRINUSE.    // Ignore other errors.    if(bind(s, (sockaddr*)&addr, sizeof(addr)))    {#ifdef _WIN32        bInUse = (WSAGetLastError() == WSAEADDRINUSE);#else        bInUse = (errno == EADDRINUSE);#endif // _WIN32        // If it failed with some other error, just try to connect.        // If we can, then it must be in use.        if(!bInUse)        {            bInUse = (connect(s, (sockaddr*)&addr, sizeof(addr)) == 0);        }    }#ifdef _WIN32    closesocket(s);#else    close(s);#endif // _WIN32    return bInUse;}/************************************************************************ * ProductInstaller::CleanUp */#ifdef _UNIXvoidProductInstaller::CleanUp(const char* szDestDir){    // We do this twice because on HP-UX we can't delete a program    // we're currently running.  So we do all the deleting we can,    // then kick off a subshell that waits for us to exit then    // deletes what's left again.    char szCmd[4096];    sprintf (szCmd, "(cd ..; rm -rf hxsetup %s/Bin/setup 2> /dev/null); ",             szDestDir);    System(szCmd);    struct stat info;    if (stat("../hxsetup", &info) == 0)    {        sprintf (szCmd,            "(cd ..; sleep 2; rm -rf hxsetup %s/Bin/setup >/dev/null 2>&1) &",            szDestDir);        System(szCmd);    }}#elsevoidProductInstaller::CleanUp(const char* szDestDir){    }#endif // _UNIX/************************************************************************ * ProductInstaller::CleanUpAndExit */#ifdef _CONSOLEvoidProductInstaller::CleanUpAndExit(int nErr, ConsoleUI* pCUI){    if(!m_bSilent)    {        pCUI->ShowMessage("Cleaning up installation files...");        pCUI->FlushOutput();        pCUI->StartPrintingDots();    }    CleanUp(m_szDestDir);    if(!m_bSilent)    {        pCUI->StopPrintingDots();        pCUI->ShowMessage("\nDone.\n\n");    }    exit(nErr);}#elsevoidProductInstaller::CleanUpAndExit(int nErr, ConsoleUI* pCUI){    CleanUp(m_szDestDir);    exit(nErr);}#endif // _CONSOLEintProductInstaller::System(const char* szCmd){    if(!m_bSilent)    {        xprintf (("\nexecuting: %s\n", szCmd));    }    return system(szCmd);}voidProductInstaller::SetInstallLog(const char* pPath){    HX_VECTOR_DELETE(m_szInstallLog);    m_szInstallLog = new_string(pPath);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -