| 255 | } |
| 256 | |
| 257 | std::vector<SaveMetadata> SaveManager::getSaveList() const |
| 258 | { |
| 259 | auto dirString = Options::saveDirOption.get(); |
| 260 | fs::path saveDirectory = dirString; |
| 261 | std::vector<SaveMetadata> saveList; |
| 262 | try |
| 263 | { |
| 264 | if (!fs::exists(saveDirectory) && !fs::create_directories(saveDirectory)) |
| 265 | { |
| 266 | LogWarning("Save directory \"%s\" not found, and could not be created!", saveDirectory); |
| 267 | return saveList; |
| 268 | } |
| 269 | |
| 270 | for (auto i = fs::directory_iterator(saveDirectory); i != fs::directory_iterator(); ++i) |
| 271 | { |
| 272 | if (i->path().extension().string() != saveFileExtension) |
| 273 | { |
| 274 | continue; |
| 275 | } |
| 276 | |
| 277 | std::string saveFileName = i->path().filename().string(); |
| 278 | // miniz can't read paths not starting with dir or with windows slashes |
| 279 | UString savePath = saveDirectory.string() + "/" + saveFileName; |
| 280 | if (auto archive = SerializationArchive::readArchive(savePath)) |
| 281 | { |
| 282 | SaveMetadata metadata; |
| 283 | if (metadata.deserializeManifest(archive.get(), savePath)) |
| 284 | { |
| 285 | saveList.push_back(metadata); |
| 286 | } |
| 287 | else // accept saves with missing manifest if extension is correct |
| 288 | { |
| 289 | saveList.push_back(SaveMetadata("Unknown(Missing manifest)", savePath, 0, |
| 290 | SaveType::Manual, nullptr)); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | catch (fs::filesystem_error &er) |
| 296 | { |
| 297 | LogError("Error while enumerating directory: \"%s\"", er.what()); |
| 298 | } |
| 299 | |
| 300 | sort(saveList.begin(), saveList.end(), [](const SaveMetadata &lhs, const SaveMetadata &rhs) { |
| 301 | return lhs.getCreationDate() > rhs.getCreationDate(); |
| 302 | }); |
| 303 | |
| 304 | return saveList; |
| 305 | } |
| 306 | |
| 307 | bool SaveManager::deleteGame(const sp<SaveMetadata> &slot) const |
| 308 | { |
no test coverage detected