GLuint CompileProgramFromFiles(const std::string &vsPath, const std::string &fsPath) { std::string vsSource = ReadFileToString(vsPath); std::string fsSource = ReadFileToString(fsPath); if (vsSource.empty() || fsSource.empty()) { return 0; } return CompileProgram(vsSource, fsSource); }
void CheckFileContents(const FilePath& rel_path, const string& expected_content) { string actual_contents; FilePath actual_path = outputDir_.Append(rel_path); if (!ReadFileToString(actual_path, &actual_contents)) { FAIL() << "Failed to read expected output file: " << rel_path.value(); } if (actual_contents != expected_content) { // When the match fails, display a diff of what's wrong. This greatly // aids in debugging. FilePath expected_path; EXPECT_TRUE(CreateTemporaryFileInDir(tmpDir_, &expected_path)); WriteFile(expected_path, expected_content.c_str(), expected_content.length()); const size_t buf_len = strlen(kDiffTemplate) + actual_path.value().length() + expected_path.value().length() + 1; unique_ptr<char[]> diff_cmd(new char[buf_len]); EXPECT_GT(snprintf(diff_cmd.get(), buf_len, kDiffTemplate, expected_path.value().c_str(), actual_path.value().c_str()), 0); system(diff_cmd.get()); FAIL() << "Actual contents of " << rel_path.value() << " did not match expected content"; } }
void RenderManager::Init() { if (!m_bulletDebugDrawer) m_bulletDebugDrawer = new BTDebugDrawer(); glewInit(); //Create shaders and add to vector std::vector<GLuint> shaderList; shaderList.push_back(CreateShader(GL_VERTEX_SHADER, ReadFileToString("VertexShader.glsl"))); shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, ReadFileToString("FragmentShader.glsl"))); //Create program m_program = CreateProgram(shaderList); m_bulletDebugDrawer->SetProgram(m_program); m_ui.m_openGLWidget->rm = this; }
GLuint CompileShaderFromFile(GLenum type, const std::string &sourcePath) { std::string source = ReadFileToString(sourcePath); if (source.empty()) { return 0; } return CompileShader(type, source); }
bool LoadBinaryResource(const char* resource_name, std::string& resource_data) { std::string path; if (!GetResourceDir(path)) return false; path.append("/"); path.append(resource_name); return ReadFileToString(path.c_str(), resource_data); }
scoped_refptr<StyleSheet> StyleSheet::LoadFromFile(const std::wstring& path) { std::string contents; if (!ReadFileToString(path, &contents)) return NULL; StyleParser parser; scoped_refptr<StyleSheet> sheet(new StyleSheet); parser.SetStyleSheet(sheet.get()); if (!parser.ParseSheet(contents, 0)) return NULL; return sheet; }
HttpResponse HttpResponse::FileNotFound() { HttpResponse response; response.m_httpVersion = Config::GetServerHttpVersion(); response.m_statusCode = respcode_notfound; std::string filePath = Config::GetRootFolder() + "/" + Config::GetDefaultPage404(); if (!CheckFileExists(filePath)) response.m_body = "<html><head><title>404 Not Found</title><meta charset = \"utf-8\"/></head><body><br><center><h1>404 Not Found</h1></center></body></html>"; else response.m_body = ReadFileToString(filePath); response.m_headers.insert({ "Content-Length", std::to_string(response.m_body.size()) }); response.m_headers.insert({ "Content-Type", "text/html" }); return response; }
GLuint CreateShader(const char *shader_file_name, GLenum target) { std::string contents = ReadFileToString(shader_file_name); GLuint shader = glCreateShader(target); const char *contents_cstr = contents.c_str(); glShaderSource(shader, 1, &contents_cstr, nullptr); glCompileShader(shader); GLint status; glGetShaderiv(shader, GL_COMPILE_STATUS, &status); if (status == GL_FALSE) { GLint info_log_len; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_len); GLchar *str_info_log = new GLchar[info_log_len + 1]; glGetShaderInfoLog(shader, info_log_len, nullptr, str_info_log); const char *shader_type_cstr = nullptr; switch (target) { case GL_VERTEX_SHADER: shader_type_cstr = "vertex"; break; case GL_GEOMETRY_SHADER: shader_type_cstr = "geometry"; break; case GL_FRAGMENT_SHADER: shader_type_cstr = "fragment"; break; } fprintf(stderr, "Compile failure in %s shader %s:\n %s\n", shader_type_cstr, shader_file_name, str_info_log); delete[] str_info_log; } return shader; }
virtual void run() { delete info_->fileLoader; info_->fileLoader = ConstructFileLoader(gamePath_); if (!info_->fileLoader->Exists()) return; std::string filename = gamePath_; info_->path = gamePath_; info_->fileType = Identify_File(info_->fileLoader); // Fallback title info_->title = getFilename(info_->path); switch (info_->fileType) { case FILETYPE_PSP_PBP: case FILETYPE_PSP_PBP_DIRECTORY: { std::string pbpFile = filename; if (info_->fileType == FILETYPE_PSP_PBP_DIRECTORY) pbpFile += "/EBOOT.PBP"; PBPReader pbp(pbpFile.c_str()); if (!pbp.IsValid()) { if (pbp.IsELF()) { goto handleELF; } ERROR_LOG(LOADER, "invalid pbp %s\n", pbpFile.c_str()); return; } // First, PARAM.SFO. size_t sfoSize; u8 *sfoData = pbp.GetSubFile(PBP_PARAM_SFO, &sfoSize); { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO(sfoData, sfoSize); info_->ParseParamSFO(); } delete [] sfoData; // Then, ICON0.PNG. { lock_guard lock(info_->lock); if (pbp.GetSubFileSize(PBP_ICON0_PNG) > 0) { pbp.GetSubFileAsString(PBP_ICON0_PNG, &info_->iconTextureData); } else { // Read standard icon size_t sz; DEBUG_LOG(LOADER, "Loading unknown.png because a PBP was missing an icon"); uint8_t *contents = VFSReadFile("unknown.png", &sz); if (contents) { lock_guard lock(info_->lock); info_->iconTextureData = std::string((const char *)contents, sz); } delete [] contents; } info_->iconDataLoaded = true; } if (info_->wantFlags & GAMEINFO_WANTBG) { if (pbp.GetSubFileSize(PBP_PIC0_PNG) > 0) { lock_guard lock(info_->lock); pbp.GetSubFileAsString(PBP_PIC0_PNG, &info_->pic0TextureData); info_->pic0DataLoaded = true; } if (pbp.GetSubFileSize(PBP_PIC1_PNG) > 0) { lock_guard lock(info_->lock); pbp.GetSubFileAsString(PBP_PIC1_PNG, &info_->pic1TextureData); info_->pic1DataLoaded = true; } } if (info_->wantFlags & GAMEINFO_WANTSND) { if (pbp.GetSubFileSize(PBP_SND0_AT3) > 0) { lock_guard lock(info_->lock); pbp.GetSubFileAsString(PBP_SND0_AT3, &info_->sndFileData); info_->sndDataLoaded = true; } } } break; case FILETYPE_PSP_ELF: handleELF: // An elf on its own has no usable information, no icons, no nothing. info_->title = getFilename(filename); info_->id = "ELF000000"; info_->id_version = "ELF000000_1.00"; info_->paramSFOLoaded = true; { // Read standard icon size_t sz; uint8_t *contents = VFSReadFile("unknown.png", &sz); DEBUG_LOG(LOADER, "Loading unknown.png because there was an ELF"); if (contents) { lock_guard lock(info_->lock); info_->iconTextureData = std::string((const char *)contents, sz); info_->iconDataLoaded = true; } delete [] contents; } break; case FILETYPE_PSP_DISC_DIRECTORY: { info_->fileType = FILETYPE_PSP_ISO; SequentialHandleAllocator handles; VirtualDiscFileSystem umd(&handles, gamePath_.c_str()); // Alright, let's fetch the PARAM.SFO. std::string paramSFOcontents; if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, 0)) { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size()); info_->ParseParamSFO(); } ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->iconTextureData, &info_->lock); info_->iconDataLoaded = true; if (info_->wantFlags & GAMEINFO_WANTBG) { ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0TextureData, &info_->lock); info_->pic0DataLoaded = true; ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1TextureData, &info_->lock); info_->pic1DataLoaded = true; } if (info_->wantFlags & GAMEINFO_WANTSND) { ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, &info_->lock); info_->pic1DataLoaded = true; } break; } case FILETYPE_PSP_ISO: case FILETYPE_PSP_ISO_NP: { info_->fileType = FILETYPE_PSP_ISO; SequentialHandleAllocator handles; // Let's assume it's an ISO. // TODO: This will currently read in the whole directory tree. Not really necessary for just a // few files. BlockDevice *bd = constructBlockDevice(info_->fileLoader); if (!bd) return; // nothing to do here.. ISOFileSystem umd(&handles, bd, "/PSP_GAME"); // Alright, let's fetch the PARAM.SFO. std::string paramSFOcontents; if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, 0)) { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size()); info_->ParseParamSFO(); if (info_->wantFlags & GAMEINFO_WANTBG) { ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0TextureData, &info_->lock); info_->pic0DataLoaded = true; ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1TextureData, &info_->lock); info_->pic1DataLoaded = true; } if (info_->wantFlags & GAMEINFO_WANTSND) { ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, &info_->lock); info_->pic1DataLoaded = true; } } // Fall back to unknown icon if ISO is broken/is a homebrew ISO, override is allowed though if (!ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->iconTextureData, &info_->lock)) { size_t sz; uint8_t *contents = VFSReadFile("unknown.png", &sz); DEBUG_LOG(LOADER, "Loading unknown.png because no icon was found"); if (contents) { lock_guard lock(info_->lock); info_->iconTextureData = std::string((const char *)contents, sz); } delete [] contents; } info_->iconDataLoaded = true; break; } case FILETYPE_ARCHIVE_ZIP: info_->paramSFOLoaded = true; { // Read standard icon size_t sz; uint8_t *contents = VFSReadFile("zip.png", &sz); if (contents) { lock_guard lock(info_->lock); info_->iconTextureData = std::string((const char *)contents, sz); info_->iconDataLoaded = true; } delete [] contents; } break; case FILETYPE_ARCHIVE_RAR: info_->paramSFOLoaded = true; { // Read standard icon size_t sz; uint8_t *contents = VFSReadFile("rargray.png", &sz); if (contents) { lock_guard lock(info_->lock); info_->iconTextureData = std::string((const char *)contents, sz); info_->iconDataLoaded = true; } delete [] contents; } break; case FILETYPE_ARCHIVE_7Z: info_->paramSFOLoaded = true; { // Read standard icon size_t sz; uint8_t *contents = VFSReadFile("7z.png", &sz); if (contents) { lock_guard lock(info_->lock); info_->iconTextureData = std::string((const char *)contents, sz); info_->iconDataLoaded = true; } delete[] contents; } break; case FILETYPE_NORMAL_DIRECTORY: default: info_->paramSFOLoaded = true; break; } if (info_->wantFlags & GAMEINFO_WANTSIZE) { info_->gameSize = info_->GetGameSizeInBytes(); info_->saveDataSize = info_->GetSaveDataSizeInBytes(); info_->installDataSize = info_->GetInstallDataSizeInBytes(); } }
// This may run off-main-thread and we thus can't use the global // pspFileSystem (well, we could with synchronization but there might not // even be a game running). GameInfo *GameInfoCache::GetInfo(const std::string &gamePath, bool wantBG) { auto iter = info_.find(gamePath); if (iter != info_.end()) { GameInfo *info = iter->second; if (!info->wantBG && wantBG) { // Need to start over. delete info; goto again; } if (info->iconTextureData.size()) { info->iconTexture = new Texture(); // TODO: We could actually do the PNG decoding as well on the async thread. // We'd have to split up Texture->LoadPNG though, creating some intermediate Image class maybe. if (info->iconTexture->LoadPNG((const u8 *)info->iconTextureData.data(), info->iconTextureData.size(), false)) { info->timeIconWasLoaded = time_now_d(); } info->iconTextureData.clear(); } if (info->pic0TextureData.size()) { info->pic0Texture = new Texture(); if (info->pic0Texture->LoadPNG((const u8 *)info->pic0TextureData.data(), info->pic0TextureData.size(), false)) { info->timePic0WasLoaded = time_now_d(); } info->pic0TextureData.clear(); } if (info->pic1TextureData.size()) { info->pic1Texture = new Texture(); if (info->pic1Texture->LoadPNG((const u8 *)info->pic1TextureData.data(), info->pic1TextureData.size(), false)) { info->timePic1WasLoaded = time_now_d(); } info->pic1TextureData.clear(); } iter->second->lastAccessedTime = time_now_d(); return iter->second; } again: // return info; // TODO: Everything below here should be asynchronous and run on a thread, // filling in the info as it goes. // A game can be either an UMD or a directory under ms0:/PSP/GAME . if (startsWith(gamePath, "ms0:/PSP/GAME")) { return 0; // TODO: The case of these extensions is not perfect. } else if (endsWith(gamePath, ".PBP") || endsWith(gamePath, ".elf")) { return 0; } else { SequentialHandleAllocator handles; // Let's assume it's an ISO. // TODO: This will currently read in the whole directory tree. Not really necessary for just a // few files. BlockDevice *bd = constructBlockDevice(gamePath.c_str()); if (!bd) return 0; // nothing to do here.. ISOFileSystem umd(&handles, bd, "/PSP_GAME"); GameInfo *info = new GameInfo(); info->wantBG = wantBG; // Alright, let's fetch the PARAM.SFO. std::string paramSFOcontents; if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents)) { lock_guard lock(info->lock); info->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size()); info->title = info->paramSFO.GetValueString("TITLE"); } ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info->iconTextureData); if (wantBG) { { lock_guard lock(info->lock); ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info->pic0TextureData); } { lock_guard lock(info->lock); ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info->pic1TextureData); } } info_[gamePath] = info; return info; } return 0; }
virtual void run() { if (!info_->LoadFromPath(gamePath_)) return; std::string filename = gamePath_; { lock_guard lock(info_->lock); info_->fileType = Identify_File(info_->GetFileLoader()); } switch (info_->fileType) { case FILETYPE_PSP_PBP: case FILETYPE_PSP_PBP_DIRECTORY: { FileLoader *pbpLoader = info_->GetFileLoader(); std::unique_ptr<FileLoader> altLoader; if (info_->fileType == FILETYPE_PSP_PBP_DIRECTORY) { pbpLoader = ConstructFileLoader(pbpLoader->Path() + "/EBOOT.PBP"); altLoader.reset(pbpLoader); } PBPReader pbp(pbpLoader); if (!pbp.IsValid()) { if (pbp.IsELF()) { goto handleELF; } ERROR_LOG(LOADER, "invalid pbp %s\n", pbpLoader->Path().c_str()); return; } // First, PARAM.SFO. std::vector<u8> sfoData; if (pbp.GetSubFile(PBP_PARAM_SFO, &sfoData)) { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO(sfoData); info_->ParseParamSFO(); } // Then, ICON0.PNG. if (pbp.GetSubFileSize(PBP_ICON0_PNG) > 0) { lock_guard lock(info_->lock); pbp.GetSubFileAsString(PBP_ICON0_PNG, &info_->iconTextureData); } else { // Read standard icon DEBUG_LOG(LOADER, "Loading unknown.png because a PBP was missing an icon"); ReadVFSToString("unknown.png", &info_->iconTextureData, &info_->lock); } info_->iconDataLoaded = true; if (info_->wantFlags & GAMEINFO_WANTBG) { if (pbp.GetSubFileSize(PBP_PIC0_PNG) > 0) { lock_guard lock(info_->lock); pbp.GetSubFileAsString(PBP_PIC0_PNG, &info_->pic0TextureData); info_->pic0DataLoaded = true; } if (pbp.GetSubFileSize(PBP_PIC1_PNG) > 0) { lock_guard lock(info_->lock); pbp.GetSubFileAsString(PBP_PIC1_PNG, &info_->pic1TextureData); info_->pic1DataLoaded = true; } } if (info_->wantFlags & GAMEINFO_WANTSND) { if (pbp.GetSubFileSize(PBP_SND0_AT3) > 0) { lock_guard lock(info_->lock); pbp.GetSubFileAsString(PBP_SND0_AT3, &info_->sndFileData); info_->sndDataLoaded = true; } } } break; case FILETYPE_PSP_ELF: handleELF: // An elf on its own has no usable information, no icons, no nothing. { lock_guard lock(info_->lock); info_->id = "ELF000000"; info_->id_version = "ELF000000_1.00"; info_->paramSFOLoaded = true; } // Read standard icon DEBUG_LOG(LOADER, "Loading unknown.png because there was an ELF"); ReadVFSToString("unknown.png", &info_->iconTextureData, &info_->lock); info_->iconDataLoaded = true; break; case FILETYPE_PSP_SAVEDATA_DIRECTORY: { SequentialHandleAllocator handles; VirtualDiscFileSystem umd(&handles, gamePath_.c_str()); // Alright, let's fetch the PARAM.SFO. std::string paramSFOcontents; if (ReadFileToString(&umd, "/PARAM.SFO", ¶mSFOcontents, 0)) { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size()); info_->ParseParamSFO(); } ReadFileToString(&umd, "/ICON0.PNG", &info_->iconTextureData, &info_->lock); info_->iconDataLoaded = true; if (info_->wantFlags & GAMEINFO_WANTBG) { ReadFileToString(&umd, "/PIC1.PNG", &info_->pic1TextureData, &info_->lock); info_->pic1DataLoaded = true; } break; } case FILETYPE_PPSSPP_SAVESTATE: { info_->SetTitle(SaveState::GetTitle(gamePath_)); lock_guard guard(info_->lock); // Let's use the screenshot as an icon, too. std::string screenshotPath = ReplaceAll(gamePath_, ".ppst", ".jpg"); if (File::Exists(screenshotPath)) { if (readFileToString(false, screenshotPath.c_str(), info_->iconTextureData)) { info_->iconDataLoaded = true; } } break; } case FILETYPE_PSP_DISC_DIRECTORY: { info_->fileType = FILETYPE_PSP_ISO; SequentialHandleAllocator handles; VirtualDiscFileSystem umd(&handles, gamePath_.c_str()); // Alright, let's fetch the PARAM.SFO. std::string paramSFOcontents; if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, 0)) { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size()); info_->ParseParamSFO(); } ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->iconTextureData, &info_->lock); info_->iconDataLoaded = true; if (info_->wantFlags & GAMEINFO_WANTBG) { ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0TextureData, &info_->lock); info_->pic0DataLoaded = true; ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1TextureData, &info_->lock); info_->pic1DataLoaded = true; } if (info_->wantFlags & GAMEINFO_WANTSND) { ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, &info_->lock); info_->pic1DataLoaded = true; } break; } case FILETYPE_PSP_ISO: case FILETYPE_PSP_ISO_NP: { info_->fileType = FILETYPE_PSP_ISO; SequentialHandleAllocator handles; // Let's assume it's an ISO. // TODO: This will currently read in the whole directory tree. Not really necessary for just a // few files. BlockDevice *bd = constructBlockDevice(info_->GetFileLoader()); if (!bd) return; // nothing to do here.. ISOFileSystem umd(&handles, bd, "/PSP_GAME"); // Alright, let's fetch the PARAM.SFO. std::string paramSFOcontents; if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, nullptr)) { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size()); info_->ParseParamSFO(); if (info_->wantFlags & GAMEINFO_WANTBG) { ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0TextureData, &info_->lock); info_->pic0DataLoaded = true; ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1TextureData, &info_->lock); info_->pic1DataLoaded = true; } if (info_->wantFlags & GAMEINFO_WANTSND) { ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, &info_->lock); info_->pic1DataLoaded = true; } } // Fall back to unknown icon if ISO is broken/is a homebrew ISO, override is allowed though if (!ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->iconTextureData, &info_->lock)) { DEBUG_LOG(LOADER, "Loading unknown.png because no icon was found"); ReadVFSToString("unknown.png", &info_->iconTextureData, &info_->lock); } info_->iconDataLoaded = true; break; } case FILETYPE_ARCHIVE_ZIP: info_->paramSFOLoaded = true; { ReadVFSToString("zip.png", &info_->iconTextureData, &info_->lock); info_->iconDataLoaded = true; } break; case FILETYPE_ARCHIVE_RAR: info_->paramSFOLoaded = true; { ReadVFSToString("rargray.png", &info_->iconTextureData, &info_->lock); info_->iconDataLoaded = true; } break; case FILETYPE_ARCHIVE_7Z: info_->paramSFOLoaded = true; { ReadVFSToString("7z.png", &info_->iconTextureData, &info_->lock); info_->iconDataLoaded = true; } break; case FILETYPE_NORMAL_DIRECTORY: default: info_->paramSFOLoaded = true; break; } info_->hasConfig = g_Config.hasGameConfig(info_->id); if (info_->wantFlags & GAMEINFO_WANTSIZE) { lock_guard lock(info_->lock); info_->gameSize = info_->GetGameSizeInBytes(); info_->saveDataSize = info_->GetSaveDataSizeInBytes(); info_->installDataSize = info_->GetInstallDataSizeInBytes(); } info_->pending = false; info_->DisposeFileLoader(); }
virtual void run() { getFileInfo(gamePath_.c_str(), &info_->fileInfo); if (!info_->fileInfo.exists) return; std::string filename = gamePath_; info_->fileType = Identify_File(filename); switch (info_->fileType) { case FILETYPE_PSP_PBP: case FILETYPE_PSP_PBP_DIRECTORY: { std::string pbpFile = filename; if (info_->fileType == FILETYPE_PSP_PBP_DIRECTORY) pbpFile += "/EBOOT.PBP"; PBPReader pbp(pbpFile.c_str()); if (!pbp.IsValid()) return; // First, PARAM.SFO. size_t sfoSize; u8 *sfoData = pbp.GetSubFile(PBP_PARAM_SFO, &sfoSize); { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO(sfoData, sfoSize); info_->title = info_->paramSFO.GetValueString("TITLE"); info_->id = info_->paramSFO.GetValueString("DISC_ID"); info_->id_version = info_->paramSFO.GetValueString("DISC_ID") + "_" + info_->paramSFO.GetValueString("DISC_VERSION"); info_->paramSFOLoaded = true; } delete [] sfoData; // Then, ICON0.PNG. { lock_guard lock(info_->lock); if (pbp.GetSubFileSize(PBP_ICON0_PNG) > 0) { pbp.GetSubFileAsString(PBP_ICON0_PNG, &info_->iconTextureData); } else { // Read standard icon size_t sz; INFO_LOG(HLE, "Loading unknown.png because a PBP was missing an icon"); uint8_t *contents = VFSReadFile("unknown.png", &sz); if (contents) { lock_guard lock(info_->lock); info_->iconTextureData = std::string((const char *)contents, sz); } delete [] contents; } } if (info_->wantBG) { if (pbp.GetSubFileSize(PBP_PIC1_PNG) > 0) { lock_guard lock(info_->lock); pbp.GetSubFileAsString(PBP_PIC1_PNG, &info_->pic1TextureData); } } } break; case FILETYPE_PSP_ELF: // An elf on its own has no usable information, no icons, no nothing. info_->title = getFilename(filename); info_->id = "ELF000000"; info_->id_version = "ELF000000_1.00"; info_->paramSFOLoaded = true; { // Read standard icon size_t sz; uint8_t *contents = VFSReadFile("unknown.png", &sz); INFO_LOG(HLE, "Loading unknown.png because there was an ELF"); if (contents) { lock_guard lock(info_->lock); info_->iconTextureData = std::string((const char *)contents, sz); } delete [] contents; } break; case FILETYPE_PSP_DISC_DIRECTORY: { info_->fileType = FILETYPE_PSP_ISO; SequentialHandleAllocator handles; VirtualDiscFileSystem umd(&handles,gamePath_.c_str()); // Alright, let's fetch the PARAM.SFO. std::string paramSFOcontents; if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, 0)) { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size()); info_->title = info_->paramSFO.GetValueString("TITLE"); info_->id = info_->paramSFO.GetValueString("DISC_ID"); info_->id_version = info_->paramSFO.GetValueString("DISC_ID") + "_" + info_->paramSFO.GetValueString("DISC_VERSION"); info_->paramSFOLoaded = true; } ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->iconTextureData, &info_->lock); if (info_->wantBG) { ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0TextureData, &info_->lock); } ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1TextureData, &info_->lock); break; } case FILETYPE_PSP_ISO: case FILETYPE_PSP_ISO_NP: { info_->fileType = FILETYPE_PSP_ISO; SequentialHandleAllocator handles; // Let's assume it's an ISO. // TODO: This will currently read in the whole directory tree. Not really necessary for just a // few files. BlockDevice *bd = constructBlockDevice(gamePath_.c_str()); if (!bd) return; // nothing to do here.. ISOFileSystem umd(&handles, bd, "/PSP_GAME"); // Alright, let's fetch the PARAM.SFO. std::string paramSFOcontents; if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, 0)) { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size()); info_->title = info_->paramSFO.GetValueString("TITLE"); info_->id = info_->paramSFO.GetValueString("DISC_ID"); info_->id_version = info_->paramSFO.GetValueString("DISC_ID") + "_" + info_->paramSFO.GetValueString("DISC_VERSION"); info_->paramSFOLoaded = true; } else { // Fall back to the filename for title if ISO is broken info_->title = gamePath_; } ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->iconTextureData, &info_->lock); if (info_->wantBG) { ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0TextureData, &info_->lock); } ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1TextureData, &info_->lock); break; } case FILETYPE_NORMAL_DIRECTORY: info_->title = gamePath_; break; default: { std::string fn, ext; SplitPath(gamePath_, 0, &fn, &ext); info_->title = fn + "." + ext; } break; } // probably only want these when we ask for the background image... // should maybe flip the flag to "onlyIcon" if (info_->wantBG) { info_->gameSize = info_->GetGameSizeInBytes(); info_->saveDataSize = info_->GetSaveDataSizeInBytes(); } }
int handleGames( ehttp &obj, void * cookie ) { string requestedFile = obj.getFilename(); // First determine what the content type is from the url path string szContentType = requestedFile.substr(1); CONTENT_ITEM_TAB contentTab = CONTENT_UNKNOWN; // Convert requested content type to CONTENT_ITEM_TAB if( szContentType.compare("360") == 0 ) contentTab = CONTENT_360; else if( szContentType.compare("XBLA") == 0 ) contentTab = CONTENT_XBLA; else if( szContentType.compare("Homebrew") == 0 ) contentTab = CONTENT_HOMEBREW; else if( szContentType.compare("Emulators") == 0 ) contentTab = CONTENT_EMULATOR; else if( szContentType.compare("Xbox1") == 0 ) contentTab = CONTENT_XBOX1; // Set Relative Paths string szGamelistRelativePath = "wwwroot\\gamelist.html"; string szEntriesRelativePath = "wwwroot\\gamelistentry.inc"; string szLoadingEntriesRelativePath = "wwwroot\\gamelistloadingentry.inc"; // Load the list entry template into our entrytemplate string string szEntryTemplate = ""; string szLoadingEntryTemplate = ""; if( HTTPServer::getInstance().bXZPMode == true ) { // Entry Template BYTE * entryTemplateData = NULL; DWORD entryTemplateSize = 0; XZPManager::getInstance().XZPOpenMemory(SkinManager::getInstance().getCurrentFullSkinPath(), szEntriesRelativePath, &entryTemplateData, (UINT*)&entryTemplateSize); // Copy the data from the file buffer to our Entry Template string char * szTempStringA = (char*)malloc(entryTemplateSize + 1); memset( szTempStringA, 0, entryTemplateSize + 1); memcpy( szTempStringA, (char*)entryTemplateData, entryTemplateSize); szEntryTemplate = szTempStringA; free(szTempStringA); free(entryTemplateData); // Loading Entry Template BYTE * loadingEntryTemplateData = NULL; DWORD loadingEntryTemplateSize = 0; XZPManager::getInstance().XZPOpenMemory(SkinManager::getInstance().getCurrentFullSkinPath(), szLoadingEntriesRelativePath, &loadingEntryTemplateData, (UINT*)&loadingEntryTemplateSize); // Copy the data from the file buffer to our Entry Template string char * szTempStringB = (char*)malloc(loadingEntryTemplateSize + 1); memset( szTempStringB, 0, loadingEntryTemplateSize + 1); memcpy( szTempStringB, (char*)loadingEntryTemplateData, loadingEntryTemplateSize); szLoadingEntryTemplate = szTempStringB; free(szTempStringB); free(loadingEntryTemplateData); } else { // Non XZP is easier to load szEntryTemplate = ReadFileToString(SkinManager::getInstance().getCurrentFullSkinPath() + szEntriesRelativePath); szLoadingEntryTemplate = ReadFileToString(SkinManager::getInstance().getCurrentFullSkinPath() + szLoadingEntriesRelativePath); } // Create entries token to be used in token_replace string szEntries = "", szLoadingEntries = ""; int nCounter = 0; vector<ContentItemNew*>::iterator iter; ContentItemVector vContentItems = ContentManager::getInstance().GetContentByItemTab(contentTab); for( iter = vContentItems.begin(); iter != vContentItems.end(); iter++ ) { ContentItemNew * pContentItem = (*iter); BYTE * iconData = NULL; DWORD iconSize = 0; iconSize = pContentItem->getIconData(&iconData); string szIconPath = sprintfaA("/memory/gameicon.png?titleid=%X&address=%X&size=%X", pContentItem->getTitleId(), iconData, iconSize ); string szContentId = sprintfaA("%X", pContentItem->GetItemId()); string szGameId = sprintfaA("game%d", nCounter); // Enumerating and Replacing Entry Template Items string szCurrentEntry = szEntryTemplate; szCurrentEntry = str_replaceallA(szCurrentEntry, "##GAMECONTENTTYPE##", sprintfaA("%d", (int)contentTab)); szCurrentEntry = str_replaceallA(szCurrentEntry, "##GAMEICON##", szIconPath); string szTitleName = wstrtostr(pContentItem->getTitle()); if(szTitleName == "") szTitleName = "Game Title Not Found"; szCurrentEntry = str_replaceallA(szCurrentEntry, "##GAMENAME##", szTitleName); szCurrentEntry = str_replaceallA(szCurrentEntry, "##GAMETITLEID##", wstrtostr(pContentItem->getId())); szCurrentEntry = str_replaceallA(szCurrentEntry, "##GAMEMEDIAID##", wstrtostr(pContentItem->getMId())); szCurrentEntry = str_replaceallA(szCurrentEntry, "##GAMECONTENTID##", szContentId); szCurrentEntry = str_replaceallA(szCurrentEntry, "##GAMEPATH##", pContentItem->getRoot() + pContentItem->getPath()); szCurrentEntry = str_replaceallA(szCurrentEntry, "##SESSIONID##", ((HTTP_SESSION_DATA*)cookie)->SessionId); szEntries = szEntries + szCurrentEntry; // Enumerating and Replacing Loading Entry Template Items string szCurrentLoadingEntry = szLoadingEntryTemplate; szCurrentLoadingEntry = str_replaceallA(szCurrentLoadingEntry, "##GAMEICON##", szIconPath); szCurrentLoadingEntry = str_replaceallA(szCurrentLoadingEntry, "##GAMECONTENTID##", szContentId); szCurrentLoadingEntry = str_replaceallA(szCurrentLoadingEntry, "##GAMEID##", szGameId); szLoadingEntries = szLoadingEntries + szCurrentLoadingEntry; nCounter++; } // Set up all of our tokens ApplyGenericTokens(obj); obj.out_replace_token("GAMELISTENTRIES", szEntries); obj.out_replace_token("GAMELISTLOADING", szLoadingEntries); SkinXMLReader xmlReader; xmlReader.LoadSettings("ScnGameView", "Captions"); switch (contentTab) { case CONTENT_360: obj.out_replace_token("GAMELISTTITLE", xmlReader.GetSetting("XBOX360", "Xbox 360 Games")); break; case CONTENT_XBLA: obj.out_replace_token("GAMELISTTITLE", xmlReader.GetSetting("XBLA", "Xbox Arcade Games")); break; case CONTENT_HOMEBREW: obj.out_replace_token("GAMELISTTITLE", xmlReader.GetSetting("HOMEBREW", "Homebrew")); break; case CONTENT_EMULATOR: obj.out_replace_token("GAMELISTTITLE", xmlReader.GetSetting("EMULATORS", "Emulators")); break; case CONTENT_XBOX1: obj.out_replace_token("GAMELISTTITLE", xmlReader.GetSetting("XBOXCLASSIC", "Xbox Classic Games")); break; }; // Load the gamelist html page, and output to browser if(HTTPServer::getInstance().bXZPMode == true) { BYTE * fileData = NULL; DWORD fileSize = 0; XZPManager::getInstance().XZPOpenMemory(SkinManager::getInstance().getCurrentFullSkinPath(), szGamelistRelativePath, &fileData, (UINT*)&fileSize); obj.out_set_file((void*)fileData, fileSize, EHTTP_TEXT_FILE); obj.out_replace_token("SESSIONID", ((HTTP_SESSION_DATA*)cookie)->SessionId); ApplyGenericTokens(obj); obj.out_replace_mem(); free(fileData); } else { string indexPath = SkinManager::getInstance().getCurrentFullSkinPath() + szGamelistRelativePath; obj.out_set_file(indexPath); obj.out_replace_token("SESSIONID", ((HTTP_SESSION_DATA*)cookie)->SessionId); ApplyGenericTokens(obj); obj.out_replace(); } return 0; }
int handleGameScreenshots( ehttp &obj, void * cookie ) { map<string,string>& mParams = obj.getUrlParams(); DWORD dwContentId = strtoul(mParams["contentid"].c_str(), NULL, 16); DWORD dwTitleId = strtoul(mParams["titleid"].c_str(), NULL, 16); int nContentType = atoi(mParams["contenttype"].c_str()); // Set up all of our tokens ApplyGenericTokens(obj); ApplyGameScreenshotTokens(obj, dwContentId, (DWORD)nContentType); ContentItemNew * pContentItem = ContentManager::getInstance().GetContentByContentId(dwContentId); if(pContentItem == NULL) return 0; // Set Relative Paths string szScreenshotRelativePath = "wwwroot\\screenshots.html"; string szEntriesRelativePath = "wwwroot\\screenshotentry.inc"; string szLoadingEntriesRelativePath = "wwwroot\\screenshotloadingentry.inc"; // Load the list entry template into our entrytemplate string string szEntryTemplate = ""; string szLoadingEntryTemplate = ""; if( HTTPServer::getInstance().bXZPMode == true ) { // Entry Template BYTE * entryTemplateData = NULL; DWORD entryTemplateSize = 0; XZPManager::getInstance().XZPOpenMemory(SkinManager::getInstance().getCurrentFullSkinPath(), szEntriesRelativePath, &entryTemplateData, (UINT*)&entryTemplateSize); // Copy the data from the file buffer to our Entry Template string char * szTempStringA = (char*)malloc(entryTemplateSize + 1); memset( szTempStringA, 0, entryTemplateSize + 1); memcpy( szTempStringA, (char*)entryTemplateData, entryTemplateSize); szEntryTemplate = szTempStringA; free(szTempStringA); free(entryTemplateData); // Loading Entry Template BYTE * loadingEntryTemplateData = NULL; DWORD loadingEntryTemplateSize = 0; XZPManager::getInstance().XZPOpenMemory(SkinManager::getInstance().getCurrentFullSkinPath(), szLoadingEntriesRelativePath, &loadingEntryTemplateData, (UINT*)&loadingEntryTemplateSize); // Copy the data from the file buffer to our Entry Template string char * szTempStringB = (char*)malloc(loadingEntryTemplateSize + 1); memset( szTempStringB, 0, loadingEntryTemplateSize + 1); memcpy( szTempStringB, (char*)loadingEntryTemplateData, loadingEntryTemplateSize); szLoadingEntryTemplate = szTempStringB; free(szTempStringB); free(loadingEntryTemplateData); } else { // Non XZP is easier to load szEntryTemplate = ReadFileToString(SkinManager::getInstance().getCurrentFullSkinPath() + szEntriesRelativePath); szLoadingEntryTemplate = ReadFileToString(SkinManager::getInstance().getCurrentFullSkinPath() + szLoadingEntriesRelativePath); } // Create entries token to be used in token_replace string szEntries = "", szLoadingEntries = ""; int nSSCount = pContentItem->getScreenshotCount(); if( nSSCount > SETTINGS::getInstance().getMaxScreenshots() ) nSSCount = SETTINGS::getInstance().getMaxScreenshots(); // Copy all of our screenshot paths to a local vector vector<string> m_ScreenshotPaths; for( int nCount = 0; nCount < nSSCount; nCount++) m_ScreenshotPaths.push_back(pContentItem->getScreenshotPath(nCount)); // Sort the vector with our custom routine to push the paths in the correct order sort(m_ScreenshotPaths.begin(), m_ScreenshotPaths.end(), sortScreenshotList); for( unsigned int nCount = 0; nCount < m_ScreenshotPaths.size(); nCount++) { string id = sprintfaA("SS%d", nCount+1); string id2 = sprintfaA("SSImg%d", nCount+1); string szDataPath = SETTINGS::getInstance().getDataPath(); string screenshotPath = m_ScreenshotPaths.at(nCount); string szFileName = screenshotPath.substr(screenshotPath.find_last_of("\\") + 1); szFileName = szFileName.substr(0, szFileName.find_first_of(".")); string ssid = szFileName.substr(strlen("screenshot")); screenshotPath = str_replaceallA(screenshotPath,szDataPath,""); screenshotPath = str_replaceallA(screenshotPath,"\\","/"); screenshotPath = str_replaceallA(screenshotPath,".dds",".dds"); string szCurrentEntry = szEntryTemplate; szCurrentEntry = str_replaceallA(szCurrentEntry, "##SCREENSHOT##", "fsdata/" + screenshotPath); szCurrentEntry = str_replaceallA(szCurrentEntry, "##SSID##", ssid); szEntries = szEntries + szCurrentEntry; // Enumerating and Replacing Loading Entry Template Items string szCurrentLoadingEntry = szLoadingEntryTemplate; szCurrentLoadingEntry = str_replaceallA(szCurrentLoadingEntry, "##SCREENSHOT##", "fsdata/" + screenshotPath); szCurrentLoadingEntry = str_replaceallA(szCurrentLoadingEntry, "##SSID##", ssid); szCurrentLoadingEntry = str_replaceallA(szCurrentLoadingEntry, "##ID##", id); szCurrentLoadingEntry = str_replaceallA(szCurrentLoadingEntry, "##ID2##", id2); szLoadingEntries = szLoadingEntries + szCurrentLoadingEntry; } // Set up all of our tokens obj.out_replace_token("SCREENSHOTLIST", szEntries); obj.out_replace_token("SCREENSHOTLOADING", szLoadingEntries); // Load the gamelist html page, and output to browser if(HTTPServer::getInstance().bXZPMode == true) { BYTE * fileData = NULL; DWORD fileSize = 0; XZPManager::getInstance().XZPOpenMemory(SkinManager::getInstance().getCurrentFullSkinPath(), szScreenshotRelativePath, &fileData, (UINT*)&fileSize); obj.out_set_file((void*)fileData, fileSize, EHTTP_TEXT_FILE); obj.out_replace_token("SESSIONID", ((HTTP_SESSION_DATA*)cookie)->SessionId); ApplyGenericTokens(obj); obj.out_replace_mem(); free(fileData); } else { string indexPath = SkinManager::getInstance().getCurrentFullSkinPath() + szScreenshotRelativePath; obj.out_replace_token("SESSIONID", ((HTTP_SESSION_DATA*)cookie)->SessionId); obj.out_set_file(indexPath); obj.out_replace(); } return 0; }
void File::ReadFileToStringOrDie(const string& filename, string* out) { ASSERT_HOST_MSG(ReadFileToString(filename, out), "Failed to read file: %s\n", filename.c_str()); }
void File::ReadFileToStringOrDie(const string& filename, string* out) { ASSERT_HOST(ReadFileToString(filename, out)); }