int main()
{
    char *fileName = "book.txt";
    char *zipFileName = "encoded.txt";
    char *unzipFileName = "decoded.txt";
    char mode;
SELECT:
    puts("Please enter 1 or 2 to select mode, 1 for code,2 for decode,3 to exit now~>_<:");
    mode=getchar();
    if (mode == '1')
    {

        ZipFile(fileName, zipFileName);
        printf("Ziped file was saved.\n");
        getchar();
        goto SELECT;
    }
    else if (mode =='2')
    {
        UnzipFile(zipFileName, unzipFileName);
        getchar();/*读走缓存区的回车*/
    }
    else if (mode=='3')
    {
        exit(0);
    }
    return 0;
}
Example #2
0
//************************************
// Method:    VOpen
// FullName:  ResourceZipFile::VOpen
// Access:    virtual public 
// Returns:   bool
// Qualifier:
//************************************
bool ResourceZipFile::VOpen()
{
	m_pZipFile = DEBUG_CLIENTBLOCK ZipFile();
	if(m_pZipFile)
	{
		return m_pZipFile->Init(m_resFileName.c_str());
	}
	return false;
}
Example #3
0
int Camera::stopRecording()
{
	record = false;
	outputVideo.release();
	char commandStr[256];

	// add the names of the source files to be zipped to sourceFiles
	std::vector<std::string>  sourceFiles;
	sourceFiles.push_back(fname);
	char zipped_file[256];
	sprintf(zipped_file, "%s.zip", fname);

	printf("String zip name = %s\n", zipped_file);

	if (false == ZipFile(sourceFiles, zipped_file))
	{
		printf("invalid input filename, can not zip it!");
		return -1;
	}
	else {
		printf("Zip completed, filename = %s\n",zipped_file);
	}

	//std::ifstream ifs("test.jpg");
	FILE* f = fopen(zipped_file, "rb");

	//std::ifstream ifs("test.jpg");
	//FILE* f = fopen("0101123457-2014107-053151.zip", "rb");
	
	//FILE* f = fopen(fname, "rb");
	// Determine file size
	fseek(f, 0, SEEK_END);
	size_t size = ftell(f);
	s_upload_file_size = size;
	char* where = new char[size];

	rewind(f);
	fread(where, sizeof(char), size, f);
	S3FileManager s3fm("AKIAJBQ2VX7SJ2NTVFGA", "KtGD8P6yqbflzf+TD+AWYkioXe97Ygk46ruqt4Kq");
	

	s3fm.S3UploadFile(where, size, zipped_file);
	return 0;
}
Example #4
0
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-//
        ZipFile ZipFile::decompress(const string &out_file)
        {
            gzFile p_in_file = gzopen(path.c_str(), "rb");
            FILE *p_out_file = fopen(out_file.c_str(), "wb");
            if (p_in_file && p_out_file)
            {
                char buffer[ Zip::getMaxCompressBlock() ];
                int num_read = 0;
                // size_t total = 0;
                while ((num_read = gzread(p_in_file, buffer, sizeof(buffer))) > 0)
                {
                    fwrite(buffer, 1, num_read, p_out_file);
                    // total += num_read;
                }

                gzclose(p_in_file);
                fclose(p_out_file);
            }
            return ZipFile(out_file);
        }
Example #5
0
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-//
        ZipFile ZipFile::compress(const string &out_file)
        {
            FILE *p_in_file = fopen(path.c_str(), "rb");
            gzFile p_out_file = gzopen(out_file.c_str(), "wb");
            if (p_in_file && p_out_file)
            {
                char buffer[Utils::Zip::getMaxCompressBlock()];
                int num_read = 0;
                // size_t total = 0;
                while ((num_read = fread(buffer, 1, sizeof(buffer), p_in_file)) > 0)
                {
                    // total +=
                    gzwrite(p_out_file, buffer, num_read);
                }

                gzclose(p_out_file);
                fclose(p_in_file);
            }
            return ZipFile(out_file);
        }
Example #6
0
int main()
{
    /*进行功能选择*/
    char *fileName = "book.txt";
    char *zipFileName = "encoded.txt";
    char *unzipFileName = "decoded.txt";
    char mode;
    while(1)
    {
        puts("Please enter 1 or 2 to select mode, 1 for encode,2 for decode,3 to exit now:");
        puts("fff");
        mode=getchar();
        if (mode == '1')
        {
            int x=ZipFile(fileName, zipFileName);
            if(x==1)continue;
            printf("Coded! Ziped file was saved.\n");
            getchar();/*读走缓存区的回车*/
        }
        else if (mode =='2')
        {
            int x=UnzipFile(zipFileName, unzipFileName);
            if(x==1)continue;
            getchar();/*读走缓存区的回车*/
        }
        else if (mode=='3')
        {
            exit(0);
        }
        else
        {
            puts("Unexpected input!\n");
            getchar();/*读走缓存区的回车*/
        }
    }
    return 0;
}
Example #7
0
void CCompressThread::HandleTask(pCOMPRESSTASK pTask)
{
	if (pTask->nCompressType == 1)
	{
		std::string strLog = "获得试卷包压缩任务: " + pTask->strSrcFilePath;
		g_pLogger->information(strLog);

		USES_CONVERSION;
		CString strInfo;
		bool bWarn = false;
	#if 1
		bool bResult = false;
		CZipObj zipObj;
		zipObj.setLogger(g_pLogger);
		bResult = zipObj.ZipFile(A2T(pTask->strSrcFilePath.c_str()), A2T(pTask->strSavePath.c_str()), A2T(pTask->strExtName.c_str()));
	#else
		bool bResult = ZipFile(A2T(pTask->strSrcFilePath.c_str()), A2T(pTask->strSavePath.c_str()), A2T(pTask->strExtName.c_str()));
	#endif
		if (!bResult)
		{
			bWarn = true;
			strInfo.Format(_T("保存%s失败"), A2T(pTask->strCompressFileName.c_str()));
		}
		else
		{
			strInfo.Format(_T("保存%s成功"), A2T(pTask->strCompressFileName.c_str()));
		}
//		((CScanToolDlg*)m_pDlg)->SetStatusShowInfo(strInfo, bWarn);

		if (bWarn)
		{
//			((CScanToolDlg*)m_pDlg)->m_bF2Enable = TRUE;
			return;
		}

		if (g_nManulUploadFile != 1)
		{
			char szFileFullPath[300] = { 0 };
			sprintf_s(szFileFullPath, "%s%s", pTask->strSavePath.c_str(), pTask->strExtName.c_str());
			pSENDTASK pSendTask = new SENDTASK;
			pSendTask->strFileName = pTask->strCompressFileName;
			pSendTask->strPath = szFileFullPath;
			g_fmSendLock.lock();
			g_lSendTask.push_back(pSendTask);
			g_fmSendLock.unlock();
		}
//		((CScanToolDlg*)m_pDlg)->m_bF2Enable = TRUE;

		//源文件夹删除
		if (pTask->bDelSrcDir)
		{
			try
			{
				Poco::File srcFileDir(CMyCodeConvert::Gb2312ToUtf8(pTask->strSrcFilePath));
				if (srcFileDir.exists())
					srcFileDir.remove(true);

				strLog = "文件[" + pTask->strCompressFileName + "]压缩完成,源文件夹删除成功";
				g_pLogger->information(strLog);
			}
			catch (Poco::Exception& exc)
			{
				std::string strErr = "文件[" + pTask->strCompressFileName + "]压缩完成,删除源文件夹(" + pTask->strSrcFilePath + ")失败: " + exc.message();
				g_pLogger->information(strErr);
			}
		}
	}
	else
	{
#if 0
		//从pkg恢复到Papers
		USES_CONVERSION;
		CString strInfo = _T("");
		strInfo.Format(_T("正在恢复试卷包(%s), 请稍后..."), A2T(pTask->strCompressFileName.c_str()));
		((CScanToolDlg*)m_pDlg)->SetStatusShowInfo(strInfo);

		std::string strPkgPath = g_strPaperBackupPath + pTask->strCompressFileName;		//utf8
		CPkgToPapers pkg2PapersObj;
		pPAPERSINFO pPapers = pkg2PapersObj.Pkg2Papers(CMyCodeConvert::Utf8ToGb2312(strPkgPath));
		
		//消息发送给主线程
		(static_cast<CScanToolDlg*>(m_pDlg))->SendMessage(MSG_Pkg2Papers_OK, (WPARAM)pPapers, NULL);
#endif
	}
}