HRESULT XZPManager::XZPOpenMemory( string xzpPath, string filePath, BYTE ** pFileData, UINT * pFileSize ) { HRESULT hr = NULL; HXUIPACKAGE hPackage; if(!FileExistsA(xzpPath)) { DebugMsg("XZPManager", "Provided XZP File Path Does Not Exist"); return S_FALSE; } // Convert absolute path to xui path string xuiPath = "file://" + xzpPath; hr = XuiResourceOpenPackage(strtowchar(xuiPath), &hPackage, false); if(hr != S_OK) { DebugMsg("XZPManager", "Failed To Open XZP Package"); return S_FALSE; } WCHAR * szLocator = strtowchar(xuiPath + "#" + filePath); BYTE * pSectionData; UINT pSectionSize; hr = XuiResourceLoadAllNoLoc(szLocator, &pSectionData, &pSectionSize); if( hr != S_OK ) { DebugMsg("XZPManager", "Failed To Load Resource File."); return S_FALSE; } *pFileData = (BYTE *)malloc(pSectionSize); memcpy(*pFileData, pSectionData, pSectionSize); *pFileSize = pSectionSize; XuiFree((void*)pSectionData); XuiResourceReleasePackage(hPackage); return S_OK; }
HRESULT XZPManager::XZPOpenBinary(string opath, string filename, string xmlname) { m_basePath = SETTINGS::getInstance().getDataPath(); string loadfilename = "file://" + opath + filename; loadfilename = str_replaceall(loadfilename, "\\", "/"); Path = strtowchar(loadfilename); DebugMsg("XZPManager", "PATH: %s, loading package", wstrtostr(Path).c_str()); HRESULT hr = XuiResourceOpenPackage(Path,&phPackage,false); if (hr != S_OK) { DebugMsg("XZPManager", "Error HRESULT: %08x", hr); return hr; } else { szLocator = strtowchar(loadfilename + "#" + xmlname); byte * buf; UINT size; hr = XuiResourceLoadAllNoLoc(szLocator, &buf, &size); if (hr != S_OK) { DebugMsg("XZPManager", "HRESULT : %08x, Loading resource"); XuiResourceReleasePackage(phPackage); return hr; } else { DebugMsg("XZPManager", "Resource is in memory Size is %d", size); string outpath = sprintfaA("%sSkins\\%s\\%s", m_basePath.c_str(), filename.c_str(), xmlname.c_str()); DebugMsg("XZPManager", "Saving file to %s", outpath.c_str()); // Write Item To File FILE * fHandle; fopen_s(&fHandle, outpath.c_str(), "wb"); fwrite(buf, size, 1, fHandle); fclose(fHandle); XuiFree((void*)buf); } } XuiResourceReleasePackage(phPackage); return S_OK; }
HRESULT XuiTextureLoader(IXuiDevice *pDevice, LPCWSTR szFileName, XUIImageInfo *pImageInfo, IDirect3DTexture9 **ppTex) { D3DXIMAGE_INFO pSrc; CONST BYTE *pbTextureData = 0; UINT cbTextureData = 0; HXUIRESOURCE hResource = 0; BOOL bIsMemoryResource = FALSE; IDirect3DDevice9 * d3dDevice = NULL; HRESULT hr = XuiResourceOpenNoLoc(szFileName, &hResource, &bIsMemoryResource); if (FAILED(hr)) return hr; if (bIsMemoryResource) { hr = XuiResourceGetBuffer(hResource, &pbTextureData); if (FAILED(hr)) goto cleanup; cbTextureData = XuiResourceGetTotalSize(hResource); } else { hr = XuiResourceRead(hResource, NULL, 0, &cbTextureData); if (FAILED(hr)) goto cleanup; pbTextureData = (BYTE *)XuiAlloc(cbTextureData); if (pbTextureData == 0) { hr = E_OUTOFMEMORY; goto cleanup; } hr = XuiResourceRead(hResource, (BYTE*)pbTextureData, cbTextureData, &cbTextureData); if (FAILED(hr)) goto cleanup; XuiResourceClose(hResource); hResource = 0; } /* Cast our d3d device into our IDirect3DDevice9* interface */ d3dDevice = (IDirect3DDevice9*)pDevice->GetD3DDevice(); if(!d3dDevice) goto cleanup; /* Create our texture based on our conditions */ hr = D3DXCreateTextureFromFileInMemoryEx( d3dDevice, pbTextureData, cbTextureData, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 1, D3DUSAGE_CPU_CACHED_MEMORY, (D3DFORMAT)d3d9_get_argb8888_format(), D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, &pSrc, NULL, ppTex ); if(hr != D3DXERR_INVALIDDATA ) { pImageInfo->Depth = pSrc.Depth; pImageInfo->Format = pSrc.Format; pImageInfo->Height = pSrc.Height; pImageInfo->ImageFileFormat = pSrc.ImageFileFormat; pImageInfo->MipLevels = pSrc.MipLevels; pImageInfo->ResourceType = pSrc.ResourceType; pImageInfo->Width = pSrc.Width; } else RARCH_ERR("D3DXERR_INVALIDDATA Encountered\n"); cleanup: if (bIsMemoryResource && hResource != 0) XuiResourceReleaseBuffer(hResource, pbTextureData); else XuiFree((LPVOID)pbTextureData); if (hResource != 0) XuiResourceClose(hResource); return hr; }