MCPcopy Create free account
hub / github.com/XorTroll/Goldleaf / PrepareInstallation

Method PrepareInstallation

Goldleaf/source/nsp/nsp_Installer.cpp:179–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177 }
178
179 Result Installer::PrepareInstallation() {
180 GLEAF_RC_UNLESS(pfs0_file.IsOk(), rc::goldleaf::ResultInvalidNsp);
181 GLEAF_RC_TRY(ncmOpenContentStorage(&this->cnt_storage, this->storage_id));
182 GLEAF_RC_TRY(ncmOpenContentMetaDatabase(&this->cnt_meta_db, this->storage_id));
183
184 std::string cnmt_nca_file_name;
185 auto cnmt_nca_file_idx = fs::PFS0::InvalidFileIndex;
186 u64 cnmt_nca_file_size = 0;
187 auto tik_file_idx = fs::PFS0::InvalidFileIndex;
188 this->tik_file_size = 0;
189 auto cert_file_idx = fs::PFS0::InvalidFileIndex;
190 const auto pfs0_files = pfs0_file.GetFiles();
191 for(u32 i = 0; i < pfs0_files.size(); i++) {
192 const auto file = pfs0_files.at(i);
193 if(fs::GetExtension(file) == "tik") {
194 this->tik_file_name = file;
195 tik_file_idx = i;
196 this->tik_file_size = pfs0_file.GetFileSize(i);
197 }
198 else if(fs::GetExtension(file) == "cert") {
199 cert_file_idx = i;
200 }
201 else {
202 if(file.length() >= __builtin_strlen("cnmt.nca")) {
203 if(file.substr(file.length() - __builtin_strlen("cnmt.nca")) == "cnmt.nca") {
204 cnmt_nca_file_name = file;
205 cnmt_nca_file_idx = i;
206 cnmt_nca_file_size = pfs0_file.GetFileSize(i);
207 }
208 }
209 }
210 }
211 GLEAF_RC_UNLESS(fs::PFS0::IsValidFileIndex(cnmt_nca_file_idx), rc::goldleaf::ResultMetaNotFound);
212 GLEAF_RC_UNLESS(cnmt_nca_file_size > 0, rc::goldleaf::ResultMetaNotFound);
213 const auto cnmt_nca_content_id = fs::GetBaseName(cnmt_nca_file_name);
214
215 auto nand_sys_explorer = fs::GetNANDSystemExplorer();
216 nand_sys_explorer->CreateDirectory(GLEAF_PATH_NAND_INSTALL_TEMP_DIR);
217
218 if(tik_file_size > 0) {
219 const auto tik_path = nand_sys_explorer->FullPathFor(GLEAF_PATH_NAND_INSTALL_TEMP_DIR "/" + tik_file_name);
220 this->pfs0_file.SaveFile(tik_file_idx, nand_sys_explorer, tik_path);
221 this->tik_file = cnt::ReadTicket(tik_path);
222
223 const auto cert_path = fs::GetFileName(tik_path) + ".cert";
224 this->pfs0_file.SaveFile(cert_file_idx, nand_sys_explorer, cert_path);
225 }
226
227 const auto cnmt_nca_temp_path = nand_sys_explorer->FullPathFor(GLEAF_PATH_NAND_INSTALL_TEMP_DIR "/" + cnmt_nca_file_name);
228 nand_sys_explorer->DeleteFile(cnmt_nca_temp_path);
229 pfs0_file.SaveFile(cnmt_nca_file_idx, nand_sys_explorer, cnmt_nca_temp_path);
230
231 char cnmt_nca_content_path[FS_MAX_PATH] = {};
232 snprintf(cnmt_nca_content_path, sizeof(cnmt_nca_content_path), GLEAF_FS_PATH_NAND_INSTALL_TEMP_DIR "/%s", cnmt_nca_file_name.c_str());
233 FsRightsId tmp_rid;
234 GLEAF_RC_TRY(fsGetRightsIdAndKeyGenerationByPath(cnmt_nca_content_path, FsContentAttributes_All, &this->keygen, &tmp_rid));
235 const auto system_keygen = hos::GetSystemKeyGeneration();
236 GLEAF_LOG_FMT("Installation: system_keygen=%d, content_keygen=%d", system_keygen, this->keygen);

Callers 1

StartInstallMethod · 0.80

Calls 15

GetExtensionFunction · 0.85
GetBaseNameFunction · 0.85
GetNANDSystemExplorerFunction · 0.85
GetFileNameFunction · 0.85
GetSystemKeyGenerationFunction · 0.85
AllocateWorkBufferFunction · 0.85
DeleteWorkBufferFunction · 0.85
ReadContentMetaFunction · 0.85
GetContentIdFunction · 0.85
ExistsApplicationContentFunction · 0.85
FormatContentIdFunction · 0.85
GetLanguageNameFunction · 0.85

Tested by

no test coverage detected