Esempio n. 1
0
VFS_BOOL CArchive::IterateDir( const VFS_String& strDirName, VFS_DirIterationProc pIterationProc, VFS_BOOL bRecursive, void* pParam ) const
{
	// Get the dir for the name.
	VFS_DWORD dwDirIndex;
	VFS_String strDir = WithoutTrailingSeparator( ToLower( strDirName ), VFS_TRUE );
	if( strDir != VFS_TEXT( "" ) )
	{
		ArchiveDirMap::const_iterator iter = m_Header.DirHash.find( ToLower( strDir ) );
		if( iter == m_Header.DirHash.end() )
		{
			SetLastError( VFS_ERROR_NOT_FOUND );
			return VFS_FALSE;
		}
		dwDirIndex = ( *iter ).second;
	}
	else
		dwDirIndex = DIR_INDEX_ROOT;

	// Iterate for all Dirs in the Dir and call IterateDir() on these (if in Recursive Mode).
	VFS_DWORD dwIndex;
	for( dwIndex = 0; dwIndex < m_Header.Dirs.size(); dwIndex++ )
	{
		if( m_Header.Dirs[ dwIndex ].dwParentDirIndex != dwDirIndex )
			continue;

		VFS_EntityInfo Info;
		Info.bArchived = VFS_TRUE;
		Info.eType = VFS_DIR;
		Info.lSize = 0;
		Info.strPath = GetFileNameWithoutExtension() + VFS_PATH_SEPARATOR + m_Header.Dirs[ dwIndex ].strName;
		if( !VFS_Util_GetName( Info.strPath, Info.strName ) )
			return VFS_FALSE;

		if( !pIterationProc( Info, pParam ) )
			return VFS_TRUE;

        if( bRecursive && !IterateDir( m_Header.Dirs[ dwIndex ].strName, pIterationProc, bRecursive, pParam ) )
			return VFS_FALSE;
	}

	// Iterate for all Files in the Dir.
	for( dwIndex = 0; dwIndex < m_Header.Files.size(); dwIndex++ )
	{
		if( m_Header.Files[ dwIndex ].dwDirIndex != dwDirIndex )
			continue;

		VFS_EntityInfo Info;
		Info.bArchived = VFS_TRUE;
		Info.eType = VFS_FILE;
		Info.lSize = m_Header.Files[ dwIndex ].dwUncompressedSize;
		Info.strPath = GetFileNameWithoutExtension() + VFS_PATH_SEPARATOR + m_Header.Files[ dwIndex ].strName;
		if( !VFS_Util_GetName( Info.strPath, Info.strName ) )
			return VFS_FALSE;

		if( !pIterationProc( Info, pParam ) )
			return VFS_TRUE;
	}

	return VFS_TRUE;
}
Esempio n. 2
0
void Model::CreateFromXFile(ID3D11Device* device, LPCWSTR fileName,
    const WCHAR* normalMapSuffix, bool generateNormals,
    bool generateTangentFrame, Mesh::IndexType idxType)
{
    _ASSERT(FileExists(fileName));

    IDirect3DDevice9Ptr d3d9Device = CreateD3D9Device();

    // Load the D3DX mesh
    ID3DXMesh* d3dxMesh = NULL;
    ID3DXBuffer* adjacencyBuffer = NULL;
    ID3DXBuffer* materialsBuffer = NULL;
    DWORD numMaterials = 0;

    UINT options = D3DXMESH_MANAGED;
    if (idxType == Mesh::Index32Bit)
        options |= D3DXMESH_32BIT;
    DXCall(D3DXLoadMeshFromXW(fileName, options, d3d9Device, &adjacencyBuffer,
        &materialsBuffer, NULL, &numMaterials, &d3dxMesh));

    IUnknownReleaser<ID3DXMesh> meshReleaser(d3dxMesh);
    IUnknownReleaser<ID3DXBuffer> adjReleaser(adjacencyBuffer);
    IUnknownReleaser<ID3DXBuffer> matReleaser(materialsBuffer);

    DWORD* initalAdjacency = reinterpret_cast<DWORD*>(adjacencyBuffer->GetBufferPointer());
    D3DXMATERIAL* materials = reinterpret_cast<D3DXMATERIAL*>(materialsBuffer->GetBufferPointer());

    // Get the directory the mesh was loaded from
    wstring fileDirectory = GetDirectoryFromFileName(fileName);

    // Convert materials
    for (UINT i = 0; i < numMaterials; ++i)
    {
        MeshMaterial material;
        D3DXMATERIAL& srcMaterial = materials[i];

        material.AmbientAlbedo = XMFLOAT3(reinterpret_cast<float*>(&srcMaterial.MatD3D.Ambient));
        material.DiffuseAlbedo = XMFLOAT3(reinterpret_cast<float*>(&srcMaterial.MatD3D.Diffuse));
        material.SpecularAlbedo = XMFLOAT3(reinterpret_cast<float*>(&srcMaterial.MatD3D.Specular));
        material.Emissive = XMFLOAT3(reinterpret_cast<float*>(&srcMaterial.MatD3D.Emissive));
        material.SpecularPower = srcMaterial.MatD3D.Power;
        material.Alpha = srcMaterial.MatD3D.Diffuse.a;
        material.DiffuseMapName = AnsiToWString(srcMaterial.pTextureFilename);

        // Add the normal map prefix
        if (normalMapSuffix && material.DiffuseMapName.length() > 0)
        {
            wstring base = GetFileNameWithoutExtension(material.DiffuseMapName.c_str());
            wstring extension = GetFileExtension(material.DiffuseMapName.c_str());
            material.NormalMapName = base + normalMapSuffix + L"." + extension;
        }

        LoadMaterialResources(material, fileDirectory, device);
    }

    // Make a single mesh
    Mesh mesh;
    mesh.CreateFromD3DXMesh(fileDirectory, device, d3d9Device, d3dxMesh, generateNormals, generateTangentFrame, initalAdjacency, idxType);
    meshes.push_back(mesh);
}
ImageGlyph::ImageGlyph(const std::string& file, AlloyContext* context,
		bool mipmap) :
		Glyph(GetFileNameWithoutExtension(file), GlyphType::Image, 0, 0), file(
				file) {
	handle = nvgCreateImage(context->nvgContext, file.c_str(),
			(mipmap) ? NVG_IMAGE_GENERATE_MIPMAPS : 0);
	int w, h;
	nvgImageSize(context->nvgContext, handle, &w, &h);
	width = (pixel) w;
	height = (pixel) h;
}
Esempio n. 4
0
void BackgroundUtil::GetBackgroundEffects( const RString &_sName, vector<RString> &vsPathsOut, vector<RString> &vsNamesOut )
{
	RString sName = _sName;
	if( sName == "" )
		sName = "*";

	vsPathsOut.clear();
	GetDirListing( BACKGROUND_EFFECTS_DIR+sName+".lua", vsPathsOut, false, true );
	
	vsNamesOut.clear();
	FOREACH_CONST( RString, vsPathsOut, s )
		vsNamesOut.push_back( GetFileNameWithoutExtension(*s) );

	StripCvsAndSvn( vsPathsOut, vsNamesOut );
}
Esempio n. 5
0
		bool LoadMeshData(const char* i_binaryMeshFile)
		{
			uint32_t vertexElementCount = 0;
			VertexElement* pVertexElement = nullptr;
			uint32_t vertexOffset = 0;
			uint32_t vertexCount = 0;
			uint32_t indexOffset = 0;
			uint32_t indexCount = 0;
			uint32_t subMeshOffset = 0;
			uint32_t subMeshCount = 0;
			uint8_t* pBuffer = LoadMeshInfo(i_binaryMeshFile, vertexElementCount, pVertexElement,
				vertexOffset, vertexCount, indexOffset, indexCount, subMeshOffset, subMeshCount);
			AOSMeshData* pAOSMeshData = new AOSMeshData();
			sVertex* pVertices = (sVertex*)(pBuffer + vertexOffset);
			for (uint32_t vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
			{
				sVertex& vertex = pVertices[vertexIndex];
				pAOSMeshData->_vertices.push_back(vertex);
			}
			uint32_t* pIndices = (uint32_t*)(pBuffer + indexOffset);
			for (uint32_t index = 0; index < indexCount; index += 3)
			{
				uint32_t& indexValue0 = pIndices[index + 0];
				uint32_t& indexValue1 = pIndices[index + 1];
				uint32_t& indexValue2 = pIndices[index + 2];
				pAOSMeshData->_indices.push_back(indexValue0);
#if defined( EAEENGINE_PLATFORM_D3D9 )
				pAOSMeshData->_indices.push_back(indexValue2);
				pAOSMeshData->_indices.push_back(indexValue1);
#elif defined( EAEENGINE_PLATFORM_GL )
				pAOSMeshData->_indices.push_back(indexValue1);
				pAOSMeshData->_indices.push_back(indexValue2);
#endif
			}
			sSubMesh* pSubMeshes = (sSubMesh*)(pBuffer + subMeshOffset);
			for (uint32_t subMeshIndex = 0; subMeshIndex < subMeshCount; ++subMeshIndex)
			{
				sSubMesh* pSubMesh = pSubMeshes + subMeshIndex;
				pAOSMeshData->_subMeshes.push_back(*pSubMesh);
			}
			std::string mesh_path(i_binaryMeshFile);
			std::string key = GetFileNameWithoutExtension(mesh_path.c_str());
			SAFE_DELETE_ARRAY(pBuffer);
			bool result = AOSMeshDataManager::GetInstance()->AddAOSMeshData(key.c_str(), pAOSMeshData);
			return result;
		}
Esempio n. 6
0
void LanguagesDlg::OnSelchangeListThemes() 
{
	// TODO: Add your control notification handler code here
	m_listLanguages.ResetContent();

	RString sTheme = GetCurrentString( m_listThemes );
	if( !sTheme.empty() )
	{
		RString sLanguagesDir = SpecialFiles::THEMES_DIR + sTheme + "/" + SpecialFiles::LANGUAGES_SUBDIR;

		vector<RString> vs;
		GetDirListing( sLanguagesDir+"*.ini", vs, false );
		FOREACH_CONST( RString, vs, s )
		{
			RString sIsoCode = GetFileNameWithoutExtension(*s);
			RString sLanguage = SMPackageUtil::GetLanguageDisplayString(sIsoCode);
			m_listLanguages.AddString( ConvertUTF8ToACP(sLanguage) );
		}
Esempio n. 7
0
AnsiString PathUtil::GetSafeLogFileName() {
	AnsiString logFileName = GetUserDirectory();

#ifdef __WIN32__
	char moduleName[MAX_PATH];
	::GetModuleFileName(NULL, moduleName, MAX_PATH);

	AnsiString fileName = GetFileNameWithoutExtension(moduleName) + ".log";
	fileName = Combine("/Wintermute Engine/Logs/", fileName);
	logFileName = Combine(logFileName, fileName);

#else
	// !PORTME
	logFileName = Combine(logFileName, "/Wintermute Engine/wme.log");
#endif

	CreateDirectory(GetDirectoryName(logFileName));
	return logFileName;
}
Esempio n. 8
0
		/////////////////////////////////////TextureManager///////////////////////////////////
		TextureInfo* TextureManager::LoadTexture(const char* pTexturePath)
		{
			std::string key = GetFileNameWithoutExtension(pTexturePath);
			for (std::map<const char*, TextureInfo>::const_iterator iter = _textures.begin(); iter != _textures.end(); ++iter)
			{
				if (strcmp(iter->first, key.c_str()) == 0)
				{
					return (TextureInfo*)&iter->second;
				}
			}
			TextureInfo textureInfo = {0.0f, 0.0f, 0};
			bool result = LoadDDSTextureStatic(pTexturePath, textureInfo);
			_textures.insert(std::pair<const char*, TextureInfo>(_strdup(key.c_str()), textureInfo));
			for (std::map<const char*, TextureInfo>::const_iterator iter = _textures.begin(); iter != _textures.end(); ++iter)
			{
				if (strcmp(iter->first, key.c_str()) == 0)
				{
					return (TextureInfo*)&iter->second;
				}
			}
			return nullptr;
		}
Esempio n. 9
0
		void LoadMaterial(const char* i_pBinaryMaterialFile)
		{
			// First, Load and set the material buffer 
			uint32_t o_lengthOfWholerMaterialBuffer = 0;
			uint32_t o_lengthOfEffectPath = 0;
			uint8_t* pBuffer = LoadMaterialInfo(i_pBinaryMaterialFile, o_lengthOfWholerMaterialBuffer, o_lengthOfEffectPath);
			if (o_lengthOfWholerMaterialBuffer == 0)
			{
				SAFE_DELETE(pBuffer);
				return;
			}
			// Second, let's copy the buffer for real material
			uint8_t* pOutBuffer = new uint8_t[o_lengthOfWholerMaterialBuffer - o_lengthOfEffectPath];
			SetMem(pOutBuffer, o_lengthOfWholerMaterialBuffer - o_lengthOfEffectPath, 0);
			CopyMem(pBuffer, pOutBuffer, o_lengthOfWholerMaterialBuffer - o_lengthOfEffectPath);
			MaterialDesc* pTtemp = (MaterialDesc*)pOutBuffer;
			assert(pTtemp->_sizeOfMaterialBuffer == o_lengthOfWholerMaterialBuffer);
			// Third, add this MaterialDesc buffer to the Material Map.
			std::string mat_path(i_pBinaryMaterialFile);
			std::string key = GetFileNameWithoutExtension(mat_path.c_str());
			MaterialManager::GetInstance()->AddMaterialDesc(key.c_str(), pOutBuffer);
			SAFE_DELETE(pBuffer);
		}
Esempio n. 10
0
// 获取随机文件名(全路径)
tstring CPath::GetRandomFileName(LPCTSTR lpszPath, LPCTSTR lpszFileName)
{
	tstring strPath, strFileName, strExtFileName, strFullPath;
	TCHAR szBuf[MAX_PATH] = {0};

	if (!IsDirectoryExist(lpszPath))
		strPath = GetCurDir();
	else
		strPath = lpszPath;

	strFileName = GetFileNameWithoutExtension(lpszFileName);
	strExtFileName = GetExtension(lpszFileName);

	for (int i = 2; i < 10000; i++)
	{
		if (strExtFileName.empty())
		{
			strFullPath = strPath;
			strFullPath += strFileName;
			wsprintf(szBuf, _T("%d"), i);
			strFullPath += szBuf;
		}
		else
		{
			strFullPath = strPath;
			strFullPath += strFileName;
			wsprintf(szBuf, _T("%d."), i);
			strFullPath += szBuf;
			strFullPath += strExtFileName;
		}
		
		if (!IsFileExist(strFullPath.c_str()))
			return strFullPath;
	}

	return _T("");
}
Esempio n. 11
0
String Path::ChangeExtension(RCString path, RCString ext) {
	return Combine(GetDirectoryName(path), GetFileNameWithoutExtension(path) + ext);
}
Esempio n. 12
0
// Extraction.
VFS_BOOL CArchive::Extract( const VFS_String& strTargetDir ) const
{
	if( !VFS_Dir_Exists( strTargetDir ) )
		if( !VFS_Dir_Create( strTargetDir, VFS_TRUE ) )
			return VFS_FALSE;
	VFS_EntityInfo Info;
	if( !VFS_Dir_GetInfo( strTargetDir, Info ) )
		return VFS_FALSE;
	VFS_String strTarget = WithoutTrailingSeparator( Info.strPath, VFS_TRUE ) + VFS_PATH_SEPARATOR;

	// Activate ourselves.
	if( !const_cast< CArchive* >( this )->Activate() )
		return VFS_FALSE;

	// Extract all Dirs.
	VFS_DWORD dwIndex;
	for( dwIndex = 0; dwIndex <	m_Header.Dirs.size(); dwIndex++ )
	{
		VFS_String strDirName = strTarget + m_Header.Dirs[ dwIndex ].strName;
		if( !VFS_Dir_Exists( strDirName ) )
			if( !VFS_Dir_Create( strDirName, VFS_TRUE ) )
				return VFS_FALSE;
	}

	// Extract all Files.
	for( dwIndex = 0; dwIndex <	m_Header.Files.size(); dwIndex++ )
	{
		VFS_String strFileName = strTarget + m_Header.Files[ dwIndex ].strName;

		// Read in the File.
		if( !VFS_File_Seek( m_hFile, m_Header.Files[ dwIndex ].dwDataOffset, VFS_SET ) )
			return VFS_FALSE;
		g_FromBuffer.resize( m_Header.Files[ dwIndex ].dwCompressedSize );
		if( !VFS_File_Read( m_hFile, &*g_FromBuffer.begin(), m_Header.Files[ dwIndex ].dwCompressedSize ) )
			return VFS_FALSE;

		// Apply the Filters.
		VFS_EntityInfo Info;
		Info.bArchived = VFS_TRUE;
		Info.eType = VFS_FILE;
		Info.lSize = m_Header.Files[ dwIndex ].dwCompressedSize;
		Info.strPath = GetFileNameWithoutExtension() + VFS_PATH_SEPARATOR + m_Header.Files[ dwIndex ].strName;
		VFS_Util_GetName( Info.strPath, Info.strName );

		for( VFS_DWORD dwFilter = 0; dwFilter != m_Header.Filters.size(); dwFilter++ )
		{
			g_FromPos = 0;
			if( !m_Header.Filters[ dwFilter ]->Decode( Reader, Writer, Info ) )
			{
				VFS_ErrorCode eError = VFS_GetLastError();
				if( eError == VFS_ERROR_NONE )
					eError = VFS_ERROR_GENERIC;
				SetLastError( eError );
				return VFS_FALSE;
			}
			g_FromBuffer = g_ToBuffer;
			g_ToBuffer.clear();
		}

		// Create the Target File.
		VFS_Handle hFile = VFS_File_Create( strFileName, VFS_WRITE );
		if( hFile == VFS_INVALID_HANDLE_VALUE )
			return VFS_FALSE;

		// Write the Data.
		if( !VFS_File_Write( hFile, &*g_FromBuffer.begin(), ( VFS_DWORD )g_FromBuffer.size() ) )
			return VFS_FALSE;

		// Close the Target File.
		if( !VFS_File_Close( hFile ) )
			return VFS_FALSE;
	}

	return VFS_TRUE;
}