Improved file formatting

This commit is contained in:
wiidev 2020-04-12 20:25:10 +01:00
parent a85d33ffd7
commit 4d6f75112b

View File

@ -265,7 +265,7 @@ void CMenu::_download(string gameId, int dl_type)
{ {
if(m_btnMgr.selected(m_downloadBtnAll) || dl_type == 1) if(m_btnMgr.selected(m_downloadBtnAll) || dl_type == 1)
{ {
m_refreshGameList = true;// not needed instead just initcf() m_refreshGameList = true; // Not needed instead just initcf()
m_btnMgr.hide(m_downloadLblCovers); m_btnMgr.hide(m_downloadLblCovers);
m_btnMgr.hide(m_downloadBtnAll); m_btnMgr.hide(m_downloadBtnAll);
@ -308,7 +308,7 @@ void CMenu::_download(string gameId, int dl_type)
m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg30", L"No covers missing.")); m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg30", L"No covers missing."));
dl_finished = true; dl_finished = true;
dl_type = 0; dl_type = 0;
//maybe show back button // Maybe show back button
//m_btnMgr.show(m_downloadBtnBack); //m_btnMgr.show(m_downloadBtnBack);
} }
if(m_btnMgr.selected(m_downloadBtnBanners) || dl_type == 2) if(m_btnMgr.selected(m_downloadBtnBanners) || dl_type == 2)
@ -346,19 +346,19 @@ void CMenu::_download(string gameId, int dl_type)
m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg14", L"Done.")); m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg14", L"Done."));
} }
else if(ret == -1) else if(ret == -1)
m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg34", L"Banner URL not set properly!"));//banner url not set m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg34", L"Banner URL not set properly!")); // Banner URL not set
else if(ret == -2) else if(ret == -2)
m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg2", L"Network initialization failed!")); m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg2", L"Network initialization failed!"));
else if(ret == -3) else if(ret == -3)
m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg33", L"No banners missing."));// no banners missing m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg33", L"No banners missing.")); // No banners missing
dl_finished = true; dl_finished = true;
dl_type = 0; dl_type = 0;
//maybe show back button // Maybe show back button
//m_btnMgr.show(m_downloadBtnBack); //m_btnMgr.show(m_downloadBtnBack);
} }
else if(m_btnMgr.selected(m_downloadBtnGameTDBDownload)) else if(m_btnMgr.selected(m_downloadBtnGameTDBDownload))
{ {
m_refreshGameList = true;// to refresh titles m_refreshGameList = true; // To refresh titles
m_btnMgr.hide(m_downloadLblCovers); m_btnMgr.hide(m_downloadLblCovers);
m_btnMgr.hide(m_downloadBtnAll); m_btnMgr.hide(m_downloadBtnAll);
m_btnMgr.hide(m_downloadBtnMissing); m_btnMgr.hide(m_downloadBtnMissing);
@ -1007,7 +1007,7 @@ int CMenu::_coverDownloader()
vector<string> coverIDList; vector<string> coverIDList;
/* create list of cover ID's that need downloading */ /* Create list of cover ID's that need downloading */
if(dl_gameID.empty()) if(dl_gameID.empty())
{ {
for(u32 i = 0; i < m_gameList.size(); ++i) for(u32 i = 0; i < m_gameList.size(); ++i)
@ -1022,7 +1022,7 @@ int CMenu::_coverDownloader()
coverIDList.push_back(dl_gameID); coverIDList.push_back(dl_gameID);
n = coverIDList.size(); n = coverIDList.size();
m_thrdTotal = n * 3;// 3 = download cover, save png, and make wfc m_thrdTotal = n * 3; // 3 = Download cover, save png and make wfc
if(m_thrdTotal == 0) if(m_thrdTotal == 0)
{ {
@ -1032,7 +1032,7 @@ int CMenu::_coverDownloader()
return -3; return -3;
} }
/* initialize network connection */ /* Initialize network connection */
m_thrdMessage = _t("dlmsg1", L"Initializing network..."); m_thrdMessage = _t("dlmsg1", L"Initializing network...");
m_thrdMessageAdded = true; m_thrdMessageAdded = true;
if(_initNetwork() < 0) if(_initNetwork() < 0)
@ -1043,7 +1043,7 @@ int CMenu::_coverDownloader()
return -2; return -2;
} }
/* download covers in the list */ /* Download covers in the list */
u32 CoverType = 0; u32 CoverType = 0;
string url; string url;
char path[256]; char path[256];
@ -1056,10 +1056,10 @@ int CMenu::_coverDownloader()
bool custom = false; bool custom = false;
int c_altCase = 0; int c_altCase = 0;
/* try downloading the cover 4 times but a different type each time.*/ /* Try downloading the cover 4 times but a different type each time.*/
for(int p = 0; p < 4; ++p) for(int p = 0; p < 4; ++p)
{ {
/* the cover type (BOX, CBOX, FLAT, CFLAT) is different each time based on m_downloadPrioVal */ /* The cover type (BOX, CBOX, FLAT, CFLAT) is different each time based on m_downloadPrioVal */
switch(p) switch(p)
{ {
case 0: case 0:
@ -1083,7 +1083,7 @@ int CMenu::_coverDownloader()
original = false; original = false;
if(!success && original) if(!success && original)
{ {
/* each fmtURL may have more than one URL */ /* Each fmtURL may have more than one URL */
for(u8 j = 0; !success && j < fmtURLBox.size(); ++j) for(u8 j = 0; !success && j < fmtURLBox.size(); ++j)
{ {
url = makeURL(fmtURLBox[j], coverID, countryCode(coverID)); url = makeURL(fmtURLBox[j], coverID, countryCode(coverID));
@ -1180,20 +1180,18 @@ int CMenu::_coverDownloader()
case ZHCN: case ZHCN:
break; break;
} }
if(tdl)// try another download if(tdl) // Try another download
{ {
m_thrdMessage = wfmt(_fmt("dlmsg3", L"Downloading %i/%i from %s"), i + 1, n, url.c_str()); m_thrdMessage = wfmt(_fmt("dlmsg3", L"Downloading %i/%i from %s"), i + 1, n, url.c_str());
m_thrdMessageAdded = true; m_thrdMessageAdded = true;
downloadfile(url.c_str(), &file); downloadfile(url.c_str(), &file);
} }
} }
/* if none of the downloads succeeded */ /* If none of the downloads succeeded */
if(file.size == 0)// || !checkPNGBuf(file.data)) if(file.size == 0)// || !checkPNGBuf(file.data))
continue; continue;
/* a download succeeded */ /* Download succeeded - save png */
/* save cover png */
strncpy(path, fmt("%s/%s.png", m_boxPicDir.c_str(), coverID.c_str()), 255); strncpy(path, fmt("%s/%s.png", m_boxPicDir.c_str(), coverID.c_str()), 255);
update_pThread(1); update_pThread(1);
m_thrdMessage = wfmt(_fmt("dlmsg4", L"Saving %s"), path); m_thrdMessage = wfmt(_fmt("dlmsg4", L"Saving %s"), path);
@ -1201,11 +1199,11 @@ int CMenu::_coverDownloader()
fsop_WriteFile(path, file.data, file.size); fsop_WriteFile(path, file.data, file.size);
MEM2_free(file.data); MEM2_free(file.data);
/* make cover cache file (wfc) */ /* Make cover cache file (wfc) */
update_pThread(1); update_pThread(1);
m_thrdMessage = wfmt(_fmt("dlmsg10", L"Making %s.wfc"), coverID.c_str()); m_thrdMessage = wfmt(_fmt("dlmsg10", L"Making %s.wfc"), coverID.c_str());
m_thrdMessageAdded = true; m_thrdMessageAdded = true;
CoverFlow.cacheCoverFile(fmt("%s/%s.wfc", m_cacheDir.c_str(), coverID.c_str()), path, true);//it may fail CoverFlow.cacheCoverFile(fmt("%s/%s.wfc", m_cacheDir.c_str(), coverID.c_str()), path, true); // Might fail if OOM
++count; ++count;
update_pThread(1); update_pThread(1);
@ -1219,7 +1217,7 @@ int CMenu::_coverDownloader()
c_altCase = c_gameTDB.GetCaseVersions(coverID.c_str()); c_altCase = c_gameTDB.GetCaseVersions(coverID.c_str());
if(!success && c_gameTDB.IsLoaded() && c_altCase > 1 && custom) if(!success && c_gameTDB.IsLoaded() && c_altCase > 1 && custom)
{ {
/* each fmtURL may have more than one URL */ /* Each fmtURL may have more than one URL */
for(u8 j = 0; !success && j < fmtURLCBox.size(); ++j) for(u8 j = 0; !success && j < fmtURLCBox.size(); ++j)
{ {
url = makeURL(fmtURLCBox[j], coverID, countryCode(coverID)); url = makeURL(fmtURLCBox[j], coverID, countryCode(coverID));
@ -1325,13 +1323,11 @@ int CMenu::_coverDownloader()
} }
} }
/* if none of the downloads succeeded */ /* If none of the downloads succeeded */
if(file.size <= 0)// || !checkPNGBuf(file.data)) if(file.size <= 0)// || !checkPNGBuf(file.data))
continue; continue;
/* a download succeeded */ /* Download succeeded - save png */
/* save cover png */
strncpy(path, fmt("%s/%s.png", m_boxPicDir.c_str(), coverID.c_str()), 255); strncpy(path, fmt("%s/%s.png", m_boxPicDir.c_str(), coverID.c_str()), 255);
update_pThread(1); update_pThread(1);
m_thrdMessage = wfmt(_fmt("dlmsg4", L"Saving %s"), path); m_thrdMessage = wfmt(_fmt("dlmsg4", L"Saving %s"), path);
@ -1339,14 +1335,14 @@ int CMenu::_coverDownloader()
fsop_WriteFile(path, file.data, file.size); fsop_WriteFile(path, file.data, file.size);
MEM2_free(file.data); MEM2_free(file.data);
/* make cover cache file (wfc) */ /* Make cover cache file (wfc) */
update_pThread(1); update_pThread(1);
m_thrdMessage = wfmt(_fmt("dlmsg10", L"Making %s.wfc"), coverID.c_str()); m_thrdMessage = wfmt(_fmt("dlmsg10", L"Making %s.wfc"), coverID.c_str());
m_thrdMessageAdded = true; m_thrdMessageAdded = true;
CoverFlow.cacheCoverFile(fmt("%s/%s.wfc", m_cacheDir.c_str(), coverID.c_str()), path, true);//it may fail CoverFlow.cacheCoverFile(fmt("%s/%s.wfc", m_cacheDir.c_str(), coverID.c_str()), path, true); // Might fail if OOM
update_pThread(1);
++count; ++count;
update_pThread(1);
success = true; success = true;
} }
} }
@ -1356,6 +1352,7 @@ int CMenu::_coverDownloader()
original = false; original = false;
if(!success && original) if(!success && original)
{ {
/* Each fmtURL may have more than one URL */
for(u8 j = 0; !success && j < fmtURLFlat.size(); ++j) for(u8 j = 0; !success && j < fmtURLFlat.size(); ++j)
{ {
url = makeURL(fmtURLFlat[j], coverID, countryCode(coverID)); url = makeURL(fmtURLFlat[j], coverID, countryCode(coverID));
@ -1460,10 +1457,11 @@ int CMenu::_coverDownloader()
} }
} }
/* If none of the downloads succeeded */
if(file.size <= 0)// || !checkPNGBuf(file.data)) if(file.size <= 0)// || !checkPNGBuf(file.data))
continue; continue;
/*download succeeded - save png */ /* Download succeeded - save png */
strncpy(path, fmt("%s/%s.png", m_picDir.c_str(), coverID.c_str()), 255); strncpy(path, fmt("%s/%s.png", m_picDir.c_str(), coverID.c_str()), 255);
update_pThread(1); update_pThread(1);
m_thrdMessage = wfmt(_fmt("dlmsg4", L"Saving %s"), path); m_thrdMessage = wfmt(_fmt("dlmsg4", L"Saving %s"), path);
@ -1471,11 +1469,11 @@ int CMenu::_coverDownloader()
fsop_WriteFile(path, file.data, file.size); fsop_WriteFile(path, file.data, file.size);
MEM2_free(file.data); MEM2_free(file.data);
/* make cover cache file (wfc) */ /* Make cover cache file (wfc) */
update_pThread(1); update_pThread(1);
m_thrdMessage = wfmt(_fmt("dlmsg10", L"Making %s"), sfmt("%s.wfc", coverID.c_str())); m_thrdMessage = wfmt(_fmt("dlmsg10", L"Making %s"), sfmt("%s.wfc", coverID.c_str()));
m_thrdMessageAdded = true; m_thrdMessageAdded = true;
CoverFlow.cacheCoverFile(fmt("%s/%s.wfc", m_cacheDir.c_str(), coverID.c_str()), path, false);//it may fail CoverFlow.cacheCoverFile(fmt("%s/%s.wfc", m_cacheDir.c_str(), coverID.c_str()), path, false); // Might fail if OOM
++countFlat; ++countFlat;
update_pThread(1); update_pThread(1);
@ -1488,6 +1486,7 @@ int CMenu::_coverDownloader()
custom = true; custom = true;
if(!success && c_gameTDB.IsLoaded() && c_altCase > 1 && custom) if(!success && c_gameTDB.IsLoaded() && c_altCase > 1 && custom)
{ {
/* Each fmtURL may have more than one URL */
for(u8 j = 0; !success && j < fmtURLCFlat.size(); ++j) for(u8 j = 0; !success && j < fmtURLCFlat.size(); ++j)
{ {
url = makeURL(fmtURLCFlat[j], coverID, countryCode(coverID)); url = makeURL(fmtURLCFlat[j], coverID, countryCode(coverID));
@ -1591,15 +1590,15 @@ int CMenu::_coverDownloader()
m_thrdMessage = wfmt(_fmt("dlmsg3", L"Downloading %i/%i from %s"), i + 1, n, url.c_str()); m_thrdMessage = wfmt(_fmt("dlmsg3", L"Downloading %i/%i from %s"), i + 1, n, url.c_str());
m_thrdMessageAdded = true; m_thrdMessageAdded = true;
LWP_MutexUnlock(m_mutex); LWP_MutexUnlock(m_mutex);
downloadfile(url.c_str(), &file); downloadfile(url.c_str(), &file);
} }
} }
/* If none of the downloads succeeded */
if(file.size <= 0)// || !checkPNGBuf(file.data)) if(file.size <= 0)// || !checkPNGBuf(file.data))
continue; continue;
/* save png */ /* Download succeeded - save png */
strncpy(path, fmt("%s/%s.png", m_picDir.c_str(), coverID.c_str()), 255); strncpy(path, fmt("%s/%s.png", m_picDir.c_str(), coverID.c_str()), 255);
update_pThread(1); update_pThread(1);
m_thrdMessage = wfmt(_fmt("dlmsg4", L"Saving %s"), path); m_thrdMessage = wfmt(_fmt("dlmsg4", L"Saving %s"), path);
@ -1607,11 +1606,11 @@ int CMenu::_coverDownloader()
fsop_WriteFile(path, file.data, file.size); fsop_WriteFile(path, file.data, file.size);
MEM2_free(file.data); MEM2_free(file.data);
/* make wfc */ /* Make cover cache file (wfc) */
update_pThread(1); update_pThread(1);
m_thrdMessage = wfmt(_fmt("dlmsg10", L"Making %s"), sfmt("%s.wfc", coverID.c_str())); m_thrdMessage = wfmt(_fmt("dlmsg10", L"Making %s"), sfmt("%s.wfc", coverID.c_str()));
m_thrdMessageAdded = true; m_thrdMessageAdded = true;
CoverFlow.cacheCoverFile(fmt("%s/%s.wfc", m_cacheDir.c_str(), coverID.c_str()), path, false);//it may fail CoverFlow.cacheCoverFile(fmt("%s/%s.wfc", m_cacheDir.c_str(), coverID.c_str()), path, false); // Might fail if OOM
++countFlat; ++countFlat;
update_pThread(1); update_pThread(1);
@ -1624,7 +1623,7 @@ int CMenu::_coverDownloader()
if(!success) if(!success)
update_pThread(3); update_pThread(3);
} }
/* cover list done and downloading complete */ /* Cover list done and downloading complete */
if(c_gameTDB.IsLoaded()) if(c_gameTDB.IsLoaded())
c_gameTDB.CloseFile(); c_gameTDB.CloseFile();
coverIDList.clear(); coverIDList.clear();
@ -1637,7 +1636,7 @@ int CMenu::_coverDownloader()
int CMenu::_gametdbDownloaderAsync() int CMenu::_gametdbDownloaderAsync()
{ {
const string &langCode = m_loc.getString(m_curLanguage, "gametdb_code", "EN"); const string &langCode = m_loc.getString(m_curLanguage, "gametdb_code", "EN");
m_thrdTotal = 3;// download, save, and unzip m_thrdTotal = 3; // Download, save and unzip
m_thrdMessage = _t("dlmsg1", L"Initializing network..."); m_thrdMessage = _t("dlmsg1", L"Initializing network...");
m_thrdMessageAdded = true; m_thrdMessageAdded = true;
@ -1657,7 +1656,7 @@ int CMenu::_gametdbDownloaderAsync()
} }
else else
{ {
update_pThread(1);//its downloaded update_pThread(1); // It's downloaded
bool res = false; bool res = false;
char *zippath = fmt_malloc("%s/wiitdb.zip", m_settingsDir.c_str()); char *zippath = fmt_malloc("%s/wiitdb.zip", m_settingsDir.c_str());
if(zippath != NULL) if(zippath != NULL)
@ -1680,7 +1679,7 @@ int CMenu::_gametdbDownloaderAsync()
} }
else else
{ {
update_pThread(1);//its saved update_pThread(1); // It's saved
gprintf("Extracting zip file: "); gprintf("Extracting zip file: ");
m_thrdMessage = wfmt(_fmt("dlmsg24", L"Extracting %s"), "wiitdb.zip"); m_thrdMessage = wfmt(_fmt("dlmsg24", L"Extracting %s"), "wiitdb.zip");
@ -1688,7 +1687,7 @@ int CMenu::_gametdbDownloaderAsync()
ZipFile zFile(zippath); ZipFile zFile(zippath);
bool zres = zFile.ExtractAll(m_settingsDir.c_str()); bool zres = zFile.ExtractAll(m_settingsDir.c_str());
gprintf(zres ? "success\n" : "failed\n"); gprintf(zres ? "success\n" : "failed\n");
//may add if zres failed return -4 extraction failed // May add if zres failed return -4 extraction failed
// We don't need the zipfile anymore // We don't need the zipfile anymore
fsop_deleteFile(zippath); fsop_deleteFile(zippath);
@ -1697,7 +1696,7 @@ int CMenu::_gametdbDownloaderAsync()
// We should always remove the offsets file to make sure it's reloaded // We should always remove the offsets file to make sure it's reloaded
fsop_deleteFile(fmt("%s/gametdb_offsets.bin", m_settingsDir.c_str())); fsop_deleteFile(fmt("%s/gametdb_offsets.bin", m_settingsDir.c_str()));
update_pThread(1);//its extracted update_pThread(1); // It's extracted
// Update cache // Update cache
m_cfg.setBool(WII_DOMAIN, "update_cache", true); m_cfg.setBool(WII_DOMAIN, "update_cache", true);
@ -1787,7 +1786,7 @@ int CMenu::_bannerDownloader()
downloadfile(banner_url_id3, &file); downloadfile(banner_url_id3, &file);
} }
/* minimum 50kb */ /* Minimum 50kb */
if(file.size > 51200 && file.data[0] != '<') if(file.size > 51200 && file.data[0] != '<')
{ {
fsop_WriteFile(fmt("%s/%s.bnr", m_customBnrDir.c_str(), BnrIDList[i].c_str()), file.data, file.size); fsop_WriteFile(fmt("%s/%s.bnr", m_customBnrDir.c_str(), BnrIDList[i].c_str()), file.data, file.size);
@ -1804,7 +1803,7 @@ int CMenu::_bannerDownloader()
/**************************************************************************************/ /**************************************************************************************/
const char *url_dl = NULL; const char *url_dl = NULL;
void CMenu::_downloadUrl(const char *url, u8 **dl_file, u32 *dl_size)// nothing uses this void CMenu::_downloadUrl(const char *url, u8 **dl_file, u32 *dl_size) // Nothing uses this
{ {
m_file = NULL; m_file = NULL;
m_filesize = 0; m_filesize = 0;