Esempio n. 1
0
DWORD WINAPI ZipThreadProc(void *)
{ int size=40*1024*1024; // 40mb big!
  char *c=new char[size]; for (int i=0; i<size; i+=4) {*(int*)(c+i) = rand();}
  CreateDirectory("\\z",0);
  HZIP hz = CreateZip("\\z\\progress.zip",0);
  ZipAdd(hz,"progress1.zip",c,size);
  ZipAdd(hz,"progress2.zip",c,size);
  CloseZip(hz);
  delete[] c;
  return 0;
}
//-----------------------------------------------------------------------------
// Uploads a screenshot to a particular listener
//-----------------------------------------------------------------------------
void CServerRemoteAccess::UploadScreenshot( const char *pFileName )
{
#ifndef SWDS
	if ( m_nScreenshotListener < 0 )
		return;

	CUtlBuffer buf( 128 * 1024, 0 );
	if ( g_pFullFileSystem->ReadFile( pFileName, "MOD", buf ) )
	{
		HZIP hZip = CreateZipZ( 0, 1024 * 1024, ZIP_MEMORY );
		void *pMem;
		unsigned long nLen;
		ZipAdd( hZip, "screenshot.jpg", buf.Base(), buf.TellMaxPut(), ZIP_MEMORY );
		ZipGetMemory( hZip, &pMem, &nLen );
		SendResponseToClient( m_nScreenshotListener, SERVERDATA_SCREENSHOT_RESPONSE, pMem, nLen );
		CloseZip( hZip );
	}
	else
	{
		LogCommand( m_nScreenshotListener, "Failed to read screenshot!\n" );
		RespondString( m_nScreenshotListener, 0, "Failed to read screenshot!\n" );
	}

	m_nScreenshotListener = -1;
#endif
}
Esempio n. 3
0
bool RecurseDirectory(HZIP hz, QString sDir, QString prevDir = "") 
{
       QDir dir(sDir);
       QFileInfoList list = dir.entryInfoList();
       for (int iList=0;iList<list.count();iList++)
       {
           QFileInfo info = list[iList];

           QString sFilePath = info.filePath();
           if (info.isDir())
           {
               // recursive
               if (info.fileName()!=".." && info.fileName()!=".")
               {
                    ZRESULT zr;
                   return RecurseDirectory(hz, sFilePath);
               }
           }
           else
           {
               // Do something with the file here
               
               if(ZipAdd(hz, (/*sDir.right(sDir.size() - sDir.lastIndexOf("/") -1) + "/" + */info.fileName()).toLatin1().data(), info.absoluteFilePath().toLatin1().data()) != ZR_OK)
                   return false;
           }
       }

       return true;
};
Esempio n. 4
0
bool CompressFiles(std::string ZipName, std::vector<std::string>* pFilePaths, std::string* pError) //pointer to a vector of filepath strings to zip into location of ZipName (also a filepath)
{
#ifdef WIN32

	HZIP hz = CreateZip(ZipName.c_str(),0);
	if (!hz){if (pError) *pError += "Could not create ZIP archive. Aborting\n"; return false;}

	int NumFiles = pFilePaths->size();
	for (int i=0; i<NumFiles; i++){
		std::string ThisFilePath = (*pFilePaths)[i];

		//extract file name (without path)
		int StartName = ThisFilePath.find_last_of('/')+1;
		int EndName = ThisFilePath.size();
		std::string Name = ThisFilePath.substr(StartName, EndName-StartName);

		//remove .tmp from end if it exists...
		std::string Last4 = Name.substr(Name.size()-4, 4);
		if (Last4.compare(".tmp")==0) Name = Name.substr(0, Name.size()-4);

		if(ZipAdd(hz, Name.c_str(), ThisFilePath.c_str()) != ZR_OK){if (pError) *pError += ("Could not add file to ZIP archive. Aborting.\n"); return false;}
	}

	if(CloseZip(hz) != ZR_OK){if (pError) *pError += ("Could not close ZIP archive. Aborting.\n"); return false;}

	return true;
#else
	//Mac/Linux Zip write code
	remove(ZipName.c_str());
	int err;
	struct zip * hz = zip_open(ZipName.c_str(), ZIP_CREATE, &err);
	if (!hz){if (pError) *pError += "Could not create ZIP archive. Aborting\n"; return false;}

	int NumFiles = pFilePaths->size();
	for (int i=0; i<NumFiles; i++){
		std::string ThisFilePath = (*pFilePaths)[i];

		//extract file name (without path)
		int StartName = ThisFilePath.find_last_of('/')+1;
		int EndName = ThisFilePath.size();
		std::string Name = ThisFilePath.substr(StartName, EndName-StartName);

		//remove .tmp from end if it exists...
		std::string Last4 = Name.substr(Name.size()-4, 4);
		if (Last4.compare(".tmp")==0) Name = Name.substr(0, Name.size()-4);

		struct zip_source * source =
		  zip_source_file(hz, ThisFilePath.c_str(), 0, 0);

		if(source == NULL || zip_add(hz, Name.c_str(), source) == -1){if (pError) *pError += ("Could not add file to ZIP archive. Aborting.\n"); return false;}
	}
	if (zip_close(hz) != 0) {if(pError) *pError += "Error closing ZIP file.\n"; return false;}
	return true;
#endif
}
Esempio n. 5
0
int main()
{   HZIP hz;

    hz = CreateZip("std1.zip",0);
    ZipAdd(hz,"znsimple.jpg", "std_sample.jpg");
    ZipAdd(hz,"znsimple.txt", "std_sample.txt");
    CloseZip(hz);

    hz = OpenZip("std1.zip",0);
    ZIPENTRY ze;
    GetZipItem(hz,-1,&ze);
    int numitems=ze.index;
    for (int zi=0; zi<numitems; zi++)
    {   GetZipItem(hz,zi,&ze);
        UnzipItem(hz,zi,ze.name);
    }
    CloseZip(hz);

    return 0;
}
Esempio n. 6
0
bool CZipObj::ZipFile(CString strSrcPath, CString strDstPath, CString strExtName /*= _T(".zip")*/)
{
	USES_CONVERSION;
	//	CString modelName = strSrcPath.Right(strSrcPath.GetLength() - strSrcPath.ReverseFind('\\') - 1);
	CString zipName = strDstPath + strExtName;
	std::string strUtf8ZipName = CMyCodeConvert::Gb2312ToUtf8(T2A(zipName));

	try
	{
		Poco::File p(strUtf8ZipName);	//T2A(zipName)
		if (p.exists())
			p.remove(true);
	}
	catch (Poco::Exception)
	{
	}

	//	std::string strModelPath = T2A(strSrcPath);
	std::string strUtf8ModelPath = CMyCodeConvert::Gb2312ToUtf8(T2A(strSrcPath));
	try
	{
		Poco::File p2(strUtf8ModelPath);	//T2A(zipName)
		if (!p2.exists())
		{
			std::string strErr = Poco::format("需要压缩的原文件夹(%s)不存在。", T2A(strSrcPath));
			RecordLog(strErr);
			return false;
		}
	}
	catch (Poco::Exception)
	{
	}

	HZIP hz = CreateZip(zipName, _strPwd.c_str());

	Poco::DirectoryIterator it(strUtf8ModelPath);	//strModelPath
	Poco::DirectoryIterator end;
	while (it != end)
	{
		Poco::Path p(it->path());
		//		std::string strZipFileName = p.getFileName();
		std::string strPath = CMyCodeConvert::Utf8ToGb2312(p.toString());
		std::string strZipFileName = CMyCodeConvert::Utf8ToGb2312(p.getFileName());
		CString strZipPath = A2T(strPath.c_str());
		CString strName = A2T(strZipFileName.c_str());
		//		ZipAdd(hz, A2T(strZipFileName.c_str()), A2T(p.toString().c_str()));
		ZipAdd(hz, strName, strZipPath);
		it++;
	}
	CloseZip(hz);

	return true;
}
Esempio n. 7
0
void CMainDlg::AddUserInfoToCrashDescriptorXML(CString sEmail, CString sDesc)
{ 
  USES_CONVERSION;

  HZIP hz = CreateZip(m_sZipName, NULL);
  
  TStrStrMap::iterator cur = m_pUDFiles.begin();
  unsigned int i;
  for (i = 0; i < m_pUDFiles.size(); i++, cur++)
  {
    CString sFileName = cur->first.c_str();
    sFileName = sFileName.Mid(sFileName.ReverseFind('\\')+1);
    if(sFileName.CompareNoCase(_T("crashrpt.xml"))==0)
    {
      TiXmlDocument doc;
  
      bool bLoad = doc.LoadFile(cur->first.c_str());
      if(!bLoad)
        return;

      TiXmlNode* root = doc.FirstChild("CrashRpt");
      if(!root)
        return;

      // Write user e-mail

      TiXmlElement* email = new TiXmlElement("UserEmail");
      root->LinkEndChild(email);

      LPSTR lpszEmail = T2A(sEmail.GetBuffer(0));
      TiXmlText* email_text = new TiXmlText(lpszEmail);
      email->LinkEndChild(email_text);              

      // Write problem description

      TiXmlElement* desc = new TiXmlElement("ProblemDescription");
      root->LinkEndChild(desc);

      LPSTR lpszDesc = T2A(sDesc.GetBuffer(0));
      TiXmlText* desc_text = new TiXmlText(lpszDesc);
      desc->LinkEndChild(desc_text);              

      doc.SaveFile();      
    }

	LPTSTR lptszFilePath = A2T((char*)cur->first.c_str());
    ZRESULT zr = ZipAdd(hz, sFileName, lptszFilePath);
    ATLASSERT(zr==ZR_OK); 
	zr;
  }  

  CloseZip(hz);
}
Esempio n. 8
0
// Packages all files in "path" into a .zip file.
void CreateArchive(string path, string name, ArchiveInfo& info)
{
	HZIP hz = CreateZip(name.c_str(), 0);

	HANDLE hFind = INVALID_HANDLE_VALUE;
    WIN32_FIND_DATA ffd;
	string spec;
    stack<string> directories;

    directories.push(path);

    while (!directories.empty()) {
        path = directories.top();
        spec = path + "/*";
        directories.pop();

        hFind = FindFirstFile(spec.c_str(), &ffd);
        if (hFind == INVALID_HANDLE_VALUE)  
            return;

        do {
            if (strcmp(ffd.cFileName, ".") != 0 && strcmp(ffd.cFileName, "..") != 0) {
                if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
					// Add folder to archive.
					ZipAddFolder(hz, string(path + "/" + ffd.cFileName).c_str());
                    directories.push(path + "/" + ffd.cFileName);
                }
                else {
					// Add file to archive.
					ZipAdd(hz, string(path + "/" + ffd.cFileName).c_str(), string(path + "/" + ffd.cFileName).c_str());
					info.files++;
					info.size += FileSize(path + "/" + ffd.cFileName);
                }
            }
        } while (FindNextFile(hFind, &ffd) != 0);

        if (GetLastError() != ERROR_NO_MORE_FILES) {
            FindClose(hFind);
            return;
        }

        FindClose(hFind);
        hFind = INVALID_HANDLE_VALUE;
    }

	CloseZip(hz);
}
Esempio n. 9
0
///////////////////////////////////////////////////////////////////////////////
// Zip
BOOL CXZipTestDlg::Zip(LPCTSTR lpszZipArchive, LPCTSTR lpszSrcFile)
{
	BOOL bResult = TRUE;

	_ASSERTE(lpszZipArchive);
	_ASSERTE(lpszZipArchive[0] != _T('\0'));

	if (!lpszZipArchive || lpszZipArchive[0] == _T('\0'))
		return FALSE;

	_ASSERTE(lpszSrcFile);
	_ASSERTE(lpszSrcFile[0] != _T('\0'));

	if (!lpszSrcFile || lpszSrcFile[0] == _T('\0'))
		return FALSE;

	// does zip source file exist?
	if (_taccess(lpszSrcFile, 04) != 0)
	{
		TRACE(_T("WARNING: zip source file '%s' cannot be found, operation aborted\n"),
			lpszSrcFile);
		return FALSE;
	}

	// use only the file name for zip file entry
	TCHAR * cp = (TCHAR *)_tcsrchr(lpszSrcFile, _T('\\'));
	if (cp == NULL)
		cp = (TCHAR *) lpszSrcFile;
	else
		cp++;

	HZIP hz = CreateZip((void *)lpszZipArchive, 0, ZIP_FILENAME);

	if (hz)
	{
		ZRESULT zr = ZipAdd(hz, cp, (void *)lpszSrcFile, 0, ZIP_FILENAME);

		CloseZip(hz);

		// did add work?
		if (zr == ZR_OK)
		{
			TRACE(_T("added '%s' to zip file '%s'\n"),
				lpszSrcFile, lpszZipArchive);

			bResult = TRUE;
		}
		else
		{
			TRACE(_T("WARNING: failed to add zip source file '%s'\n"),
				lpszSrcFile);
			bResult = FALSE;
		}
	}
	else
	{
		TRACE(_T("ERROR: failed to create zip file '%s'\n"), 
			lpszZipArchive);
		bResult = FALSE;
	}

	return bResult;
}
Esempio n. 10
0
///////////////////////////////////////////////////////////////////////////////
// OnTest
void CXZipTestDlg::OnTest() 
{
#ifdef _UNICODE
	ZIPENTRYW ze;
#else
	ZIPENTRY ze; 
#endif

	memset(&ze, 0, sizeof(ze));
	TCHAR * pszArchive1 = _T("_TestZipTmp1.zip");
	TCHAR * pszArchive2 = _T("_TestZipTmp2.zip");

	// text files
	TCHAR * pszName1    = _T("_TestZipTmp1.txt");
	TCHAR * pszName2    = _T("_TestZipTmp2.txt");
	TCHAR * pszName3    = _T("_TestZipTmp3.txt");

	// binary files
	TCHAR * pszName4    = _T("_TestZipTmp4.bin");
	TCHAR * pszName5    = _T("_TestZipTmp5.bin");
	TCHAR * pszName6    = _T("_TestZipTmp6.bin");
	TCHAR * pszName7    = _T("_TestZipTmp7.bin");
	TCHAR * pszName8    = _T("_TestZipTmp8.bin");
	TCHAR * pszName9    = _T("_TestZipTmp9.bin");

	// delete zip files
	::DeleteFile(pszArchive1);
	::DeleteFile(pszArchive2);

	// create .txt files
	CreateTextFile(pszName1, 10000);
	CreateTextFile(pszName2, 100);
	CreateTextFile(pszName3, 10);

	// create .bin files
	CreateBinaryFile(pszName4, 16384);
	CreateBinaryFile(pszName5, 3*16384);
	CreateBinaryFile(pszName6, 8*16384);
	CreateBinaryFile(pszName7, 123);
	CreateBinaryFile(pszName8, 17000);
	CreateBinaryFile(pszName9, 8*16384+1);

	///////////////////////////////////////////////////////////////////////////
	// single-file zip

	m_List.AddLine(CXListBox::Blue, CXListBox::White, _T(""));

	m_List.Printf(CXListBox::Navy, CXListBox::White, 0, 
		_T("    === Testing single-file zip ==="));

	BOOL bRet = Zip(pszArchive1, pszName1);

	if (bRet)
	{
		m_List.Printf(CXListBox::Green, CXListBox::White, 0, 
			_T("    Zip archive created OK"));

		m_List.Printf(CXListBox::Black, CXListBox::White, 0, 
			_T("    === Testing unzip ==="));

		HZIP hz = OpenZip(pszArchive1, 0, ZIP_FILENAME);

		if (hz)
		{
			ZRESULT zr = GetZipItem(hz, -1, &ze); 

			if (zr == ZR_OK)
			{
				int numitems = ze.index;

				if (numitems == 1)
				{
					m_List.Printf(CXListBox::Green, CXListBox::White, 0, 
						_T("    Zip archive contains 1 file ==> OK"));

					VerifyZip(hz, pszName1);

					CloseZip(hz);
				}
				else
				{
					m_List.Printf(CXListBox::Red, CXListBox::White, 0, 
						_T("    Zip contents bad"));
				}
			}
			else
			{
				m_List.Printf(CXListBox::Red, CXListBox::White, 0, 
					_T("    GetZipItem failed"));
			}
		}
		else
		{
			m_List.Printf(CXListBox::Red, CXListBox::White, 0, 
				_T("   Failed to open zip file '%s'"), pszArchive1);
		}
	}
	else
	{
		m_List.Printf(CXListBox::Red, CXListBox::White, 0, 
			_T("    Failed to create zip"));
	}


	///////////////////////////////////////////////////////////////////////////
	// multi-file zip

	m_List.AddLine(CXListBox::Blue, CXListBox::White, _T(""));

	m_List.Printf(CXListBox::Navy, CXListBox::White, 0, 
		_T("    === Testing multi-file zip ==="));

	HZIP hz = CreateZip(pszArchive2, 0, ZIP_FILENAME);

	if (hz)
	{
		m_List.Printf(CXListBox::Green, CXListBox::White, 0, 
			_T("    Zip archive created OK"));

		if ((ZipAdd(hz, pszName1,  pszName1, 0, ZIP_FILENAME) == ZR_OK) &&
			(ZipAdd(hz, pszName2,  pszName2, 0, ZIP_FILENAME) == ZR_OK) &&
			(ZipAdd(hz, pszName3,  pszName3, 0, ZIP_FILENAME) == ZR_OK) &&
			(ZipAdd(hz, pszName4,  pszName4, 0, ZIP_FILENAME) == ZR_OK) &&
			(ZipAdd(hz, pszName5,  pszName5, 0, ZIP_FILENAME) == ZR_OK) &&
			(ZipAdd(hz, pszName6,  pszName6, 0, ZIP_FILENAME) == ZR_OK) &&
			(ZipAdd(hz, pszName7,  pszName7, 0, ZIP_FILENAME) == ZR_OK) &&
			(ZipAdd(hz, pszName8,  pszName8, 0, ZIP_FILENAME) == ZR_OK) &&
			(ZipAdd(hz, pszName9,  pszName9, 0, ZIP_FILENAME) == ZR_OK))
		{
			m_List.Printf(CXListBox::Green, CXListBox::White, 0, 
				_T("    Files added to zip archive OK"));

			CloseZip(hz);

			hz = OpenZip(pszArchive2, 0, ZIP_FILENAME);

			if (hz)
			{
				m_List.Printf(CXListBox::Green, CXListBox::White, 0, 
					_T("    Zip archive opened OK"));

				GetZipItem(hz, -1, &ze); 
				int numitems = ze.index;

				if (numitems == 9)
				{
					m_List.Printf(CXListBox::Green, CXListBox::White, 0, 
						_T("    Zip archive contains correct number of entries"));


					for (int i = 0; i < numitems; i++)
					{ 
						GetZipItem(hz, i, &ze);
						m_List.Printf(CXListBox::Black, CXListBox::White, 0, 
							_T("        %d:  %s"), i, ze.name);
					}

					VerifyZip(hz, pszName1);
					VerifyZip(hz, pszName2);
					VerifyZip(hz, pszName3);
					VerifyZip(hz, pszName4);
					VerifyZip(hz, pszName5);
					VerifyZip(hz, pszName6);
					VerifyZip(hz, pszName7);
					VerifyZip(hz, pszName8);
					VerifyZip(hz, pszName9);
				}
				else
				{
					m_List.Printf(CXListBox::Red, CXListBox::White, 0, 
						_T("    Number of entries in zip archive is incorrect"));
				}
			}
			else
			{
				m_List.Printf(CXListBox::Red, CXListBox::White, 0, 
					_T("    Failed to open zip archive"));
			}
		}
		else
		{
			m_List.Printf(CXListBox::Red, CXListBox::White, 0, 
				_T("    Failed to add file to zip archive"));
		}
	}
	else
	{
		m_List.Printf(CXListBox::Red, CXListBox::White, 0, 
			_T("    Failed to create zip archive"));
	}

	CloseZip(hz);

	// the files are not deleted - you can inspect them after running test

	//::DeleteFile(pszArchive1);
	//::DeleteFile(pszArchive2);
	//::DeleteFile(pszName1);
	//::DeleteFile(pszName2);
	//::DeleteFile(pszName3);

	m_List.AddLine(CXListBox::Blue, CXListBox::White, _T(""));
}
Esempio n. 11
0
void tSendInnerErrorReport(HWND hInnerWnd)
{
	//-------------------------------------------------------
	CHAR szCurrentDir[MAX_PATH] = {0};
	::GetCurrentDirectory(MAX_PATH, szCurrentDir);

	CHAR szCrashFile[MAX_PATH] = {0};
	SYSTEMTIME timeNow;
	::GetLocalTime(&timeNow);
	_snprintf(szCrashFile, MAX_PATH, "crash%02d_%02d_%02d_%02d.zip", timeNow.wMonth, timeNow.wDay, timeNow.wHour, timeNow.wMinute,timeNow.wSecond);

	//-------------------------------------------------------
	CHAR szLocalFile[MAX_PATH] = {0};
	strncpy(szLocalFile, szCurrentDir, MAX_PATH);
	PathAppend(szLocalFile, szCrashFile);
	HZIP hz = CreateZip((void *)szLocalFile, 0, ZIP_FILENAME);
	if(!hz) 
	{
		MessageBox(hInnerWnd, "Create Error.zip error!", "ErrorReport", MB_OK | MB_ICONSTOP);
		return;
	}

	ZipAdd(hz, "dump.dmp", (void *)g_strDumpFile.c_str(), 0, ZIP_FILENAME);

	//CHAR szLogFile[MAX_PATH];

	//strncpy(szLogFile, szCurrentDir, MAX_PATH);
	//PathAppend(szLogFile, "Fairy.log");
	//ZipAdd(hz, "Fairy.log", (void *)szLogFile, 0, ZIP_FILENAME);

	//strncpy(szLogFile, szCurrentDir, MAX_PATH);
	//PathAppend(szLogFile, "CEGUI.log");
	//ZipAdd(hz, "CEGUI.log", (void *)szLogFile, 0, ZIP_FILENAME);

	CloseZip(hz);

	//-------------------------------------------------------
	//BROWSEINFO binfo; ZeroMemory(&binfo, sizeof(BROWSEINFO));
	//binfo.hwndOwner = hInnerWnd;
	//binfo.pidlRoot = NULL;
	//binfo.ulFlags = BIF_NEWDIALOGSTYLE|BIF_RETURNONLYFSDIRS;
	//binfo.pszDisplayName = NULL;
	//binfo.lpszTitle = "选择一个目录用以保存数据文件";

	//LPITEMIDLIST pRetFold = ::SHBrowseForFolder(&binfo);
	//if(!pRetFold) return;

	//CHAR szReturn[MAX_PATH] = {0};
	//::SHGetPathFromIDList(pRetFold, szReturn);

	////-------------------------------------------------------
	//CHAR szSaveAs[MAX_PATH] = {0};
	//strncpy(szSaveAs, szReturn, MAX_PATH);
	//PathAppend(szSaveAs, szCrashFile);
	//CopyFile(szLocalFile, szSaveAs, FALSE);

	char szCommand[MAX_PATH] = {0};
	PathAppend(szCommand, "upload_dump.bat ");
	strcat(szCommand, szCrashFile);
	system(szCommand);
}
//-----------------------------------------------------------------------------
// Purpose: handles a request
//-----------------------------------------------------------------------------
void CServerRemoteAccess::WriteDataRequest( CRConServer *pNetworkListener, ra_listener_id listener, const void *buffer, int bufferSize)
{
	m_iBytesReceived += bufferSize;
	// ConMsg("RemoteAccess: bytes received: %d\n", m_iBytesReceived);

	if ( bufferSize < 2*sizeof(int) ) // check that the buffer contains at least the id and type
	{
		return;
	}

	CUtlBuffer cmd(buffer, bufferSize, CUtlBuffer::READ_ONLY);
	bool invalidRequest = false;

	while ( invalidRequest == false && (int)cmd.TellGet() < (int)(cmd.Size() - 2 * sizeof(int) ) ) // while there is commands to read
	{
		// parse out the buffer
		int requestID = cmd.GetInt();
		pNetworkListener->SetRequestID( listener, requestID ); // tell the rcon server the ID so it can reflect it when the console redirect flushes
		int requestType = cmd.GetInt();

		switch (requestType)
		{
			case SERVERDATA_REQUESTVALUE:
				{
					if ( IsAuthenticated(listener) )
					{
						char variable[256];
						if ( !GetStringHelper( cmd, variable, sizeof(variable) ) )
						{
							invalidRequest = true;
							break;
						}
						RequestValue( listener, requestID, variable);
						if ( !GetStringHelper( cmd, variable, sizeof(variable) ) )
						{
							invalidRequest = true;
							break;
						}
					}
					else
					{
						char variable[256];
						if ( !GetStringHelper( cmd, variable, sizeof(variable) ) )
						{
							invalidRequest = true;
							break;
						}
						if ( !GetStringHelper( cmd, variable, sizeof(variable) ) )
						{
							invalidRequest = true;
							break;
						}
					}
				}
				break;

			case SERVERDATA_SETVALUE:
				{
					if ( IsAuthenticated(listener) )
					{
						char variable[256];
						char value[256];
						if ( !GetStringHelper( cmd, variable, sizeof(variable) ) )
						{
							invalidRequest = true;
							break;
						}
						if ( !GetStringHelper( cmd, value, sizeof(value) ) )
						{
							invalidRequest = true;
							break;
						}
						SetValue(variable, value);
					}
					else
					{
						char command[512];
						if ( !GetStringHelper( cmd, command, sizeof(command) ) )
						{
							invalidRequest = true;
							break;
						}
						if ( !GetStringHelper( cmd, command, sizeof(command) ) )
						{
							invalidRequest = true;
							break;
						}
					}
				}
				break;

			case SERVERDATA_EXECCOMMAND:
				{
					if ( IsAuthenticated(listener) )
					{
						char command[512];
						if ( !GetStringHelper( cmd, command, sizeof(command) ) )
						{
							invalidRequest = true;
							break;
						}
						
						ExecCommand(command);
						
						if ( listener != m_AdminUIID )
						{
							LogCommand( listener, va( "command \"%s\"", command) );
						}
						if ( !GetStringHelper( cmd, command, sizeof(command) ) )
						{
							invalidRequest = true;
							break;
						}
					}
					else
					{
						char command[512];
						if ( !GetStringHelper( cmd, command, sizeof(command) ) )
						{
							invalidRequest = true;
							break;
						}
						if ( !GetStringHelper( cmd, command, sizeof(command) ) )
						{
							invalidRequest = true;
							break;
						}
						LogCommand( listener, "Bad Password" );
					}
				}
				break;

			case SERVERDATA_AUTH:
				{
					char password[512];
					if ( !GetStringHelper( cmd, password, sizeof(password) ) )
					{
						invalidRequest = true;
						break;
					}
					CheckPassword( pNetworkListener, listener, requestID, password );
					if ( !GetStringHelper( cmd, password, sizeof(password) ) )
					{
						invalidRequest = true;
						break;
					}

					if ( m_ListenerIDs[ listener ].authenticated )
					{
						// if the second string has a non-zero value, it is a userid.
						int userID = atoi( password );
						const ConCommandBase *var = g_pCVar->GetCommands();
						while ( var )
						{
							if ( var->IsCommand() )
							{
								if ( Q_stricmp( var->GetName(), "mp_disable_autokick" ) == 0 )
								{
									Cbuf_AddText( va( "mp_disable_autokick %d\n", userID ) );
									Cbuf_Execute();
									break;
								}
							}
							var = var->GetNext();
						}
					}
				}
				break;

			case SERVERDATA_TAKE_SCREENSHOT:
#ifndef SWDS
				m_nScreenshotListener = listener;
				CL_TakeJpeg( );
#endif
				break;

			case SERVERDATA_SEND_CONSOLE_LOG:
				{
#ifndef SWDS
					const char *pLogFile = GetConsoleLogFilename();
					CUtlBuffer buf( 1024, 0, CUtlBuffer::TEXT_BUFFER );
					if ( g_pFullFileSystem->ReadFile( pLogFile, "GAME", buf ) )
					{
						HZIP hZip = CreateZipZ( 0, 1024 * 1024, ZIP_MEMORY );
						void *pMem;
						unsigned long nLen;
						ZipAdd( hZip, "console.log", buf.Base(), buf.TellMaxPut(), ZIP_MEMORY );
						ZipGetMemory( hZip, &pMem, &nLen );
						SendResponseToClient( listener, SERVERDATA_CONSOLE_LOG_RESPONSE, pMem, nLen );
						CloseZip( hZip );
					}
					else
					{
						LogCommand( listener, "Failed to read console log!\n" );
						RespondString( listener, requestID, "Failed to read console log!\n" );
					}
#endif
				}
				break;

#ifdef VPROF_ENABLED
			case SERVERDATA_VPROF:
				{
					char password[25];
					if ( !GetStringHelper( cmd, password, sizeof(password) ) )
					{
						invalidRequest = true;
						break;
					}
					if ( !GetStringHelper( cmd, password, sizeof(password) ) )
					{
						invalidRequest = true;
						break;
					}
					if ( IsAuthenticated(listener) )
					{
						RegisterVProfDataListener( listener );
						LogCommand( listener, "Remote VProf started!\n" );
						RespondString( listener, requestID, "Remote VProf started!\n" );
					}
				}
				break;
		
			case SERVERDATA_REMOVE_VPROF:
				{
					char password[25];
					if ( !GetStringHelper( cmd, password, sizeof(password) ) )
					{
						invalidRequest = true;
						break;
					}
					if ( !GetStringHelper( cmd, password, sizeof(password) ) )
					{
						invalidRequest = true;
						break;
					}
					if ( IsAuthenticated(listener) )
					{
						RemoveVProfDataListener( listener );
						LogCommand( listener, "Remote VProf finished!\n" );
						RespondString( listener, requestID, "Remote VProf finished!\n" );
					}
				}
				break;
#endif

			default:
				Assert(!("Unknown requestType in CServerRemoteAccess::WriteDataRequest()"));
				cmd.Purge();
				invalidRequest = true;
				break;
		};
	}
}
Esempio n. 13
0
ZIP_API ZRESULT ZipAddData(HZIP zip_handle, const TCHAR* destination_file_name, void* data, unsigned int length){return ZipAdd(zip_handle, destination_file_name, data, length);}
Esempio n. 14
0
int CMainDialog::ZipFiles()
{
	CCrashReporterApp* pApp = DYNAMIC_DOWNCAST(CCrashReporterApp, AfxGetApp());
	ASSERT_VALID(pApp);

	int nFiles = 0;

	// generate zip file name
	m_strZipFile = pApp->m_strAppDataPath;
	m_strZipFile += pApp->m_strUpdateItExe;
	int index = m_strZipFile.ReverseFind(_T('.'));
	if (index > 0)
		m_strZipFile = m_strZipFile.Left(index);
	m_strZipFile += _T(".zip");
	TRACE(_T("m_strZipPath = <%s>\n"), m_strZipFile);

	// backup old zip if it exists
	BackupFile(m_strZipFile);

	HZIP hZip = NULL;

	for (int i = 0; i < m_aFileDetails.GetSize(); i++)
	{
		FILEDETAILS *fd = (FILEDETAILS *) m_aFileDetails[i];

		if (fd)
		{
			// make sure file exists
			if ((_taccess(fd->strFilePath, 00) == 0) && fd->bSend)
			{
				// if this is first file, create zip now
				if (!hZip)
				{
					hZip = CreateZip((LPVOID)(LPCTSTR)m_strZipFile, 0, ZIP_FILENAME);

					if (!hZip)
					{
						TRACE(_T("ERROR - failed to create %s\n"), m_strZipFile);
						break;
					}
				}

				// zip is open, add file

				CString strName = fd->strFilePath;
				int index = strName.ReverseFind(_T('\\'));
				if (index > 0)
					strName = strName.Right(strName.GetLength()-index-1);
				TRACE(_T("strName=<%s>\n"), strName);

				ZRESULT zr = ZipAdd(hZip, 
									strName, 
									(LPVOID)(LPCTSTR)fd->strFilePath, 
									0, 
									ZIP_FILENAME);
				if (zr == ZR_OK)
				{
					nFiles++;
				}
				else
				{
					TRACE(_T("ERROR - failed to add '%s' to zip\n"), fd->strFilePath);
				}
			}
		}
	}

	if (hZip)
		CloseZip(hZip);

	return nFiles;
}
Esempio n. 15
0
ZIP_API ZRESULT ZipAddFile(HZIP zip_handle, const TCHAR* destination_file_name, const TCHAR* source_file_name){return ZipAdd(zip_handle, destination_file_name, source_file_name);}
Esempio n. 16
0
int ArchiveFileRaw(RecorderProperties *ws, bool sender) {

	if (CloseFileStream(ws->rawStream) != status_ok) {
		return status_io_error;
	}
	if (CloseFileStream(ws->logStream) != status_ok) {
		return status_io_error;
	}

	time_t now_local = time(NULL);

	struct tm lt;

	now_local -= 3600; //prev day
	localtime_s(&lt, &now_local);

	wchar_t szBuf[MAX_PATH];
	_snwprintf(szBuf, MAX_PATH, L"%d-%02d-%02d\\", lt.tm_year + 1900,
			lt.tm_mon + 1, lt.tm_mday);
	wstring todayFolder = ws->parameters.logDailyPath + szBuf;

	CreateDirectory(todayFolder.data(), 0);
	HZIP todayZip;
	ZRESULT zipResult;
	//ziping raw
	if (!sender) {
		wstring archiveRawFilePath = todayFolder + ws->parameters.rawCurrentFile
				+ L".zip";
		todayZip = CreateZip((void*) archiveRawFilePath.data(), 0,
		ZIP_FILENAME);
		zipResult = ZipAdd(todayZip, ws->parameters.rawCurrentFile.data(),
				(void*) (ws->parameters.rawCurrentPath
						+ ws->parameters.rawCurrentFile).data(), 0,
				ZIP_FILENAME);
		CloseZip(todayZip);
		if (zipResult != ZR_OK) {
			WriteFileLogf(L"Raw zip creation failed");
		}
	}

	//ziping log
	wstring archiveLogFilePath = todayFolder + ws->parameters.name + L"log.zip";
	todayZip = CreateZip((void*) archiveLogFilePath.data(), 0, ZIP_FILENAME);
	wstring logFile = wstring(ws->parameters.name + L"rec.log");
	zipResult = ZipAdd(todayZip, logFile.data(),
			(void*) (ws->parameters.rawCurrentPath + logFile).data(), 0,
			ZIP_FILENAME);
	CloseZip(todayZip);
	if (zipResult != ZR_OK) {
		WriteFileLogf(L"Log zip creation failed");
	}

	if (!sender
			&& OpenFileStream(ws->rawStream,
					ws->parameters.rawCurrentPath
							+ ws->parameters.rawCurrentFile, true)
					!= status_ok) {
		return status_io_error;
	}

	if (OpenFileStream(ws->logStream, ws->sysLogPath, true) != status_ok) {
		return status_io_error;
	}

	return status_ok;
}
Esempio n. 17
0
void main()
{ CreateFiles();
  HZIP hz; DWORD writ;

  // EXAMPLE 1 - create a zipfile from existing files
  hz = CreateZip(_T("\\simple1.zip"),0);
  ZipAdd(hz,_T("znsimple.bmp"), _T("\\simple.bmp"));
  ZipAdd(hz,_T("znsimple.txt"), _T("\\simple.txt"));
  CloseZip(hz);
  _tprintf(_T("Created '\\simple1.zip'\n"));


  // EXAMPLE 2 - unzip it with the names suggested in the zip
  hz = OpenZip(_T("\\simple1.zip"),0);
  SetUnzipBaseDir(hz,_T("\\"));
  ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index;
  for (int zi=0; zi<numitems; zi++)
  { GetZipItem(hz,zi,&ze);
    UnzipItem(hz,zi,ze.name);
  }
  CloseZip(hz);
  _tprintf(_T("Unzipped 'znsimple.bmp' and 'znsimple.txt' from 'simple1.zip'\n"));



  // EXAMPLE 3 - create an auto-allocated pagefile-based zip file from various sources
  // the second argument says how much address space to reserve for it. We can
  // afford to be generous: no address-space is allocated unless it's actually needed.
  hz = CreateZip(0,100000,"password");
  // adding a conventional file...
  ZipAdd(hz,_T("znsimple.txt"),  _T("\\simple.txt"));
  // adding something from memory...
  char buf[1000]; for (int zj=0; zj<1000; zj++) buf[zj]=(char)(zj&0x7F);
  ZipAdd(hz,_T("simple.dat"),  buf,1000);
  // adding something from a pipe...
#ifndef UNDER_CE
  HANDLE hread,hwrite; CreatePipe(&hread,&hwrite,NULL,0);
  DWORD WINAPI Ex3ThreadFunc(void *dat);
  HANDLE hthread = CreateThread(0,0,Ex3ThreadFunc,(void*)hwrite,0,0);
  ZipAddHandle(hz,_T("simple3.dat"),  hread,1000);  // the '1000' is optional, but it makes for nicer zip files if sizes are known in advance.
  WaitForSingleObject(hthread,INFINITE);
  CloseHandle(hthread); CloseHandle(hread); // the thread will close hwrite
#endif
  //
  // and now that the zip is created in pagefile, let's do something with it:
  void *zbuf; unsigned long zlen; ZipGetMemory(hz,&zbuf,&zlen);
  HANDLE hfz = CreateFile(_T("\\simple3 - pwd is 'password'.zip"),GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
  WriteFile(hfz,zbuf,zlen,&writ,NULL);
  CloseHandle(hfz);
  CloseZip(hz);
  _tprintf(_T("Created 'simple3.zip' via pagefile\n"));


  // EXAMPLE 4 - unzip directly from resource into a file
  // resource RT_RCDATA/#1 happens to be a zip file...
  HINSTANCE hInstance=GetModuleHandle(0);
  HRSRC hrsrc = FindResource(hInstance,MAKEINTRESOURCE(1),RT_RCDATA);
  HANDLE hglob = LoadResource(hInstance,hrsrc);
  void *zipbuf=LockResource(hglob);
  unsigned int ziplen=SizeofResource(hInstance,hrsrc);
  hz = OpenZip(zipbuf, ziplen, 0);  SetUnzipBaseDir(hz,_T("\\"));
  int i; FindZipItem(hz,_T("simple.jpg"),true,&i,&ze);
  //   - unzip to a file -
  UnzipItem(hz,i,ze.name);
  //   - unzip to a membuffer -
  char *ibuf = new char[ze.unc_size];
  UnzipItem(hz,i, ibuf, ze.unc_size);
  delete[] ibuf;
  //   - unzip to a fixed membuff, bit by bit -
  char fbuf[1024]; ZRESULT zr=ZR_MORE; unsigned long totsize=0;
  while (zr==ZR_MORE)
  { zr = UnzipItem(hz,i, fbuf,1024);
    unsigned long bufsize=1024; if (zr==ZR_OK) bufsize=ze.unc_size-totsize;
    // now do something with this chunk which we just unzipped...
    totsize+=bufsize;
  }
  //   - finished -
  CloseZip(hz);
  // note: no need to free resources obtained through Find/Load/LockResource
  _tprintf(_T("Unzipped 'simple.jpg' from resource zipfile\n"));


  
  DeleteFile(_T("\\simple.txt"));
  DeleteFile(_T("\\simple.bmp"));
  _tprintf(_T("Deleted 'simple.txt' and 'simple.bmp'\n"));
}