コード例 #1
0
ファイル: ZipSS.cpp プロジェクト: geoffsmith82/delphizip
int ZipOp::ZipStreamStream(void)
{
    fwindow_size = 0L;

    if (fGEncrypt)
    {
        fkey = fGPassword;

        if (!fkey || !*(fkey))
        {
            // use global
            if (GetUserPW() != DZ_ERR_GOOD)
                return -1;  // error

            fkey = fuser_key;
        }
    }

    fZipInfile = new ZStream(this, _T("0:<INSTREAM>"), fSS->fSSInput);

    AutoStream inz(&fZipInfile);
    fimax = fSS->Size;
    fcrc = crc32(0L, NULL, 0);
    fisize = 0;
    CB->SetArg1(1);
    CB->UserCB(zacCount);

    // Pass total filesize.
    CB->SetFileSize(fimax);
    CB->UserCB(zacSize);
    ulg f_crc = 0;
    __int64 fsz = 0;
    bool haveCRC = false;

    if (fkey)
    {
        if (!fNoPrecalc)
        {
            if (Verbose < 0)
                Notify(ITRACE,  _T("about to call Precalculate CRC"));

            // +++++ get CRC before we start
			CB->UserXItem(fimax, 13, _T("*PreCalculate"));
            __int64 pos1 = 0;

            if (!fZipInfile->IsFile)
                pos1 = fZipInfile->SetPosition(0, FILE_CURRENT); // get start posn

			f_crc = crc32(0L, NULL, 0);
            unsigned long byts;

            while (true)
            {
                unsigned ToRead = sizeof(fwindow);

                if (fimax > 0 && (fsz + ToRead) > fimax)
                {
                    ToRead = (unsigned)(fimax - fsz);

                    if (!ToRead)
                        break;
                }

                if (!fZipInfile->Read(fwindow, ToRead, &byts) || !byts)
                    break;

				fsz += byts;
				f_crc = crc32(f_crc, (const uch*)fwindow, (int)byts);
				CB->UserXProgress(byts, 13);

                if (Abort_Flag)
					Fatal(DZ_ERM_ABORT, 0);
            }

            fSS->CRC = f_crc;

            haveCRC = true;
            // reposition

            if (fZipInfile->SetPosition(pos1, FILE_BEGIN) != pos1)
            {
                if (Verbose)
					Notify(IVERBOSE, _T("Could not reposition %s [%s]"),
						fZipInfile->fname.c_str(), SysMsg().c_str());

				return  DZError(DZ_ERM_ERROR_SEEK);
			}

            if (fimax > fsz)
                fimax = fsz;
        }

        // ----- get CRC before we start
        // Since we do not yet know the crc here, we pretend that the crc is the
        //   modification time:
//    if (!haveCRC)
//      fSS->CRC = z->tim << 16;
        if (Verbose < 0)
            Notify(ITRACE,  _T("using supplied CRC %lu"), fSS->CRC);
    }

    // connect to output
    fZipOutfile = new ZStream(this, _T("0:<OUTSTREAM>"), fSS->fSSOutput);

    AutoStream outz(&fZipOutfile);

    CB->UserItem(fimax, _T("<INSTREAM>"));

	if (fkey)
		crypthead(fkey, fSS->CRC);  // write

    // Write stored or deflated file to zip file
    fSS->Method &= 0xFF;

    if (fSS->Method != DEFLATE)
        fSS->Method = 0;

    if (flevel < 1)
        fSS->Method = 0;

	int mthd = (int)fSS->Method;

    if (mthd == DEFLATE)
    {
        if (Verbose < 0)
            Notify(ITRACE,  _T("about to call Deflate"));

        bi_init();
        ush att = BINARY;
        ush flg = FLAG_ENCRYPT_BIT;

        // will be changed in deflate()
        ct_init(&att, &mthd);
        lm_init(flevel, &flg);

        // PERFORM THE DEFLATE
        fSS->Size = deflate();

        if (Abort_Flag)
			Fatal(DZ_ERM_ABORT, 0);
    }
    else
    {
        int k;

        if (Verbose)
            Notify(IVERBOSE, _T("Storing %s "), fZipInfile->fname.c_str());

        while ((k = read_buf(fwindow, sizeof(fwindow))) > 0
                && k != EOF)
        {
            if (Abort_Flag)
				Fatal(DZ_ERM_ABORT, 0);

			if (!zfwrite(fwindow,  (extent)k))
				return DZ_ERM_TEMP_FAILED;
        }

    }
    /*  Finished Item */
    CB->UserItem(-1, _T("<INSTREAM>")); // mark end of item
    CB->UserCB(zacEndOfBatch); // done with stream compression

    if (haveCRC)
    {
        if (f_crc != fcrc)
            Notify(DZ_ERR_ERROR_READ | IWARNING, _T(" File CRC changed while zipping: %s"),
                   fZipInfile->fname.c_str());

        if (fisize != fsz)
            Notify(DZ_ERR_ERROR_READ | IWARNING, _T(" File size changed while zipping: %s"),
                   fZipInfile->fname.c_str());
    }

    fSS->Size = fisize;

    fSS->CRC = fcrc;
    fSS->Method = (DWORD)mthd | (fkey ? 0xff00 : 0);
    return DZ_ERR_GOOD;
}
コード例 #2
0
ファイル: news_viewer.c プロジェクト: ccns/BBS_SourceCode
int fmain_menu()
{
	char c;
	int i, x, y;
	int now_main = site, old_main = 0;

	clear();
	draw_banner(MAIN_MENU_TOP - 6);

	move(MAIN_MENU_TOP - 2, MAIN_MENU_LEFT);
	prints("¢~שששששששששששששששששששששששששששששששששששששששששששששששששששששששששששששששששש¢¡");
	for (i = 0;i < total_nall;i++)
	{
		x = i % MAX_MAIN_MENU ;
		y = i / MAX_MAIN_MENU ;
		if (y == 0)
		{
			move(MAIN_MENU_TOP + x, MAIN_MENU_LEFT);
			clrtohol();
		}
		move(MAIN_MENU_TOP + x, MAIN_MENU_LEFT + y*37);
		prints("%s%12s  %s", ORG_BAR, main_menu[i], ORG_BAR);
	}
	move(MAIN_MENU_TOP + MAX_MAIN_MENU + 1, MAIN_MENU_LEFT);
	prints("¢¢שששששששששששששששששששששששששששששששששששששששששששששששששששששששששששששששששש¢£");
	outz("\033[46;44m ¡i¾�§@»¡©ת¡j \033[47;31m  (¡פ¡ץ¡צ¡ק) \033[30m¿ן¾� \033[31m(Enter) \033[30m½T©w\033[31m (q)\033[30m ֲק¶}                          \033[m");
	draw_main_menu(site, site);

	do
	{
		old_main = now_main;
		c = vkey();
		switch (c)
		{
		case KEY_DOWN:
			now_main ++;
			if (now_main == total_nall)
				now_main = 0;
			draw_main_menu(now_main, old_main);
			break;
		case KEY_UP:
			now_main --;
			if (now_main < 0)
				now_main = total_nall - 1;
			draw_main_menu(now_main, old_main);
			break;
		case KEY_HOME:
		case '0':
			now_main = 0;
			draw_main_menu(now_main, old_main);
			break;
		case KEY_END:
		case '$':
			now_main = total_nall - 1;
			draw_main_menu(now_main, old_main);
			break;
		case Ctrl('U'):
						every_U();
			break;
		case KEY_RIGHT:
			now_main += MAX_MAIN_MENU ;
			if (now_main > total_nall - 1)
				now_main %= MAX_MAIN_MENU ;
			draw_main_menu(now_main, old_main);
			break ;
		case KEY_LEFT:
			if (now_main < MAX_MAIN_MENU)
	{
				if (now_main <= (total_nall - 1) % MAX_MAIN_MENU)
				{
					now_main += MAX_MAIN_MENU * ((total_nall - 1) / MAX_MAIN_MENU);
				}
				else
				{
					now_main = total_nall - 1;
				}
			}
			else
				now_main -= MAX_MAIN_MENU ;
			draw_main_menu(now_main, old_main);
			break;
		case '\n':
		case '\r':
			return now_main;
		}
	}
	while (c != 'q' && c != 'Q' && c != KEY_ESC);
	return -1;
}
コード例 #3
0
void help_classtable(void)
{
	outz("\033[1;37;42m 【操作說明】a)新增 e)修改 d)刪除 q)離開 i)匯入 c)清除 \033[1;30mCopyRight By verit@yzu \033[m");
}