void SPTexture::Load( SPString setPath ) { D3DXIMAGE_INFO i; //PALETTEENTRY p; Don't know why we cannot make use of both palette and info. // Ether of them is used. // Open texture file. SPFilePtr file = SPFileManager::GetSingleton()->OpenFile(setPath); if (!file) { SPLogHelper::WriteLog(L"[SPGraphics] WARNING: Failed to open file: " + setPath); return; } // Read file data. LONGLONG length = file->GetFileLength(); char* pData = new char[(unsigned int)length]; if (!file->Read(pData, (DWORD)length)) { SPLogHelper::WriteLog(L"[SPGraphics] WARNING: Failed to read file: " + setPath); return; } SPGameManager::GetSingleton()->GetGame()->LockDrawing(); // Create texture from memory. HRESULT hr = D3DXCreateTextureFromFileInMemoryEx( SPDevice::GetSingleton()->GetD3DDevice(), pData, (UINT)length, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, D3DX_FROM_FILE, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE, D3DCOLOR_RGBA(0,0,0,0), &i, NULL, &texture); SPGameManager::GetSingleton()->GetGame()->UnlockDrawing(); // Close texture file. SPFileManager::GetSingleton()->CloseFile(setPath); delete [] pData; pData = NULL; if (FAILED(hr)) { texture = NULL; return; } path = setPath; height = i.Height; width = i.Width; format = D3DFMT_A8R8G8B8; }
bool SPInputManager::SetCursor( SPString path ) { SPFilePtr file = SPFileManager::GetSingleton().OpenFile(path); if (!file) { return false; } LONGLONG length = file->GetFileLength(); char* pData = new char[length]; file->Read(pData, length); wchar_t tname[10]; _wtmpnam_s(tname, 10); SPString name = SPString(tname);// + path.substr(path.find_last_of(L".") + 1); HANDLE newFile = CreateFile(name.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (newFile == INVALID_HANDLE_VALUE) { return false; } DWORD numOfByte; if(FALSE == WriteFile(newFile, pData, length, &numOfByte, NULL)) { delete [] pData; SPFileManager::GetSingleton().CloseFile(path); CloseHandle(newFile); DeleteFile(name.c_str()); return false; } CloseHandle(newFile); HCURSOR cursor = LoadCursorFromFile(name.c_str()); if (!cursor) { DWORD err = GetLastError(); delete [] pData; SPFileManager::GetSingleton().CloseFile(path); CloseHandle(newFile); DeleteFile(name.c_str()); return false; } SPWindow::GetSingleton().SetCursor(cursor); DeleteFile(name.c_str()); delete [] pData; SPFileManager::GetSingleton().CloseFile(path); //CloseHandle(newFile); return true; }
bool SPPixelShaderCore::Load( SPString path ) { name = path; SPFilePtr file = SPFileManager::GetSingleton().OpenFile(path); if (!file) { SPLogHelper::WriteLog(L"[SPShader] WARNING: Failed to open shader file: " + path); return false; } ID3DXBuffer* shaderBuffer = NULL; ID3DXBuffer* errorBuffer = NULL; LONGLONG length = file->GetFileLength(); char* pData = new char[(UINT)length]; if(!file->Read(pData, (DWORD)length)) { SPLogHelper::WriteLog(L"[SPShader] WARNING: Failed to read shader file: " + path); return false; } // Compile shader files. HRESULT hr = D3DXCompileShader( pData, (UINT)length, 0, 0, "Main", "ps_2_0", D3DXSHADER_DEBUG, &shaderBuffer, &errorBuffer, &constantTable); delete [] pData; SPFileManager::GetSingleton().CloseFile(path); if (errorBuffer) { SPLogHelper::WriteLog(L"[SPShader] WARNING: There is error in shader file: " + path); SPLogHelper::WriteLog("[SPShader] Message: " + string((char*)errorBuffer->GetBufferPointer())); errorBuffer->Release(); } if (FAILED(hr)) { SPLogHelper::WriteLog(L"[SPShader] WARNING: Failed to compile shader file: " + path); return false; } // Create pixel shader. hr = SPDevice::GetSingleton().GetD3DDevice()->CreatePixelShader( (DWORD*)shaderBuffer->GetBufferPointer(), &pixelShader); if (FAILED(hr)) { SPLogHelper::WriteLog(L"[SPShader] WARNING: Failed to create pixel shader"); if (shaderBuffer) { shaderBuffer->Release(); shaderBuffer = NULL; } return false; } shaderBuffer->Release(); shaderBuffer = NULL; return true; }
BOOL SPFileSourceFilter::ReadTheFile(LPCTSTR lpszFileName) { //DWORD dwBytesRead; // Open the requested file wstring wName = lpszFileName; SPString name = SPString(wName.begin(), wName.end()); SPFilePtr file = SPFileManager::GetSingleton().OpenFile(name); if (!file) { SPLogHelper::WriteLog(L"[DShow] WARNING: Failed to open video file: " + name); return FALSE; } //HANDLE hFile = CreateFile(lpszFileName, // GENERIC_READ, // FILE_SHARE_READ, // NULL, // OPEN_EXISTING, // 0, // NULL); //if (hFile == INVALID_HANDLE_VALUE) //{ // DbgLog((LOG_TRACE, 2, TEXT("Could not open %s\n"), lpszFileName)); // return FALSE; //} // Determine the file size //ULARGE_INTEGER uliSize; //uliSize.LowPart = GetFileSize(hFile, &uliSize.HighPart); PBYTE pbMem = new BYTE[(unsigned int)file->GetFileLength()]; if (pbMem == NULL) { //CloseHandle(hFile); SPLogHelper::WriteLog("[DShow] WARNING: Failed to create buffer!"); SPFileManager::GetSingleton().CloseFile(name); return FALSE; } // Read the data from the file //if (!ReadFile(hFile, // (LPVOID) pbMem, // uliSize.LowPart, // &dwBytesRead, // NULL) || // (dwBytesRead != uliSize.LowPart)) //{ // DbgLog((LOG_TRACE, 1, TEXT("Could not read file\n"))); // delete [] pbMem; // CloseHandle(hFile); // return FALSE; //} if(!file->Read(pbMem, (DWORD)file->GetFileLength())) { delete [] pbMem; SPLogHelper::WriteLog("[DShow] WARNING: Failed to read file!"); SPFileManager::GetSingleton().CloseFile(name); return FALSE; } // Save a pointer to the data that was read from the file m_pbData = pbMem; //m_llSize = (LONGLONG)uliSize.QuadPart; m_llSize = file->GetFileLength(); // Close the file //CloseHandle(hFile); SPFileManager::GetSingleton().CloseFile(name); return TRUE; }