-added proper banner caching using the wiiflow/cache folder, that

means we can properly see if cached or custom banner is loaded
-corrected bug which didnt copy back the banner md5 before writing
banner cache, means all cached banners dont have the security check
anymore
This commit is contained in:
fix94.1 2012-07-05 16:18:23 +00:00
parent e62dcd8a09
commit 24899a421a
4 changed files with 72 additions and 44 deletions

View File

@ -62,8 +62,9 @@ Banner::Banner(u8 *bnr, u32 bnr_size, u64 title, bool custom)
memcpy(imetmd5, imet->md5, 16);
memset(imet->md5, 0, 16);
MD5(md5, (unsigned char*)(imet), sizeof(IMET));
memcpy(imet->md5, imetmd5, 16);
if(memcmp(imetmd5, md5, 16) == 0 || custom)
this->imet = imet;
else

View File

@ -284,9 +284,17 @@ void CMenu::init(void)
m_app_update_zip = sfmt("%s/update.zip", m_appDir.c_str());
m_data_update_zip = sfmt("%s/update.zip", m_dataDir.c_str());
m_bannerDir = m_cfg.getString("GENERAL", "dir_banners", sfmt("%s/banners", m_dataDir.c_str()));
m_customBnrDir = m_cfg.getString("GENERAL", "dir_custom_banners", sfmt("%s/custom_banners", m_dataDir.c_str()));
m_pluginsDir = m_cfg.getString("GENERAL", "dir_plugins", sfmt("%s/plugins", m_dataDir.c_str()));
m_cacheDir = m_cfg.getString("GENERAL", "dir_cache", sfmt("%s/cache", m_dataDir.c_str()));
m_listCacheDir = m_cfg.getString("GENERAL", "dir_list_cache", sfmt("%s/lists", m_cacheDir.c_str()));
m_bnrCacheDir = m_cfg.getString("GENERAL", "dir_banner_cache", sfmt("%s/banners", m_cacheDir.c_str()));
m_txtCheatDir = m_cfg.getString("GENERAL", "dir_txtcheat", sfmt("%s/codes", m_dataDir.c_str()));
m_cheatDir = m_cfg.getString("GENERAL", "dir_cheat", sfmt("%s/gct", m_txtCheatDir.c_str()));
m_wipDir = m_cfg.getString("GENERAL", "dir_wip", sfmt("%s/wip", m_txtCheatDir.c_str()));
m_settingsDir = m_cfg.getString("GENERAL", "dir_settings", sfmt("%s/settings", m_dataDir.c_str()));
m_languagesDir = m_cfg.getString("GENERAL", "dir_languages", sfmt("%s/languages", m_dataDir.c_str()));
m_boxPicDir = m_cfg.getString("GENERAL", "dir_box_covers", sfmt("%s/boxcovers", m_dataDir.c_str()));
@ -296,10 +304,6 @@ void CMenu::init(void)
m_videoDir = m_cfg.getString("GENERAL", "dir_trailers", sfmt("%s/trailers", m_dataDir.c_str()));
m_fanartDir = m_cfg.getString("GENERAL", "dir_fanart", sfmt("%s/fanart", m_dataDir.c_str()));
m_screenshotDir = m_cfg.getString("GENERAL", "dir_screenshot", sfmt("%s/screenshots", m_dataDir.c_str()));
m_txtCheatDir = m_cfg.getString("GENERAL", "dir_txtcheat", sfmt("%s/codes", m_dataDir.c_str()));
m_cheatDir = m_cfg.getString("GENERAL", "dir_cheat", sfmt("%s/gct", m_txtCheatDir.c_str()));
m_wipDir = m_cfg.getString("GENERAL", "dir_wip", sfmt("%s/wip", m_txtCheatDir.c_str()));
m_listCacheDir = m_cfg.getString("GENERAL", "dir_list_cache", sfmt("%s/lists", m_cacheDir.c_str()));
m_helpDir = m_cfg.getString("GENERAL", "dir_help", sfmt("%s/help", m_dataDir.c_str()));
DeviceHandler::SetWatchdog(m_cfg.getUInt("GENERAL", "watchdog_timeout", 10));
@ -328,12 +332,22 @@ void CMenu::init(void)
}
}
}
m_cf.init(m_base_font, m_base_font_size, m_vid.vid_50hz());
//Make important folders first.
fsop_MakeFolder((char *)m_dataDir.c_str()); //D'OH!
fsop_MakeFolder((char *)m_customBnrDir.c_str());
fsop_MakeFolder((char *)m_pluginsDir.c_str());
fsop_MakeFolder((char *)m_cacheDir.c_str());
fsop_MakeFolder((char *)m_listCacheDir.c_str());
fsop_MakeFolder((char *)m_bnrCacheDir.c_str());
fsop_MakeFolder((char *)m_txtCheatDir.c_str());
fsop_MakeFolder((char *)m_cheatDir.c_str());
fsop_MakeFolder((char *)m_wipDir.c_str());
fsop_MakeFolder((char *)m_settingsDir.c_str());
fsop_MakeFolder((char *)m_languagesDir.c_str());
fsop_MakeFolder((char *)m_boxPicDir.c_str());
@ -343,13 +357,7 @@ void CMenu::init(void)
fsop_MakeFolder((char *)m_videoDir.c_str());
fsop_MakeFolder((char *)m_fanartDir.c_str());
fsop_MakeFolder((char *)m_screenshotDir.c_str());
fsop_MakeFolder((char *)m_txtCheatDir.c_str());
fsop_MakeFolder((char *)m_cheatDir.c_str());
fsop_MakeFolder((char *)m_wipDir.c_str());
fsop_MakeFolder((char *)m_listCacheDir.c_str());
fsop_MakeFolder((char *)m_helpDir.c_str());
fsop_MakeFolder((char *)m_pluginsDir.c_str());
fsop_MakeFolder((char *)m_bannerDir.c_str());
// INI files
m_cat.load(fmt("%s/" CAT_FILENAME, m_settingsDir.c_str()));

View File

@ -89,13 +89,14 @@ private:
string m_themeDataDir;
string m_appDir;
string m_dataDir;
string m_bannerDir;
string m_pluginsDir;
string m_customBnrDir;
string m_picDir;
string m_boxPicDir;
string m_cpicDir;
string m_boxcPicDir;
string m_cacheDir;
string m_listCacheDir;
string m_bnrCacheDir;
string m_themeDir;
string m_musicDir;
string m_txtCheatDir;
@ -106,7 +107,6 @@ private:
string m_screenshotDir;
string m_settingsDir;
string m_languagesDir;
string m_listCacheDir;
string m_DMLgameDir;
string m_helpDir;

View File

@ -1523,44 +1523,65 @@ void CMenu::_gameSoundThread(CMenu *m)
m->m_gamesound_changed = true;
return;
}
bool custom = false;
bool custom = false;
u8 *custom_bnr_file = NULL;
u32 custom_bnr_size = 0;
char custom_banner[256];
snprintf(custom_banner, sizeof(custom_banner), "%s/%.6s.bnr", m->m_bannerDir.c_str(), m->m_cf.getHdr()->id);
FILE *fp = fopen(custom_banner, "rb");
if(!fp)
{
snprintf(custom_banner, sizeof(custom_banner), "%s/%.3s.bnr", m->m_bannerDir.c_str(), m->m_cf.getHdr()->id);
fp = fopen(custom_banner, "rb");
if(!fp && m->m_cf.getHdr()->type == TYPE_GC_GAME)
{
m_banner->DeleteBanner();
m->m_gameSound.Load(gc_ogg, gc_ogg_size, false);
m->m_gamesound_changed = true;
return;
}
}
bool cached = false;
u8 *cached_bnr_file = NULL;
u32 cached_bnr_size = 0;
char cached_banner[256];
snprintf(cached_banner, sizeof(cached_banner), "%s/%.6s.bnr", m->m_bnrCacheDir.c_str(), m->m_cf.getHdr()->id);
FILE *fp = fopen(cached_banner, "rb");
if(fp)
{
custom = true;
gprintf("Custom Banner detected for: %s\n", m->m_cf.getHdr()->id);
cached = true;
fseek(fp, 0, SEEK_END);
custom_bnr_size = ftell(fp);
cached_bnr_size = ftell(fp);
fseek(fp, 0, SEEK_SET);
custom_bnr_file = (u8*)MEM2_alloc(custom_bnr_size);
fread(custom_bnr_file, 1, custom_bnr_size, fp);
cached_bnr_file = (u8*)MEM2_alloc(cached_bnr_size);
fread(cached_bnr_file, 1, cached_bnr_size, fp);
fclose(fp);
}
else
{
char custom_banner[256];
snprintf(custom_banner, sizeof(custom_banner), "%s/%.6s.bnr", m->m_customBnrDir.c_str(), m->m_cf.getHdr()->id);
FILE *fp = fopen(custom_banner, "rb");
if(!fp)
{
snprintf(custom_banner, sizeof(custom_banner), "%s/%.3s.bnr", m->m_customBnrDir.c_str(), m->m_cf.getHdr()->id);
fp = fopen(custom_banner, "rb");
if(!fp && m->m_cf.getHdr()->type == TYPE_GC_GAME)
{
m_banner->DeleteBanner();
m->m_gameSound.Load(gc_ogg, gc_ogg_size, false);
m->m_gamesound_changed = true;
return;
}
}
if(fp)
{
custom = true;
gprintf("Custom Banner detected for: %s\n", m->m_cf.getHdr()->id);
fseek(fp, 0, SEEK_END);
custom_bnr_size = ftell(fp);
fseek(fp, 0, SEEK_SET);
custom_bnr_file = (u8*)MEM2_alloc(custom_bnr_size);
fread(custom_bnr_file, 1, custom_bnr_size, fp);
fclose(fp);
}
}
m->m_gameSoundHdr = m->m_cf.getHdr();
m->m_gamesound_changed = false;
u32 sndSize = 0;
Banner *banner = custom_bnr_file != NULL ? new Banner((u8 *)custom_bnr_file, custom_bnr_size, 0, true) :
Banner *banner = cached ? new Banner((u8 *)cached_bnr_file, cached_bnr_size) :
(custom ? new Banner((u8 *)custom_bnr_file, custom_bnr_size, 0, true) :
(m->m_gameSoundHdr->type == TYPE_WII_GAME ? _extractBnr(m->m_gameSoundHdr) : (m->m_gameSoundHdr->type == TYPE_CHANNEL ?
_extractChannelBnr(TITLE_ID(m->m_gameSoundHdr->settings[0],m->m_gameSoundHdr->settings[1])) : NULL));
_extractChannelBnr(TITLE_ID(m->m_gameSoundHdr->settings[0],m->m_gameSoundHdr->settings[1])) : NULL)));
m->m_gameSoundHdr = NULL;
if (banner == NULL || !banner->IsValid())
@ -1570,11 +1591,9 @@ void CMenu::_gameSoundThread(CMenu *m)
delete banner;
return;
}
else if(!custom)
else if(!custom && !cached)
{
char custom_banner[256];
snprintf(custom_banner, sizeof(custom_banner), "%s/%.6s.bnr", m->m_bannerDir.c_str(), m->m_cf.getHdr()->id);
FILE *fp = fopen(custom_banner, "wb");
FILE *fp = fopen(cached_banner, "wb");
fwrite(banner->GetBannerFile(), 1, banner->GetBannerFileSize(), fp);
fclose(fp);
}