@@ -173,7 +173,7 @@ namespace nsp {
173173 }
174174
175175 Installer::~Installer () {
176- FinalizeInstallation ();
176+ this -> FinalizeInstallation ();
177177 }
178178
179179 Result Installer::PrepareInstallation () {
@@ -347,7 +347,49 @@ namespace nsp {
347347 GLEAF_RC_SUCCEED;
348348 }
349349
350- Result Installer::StartInstallation () {
350+ Result Installer::InstallTicketCertificate () {
351+ if (this ->tik_file_size > 0 ) {
352+ auto tik_buf = fs::AllocateWorkBuffer (this ->tik_file_size );
353+ ScopeGuard on_exit ([&]() {
354+ fs::DeleteWorkBuffer (tik_buf);
355+ });
356+
357+ const auto tik_path = GLEAF_PATH_NAND_INSTALL_TEMP_DIR " /" + this ->tik_file_name ;
358+ auto nand_sys_explorer = fs::GetNANDSystemExplorer ();
359+ nand_sys_explorer->ReadFile (tik_path, 0 , this ->tik_file .GetFullSize (), tik_buf);
360+
361+ auto tik_signature = *reinterpret_cast <cnt::TicketSignature*>(tik_buf);
362+ auto tik_data = reinterpret_cast <cnt::TicketData*>(tik_buf + cnt::GetTicketSignatureSize (tik_signature));
363+
364+ // Make temporary tickets permanent
365+ if (static_cast <bool >(tik_data->flags & cnt::TicketFlags::Temporary)) {
366+ tik_data->flags = tik_data->flags & ~cnt::TicketFlags::Temporary;
367+ }
368+
369+ const auto cert_path = GLEAF_PATH_NAND_INSTALL_TEMP_DIR " /" + fs::GetFileName (this ->tik_file_name ) + " .cert" ;
370+ if (nand_sys_explorer->IsFile (cert_path)) {
371+ const auto cert_file_size = nand_sys_explorer->GetFileSize (cert_path);
372+ auto cert_buf = fs::AllocateWorkBuffer (cert_file_size);
373+ ScopeGuard on_exit ([&]() {
374+ fs::DeleteWorkBuffer (cert_buf);
375+ });
376+ nand_sys_explorer->ReadFile (cert_path, 0 , cert_file_size, cert_buf);
377+
378+ GLEAF_LOG_FMT (" Importing ticket with cert!" );
379+ GLEAF_RC_TRY (esImportTicket (tik_buf, this ->tik_file_size , cert_buf, cert_file_size));
380+ }
381+ else {
382+ GLEAF_LOG_FMT (" Importing ticket!" );
383+ GLEAF_RC_TRY (esImportTicket (tik_buf, this ->tik_file_size , es::CommonCertificateData, es::CommonCertificateSize));
384+ }
385+
386+ // We installed a ticket, so we need to refresh the ticket list for future uses
387+ cnt::NotifyTicketsChanged ();
388+ }
389+ GLEAF_RC_SUCCEED;
390+ }
391+
392+ Result Installer::UpdateRecordAndContentMetas () {
351393 const auto &main_program = this ->inst_contents .front ();
352394 const auto base_app_id = cnt::GetBaseApplicationId (main_program.meta_key .id , static_cast <NcmContentMetaType>(main_program.meta_key .type ));
353395
@@ -388,44 +430,6 @@ namespace nsp {
388430 nsextDeleteApplicationRecord (base_app_id);
389431 GLEAF_RC_TRY (nsextPushApplicationRecord (base_app_id, NsExtApplicationEvent_Present, content_storage_meta_keys.data (), content_storage_meta_keys.size ()));
390432
391- if (this ->tik_file_size > 0 ) {
392- auto tik_buf = fs::AllocateWorkBuffer (this ->tik_file_size );
393- ScopeGuard on_exit ([&]() {
394- fs::DeleteWorkBuffer (tik_buf);
395- });
396-
397- const auto tik_path = GLEAF_PATH_NAND_INSTALL_TEMP_DIR " /" + this ->tik_file_name ;
398- auto nand_sys_explorer = fs::GetNANDSystemExplorer ();
399- nand_sys_explorer->ReadFile (tik_path, 0 , this ->tik_file .GetFullSize (), tik_buf);
400-
401- auto tik_signature = *reinterpret_cast <cnt::TicketSignature*>(tik_buf);
402- auto tik_data = reinterpret_cast <cnt::TicketData*>(tik_buf + cnt::GetTicketSignatureSize (tik_signature));
403-
404- // Make temporary tickets permanent
405- if (static_cast <bool >(tik_data->flags & cnt::TicketFlags::Temporary)) {
406- tik_data->flags = tik_data->flags & ~cnt::TicketFlags::Temporary;
407- }
408-
409- const auto cert_path = GLEAF_PATH_NAND_INSTALL_TEMP_DIR " /" + fs::GetFileName (this ->tik_file_name ) + " .cert" ;
410- if (nand_sys_explorer->IsFile (cert_path)) {
411- const auto cert_file_size = nand_sys_explorer->GetFileSize (cert_path);
412- auto cert_buf = fs::AllocateWorkBuffer (cert_file_size);
413- ScopeGuard on_exit ([&]() {
414- fs::DeleteWorkBuffer (cert_buf);
415- });
416- nand_sys_explorer->ReadFile (cert_path, 0 , cert_file_size, cert_buf);
417-
418- GLEAF_LOG_FMT (" Importing ticket with cert!" );
419- GLEAF_RC_TRY (esImportTicket (tik_buf, this ->tik_file_size , cert_buf, cert_file_size));
420- }
421- else {
422- GLEAF_LOG_FMT (" Importing ticket!" );
423- GLEAF_RC_TRY (esImportTicket (tik_buf, this ->tik_file_size , es::CommonCertificateData, es::CommonCertificateSize));
424- }
425-
426- // We installed a ticket, so we need to refresh the ticket list for future uses
427- cnt::NotifyTicketsChanged ();
428- }
429433 GLEAF_RC_SUCCEED;
430434 }
431435
0 commit comments