| 253 | static std::atomic<int> gExtractCounter{0}; |
| 254 | |
| 255 | std::string StudioApp::extractPboFile(const std::string& pboPath, const std::string& pboFilename) |
| 256 | { |
| 257 | try |
| 258 | { |
| 259 | QFBank bank; |
| 260 | std::string bankName = StripPboExtension(pboPath); |
| 261 | if (!bank.open(RString(bankName.c_str()))) |
| 262 | return {}; |
| 263 | bank.Lock(); |
| 264 | if (bank.error()) |
| 265 | return {}; |
| 266 | Ref<IFileBuffer> data = bank.Read(pboFilename.c_str()); |
| 267 | if (!data || data->GetSize() == 0) |
| 268 | return {}; |
| 269 | auto tempDir = std::filesystem::temp_directory_path(); |
| 270 | auto ext = std::filesystem::path(pboFilename).extension().string(); |
| 271 | int id = gExtractCounter++; |
| 272 | std::string tmpPath = (tempDir / ("poseidon_xref_" + std::to_string(id) + ext)).string(); |
| 273 | std::ofstream out(tmpPath, std::ios::binary); |
| 274 | if (!out) |
| 275 | return {}; |
| 276 | out.write(static_cast<const char*>(data->GetData()), data->GetSize()); |
| 277 | out.close(); |
| 278 | return tmpPath; |
| 279 | } |
| 280 | catch (...) |
| 281 | { |
| 282 | return {}; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | std::string StudioApp::extractVirtualFile(const FileEntry& entry) |
| 287 | { |