Change caching system

This commit is contained in:
XorTroll 2019-12-30 17:19:27 +01:00
parent ff8ee3e514
commit 50f40793db
6 changed files with 56 additions and 22 deletions

View file

@ -85,8 +85,9 @@ namespace cfg
#define CFG_LANG_DEFAULT "romfs:/LangDefault.json"
#define CFG_CONFIG_JSON Q_BASE_SD_DIR "/config.json"
TitleList LoadTitleList(bool cache);
TitleList LoadTitleList();
std::vector<TitleRecord> QueryAllHomebrew(std::string base = "sdmc:/switch");
void CacheEverything(std::string hb_base_path = "sdmc:/switch");
std::string GetRecordIconPath(TitleRecord record);
RecordInformation GetRecordInformation(TitleRecord record);

View file

@ -13,5 +13,5 @@ namespace os
return (app_id == OS_FLOG_APP_ID);
}
std::vector<cfg::TitleRecord> QueryInstalledTitles(bool cache);
std::vector<cfg::TitleRecord> QueryInstalledTitles();
}

View file

@ -58,7 +58,6 @@ namespace cfg
rec.title_type = (u32)TitleType::Homebrew;
strcpy(rec.nro_target.nro_path, path.c_str());
nros.push_back(rec);
CacheHomebrew(path); // Always cache when querying.
}
}
})
@ -66,6 +65,50 @@ namespace cfg
return nros;
}
static void CacheInstalledTitles()
{
NsApplicationRecord *recordbuf = new NsApplicationRecord[OS_MAX_TITLE_COUNT]();
s32 record_count = 0;
auto rc = nsListApplicationRecord(recordbuf, OS_MAX_TITLE_COUNT, 0, &record_count);
if(R_SUCCEEDED(rc))
{
for(s32 i = 0; i < record_count; i++)
{
u64 appid = recordbuf[i].application_id;
NsApplicationControlData control = {};
size_t dummy;
auto rc = nsGetApplicationControlData(NsApplicationControlSource_Storage, appid, &control, sizeof(control), &dummy);
if(R_SUCCEEDED(rc))
{
auto fname = cfg::GetTitleCacheIconPath(appid);
fs::WriteFile(fname, control.icon, sizeof(control.icon), true);
}
}
}
delete[] recordbuf;
}
static void CacheAllHomebrew(std::string hb_base_path)
{
FS_FOR(hb_base_path, name, path,
{
if(dt->d_type & DT_DIR)
{
CacheAllHomebrew(path);
}
else
{
if(util::StringEndsWith(name, ".nro")) CacheHomebrew(path);
}
})
}
void CacheEverything(std::string hb_base_path)
{
CacheInstalledTitles();
CacheAllHomebrew(hb_base_path);
}
std::string GetRecordIconPath(TitleRecord record)
{
std::string icon = record.icon;
@ -560,12 +603,12 @@ namespace cfg
return title_found;
}
TitleList LoadTitleList(bool cache)
TitleList LoadTitleList()
{
TitleList list = {};
// Installed titles first
auto titles = os::QueryInstalledTitles(cache);
auto titles = os::QueryInstalledTitles();
FS_FOR(std::string(Q_ENTRIES_PATH), name, path,
{
@ -626,9 +669,7 @@ namespace cfg
rec.name = entry.value("name", "");
rec.author = entry.value("author", "");
rec.version = entry.value("version", "");
// Only cache homebrew added to main menu.
CacheHomebrew(nropath);
std::string argv = entry.value("nro_argv", "");
strcpy(rec.nro_target.nro_path, nropath.c_str());
if(!argv.empty()) strcpy(rec.nro_target.argv, argv.c_str());

View file

@ -4,12 +4,12 @@
namespace os
{
std::vector<cfg::TitleRecord> QueryInstalledTitles(bool cache)
std::vector<cfg::TitleRecord> QueryInstalledTitles()
{
std::vector<cfg::TitleRecord> titles;
NsApplicationRecord *recordbuf = new NsApplicationRecord[OS_MAX_TITLE_COUNT]();
s32 record_count = 0;
auto rc = nsListApplicationRecord(recordbuf, OS_MAX_TITLE_COUNT * sizeof(NsApplicationRecord), 0, &record_count);
auto rc = nsListApplicationRecord(recordbuf, OS_MAX_TITLE_COUNT, 0, &record_count);
if(R_SUCCEEDED(rc))
{
for(s32 i = 0; i < record_count; i++)
@ -18,17 +18,6 @@ namespace os
rec.app_id = recordbuf[i].application_id;
rec.title_type = (u32)cfg::TitleType::Installed;
if(rec.app_id == 0) continue;
if(cache)
{
NsApplicationControlData control = {};
size_t dummy;
auto rc = nsGetApplicationControlData(NsApplicationControlSource_Storage, rec.app_id, &control, sizeof(control), &dummy);
if(R_SUCCEEDED(rc))
{
auto fname = cfg::GetTitleCacheIconPath(rec.app_id);
fs::WriteFile(fname, control.icon, sizeof(control.icon), true);
}
}
titles.push_back(rec);
}
}

View file

@ -82,7 +82,7 @@ int main()
app_buf = new u8[RawRGBAScreenBufferSize]();
qmenu::Initialize();
list = cfg::LoadTitleList(true);
list = cfg::LoadTitleList();
// Get system language and load translations (default one if not present)
u64 lcode = 0;

View file

@ -524,6 +524,9 @@ int main()
// Force disable USB since it's broken :(
// if(config.viewer_usb_enabled) qdaemon::LaunchForegroundThread();
// Cache everything on startup
cfg::CacheEverything();
auto status = CreateStatus();
Q_R_TRY(am::QDaemon_LaunchQMenu(am::QMenuStartMode::StartupScreen, status))