Пример #1
0
UINT WINAPI CExtractData::DecodeThread(LPVOID lpParam)
{
	CExtractData* pObj = (CExtractData*)lpParam;
	CArcFile* pclArc = NULL;

	try
	{
		SOption* pOption  = pObj->m_pOption;
		LPCTSTR  pSaveDir = pObj->m_pSaveDir;
		BOOL     bConvert = pObj->m_bConvert;

		// Determine entire filesize
		std::vector<int> nSelects;
		QWORD AllFileSize = 0;
		std::vector<CArcFile*>& rArcList = pObj->m_ArcList;
		if (pObj->m_dwExtractMode == EXTRACT_SELECT)
		{
			int nItem = -1;
			while ((nItem = pObj->m_pListView->GetNextItem(nItem)) != -1)
			{
				nSelects.push_back(nItem);
				AllFileSize += rArcList[0]->GetFileInfo(nItem)->sizeOrg;
			}
		}
		else
		{
			size_t nItemCount = rArcList[0]->GetFileInfo().size();
			for (int nItem = 0; nItem < (int)nItemCount; nItem++)
			{
				nSelects.push_back(nItem);
				AllFileSize += rArcList[0]->GetFileInfo(nItem)->sizeOrg;
			}
		}

		// Initialize progressbar
		CProgBar prog;
		prog.Init(pObj->m_hWnd, AllFileSize);

		for (size_t i = 0; i < nSelects.size(); i++)
		{
			SFileInfo* pInfFile = rArcList[0]->GetFileInfo(nSelects[i]);
			pclArc = rArcList[pInfFile->arcID];
			pclArc->SetProg(prog);

			// Create destination folder name from the destination filename input
			if (pSaveDir == NULL && pOption->bSaveSrc == TRUE)
			{
				TCHAR SaveDir[MAX_PATH];

				// Get input
				lstrcpy(SaveDir, pclArc->GetArcPath());

				// Delete the filename
				PathRemoveFileSpec(SaveDir);

				if (pclArc->GetCtEnt() == 1)
				{
					// Archive folder creation stores files one by one
					TCHAR ArcDirName[_MAX_DIR];
					lstrcpy(ArcDirName, PathFindFileName(SaveDir));
					PathAppend(SaveDir, _T("_"));
					lstrcat(SaveDir, ArcDirName);
				}
				else
				{
					// Create a folder with the name of the archive files if there are more than two files present
					PathAppend(SaveDir, _T("_"));
					lstrcat(SaveDir, pclArc->GetArcName());
				}
				pclArc->SetSaveDir(SaveDir);
			}
			else
			{
				pclArc->SetSaveDir(pSaveDir);
			}

			pclArc->SetFileInfo(nSelects[i]);

			// View filename
			prog.SetFileName(pInfFile->name);

			// Extraction
			CExtract::Decode(pclArc, bConvert);

			// Close the file (For when I forget to close it)
			pclArc->CloseFile();
		}
		//MessageBox(pObj->m_hWnd, "", "", MB_OK);
	}
	catch (std::bad_alloc)
	{
		// Out of memory error
		CError error;
		error.bad_alloc(pObj->m_hWnd);
	}
	catch (...)
	{
		// Or if we cancel the operation
		//CError error;
		//error.Message(pObj->m_hWnd, "");
		// Corresponds to the case where the file was still not closed, even with the exception thrown.
		//if (pclArc != NULL)
		//	pclArc->CloseFile();
	}

	// Corresponds to the case where the file was still not closed, even with the exception thrown.
	if (pclArc != NULL)
		pclArc->CloseFile();

	// Send message to terminate the thread
	PostMessage(pObj->m_hWnd, WM_THREAD_END, 0, 0);

	_endthreadex(0);

	return 0;
}
Пример #2
0
UINT WINAPI CExtractData::MountThread(LPVOID lpParam)
{
	CExtractData* pObj = (CExtractData*)lpParam;

	try
	{
		SOption* pOption = pObj->m_pOption;
		LPCTSTR pclArcNames = pObj->m_pclArcNames;
		std::vector<SFileInfo>& rEnt = pObj->m_pListView->GetFileInfo();

		std::vector<YCString> sArcNameList;

		YCString sArcNames(pclArcNames);
		sArcNameList.push_back(sArcNames);
		pclArcNames += lstrlen(pclArcNames) + 1; // Because of ZeroMemory, we have to add one for the null terminator char.

		// If you select more than one
		if (lstrcmp(pclArcNames, _T("")) != 0)
		{
			// Get directory name
			TCHAR tmpDir[_MAX_DIR];
			lstrcpy(tmpDir, sArcNameList[0]);
			PathAddBackslash(tmpDir);
			YCString Dir(tmpDir);
			sArcNameList.clear();

			// Directory Name + Filename in the list.
			while (lstrcmp(pclArcNames, _T("")) != 0)
			{
				YCString sArcName(pclArcNames);
				sArcNameList.push_back(Dir + sArcName);
				pclArcNames += lstrlen(pclArcNames) + 1;
			}

			sort(sArcNameList.begin(), sArcNameList.end());
		}

		// Entire file size
		QWORD AllArcSize = 0;
		std::vector<CArcFile*>& rArcList = pObj->m_ArcList;
		for (std::vector<YCString>::iterator itr = sArcNameList.begin(); itr != sArcNameList.end(); )
		{
			// Open the archive file
			CArcFile* pclArc = new CArcFile();

			if (!pclArc->Open(*itr))
			{
				itr = sArcNameList.erase(itr); // Remove archive files that could not be opened from the list
				delete pclArc;
			}
			else
			{
				// Add archive filesize

				AllArcSize += pclArc->GetArcSize();
				rArcList.push_back(pclArc);
				itr++;
			}
		}

		// Initialize the progress bar
		CProgBar prog;
		prog.Init(pObj->m_hWnd, AllArcSize);

		// Reading
		DWORD dwArcID = 0;
		//for (std::vector<CArcFile*>::iterator itrArc = rArcList.begin(); itrArc != rArcList.end(); ) {
		for (size_t i = 0; i < rArcList.size(); i++)
		{
			CArcFile* pclArc = rArcList[i];
			pclArc->SetArcID(dwArcID);
			pclArc->SetEnt(rEnt);
			pclArc->SetProg(prog);
			pclArc->SetOpt(pOption);

			// View the archive filename
			prog.SetArcName(pclArc->GetArcName());

			// Corresponding file
			if (CExtract::Mount(pclArc) == TRUE)
			{
				dwArcID++;
				pclArc->SetState(TRUE);
			}
		}
		//MessageBox(pObj->m_hWnd, "", "", MB_OK);
		// Progress towards 100%
		prog.UpdatePercent();
	}
	catch (std::bad_alloc)
	{
		// Out of memory
		CError error;
		error.bad_alloc(pObj->m_hWnd);
	}
	catch (...)
	{
		// or if canceled
	}

	PostMessage(pObj->m_hWnd, WM_THREAD_END, 0, 0);

	_endthreadex(0);

	return 0;
}