Ejemplo n.º 1
0
BOOL fsUploadMgr::ZipFiles ()
{
	if (m_bZipFileCreated)
		return TRUE;

	Event (UMGRE_ZIP_FILES_START);

	char szTmpFile [MAX_PATH];
	char szTmpPath [MAX_PATH];
	GetTempPath (MAX_PATH, szTmpPath);
	GetTempFileName (szTmpPath, "tmp", 0, szTmpFile);
	m_strUploadFile = szTmpFile;
	
	zipFile zip = zipOpen (m_strUploadFile, 0);
	BOOL bOk = TRUE;

	m_strZipContentsDescHtml = "<ul>";

	for (size_t i = 0; i < m_pkg.m_vPathes.size () && bOk && m_bNeedStop == false; i++)
	{
		LPCSTR psz = m_pkg.m_vPathes [i];

		char szName [1000] = "";
		fsGetFileName (psz, szName);

		if (GetFileAttributes (psz) & FILE_ATTRIBUTE_DIRECTORY)
		{
			AddItemToZipContentsDescHtml (szName, _UI64_MAX);
			m_strZipContentsDescHtml += "<ul>";
			bOk = bOk && Zip_AddFolder (zip, psz, NULL, 1);
			m_strZipContentsDescHtml += "</ul>";
		}
		else
		{
			bOk = bOk && Zip_AddFile (zip, psz, NULL);
			if (bOk)
			{
				WIN32_FILE_ATTRIBUTE_DATA wfad;
				GetFileAttributesEx (psz, GetFileExInfoStandard, &wfad);
				AddItemToZipContentsDescHtml (szName, ((UINT64)wfad.nFileSizeHigh << 32) + wfad.nFileSizeLow);
			}
		}
	}

	m_strZipContentsDescHtml += "</ul>";

	zipClose (zip, NULL);

	if (m_bNeedStop || bOk == FALSE)
		DeleteFile (m_strUploadFile);
	else
		m_bZipFileCreated = TRUE;

	if (m_bNeedStop == false)
		Event (bOk ? UMGRE_ZIP_FILES_DONE : UMGRE_ZIP_FILES_FAILED);

	return m_bZipFileCreated;
}
Ejemplo n.º 2
0
//
// D_addBinaryFileToZip
//
// Add a binary file from the /res folder into the zip.
//
static void D_addBinaryFileToZip(ziparchive_t *zip, const char *filename, 
                                 const char *lumpname)
{
   qstring srcpath;

   srcpath = filename;
   D_MakeResourceFilePath(srcpath);

   Zip_AddFile(zip, lumpname, srcpath.constPtr(), false);
}
Ejemplo n.º 3
0
//
// D_addResourceScriptToZip
//
// Add a file from the resource directory as a script lump.
//
static void D_addResourceScriptToZip(ziparchive_t *zip, const char *filename)
{
   qstring srcpath;

   srcpath = filename;
   D_MakeResourceFilePath(srcpath);

   char *text;
   if(!(text = M_LoadStringFromFile(srcpath.constPtr())))
      I_Error("D_addResourceScript: unable to load resource %s\n", srcpath.constPtr());

   Zip_AddFile(zip, filename, reinterpret_cast<byte *>(text), 
               static_cast<uint32_t>(strlen(text)), ZIP_FILE_TEXT, true);
}
Ejemplo n.º 4
0
BOOL fsUploadMgr::Zip_AddFolder(void *zip, LPCSTR pszFolder, LPCSTR pszFolderNameInZip, int nDepth)
{
	fsString strDir = pszFolder;
	if (strDir [strDir.GetLength () - 1] != '\\')
		strDir += '\\';
	fsString strMask = strDir; strMask += "*.*";
	fsString strFolderNameInZip;
	if (pszFolderNameInZip == NULL)
	{
		LPCSTR psz = strrchr (pszFolder, '\\');
		if (psz)
		{
			if (psz [1] == 0)
				while (*(--psz) != '\\');
			psz++;
		}
		if (psz == NULL)
			psz = pszFolder;
		strFolderNameInZip = psz;
	}
	else
		strFolderNameInZip = pszFolderNameInZip;
	if (strFolderNameInZip.IsEmpty () == FALSE && 
			strFolderNameInZip [strFolderNameInZip.GetLength () - 1] != '\\')
		strFolderNameInZip += '\\';
	pszFolderNameInZip = strFolderNameInZip;

	WIN32_FIND_DATA wfd;
	HANDLE hFind = FindFirstFile (strMask, &wfd);
	if (hFind == NULL)
		return TRUE;

	do
	{
		if (strcmp (wfd.cFileName, ".") == 0 || strcmp (wfd.cFileName, "..") == 0)
			continue;

		fsString str = strDir;
		str += wfd.cFileName;

		fsString strNameInZip = pszFolderNameInZip;
		strNameInZip += wfd.cFileName;

		if (GetFileAttributes (str) & FILE_ATTRIBUTE_DIRECTORY)
		{
			AddItemToZipContentsDescHtml (wfd.cFileName, _UI64_MAX);
			strNameInZip += '\\';
			m_strZipContentsDescHtml += "<ul>";
			if (FALSE == Zip_AddFolder (zip, str, strNameInZip, nDepth+1))
				return FALSE;
			m_strZipContentsDescHtml += "</ul>";
		}
		else
		{
			if (FALSE == Zip_AddFile (zip, str, strNameInZip))
				return FALSE;
			AddItemToZipContentsDescHtml (wfd.cFileName, ((UINT64)wfd.nFileSizeHigh << 32) + wfd.nFileSizeLow);
		}
	}
	while (FindNextFile (hFind, &wfd));

	FindClose (hFind);

	return TRUE;
}