Skip to content

Commit

Permalink
Actually find valid NROs
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Feb 6, 2022
1 parent 4d915bc commit a01f509
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

export UL_MAJOR := 0
export UL_MINOR := 3
export UL_MICRO := 1
export UL_MINOR := 4
export UL_MICRO := 0
export UL_VERSION := $(UL_MAJOR).$(UL_MINOR).$(UL_MICRO)

export UL_DEFS := -DUL_MAJOR=$(UL_MAJOR) -DUL_MINOR=$(UL_MINOR) -DUL_MICRO=$(UL_MICRO) -DUL_VERSION=\"$(UL_VERSION)\"
Expand Down
53 changes: 36 additions & 17 deletions uLaunch/source/cfg/cfg_Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ namespace cfg {
const auto cache_nro_icon_path = GetNroCacheIconPath(nro_path);
auto f = fopen(nro_path.c_str(), "rb");
if(f) {
fseek(f, sizeof(NroStart), SEEK_SET);
NroHeader nro_header = {};
if(fread(&nro_header, sizeof(nro_header), 1, f) == 1) {
fseek(f, nro_header.size, SEEK_SET);
NroAssetHeader asset_header = {};
if(fread(&asset_header, sizeof(asset_header), 1, f) == 1) {
if(asset_header.magic == NROASSETHEADER_MAGIC) {
if((asset_header.icon.offset > 0) && (asset_header.icon.size > 0)) {
auto icon_buf = new u8[asset_header.icon.size]();
fseek(f, nro_header.size + asset_header.icon.offset, SEEK_SET);
fread(icon_buf, asset_header.icon.size, 1, f);
fs::WriteFile(cache_nro_icon_path, icon_buf, asset_header.icon.size, true);
delete[] icon_buf;
if(fseek(f, sizeof(NroStart), SEEK_SET) == 0) {
NroHeader header = {};
if(fread(&header, sizeof(header), 1, f) == 1) {
if(fseek(f, header.size, SEEK_SET) == 0) {
NroAssetHeader asset_header = {};
if(fread(&asset_header, sizeof(asset_header), 1, f) == 1) {
if(asset_header.magic == NROASSETHEADER_MAGIC) {
if((asset_header.icon.offset > 0) && (asset_header.icon.size > 0)) {
auto icon_buf = new u8[asset_header.icon.size]();
if(fseek(f, header.size + asset_header.icon.offset, SEEK_SET) == 0) {
if(fread(icon_buf, asset_header.icon.size, 1, f) == 1) {
fs::WriteFile(cache_nro_icon_path, icon_buf, asset_header.icon.size, true);
}
}
delete[] icon_buf;
}
}
}
}
}
Expand Down Expand Up @@ -90,10 +94,25 @@ namespace cfg {
}
else {
if(util::StringEndsWith(name, ".nro")) {
TitleRecord rec = {};
rec.title_type = TitleType::Homebrew;
strcpy(rec.nro_target.nro_path, path.c_str());
nros.push_back(rec);
auto f = fopen(path.c_str(), "rb");
if(f) {
fseek(f, 0, SEEK_END);
const auto f_size = ftell(f);
rewind(f);

if(fseek(f, sizeof(NroStart), SEEK_SET) == 0) {
NroHeader header;
if(fread(&header, sizeof(header), 1, f) == 1) {
if((header.magic == NROHEADER_MAGIC) && (f_size >= header.size)) {
TitleRecord rec = {};
rec.title_type = TitleType::Homebrew;
strcpy(rec.nro_target.nro_path, path.c_str());
nros.push_back(rec);
}
}
}
fclose(f);
}
}
}
});
Expand Down

0 comments on commit a01f509

Please sign in to comment.