Pulls the current slot's bare save out of the AGBSAVE container behind `file` into a fresh buffer. Used both on the PXI file (backup) and on a legacy full-container SD dump (restore of a pre-format-change backup).
| 149 | // `file` into a fresh buffer. Used both on the PXI file (backup) and on a |
| 150 | // legacy full-container SD dump (restore of a pre-format-change backup). |
| 151 | Result extractCurrentSave(FSStream& file, AgbSaveHeader& hdr, std::unique_ptr<u8[]>& save) |
| 152 | { |
| 153 | u32 slotOffset = 0; |
| 154 | if (!locateCurrentSlot(file, hdr, slotOffset)) { |
| 155 | return GbaSave::resNoSave; |
| 156 | } |
| 157 | save = std::make_unique<u8[]>(hdr.saveSize); |
| 158 | file.offset(slotOffset + kHeaderSize); |
| 159 | if (file.read(save.get(), hdr.saveSize) != hdr.saveSize || R_FAILED(file.result())) { |
| 160 | return R_FAILED(file.result()) ? file.result() : GbaSave::resBadBackup; |
| 161 | } |
| 162 | return 0; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | Result GbaSave::backup(FSPXI_Archive arch, FS_Archive sdmc, const std::u16string& dstPath, ProgressSink& sink) |