bool MkInterfaceForZipFileWriting::SetUp(const MkPathName& filePath, bool overwrite, bool makeDirectoryPath)
{
	Clear();

	m_CurrentFilePath.ConvertToRootBasisAbsolutePath(filePath);

	if (makeDirectoryPath)
	{
		MkPathName dirPath = m_CurrentFilePath.GetPath();
		bool ok = dirPath.MakeDirectoryPath();
		MK_CHECK(ok, m_CurrentFilePath.GetFileName() + L" 파일을 위한 " + dirPath + L" 경로 생성 실패")
			return false;
	}

	int append = APPEND_STATUS_CREATE;
	if (m_CurrentFilePath.CheckAvailable())
	{
		if (overwrite)
		{
			append = APPEND_STATUS_ADDINZIP;
		}
		else
		{
			m_CurrentFilePath.DeleteCurrentFile();
		}
	}

	std::string charPath;
	m_CurrentFilePath.ExportMultiByteString(charPath);
	m_ZipFile = zipOpen(charPath.c_str(), append);
	return (m_ZipFile != NULL);
}
bool MkInterfaceForZipFileWriting::Write(const MkPathName& filePath, const MkByteArray& srcArray)
{
	if (m_ZipFile == NULL)
		return false;

	std::string charPath;
	filePath.ExportMultiByteString(charPath);
	if (zipOpenNewFileInZip(m_ZipFile, charPath.c_str(), NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION) != ZIP_OK)
		return false;
	
	if (zipWriteInFileInZip(m_ZipFile, srcArray.GetPtr(), srcArray.GetSize()) < 0)
		return false;

	zipCloseFileInZip(m_ZipFile);
	return true;
}
Пример #3
0
bool MkSoundBuffer::SetUp(LPDIRECTSOUND directSound, const MkPathName& filePath)
{
	if (directSound == NULL)
		return false;

	Clear();

	do
	{
		MkStr ext = filePath.GetFileExtension();
		ext.ToLower();

		bool isWave = ext.Equals(0, L"wav");
		bool isOgg = ext.Equals(0, L"ogg");
		
		if ((!isWave) && (!isOgg))
			break;

		// file data
		MkByteArray srcData;
		MK_CHECK(MkFileManager::GetFileData(filePath, srcData), L"음원 파일 로딩 실패 : " + filePath)
			break;

		if (srcData.Empty())
			break;

		if (isWave)
		{
			if (!_CreateBufferFromWaveFile(directSound, srcData))
				break;
		}
		else if (isOgg)
		{
			if (!_CreateBufferFromOggFile(directSound, srcData))
				break;
		}
		else
			break;

		_UpdateInformation();
		return true;
	}
	while (false);

	Clear();
	return false;
}
Пример #4
0
bool MkFileChunk::AttachOriginalFiles
(const MkPathName& chunkFilePath, MkFilePathListContainer& filePathListContainer, MkArray<MkPathName>& memberFilePathList,
 unsigned int chunkSizeGuideline, unsigned int percentageForCompressing, bool createNewChunk)
{
	memberFilePathList.Clear();

	MkArray<MkPathName>& relativeFilePathList = filePathListContainer.GetRelativeFilePathList();
	unsigned int startCount = relativeFilePathList.GetSize();
	MK_CHECK(startCount > 0, L"파일 경로 리스트가 비어 " + m_AbsoluteChunkFilePath + L" 청크 파일 구성 불가")
		return false;

	if (createNewChunk)
	{
		MK_CHECK(!chunkFilePath.IsDirectoryPath(), chunkFilePath + L" 청크 파일 경로 오류")
			return false;

		Clear();

		// 새 청크 파일 이름
		m_AbsoluteChunkFilePath.ConvertToRootBasisAbsolutePath(chunkFilePath);
	}

	// 크기 예약
	m_BlockList.Reserve(m_BlockList.GetSize() + startCount);
	memberFilePathList.Reserve(startCount);

	// 인터페이스 생성. createNewChunk에 따라 청크 파일 생성
	MkInterfaceForFileWriting chunkFileInterface;
	if (!chunkFileInterface.SetUp(m_AbsoluteChunkFilePath, createNewChunk))
		return false;

	// 새 청크 파일의 경우 블록 카운트를 기록하기 위한 태그 공간 확보
	if (createNewChunk)
	{
		m_ChunkSize = sizeof(unsigned int);
		_AddCountTag(chunkFileInterface, m_ChunkSize);
	}

	// 뒤에서부터 앞으로 순회
	MK_INDEXING_RLOOP(relativeFilePathList, i)
	{
		const MkPathName& currPath = filePathListContainer.GetRelativeFilePath(i);

		MkFileBlock& currBlock = m_BlockList.PushBack();
		unsigned int blockSize = currBlock.SetUpFromOriginalFileAndAttachToChunkFile
			(filePathListContainer.GetAbsoluteOriginalFilePath(i), currPath, chunkFileInterface, percentageForCompressing, filePathListContainer.GetOuterWrittenTime(i));

		if (blockSize == 0)
		{
			if (createNewChunk)
			{
				m_AbsoluteChunkFilePath.DeleteCurrentFile();
			}
			return false;
		}

		memberFilePathList.PushBack(currPath);

		++m_AvailableBlockCount;

		m_ChunkSize += blockSize;
		if (m_ChunkSize >= chunkSizeGuideline)
			break;
	}

	chunkFileInterface.Clear();

	// 블록 카운트 수정
	MkInterfaceForFileTag<unsigned int> ftInterface;
	if (!ftInterface.SetUp(m_AbsoluteChunkFilePath))
	{
		if (createNewChunk)
		{
			m_AbsoluteChunkFilePath.DeleteCurrentFile();
		}
		return false;
	}

	ftInterface.Overwrite(m_BlockList.GetSize(), 0);
	ftInterface.Clear();

	// 청크에 구성된 파일들을 리스트에서 삭제
	filePathListContainer.PopBack(memberFilePathList.GetSize());
	return true;
}
Пример #5
0
void MkShaderEffectPool::SetUp(const MkPathName& shaderDirectory)
{
	LPDIRECT3DDEVICE9 device = MK_DEVICE_MGR.GetDevice();
	MK_CHECK(device != NULL, L"NULL device여서 MkShaderEffectPool 초기화 실패")
		return;

	// 경로 점검
	MkPathName dirPath;
	dirPath.ConvertToRootBasisAbsolutePath(shaderDirectory);
	dirPath.CheckAndAddBackslash();
	MK_CHECK(dirPath.IsDirectoryPath() && dirPath.CheckAvailable(), dirPath + L" 경로가 존재하지 않아 MkShaderEffectPool 초기화 실패")
		return;

	// fxo 파일 검색
	MkArray<MkPathName> filePathList;
	MkArray<MkPathName> emptyFilter;
	MkArray<MkStr> prefixFilter;
	MkArray<MkPathName> extensionFilter;
	extensionFilter.PushBack(L"fxo");
	dirPath.GetWhiteFileList(filePathList, emptyFilter, extensionFilter, prefixFilter, emptyFilter, false, false);

	MK_INDEXING_LOOP(filePathList, i)
	{
		MkHashStr effectName = filePathList[i].GetFileName(false);
		MkPathName currFilePath = dirPath + filePathList[i];
		unsigned int fileSize = currFilePath.GetFileSize();
		unsigned int writtenTime = currFilePath.GetWrittenTime();
		
		if (m_Pool.Exist(effectName))
		{
			_EffectData& ed = m_Pool[effectName];
			if ((ed.fileSize != fileSize) || (ed.fileWrittenTime != writtenTime)) // 크기/수정일시 변경 확인
			{
				ed.effect->Clear();
				if (ed.effect->SetUp(effectName, currFilePath))
				{
					ed.fileSize = fileSize;
					ed.fileWrittenTime = writtenTime;

					MK_DEV_PANEL.MsgToLog(effectName.GetString() + L" effect 갱신");
				}
				else
				{
					delete ed.effect;
					m_Pool.Erase(effectName);
				}
			}
		}
		else
		{
			MkShaderEffect* effect = new MkShaderEffect;
			MK_CHECK(effect != NULL, effectName.GetString() + L" effect 객체 생성 실패")
				continue;

			if (effect->SetUp(effectName, currFilePath))
			{
				_EffectData& ed = m_Pool.Create(effectName);
				ed.effect = effect;
				ed.fileSize = fileSize;
				ed.fileWrittenTime = writtenTime;

				MK_DEV_PANEL.MsgToLog(effectName.GetString() + L" effect 생성");
			}
			else
			{
				delete effect;
			}
		}
	}
Пример #6
0
	virtual bool SetUp(MkDataNode& sharingNode)
	{
		// [ data 형태 정의 ]
		//------------------------------------------------------------------------------------------------//
		// int a;
		// float b;
		// MkVec3 c;
		// wchar_t d[64];
		//------------------------------------------------------------------------------------------------//

		// data 크기 계산
		const unsigned int sizeOfUnit =
			sizeof(int) // a
			+ sizeof(float) // b
			+ sizeof(MkVec3) // c
			+ sizeof(wchar_t) * 64; // d

		const unsigned int sizeOfData = sizeOfUnit * SIZE_COUNT;

		// chunk data 생성
		unsigned char* chunkData = new unsigned char[sizeOfData];
		ZeroMemory(chunkData, sizeOfData);

		unsigned int recordPosition = 0;
		for (int i=0; i<SIZE_COUNT; ++i)
		{
			float f = static_cast<float>(i);

			// a
			const int a = i;
			memcpy_s(&chunkData[recordPosition], sizeof(int), reinterpret_cast<const unsigned char*>(&a), sizeof(int));
			recordPosition += sizeof(int);

			// b
			const float b = f * -10.f;
			memcpy_s(&chunkData[recordPosition], sizeof(float), reinterpret_cast<const unsigned char*>(&b), sizeof(float));
			recordPosition += sizeof(float);

			// c
			const MkVec3 c = MkVec3(f, f * -2.f, f * 3.f);
			memcpy_s(&chunkData[recordPosition], sizeof(MkVec3), reinterpret_cast<const unsigned char*>(&c), sizeof(MkVec3));
			recordPosition += sizeof(MkVec3);

			// d
			wcscpy_s(reinterpret_cast<wchar_t*>(&chunkData[recordPosition]), 64, L"잘생겨서 죄송요~");
			recordPosition += sizeof(wchar_t) * 64;
		}

		// chunkData -> 파일로 출력
		std::ofstream ostream;
		ostream.open(L"test.data", std::ios::out | std::ios::binary | std::ios::trunc);
		if (ostream.is_open())
		{
			ostream.write(reinterpret_cast<const char*>(chunkData), sizeOfData);
			ostream.close();
		}

		delete [] chunkData;

		// chunk data 버퍼 생성 및 초기화
		unsigned char* chunkBuffer = new unsigned char[sizeOfData];
		ZeroMemory(chunkBuffer, sizeOfData);

		// 파일에서 읽기 -> chunkBuffer
		std::ifstream rstream;
		rstream.open(L"test.data", std::ios::in | std::ios::binary);
		if (rstream.is_open())
		{
			rstream.read(reinterpret_cast<char*>(chunkBuffer), sizeOfData);
			rstream.close();
		}

		MK_DEV_PANEL.MsgToLog(MkStr::EMPTY); // 빈 칸 하나 넣고,

		// 읽어들인 결과 출력. 첫번째와 마지막 unit 대상
		unsigned int readPosition = 0;

		// 첫번째 unit
		int a = 0;
		memcpy_s(reinterpret_cast<unsigned char*>(&a), sizeof(int), &chunkBuffer[readPosition], sizeof(int));
		readPosition += sizeof(int);

		float b = 0.f;
		memcpy_s(reinterpret_cast<unsigned char*>(&b), sizeof(float), &chunkBuffer[readPosition], sizeof(float));
		readPosition += sizeof(float);

		MkVec3 c = MkVec3::Zero;
		memcpy_s(reinterpret_cast<unsigned char*>(&c), sizeof(MkVec3), &chunkBuffer[readPosition], sizeof(MkVec3));
		readPosition += sizeof(MkVec3);

		wchar_t d[64] = {0, };
		memcpy_s(reinterpret_cast<unsigned char*>(d), sizeof(wchar_t) * 64, &chunkBuffer[readPosition], sizeof(wchar_t) * 64);

		MK_DEV_PANEL.MsgToLog(L"[ First unit ]");
		MK_DEV_PANEL.MsgToLog(L"   a : " + MkStr(a));
		MK_DEV_PANEL.MsgToLog(L"   b : " + MkStr(b));
		MK_DEV_PANEL.MsgToLog(L"   c : " + MkStr(c));
		MK_DEV_PANEL.MsgToLog(L"   d : " + MkStr(d));

		// 마지막 unit
		readPosition = sizeOfUnit * (SIZE_COUNT - 1);

		a = 0;
		memcpy_s(reinterpret_cast<unsigned char*>(&a), sizeof(int), &chunkBuffer[readPosition], sizeof(int));
		readPosition += sizeof(int);

		b = 0.f;
		memcpy_s(reinterpret_cast<unsigned char*>(&b), sizeof(float), &chunkBuffer[readPosition], sizeof(float));
		readPosition += sizeof(float);

		c = MkVec3::Zero;
		memcpy_s(reinterpret_cast<unsigned char*>(&c), sizeof(MkVec3), &chunkBuffer[readPosition], sizeof(MkVec3));
		readPosition += sizeof(MkVec3);

		ZeroMemory(d, sizeof(wchar_t) * 64);
		memcpy_s(reinterpret_cast<unsigned char*>(d), sizeof(wchar_t) * 64, &chunkBuffer[readPosition], sizeof(wchar_t) * 64);

		MK_DEV_PANEL.MsgToLog(L"[ Last unit ]");
		MK_DEV_PANEL.MsgToLog(L"   a : " + MkStr(a));
		MK_DEV_PANEL.MsgToLog(L"   b : " + MkStr(b));
		MK_DEV_PANEL.MsgToLog(L"   c : " + MkStr(c));
		MK_DEV_PANEL.MsgToLog(L"   d : " + MkStr(d));

		delete [] chunkBuffer;

		// 출력 폴더 열기
		MkPathName targetDir = MkPathName::GetRootDirectory() + L"..\\..\\"; // project foler
		targetDir.OpenDirectoryInExplorer();

		return true;
	}