mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00:00 
			
		
		
		
	cfg: access FS via backend directly
This commit is contained in:
		
							parent
							
								
									2757eff122
								
							
						
					
					
						commit
						bcb5d438a9
					
				
					 2 changed files with 22 additions and 17 deletions
				
			
		|  | @ -5,6 +5,7 @@ | ||||||
| #include <algorithm> | #include <algorithm> | ||||||
| #include <cryptopp/osrng.h> | #include <cryptopp/osrng.h> | ||||||
| #include <cryptopp/sha.h> | #include <cryptopp/sha.h> | ||||||
|  | #include "common/common_paths.h" | ||||||
| #include "common/file_util.h" | #include "common/file_util.h" | ||||||
| #include "common/logging/log.h" | #include "common/logging/log.h" | ||||||
| #include "common/string_util.h" | #include "common/string_util.h" | ||||||
|  | @ -388,7 +389,7 @@ ResultCode Module::CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const | ||||||
| 
 | 
 | ||||||
| ResultCode Module::DeleteConfigNANDSaveFile() { | ResultCode Module::DeleteConfigNANDSaveFile() { | ||||||
|     FileSys::Path path("/config"); |     FileSys::Path path("/config"); | ||||||
|     return Service::FS::DeleteFileFromArchive(cfg_system_save_data_archive, path); |     return cfg_system_save_data_archive->DeleteFile(path); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ResultCode Module::UpdateConfigNANDSavegame() { | ResultCode Module::UpdateConfigNANDSavegame() { | ||||||
|  | @ -398,11 +399,11 @@ ResultCode Module::UpdateConfigNANDSavegame() { | ||||||
| 
 | 
 | ||||||
|     FileSys::Path path("/config"); |     FileSys::Path path("/config"); | ||||||
| 
 | 
 | ||||||
|     auto config_result = Service::FS::OpenFileFromArchive(cfg_system_save_data_archive, path, mode); |     auto config_result = cfg_system_save_data_archive->OpenFile(path, mode); | ||||||
|     ASSERT_MSG(config_result.Succeeded(), "could not open file"); |     ASSERT_MSG(config_result.Succeeded(), "could not open file"); | ||||||
| 
 | 
 | ||||||
|     auto config = std::move(config_result).Unwrap(); |     auto config = std::move(config_result).Unwrap(); | ||||||
|     config->backend->Write(0, CONFIG_SAVEFILE_SIZE, 1, cfg_config_file_buffer.data()); |     config->Write(0, CONFIG_SAVEFILE_SIZE, 1, cfg_config_file_buffer.data()); | ||||||
| 
 | 
 | ||||||
|     return RESULT_SUCCESS; |     return RESULT_SUCCESS; | ||||||
| } | } | ||||||
|  | @ -527,36 +528,36 @@ ResultCode Module::FormatConfig() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ResultCode Module::LoadConfigNANDSaveFile() { | ResultCode Module::LoadConfigNANDSaveFile() { | ||||||
|  |     std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); | ||||||
|  |     FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory(nand_directory); | ||||||
|  | 
 | ||||||
|     // Open the SystemSaveData archive 0x00010017
 |     // Open the SystemSaveData archive 0x00010017
 | ||||||
|     FileSys::Path archive_path(cfg_system_savedata_id); |     FileSys::Path archive_path(cfg_system_savedata_id); | ||||||
|     auto archive_result = |     auto archive_result = systemsavedata_factory.Open(archive_path); | ||||||
|         Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); |  | ||||||
| 
 | 
 | ||||||
|     // If the archive didn't exist, create the files inside
 |     // If the archive didn't exist, create the files inside
 | ||||||
|     if (archive_result.Code() == FileSys::ERR_NOT_FORMATTED) { |     if (archive_result.Code() == FileSys::ERR_NOT_FORMATTED) { | ||||||
|         // Format the archive to create the directories
 |         // Format the archive to create the directories
 | ||||||
|         Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SystemSaveData, |         systemsavedata_factory.Format(archive_path, FileSys::ArchiveFormatInfo()); | ||||||
|                                    FileSys::ArchiveFormatInfo(), archive_path); |  | ||||||
| 
 | 
 | ||||||
|         // Open it again to get a valid archive now that the folder exists
 |         // Open it again to get a valid archive now that the folder exists
 | ||||||
|         archive_result = |         cfg_system_save_data_archive = systemsavedata_factory.Open(archive_path).Unwrap(); | ||||||
|             Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); |     } else { | ||||||
|  |         ASSERT_MSG(archive_result.Succeeded(), "Could not open the CFG SystemSaveData archive!"); | ||||||
|  | 
 | ||||||
|  |         cfg_system_save_data_archive = std::move(archive_result).Unwrap(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     ASSERT_MSG(archive_result.Succeeded(), "Could not open the CFG SystemSaveData archive!"); |  | ||||||
| 
 |  | ||||||
|     cfg_system_save_data_archive = *archive_result; |  | ||||||
| 
 |  | ||||||
|     FileSys::Path config_path("/config"); |     FileSys::Path config_path("/config"); | ||||||
|     FileSys::Mode open_mode = {}; |     FileSys::Mode open_mode = {}; | ||||||
|     open_mode.read_flag.Assign(1); |     open_mode.read_flag.Assign(1); | ||||||
| 
 | 
 | ||||||
|     auto config_result = Service::FS::OpenFileFromArchive(*archive_result, config_path, open_mode); |     auto config_result = cfg_system_save_data_archive->OpenFile(config_path, open_mode); | ||||||
| 
 | 
 | ||||||
|     // Read the file if it already exists
 |     // Read the file if it already exists
 | ||||||
|     if (config_result.Succeeded()) { |     if (config_result.Succeeded()) { | ||||||
|         auto config = std::move(config_result).Unwrap(); |         auto config = std::move(config_result).Unwrap(); | ||||||
|         config->backend->Read(0, CONFIG_SAVEFILE_SIZE, cfg_config_file_buffer.data()); |         config->Read(0, CONFIG_SAVEFILE_SIZE, cfg_config_file_buffer.data()); | ||||||
|         return RESULT_SUCCESS; |         return RESULT_SUCCESS; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -8,7 +8,11 @@ | ||||||
| #include <memory> | #include <memory> | ||||||
| #include <string> | #include <string> | ||||||
| #include "common/common_types.h" | #include "common/common_types.h" | ||||||
| #include "core/hle/service/fs/archive.h" | #include "core/hle/service/service.h" | ||||||
|  | 
 | ||||||
|  | namespace FileSys { | ||||||
|  | class ArchiveBackend; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| namespace Service::CFG { | namespace Service::CFG { | ||||||
| 
 | 
 | ||||||
|  | @ -399,7 +403,7 @@ public: | ||||||
| private: | private: | ||||||
|     static constexpr u32 CONFIG_SAVEFILE_SIZE = 0x8000; |     static constexpr u32 CONFIG_SAVEFILE_SIZE = 0x8000; | ||||||
|     std::array<u8, CONFIG_SAVEFILE_SIZE> cfg_config_file_buffer; |     std::array<u8, CONFIG_SAVEFILE_SIZE> cfg_config_file_buffer; | ||||||
|     Service::FS::ArchiveHandle cfg_system_save_data_archive; |     std::unique_ptr<FileSys::ArchiveBackend> cfg_system_save_data_archive; | ||||||
|     u32 preferred_region_code = 0; |     u32 preferred_region_code = 0; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue