| 2126 | } |
| 2127 | |
| 2128 | void GameEventHandler::ExtractPakFile(StringView pakFile, StringView targetPath) |
| 2129 | { |
| 2130 | PakFile pak(pakFile); |
| 2131 | if (!pak.IsValid()) { |
| 2132 | LOGE("Invalid .pak file specified"); |
| 2133 | return; |
| 2134 | } |
| 2135 | |
| 2136 | LOGI("Extracting files from \"{}\" to \"{}\"...", pakFile, targetPath); |
| 2137 | |
| 2138 | SmallVector<String> queue; |
| 2139 | queue.emplace_back(); // Root |
| 2140 | |
| 2141 | std::int32_t successCount = 0, errorCount = 0; |
| 2142 | for (std::size_t i = 0; i < queue.size(); i++) { |
| 2143 | for (auto childItem : PakFile::Directory(pak, queue[i])) { |
| 2144 | auto sourceFile = pak.OpenFile(childItem); |
| 2145 | if (sourceFile != nullptr) { |
| 2146 | auto targetFilePath = fs::CombinePath(targetPath, childItem); |
| 2147 | fs::CreateDirectories(fs::GetDirectoryName(targetFilePath)); |
| 2148 | auto targetFile = fs::Open(targetFilePath, FileAccess::Write); |
| 2149 | if (targetFile->IsValid()) { |
| 2150 | sourceFile->CopyTo(*targetFile); |
| 2151 | successCount++; |
| 2152 | } else { |
| 2153 | LOGE("Failed to create target file \"{}\"", targetFilePath); |
| 2154 | errorCount++; |
| 2155 | } |
| 2156 | } else { |
| 2157 | // Probably directory |
| 2158 | queue.emplace_back(childItem); |
| 2159 | } |
| 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | LOGI("{} files extracted successfully, {} files failed with error", successCount, errorCount); |
| 2164 | } |
| 2165 | |
| 2166 | #if defined(DEATH_TARGET_ANDROID) |
| 2167 | std::unique_ptr<IAppEventHandler> CreateAppEventHandler() |