| 296 | } |
| 297 | |
| 298 | Result io::copyTree(FS_Archive srcArch, FS_Archive dstArch, const std::u16string& srcRoot, const std::u16string& dstRoot, |
| 299 | const std::vector<TreeEntry>& entries, ProgressSink& sink) |
| 300 | { |
| 301 | // One scratch buffer for every file in the tree instead of a per-file new/delete. |
| 302 | auto buf = std::make_unique<u8[]>(BUFFER_SIZE); |
| 303 | Result res = 0; |
| 304 | |
| 305 | for (const auto& entry : entries) { |
| 306 | if (sink.cancelled()) { |
| 307 | break; |
| 308 | } |
| 309 | std::u16string dst = dstRoot + entry.rel; |
| 310 | if (entry.folder) { |
| 311 | res = io::createDirectory(dstArch, dst); |
| 312 | // An existing directory is as good as a new one. |
| 313 | if (R_FAILED(res) && (u32)res != RES_FS_DIR_EXISTS) { |
| 314 | return res; |
| 315 | } |
| 316 | res = 0; |
| 317 | } |
| 318 | else { |
| 319 | res = io::copyFile(srcArch, dstArch, srcRoot + entry.rel, dst, sink, buf.get()); |
| 320 | if (R_FAILED(res)) { |
| 321 | return res; |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | return res; |
| 327 | } |
| 328 | |
| 329 | Result io::createDirectory(FS_Archive archive, const std::u16string& path) |
| 330 | { |