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

📄 stage1.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        fp = fopen(szFile, "w");    }    // we read it in 20 chunks so it's easy to get "."'s printed    int nWriteSize = nArchiveSize / 20;    for (int nPos = 0; nPos < nBytes; nPos += nArchiveSize / 20)    {        if(!(m_ulInstFlags & INST_SILENT))        {            printf(".");            fflush(0);        }        if (nPos + nArchiveSize / 20 > nArchiveSize)        {            nWriteSize = nArchiveSize - nPos;        }        fwrite(pArchiveData + nPos, sizeof(char), nWriteSize, fp);    }    if (bUsePipe)    {        pclose(fp);    }    else    {        fclose(fp);        if(!(m_ulInstFlags & INST_SILENT))        {            //printf ("\n(%s)\n", szCmd);            printf ("\nDecompressing files... (please wait)\n");        }        system(szCmd);    }    if (nArchiveProgSize)    {        unlink(TMP_EXTRACT_PROG);    }    if(!(m_ulInstFlags & INST_SILENT))    {        printf("\n");    }    RunSecondStage(argc, argv); //only returns if second stage installer not found    exit(nRet);    return 0; //shut-up HP}/************************************************************************ * Stage1::RunSecondStage - invoke the second-stage installer * * Note, does not return if successful. Second-stage installer * is responsible for all cleanup. */voidStage1::RunSecondStage(int argc, char* argv[]){    char szCmd[1024];    struct stat info;    char** newargv = new char* [argc + 1];    memcpy (newargv, argv, (argc+1) * sizeof(char*));    //printf("Checking for second stage installer...");    fflush(0);    if (chdir(DESTDIR) == 0)    {        //        // check for install binary first        //        sprintf(szCmd, ".%s%s", PATH_SEP, SECOND_STAGE_PROG);#ifdef _WIN32 //win32 not really supported yet...maybe someday        strcat(szCmd, ".exe");#endif        if (stat(szCmd, &info) == 0)        {            chmod(szCmd, 0755);            newargv[0] = szCmd;            execvp(szCmd, newargv);        }        //        // check for install scripts in various languages next        //        sprintf(szCmd, ".%s%s.sh", PATH_SEP, SECOND_STAGE_PROG);        if (stat (szCmd, &info) == 0)        {            newargv[0] = szCmd;            execvp("bash", newargv);        }        sprintf(szCmd, ".%s%s.pl", PATH_SEP, SECOND_STAGE_PROG);        if (stat (szCmd, &info) == 0)        {            newargv[0] = szCmd;            execvp("perl", newargv);        }        sprintf(szCmd, ".%s%s.py", PATH_SEP, SECOND_STAGE_PROG);        if (stat (szCmd, &info) == 0)        {            newargv[0] = szCmd;            execvp("python", newargv);        }    }    delete[] newargv;    if(!(m_ulInstFlags & INST_SILENT))    {        printf("Warning: second stage installer not found!\n");        fflush(0);    }}#endif // _CONSOLE/************************************************************************ * Stage1::Bail - print a message and exit */voidStage1::Bail (int nRet, const char* szMessage){    if (!(m_ulInstFlags & INST_SILENT) && szMessage)    {        printf("%s", szMessage);        fflush(0);    }    exit(nRet);}/************************************************************************ * Stage1::PrintVersion - Print the version */voidStage1::PrintVersion(void){    printf("%s\n", ProductInstaller::VersionBanner());}/************************************************************************ * Stage1::PrintUsage - Print command-line usage information */voidStage1::PrintUsage(const char* szProg){    fprintf(stderr, "\nUsage: %s [options]\n"        "\nWhere options are:\n%s\n", szProg,         PackageInfo::CommandLineHelpString(m_szPassword ? TRUE : FALSE));}/************************************************************************ * Stage1::ParseCmdLine - Parse the command-line options * * We pass our command-line options to the second-stage installer, * so most of them will be parsed by it.  We just grab -h and -v * here so we don't have to extract the archive before handling them. */voidStage1::ParseCmdLine(int argc, char* argv[]){    int i=0;    char** arg=0;    // strip off any path information    g_szProg = argv[0] + strlen(argv[0]);    while (g_szProg > argv[0] && *g_szProg != '/' && *g_szProg != '\\')    {        --g_szProg;    }    if (*g_szProg == '/' || *g_szProg == '\\')    {        ++g_szProg;    }        // First, scan all args for -v or -h; if there we want to exit now...    for (i = argc, arg = argv; i; arg++, i--)    {        if (!strcmp(*arg, "--version") ||            !strcmp(*arg, "-v"))        {            PrintVersion();            Bail(-1,"");        }        if (!strcmp(*arg, "--help") ||            !strcmp(*arg, "-h") ||            !strcmp(*arg, "-?") ||            !strcmp(*arg, "/?")) // for win32-heads        {            PrintVersion();            PrintUsage();            Bail(-1,"");        }    }    for (i = argc, arg = argv; i; arg++, i--)    {        if(!strcmp(*arg, "--silent") ||           !strcmp(*arg, "-s") ||           !strcmp(*arg, "/s"))        {            m_ulInstFlags |= INST_SILENT | INST_NON_INTERACTIVE;        }        else if(!strcmp(*arg, "--progress-only") ||                !strcmp(*arg, "-p"))        {            m_ulInstFlags |= INST_NON_INTERACTIVE;        }        else if(!strcmp(*arg, "--password"))        {            if(i > 1)            {                i--;                 arg++;                strncpy(m_szUserPass, *arg, MAX_PASS-1);            }        }    }    // any other args will be parsed by the second-stage installer    // so ignore them}#ifdef _CONSOLEvoidStage1::SetEchoOff(void){    ioctl(0, TCGETS, &g_oldtty);    struct termios tty = g_oldtty;    tty.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL);    tty.c_cc[VMIN] = 1;    tty.c_cc[VTIME] = 0;    ioctl(0, TCSETS, &tty);}voidStage1::SetEchoOn(void){    ioctl(0, TCSETS, &g_oldtty);}BOOLStage1::PasswordPrompt(void){    BOOL bMatch = FALSE;    SetEchoOff();    UINT8 i = 0;    for(;;)    {        printf("Please enter the installation password: ");                if(!fgets(m_szUserPass, MAX_PASS, stdin))        {            break;        }        // Trim the newline        m_szUserPass[strlen(m_szUserPass) - 1] = '\0';        if(strcmp(m_szUserPass, m_szPassword) == 0)        {            bMatch = TRUE;            break;        }        if(++i < MAX_PASS_ATTEMPTS)        {            printf("\nThe password you entered is incorrect.\n");            sleep(1);        }        else        {           printf("\nThe maximum number of installation attempts has "                  "been exceeded.\n");           break;        }    }    printf("\n");    SetEchoOn();    return bMatch;}#endif // _CONSOLE

⌨️ 快捷键说明

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