mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	Services/AM: Return InstallStatus for InstallCIA
This commit is contained in:
		
							parent
							
								
									553ca2bfe0
								
							
						
					
					
						commit
						253954930f
					
				
					 3 changed files with 20 additions and 9 deletions
				
			
		|  | @ -98,7 +98,8 @@ int main(int argc, char** argv) { | ||||||
|                 const auto cia_progress = [](size_t written, size_t total) { |                 const auto cia_progress = [](size_t written, size_t total) { | ||||||
|                     LOG_INFO(Frontend, "%02zu%%", (written * 100 / total)); |                     LOG_INFO(Frontend, "%02zu%%", (written * 100 / total)); | ||||||
|                 }; |                 }; | ||||||
|                 if (!Service::AM::InstallCIA(std::string(optarg), cia_progress)) |                 if (Service::AM::InstallCIA(std::string(optarg), cia_progress) != | ||||||
|  |                     Service::AM::InstallStatus::Success) | ||||||
|                     errno = EINVAL; |                     errno = EINVAL; | ||||||
|                 if (errno != 0) |                 if (errno != 0) | ||||||
|                     exit(1); |                     exit(1); | ||||||
|  |  | ||||||
|  | @ -283,12 +283,13 @@ bool CIAFile::Close() const { | ||||||
| 
 | 
 | ||||||
| void CIAFile::Flush() const {} | void CIAFile::Flush() const {} | ||||||
| 
 | 
 | ||||||
| bool InstallCIA(const std::string& path, std::function<ProgressCallback>&& update_callback) { | InstallStatus InstallCIA(const std::string& path, | ||||||
|  |                          std::function<ProgressCallback>&& update_callback) { | ||||||
|     LOG_INFO(Service_AM, "Installing %s...", path.c_str()); |     LOG_INFO(Service_AM, "Installing %s...", path.c_str()); | ||||||
| 
 | 
 | ||||||
|     if (!FileUtil::Exists(path)) { |     if (!FileUtil::Exists(path)) { | ||||||
|         LOG_ERROR(Service_AM, "File %s does not exist!", path.c_str()); |         LOG_ERROR(Service_AM, "File %s does not exist!", path.c_str()); | ||||||
|         return false; |         return InstallStatus::ErrorFileNotFound; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     FileSys::CIAContainer container; |     FileSys::CIAContainer container; | ||||||
|  | @ -298,7 +299,7 @@ bool InstallCIA(const std::string& path, std::function<ProgressCallback>&& updat | ||||||
| 
 | 
 | ||||||
|         FileUtil::IOFile file(path, "rb"); |         FileUtil::IOFile file(path, "rb"); | ||||||
|         if (!file.IsOpen()) |         if (!file.IsOpen()) | ||||||
|             return false; |             return InstallStatus::ErrorFailedToOpenFile; | ||||||
| 
 | 
 | ||||||
|         std::array<u8, 0x10000> buffer; |         std::array<u8, 0x10000> buffer; | ||||||
|         size_t total_bytes_read = 0; |         size_t total_bytes_read = 0; | ||||||
|  | @ -312,18 +313,18 @@ bool InstallCIA(const std::string& path, std::function<ProgressCallback>&& updat | ||||||
|             if (result.Failed()) { |             if (result.Failed()) { | ||||||
|                 LOG_ERROR(Service_AM, "CIA file installation aborted with error code %08x", |                 LOG_ERROR(Service_AM, "CIA file installation aborted with error code %08x", | ||||||
|                           result.Code()); |                           result.Code()); | ||||||
|                 return false; |                 return InstallStatus::ErrorAborted; | ||||||
|             } |             } | ||||||
|             total_bytes_read += bytes_read; |             total_bytes_read += bytes_read; | ||||||
|         } |         } | ||||||
|         installFile.Close(); |         installFile.Close(); | ||||||
| 
 | 
 | ||||||
|         LOG_INFO(Service_AM, "Installed %s successfully.", path.c_str()); |         LOG_INFO(Service_AM, "Installed %s successfully.", path.c_str()); | ||||||
|         return true; |         return InstallStatus::Success; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     LOG_ERROR(Service_AM, "CIA file %s is invalid!", path.c_str()); |     LOG_ERROR(Service_AM, "CIA file %s is invalid!", path.c_str()); | ||||||
|     return false; |     return InstallStatus::ErrorInvalid; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Service::FS::MediaType GetTitleMediaType(u64 titleId) { | Service::FS::MediaType GetTitleMediaType(u64 titleId) { | ||||||
|  |  | ||||||
|  | @ -42,6 +42,15 @@ enum class CIAInstallState : u32 { | ||||||
|     ContentWritten, |     ContentWritten, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | enum class InstallStatus : u32 { | ||||||
|  |     Success, | ||||||
|  |     ErrorFailedToOpenFile, | ||||||
|  |     ErrorFileNotFound, | ||||||
|  |     ErrorAborted, | ||||||
|  |     ErrorInvalid, | ||||||
|  |     ErrorEncrypted, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| // Progress callback for InstallCIA, recieves bytes written and total bytes
 | // Progress callback for InstallCIA, recieves bytes written and total bytes
 | ||||||
| using ProgressCallback = void(size_t, size_t); | using ProgressCallback = void(size_t, size_t); | ||||||
| 
 | 
 | ||||||
|  | @ -83,8 +92,8 @@ private: | ||||||
|  * @param update_callback callback function called during filesystem write |  * @param update_callback callback function called during filesystem write | ||||||
|  * @returns bool whether the install was successful |  * @returns bool whether the install was successful | ||||||
|  */ |  */ | ||||||
| bool InstallCIA(const std::string& path, | InstallStatus InstallCIA(const std::string& path, | ||||||
|                 std::function<ProgressCallback>&& update_callback = nullptr); |                          std::function<ProgressCallback>&& update_callback = nullptr); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Get the mediatype for an installed title |  * Get the mediatype for an installed title | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue