diff options
| author | 2015-02-05 22:32:15 -0200 | |
|---|---|---|
| committer | 2015-02-10 13:43:43 -0200 | |
| commit | 4468625080c9388f2fe81a791e8295e6961e96f5 (patch) | |
| tree | fbebb2112bcb77bfe6c13c9fa226df468aa1293a /src | |
| parent | Merge pull request #553 from lioncash/denorm (diff) | |
| download | yuzu-4468625080c9388f2fe81a791e8295e6961e96f5.tar.gz yuzu-4468625080c9388f2fe81a791e8295e6961e96f5.tar.xz yuzu-4468625080c9388f2fe81a791e8295e6961e96f5.zip | |
FS: Get rid of completely useless Archive class
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/fs/archive.cpp | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index ccf132f31..6030e05e0 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp | |||
| @@ -74,18 +74,6 @@ enum class DirectoryCommand : u32 { | |||
| 74 | Close = 0x08020000, | 74 | Close = 0x08020000, |
| 75 | }; | 75 | }; |
| 76 | 76 | ||
| 77 | class Archive { | ||
| 78 | public: | ||
| 79 | Archive(std::unique_ptr<FileSys::ArchiveBackend>&& backend, ArchiveIdCode id_code) | ||
| 80 | : id_code(id_code), backend(std::move(backend)) { | ||
| 81 | } | ||
| 82 | |||
| 83 | std::string GetName() const { return "Archive: " + backend->GetName(); } | ||
| 84 | |||
| 85 | ArchiveIdCode id_code; ///< Id code of the archive | ||
| 86 | std::unique_ptr<FileSys::ArchiveBackend> backend; ///< Archive backend interface | ||
| 87 | }; | ||
| 88 | |||
| 89 | class File : public Kernel::Session { | 77 | class File : public Kernel::Session { |
| 90 | public: | 78 | public: |
| 91 | File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path& path) | 79 | File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path& path) |
| @@ -244,19 +232,21 @@ public: | |||
| 244 | 232 | ||
| 245 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 233 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 246 | 234 | ||
| 235 | using FileSys::ArchiveBackend; | ||
| 236 | |||
| 247 | /** | 237 | /** |
| 248 | * Map of registered archives, identified by id code. Once an archive is registered here, it is | 238 | * Map of registered archives, identified by id code. Once an archive is registered here, it is |
| 249 | * never removed until the FS service is shut down. | 239 | * never removed until the FS service is shut down. |
| 250 | */ | 240 | */ |
| 251 | static std::unordered_map<ArchiveIdCode, std::unique_ptr<Archive>> id_code_map; | 241 | static std::unordered_map<ArchiveIdCode, std::unique_ptr<ArchiveBackend>> id_code_map; |
| 252 | 242 | ||
| 253 | /** | 243 | /** |
| 254 | * Map of active archive handles. Values are pointers to the archives in `idcode_map`. | 244 | * Map of active archive handles. Values are pointers to the archives in `idcode_map`. |
| 255 | */ | 245 | */ |
| 256 | static std::unordered_map<ArchiveHandle, Archive*> handle_map; | 246 | static std::unordered_map<ArchiveHandle, ArchiveBackend*> handle_map; |
| 257 | static ArchiveHandle next_handle; | 247 | static ArchiveHandle next_handle; |
| 258 | 248 | ||
| 259 | static Archive* GetArchive(ArchiveHandle handle) { | 249 | static ArchiveBackend* GetArchive(ArchiveHandle handle) { |
| 260 | auto itr = handle_map.find(handle); | 250 | auto itr = handle_map.find(handle); |
| 261 | return (itr == handle_map.end()) ? nullptr : itr->second; | 251 | return (itr == handle_map.end()) ? nullptr : itr->second; |
| 262 | } | 252 | } |
| @@ -271,7 +261,7 @@ ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archi | |||
| 271 | ErrorSummary::NotFound, ErrorLevel::Permanent); | 261 | ErrorSummary::NotFound, ErrorLevel::Permanent); |
| 272 | } | 262 | } |
| 273 | 263 | ||
| 274 | ResultCode res = itr->second->backend->Open(archive_path); | 264 | ResultCode res = itr->second->Open(archive_path); |
| 275 | if (!res.IsSuccess()) | 265 | if (!res.IsSuccess()) |
| 276 | return res; | 266 | return res; |
| 277 | 267 | ||
| @@ -293,7 +283,7 @@ ResultCode CloseArchive(ArchiveHandle handle) { | |||
| 293 | // TODO(yuriks): This might be what the fs:REG service is for. See the Register/Unregister calls in | 283 | // TODO(yuriks): This might be what the fs:REG service is for. See the Register/Unregister calls in |
| 294 | // http://3dbrew.org/wiki/Filesystem_services#ProgramRegistry_service_.22fs:REG.22 | 284 | // http://3dbrew.org/wiki/Filesystem_services#ProgramRegistry_service_.22fs:REG.22 |
| 295 | ResultCode CreateArchive(std::unique_ptr<FileSys::ArchiveBackend>&& backend, ArchiveIdCode id_code) { | 285 | ResultCode CreateArchive(std::unique_ptr<FileSys::ArchiveBackend>&& backend, ArchiveIdCode id_code) { |
| 296 | auto result = id_code_map.emplace(id_code, Common::make_unique<Archive>(std::move(backend), id_code)); | 286 | auto result = id_code_map.emplace(id_code, std::move(backend)); |
| 297 | 287 | ||
| 298 | bool inserted = result.second; | 288 | bool inserted = result.second; |
| 299 | _dbg_assert_msg_(Service_FS, inserted, "Tried to register more than one archive with same id code"); | 289 | _dbg_assert_msg_(Service_FS, inserted, "Tried to register more than one archive with same id code"); |
| @@ -305,11 +295,11 @@ ResultCode CreateArchive(std::unique_ptr<FileSys::ArchiveBackend>&& backend, Arc | |||
| 305 | 295 | ||
| 306 | ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenFileFromArchive(ArchiveHandle archive_handle, | 296 | ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenFileFromArchive(ArchiveHandle archive_handle, |
| 307 | const FileSys::Path& path, const FileSys::Mode mode) { | 297 | const FileSys::Path& path, const FileSys::Mode mode) { |
| 308 | Archive* archive = GetArchive(archive_handle); | 298 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 309 | if (archive == nullptr) | 299 | if (archive == nullptr) |
| 310 | return ERR_INVALID_HANDLE; | 300 | return ERR_INVALID_HANDLE; |
| 311 | 301 | ||
| 312 | std::unique_ptr<FileSys::FileBackend> backend = archive->backend->OpenFile(path, mode); | 302 | std::unique_ptr<FileSys::FileBackend> backend = archive->OpenFile(path, mode); |
| 313 | if (backend == nullptr) { | 303 | if (backend == nullptr) { |
| 314 | return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, | 304 | return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, |
| 315 | ErrorSummary::NotFound, ErrorLevel::Status); | 305 | ErrorSummary::NotFound, ErrorLevel::Status); |
| @@ -320,11 +310,11 @@ ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenFileFromArchive(ArchiveHandle | |||
| 320 | } | 310 | } |
| 321 | 311 | ||
| 322 | ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { | 312 | ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { |
| 323 | Archive* archive = GetArchive(archive_handle); | 313 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 324 | if (archive == nullptr) | 314 | if (archive == nullptr) |
| 325 | return ERR_INVALID_HANDLE; | 315 | return ERR_INVALID_HANDLE; |
| 326 | 316 | ||
| 327 | if (archive->backend->DeleteFile(path)) | 317 | if (archive->DeleteFile(path)) |
| 328 | return RESULT_SUCCESS; | 318 | return RESULT_SUCCESS; |
| 329 | return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description | 319 | return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description |
| 330 | ErrorSummary::Canceled, ErrorLevel::Status); | 320 | ErrorSummary::Canceled, ErrorLevel::Status); |
| @@ -332,13 +322,13 @@ ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Pa | |||
| 332 | 322 | ||
| 333 | ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle, const FileSys::Path& src_path, | 323 | ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle, const FileSys::Path& src_path, |
| 334 | ArchiveHandle dest_archive_handle, const FileSys::Path& dest_path) { | 324 | ArchiveHandle dest_archive_handle, const FileSys::Path& dest_path) { |
| 335 | Archive* src_archive = GetArchive(src_archive_handle); | 325 | ArchiveBackend* src_archive = GetArchive(src_archive_handle); |
| 336 | Archive* dest_archive = GetArchive(dest_archive_handle); | 326 | ArchiveBackend* dest_archive = GetArchive(dest_archive_handle); |
| 337 | if (src_archive == nullptr || dest_archive == nullptr) | 327 | if (src_archive == nullptr || dest_archive == nullptr) |
| 338 | return ERR_INVALID_HANDLE; | 328 | return ERR_INVALID_HANDLE; |
| 339 | 329 | ||
| 340 | if (src_archive == dest_archive) { | 330 | if (src_archive == dest_archive) { |
| 341 | if (src_archive->backend->RenameFile(src_path, dest_path)) | 331 | if (src_archive->RenameFile(src_path, dest_path)) |
| 342 | return RESULT_SUCCESS; | 332 | return RESULT_SUCCESS; |
| 343 | } else { | 333 | } else { |
| 344 | // TODO: Implement renaming across archives | 334 | // TODO: Implement renaming across archives |
| @@ -352,30 +342,30 @@ ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle, const Fil | |||
| 352 | } | 342 | } |
| 353 | 343 | ||
| 354 | ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { | 344 | ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { |
| 355 | Archive* archive = GetArchive(archive_handle); | 345 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 356 | if (archive == nullptr) | 346 | if (archive == nullptr) |
| 357 | return ERR_INVALID_HANDLE; | 347 | return ERR_INVALID_HANDLE; |
| 358 | 348 | ||
| 359 | if (archive->backend->DeleteDirectory(path)) | 349 | if (archive->DeleteDirectory(path)) |
| 360 | return RESULT_SUCCESS; | 350 | return RESULT_SUCCESS; |
| 361 | return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description | 351 | return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description |
| 362 | ErrorSummary::Canceled, ErrorLevel::Status); | 352 | ErrorSummary::Canceled, ErrorLevel::Status); |
| 363 | } | 353 | } |
| 364 | 354 | ||
| 365 | ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path& path, u32 file_size) { | 355 | ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path& path, u32 file_size) { |
| 366 | Archive* archive = GetArchive(archive_handle); | 356 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 367 | if (archive == nullptr) | 357 | if (archive == nullptr) |
| 368 | return ERR_INVALID_HANDLE; | 358 | return ERR_INVALID_HANDLE; |
| 369 | 359 | ||
| 370 | return archive->backend->CreateFile(path, file_size); | 360 | return archive->CreateFile(path, file_size); |
| 371 | } | 361 | } |
| 372 | 362 | ||
| 373 | ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { | 363 | ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { |
| 374 | Archive* archive = GetArchive(archive_handle); | 364 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 375 | if (archive == nullptr) | 365 | if (archive == nullptr) |
| 376 | return ERR_INVALID_HANDLE; | 366 | return ERR_INVALID_HANDLE; |
| 377 | 367 | ||
| 378 | if (archive->backend->CreateDirectory(path)) | 368 | if (archive->CreateDirectory(path)) |
| 379 | return RESULT_SUCCESS; | 369 | return RESULT_SUCCESS; |
| 380 | return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description | 370 | return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description |
| 381 | ErrorSummary::Canceled, ErrorLevel::Status); | 371 | ErrorSummary::Canceled, ErrorLevel::Status); |
| @@ -383,13 +373,13 @@ ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSy | |||
| 383 | 373 | ||
| 384 | ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, const FileSys::Path& src_path, | 374 | ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, const FileSys::Path& src_path, |
| 385 | ArchiveHandle dest_archive_handle, const FileSys::Path& dest_path) { | 375 | ArchiveHandle dest_archive_handle, const FileSys::Path& dest_path) { |
| 386 | Archive* src_archive = GetArchive(src_archive_handle); | 376 | ArchiveBackend* src_archive = GetArchive(src_archive_handle); |
| 387 | Archive* dest_archive = GetArchive(dest_archive_handle); | 377 | ArchiveBackend* dest_archive = GetArchive(dest_archive_handle); |
| 388 | if (src_archive == nullptr || dest_archive == nullptr) | 378 | if (src_archive == nullptr || dest_archive == nullptr) |
| 389 | return ERR_INVALID_HANDLE; | 379 | return ERR_INVALID_HANDLE; |
| 390 | 380 | ||
| 391 | if (src_archive == dest_archive) { | 381 | if (src_archive == dest_archive) { |
| 392 | if (src_archive->backend->RenameDirectory(src_path, dest_path)) | 382 | if (src_archive->RenameDirectory(src_path, dest_path)) |
| 393 | return RESULT_SUCCESS; | 383 | return RESULT_SUCCESS; |
| 394 | } else { | 384 | } else { |
| 395 | // TODO: Implement renaming across archives | 385 | // TODO: Implement renaming across archives |
| @@ -404,11 +394,11 @@ ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, cons | |||
| 404 | 394 | ||
| 405 | ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenDirectoryFromArchive(ArchiveHandle archive_handle, | 395 | ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenDirectoryFromArchive(ArchiveHandle archive_handle, |
| 406 | const FileSys::Path& path) { | 396 | const FileSys::Path& path) { |
| 407 | Archive* archive = GetArchive(archive_handle); | 397 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 408 | if (archive == nullptr) | 398 | if (archive == nullptr) |
| 409 | return ERR_INVALID_HANDLE; | 399 | return ERR_INVALID_HANDLE; |
| 410 | 400 | ||
| 411 | std::unique_ptr<FileSys::DirectoryBackend> backend = archive->backend->OpenDirectory(path); | 401 | std::unique_ptr<FileSys::DirectoryBackend> backend = archive->OpenDirectory(path); |
| 412 | if (backend == nullptr) { | 402 | if (backend == nullptr) { |
| 413 | return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, | 403 | return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, |
| 414 | ErrorSummary::NotFound, ErrorLevel::Permanent); | 404 | ErrorSummary::NotFound, ErrorLevel::Permanent); |
| @@ -426,7 +416,7 @@ ResultCode FormatSaveData() { | |||
| 426 | } | 416 | } |
| 427 | 417 | ||
| 428 | // Use an empty path, we do not use it when formatting the savedata | 418 | // Use an empty path, we do not use it when formatting the savedata |
| 429 | return archive_itr->second->backend->Format(FileSys::Path()); | 419 | return archive_itr->second->Format(FileSys::Path()); |
| 430 | } | 420 | } |
| 431 | 421 | ||
| 432 | ResultCode CreateExtSaveData(u32 high, u32 low) { | 422 | ResultCode CreateExtSaveData(u32 high, u32 low) { |