Services/AM: Return InstallStatus for InstallCIA
This commit is contained in:
parent
553ca2bfe0
commit
253954930f
|
@ -98,7 +98,8 @@ int main(int argc, char** argv) {
|
|||
const auto cia_progress = [](size_t written, size_t 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;
|
||||
if (errno != 0)
|
||||
exit(1);
|
||||
|
|
|
@ -283,12 +283,13 @@ bool CIAFile::Close() 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());
|
||||
|
||||
if (!FileUtil::Exists(path)) {
|
||||
LOG_ERROR(Service_AM, "File %s does not exist!", path.c_str());
|
||||
return false;
|
||||
return InstallStatus::ErrorFileNotFound;
|
||||
}
|
||||
|
||||
FileSys::CIAContainer container;
|
||||
|
@ -298,7 +299,7 @@ bool InstallCIA(const std::string& path, std::function<ProgressCallback>&& updat
|
|||
|
||||
FileUtil::IOFile file(path, "rb");
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
return InstallStatus::ErrorFailedToOpenFile;
|
||||
|
||||
std::array<u8, 0x10000> buffer;
|
||||
size_t total_bytes_read = 0;
|
||||
|
@ -312,18 +313,18 @@ bool InstallCIA(const std::string& path, std::function<ProgressCallback>&& updat
|
|||
if (result.Failed()) {
|
||||
LOG_ERROR(Service_AM, "CIA file installation aborted with error code %08x",
|
||||
result.Code());
|
||||
return false;
|
||||
return InstallStatus::ErrorAborted;
|
||||
}
|
||||
total_bytes_read += bytes_read;
|
||||
}
|
||||
installFile.Close();
|
||||
|
||||
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());
|
||||
return false;
|
||||
return InstallStatus::ErrorInvalid;
|
||||
}
|
||||
|
||||
Service::FS::MediaType GetTitleMediaType(u64 titleId) {
|
||||
|
|
|
@ -42,6 +42,15 @@ enum class CIAInstallState : u32 {
|
|||
ContentWritten,
|
||||
};
|
||||
|
||||
enum class InstallStatus : u32 {
|
||||
Success,
|
||||
ErrorFailedToOpenFile,
|
||||
ErrorFileNotFound,
|
||||
ErrorAborted,
|
||||
ErrorInvalid,
|
||||
ErrorEncrypted,
|
||||
};
|
||||
|
||||
// Progress callback for InstallCIA, recieves bytes written and total bytes
|
||||
using ProgressCallback = void(size_t, size_t);
|
||||
|
||||
|
@ -83,8 +92,8 @@ private:
|
|||
* @param update_callback callback function called during filesystem write
|
||||
* @returns bool whether the install was successful
|
||||
*/
|
||||
bool InstallCIA(const std::string& path,
|
||||
std::function<ProgressCallback>&& update_callback = nullptr);
|
||||
InstallStatus InstallCIA(const std::string& path,
|
||||
std::function<ProgressCallback>&& update_callback = nullptr);
|
||||
|
||||
/**
|
||||
* Get the mediatype for an installed title
|
||||
|
|
Loading…
Reference in New Issue