-added progress bar to the wad installer

-updated the gc game installer progress bar
This commit is contained in:
fix94.1 2013-08-14 19:11:38 +00:00
parent 57b02cac30
commit a59330463e
5 changed files with 113 additions and 30 deletions

View File

@ -161,7 +161,7 @@ s32 GCDump::__DiscWriteFile(FILE *f, u64 offset, u32 length, u8 *ReadBuffer)
offset += toread; offset += toread;
length -= toread; length -= toread;
gc_done += toread; gc_done += toread;
mainMenu.GC_Refresh(gc_done/1024, DiscSizeCalculated); mainMenu.update_pThread(toread);
} }
return wrote; return wrote;
} }
@ -666,6 +666,7 @@ s32 GCDump::CheckSpace(u32 *needed, bool comp)
gamedone = true; gamedone = true;
} }
MEM2_free(ReadBuffer); MEM2_free(ReadBuffer);
mainMenu.m_thrdTotal = size;
DiscSizeCalculated = size/0x400; DiscSizeCalculated = size/0x400;
*needed = (size/0x8000) >> 2; *needed = (size/0x8000) >> 2;
gprintf("Free space needed: %d Mb (%d blocks)\n", size/0x100000, (size/0x8000) >> 2); gprintf("Free space needed: %d Mb (%d blocks)\n", size/0x100000, (size/0x8000) >> 2);

View File

@ -135,6 +135,13 @@ CMenu::CMenu()
m_file = NULL; m_file = NULL;
m_buffer = NULL; m_buffer = NULL;
m_filesize = 0; m_filesize = 0;
/* thread stuff */
m_thrdPtr = LWP_THREAD_NULL;
m_thrdInstalling = false;
m_thrdUpdated = false;
m_thrdDone = false;
m_thrdWritten = 0;
m_thrdTotal = 0;
} }
void CMenu::init() void CMenu::init()

View File

@ -1069,9 +1069,21 @@ private:
public: public:
void _hideWaitMessage(); void _hideWaitMessage();
bool m_Emulator_boot; bool m_Emulator_boot;
void GC_Refresh(int status, int total);
void GC_Messenger(int message, int info, char *cinfo); void GC_Messenger(int message, int info, char *cinfo);
/* general thread updating stuff */
u64 m_thrdTotal;
void update_pThread(u64 added);
private: private:
static int _pThread(void *obj);
void _start_pThread(void);
void _stop_pThread(void);
lwp_t m_thrdPtr;
volatile bool m_thrdInstalling;
volatile bool m_thrdUpdated;
volatile bool m_thrdDone;
vu64 m_thrdWritten;
GuiSound *_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, const u8 * snd, u32 len, const char *name, bool isAllocated); GuiSound *_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, const u8 * snd, u32 len, const char *name, bool isAllocated);
GuiSound *_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, const char *name); GuiSound *_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, const char *name);
u16 _textStyle(const char *domain, const char *key, u16 def); u16 _textStyle(const char *domain, const char *key, u16 def);

View File

@ -76,8 +76,8 @@ int installWad(const char *path)
fread(&hdr, sizeof(hdr), 1, wad_file); fread(&hdr, sizeof(hdr), 1, wad_file);
skip_align(wad_file, sizeof(hdr)); skip_align(wad_file, sizeof(hdr));
if(size < (hdr.certs_len + hdr.crl_len + hdr.tik_len + hdr.tmd_len + hdr.data_len + hdr.footer_len) mainMenu.m_thrdTotal = (hdr.certs_len + hdr.crl_len + hdr.tik_len + hdr.tmd_len + hdr.data_len + hdr.footer_len);
|| hdr.tik_len == 0 || hdr.tmd_len == 0 || hdr.data_len == 0) if(size < mainMenu.m_thrdTotal || hdr.tik_len == 0 || hdr.tmd_len == 0 || hdr.data_len == 0)
{ {
fclose(wad_file); fclose(wad_file);
return -3; return -3;
@ -234,6 +234,7 @@ int installWad(const char *path)
ISFS_Write(fd, decBuf, size_dec); ISFS_Write(fd, decBuf, size_dec);
/* dont forget to increase the read size */ /* dont forget to increase the read size */
read += size_enc; read += size_enc;
mainMenu.update_pThread(size_enc);
} }
sha1 app_sha1; sha1 app_sha1;
SHA1Final(app_sha1, &ctx); SHA1Final(app_sha1, &ctx);
@ -344,6 +345,75 @@ int getTID(const char *path, u64 *tid)
return 0; return 0;
} }
int CMenu::_pThread(void *obj)
{
CMenu *m = (CMenu*)obj;
while(m->m_thrdInstalling)
{
m->_mainLoopCommon();
if(m->m_thrdUpdated)
{
m->m_thrdUpdated = false;
m->_addDiscProgress(m->m_thrdWritten, m->m_thrdTotal, obj);
m->m_thrdDone = true;
}
if(m->m_thrdMessageAdded)
{
m->m_thrdMessageAdded = false;
if(!m->m_thrdMessage.empty())
m_btnMgr.setText(m->m_wbfsLblDialog, m->m_thrdMessage);
if(m->m_thrdProgress > 0.f)
{
m_btnMgr.setText(m->m_wbfsLblMessage, wfmt(L"%i%%", (int)(m->m_thrdProgress * 100.f)));
m_btnMgr.setProgress(m->m_wbfsPBar, m->m_thrdProgress);
}
}
}
m->m_thrdWorking = false;
return 0;
}
void CMenu::_start_pThread(void)
{
m_thrdPtr = LWP_THREAD_NULL;
m_thrdWorking = true;
m_thrdMessageAdded = false;
m_thrdInstalling = true;
m_thrdUpdated = false;
m_thrdDone = true;
m_thrdProgress = 0.f;
m_thrdWritten = 0;
m_thrdTotal = 0;
LWP_CreateThread(&m_thrdPtr, (void *(*)(void *))_pThread, (void*)this, 0, 8 * 1024, 64);
}
void CMenu::_stop_pThread(void)
{
if(m_thrdPtr == LWP_THREAD_NULL)
return;
if(LWP_ThreadIsSuspended(m_thrdPtr))
LWP_ResumeThread(m_thrdPtr);
m_thrdInstalling = false;
while(m_thrdWorking)
usleep(50);
LWP_JoinThread(m_thrdPtr, NULL);
m_thrdPtr = LWP_THREAD_NULL;
m_btnMgr.setProgress(m_wbfsPBar, 1.f);
m_btnMgr.setText(m_wbfsLblMessage, L"100%");
}
void CMenu::update_pThread(u64 added)
{
if(m_thrdDone)
{
m_thrdDone = false;
m_thrdWritten += added;
m_thrdUpdated = true;
}
}
void CMenu::_Wad(const char *wad_path) void CMenu::_Wad(const char *wad_path)
{ {
if(wad_path == NULL) if(wad_path == NULL)
@ -383,22 +453,27 @@ void CMenu::_Wad(const char *wad_path)
if(m_btnMgr.selected(m_wadBtnInstall)) if(m_btnMgr.selected(m_wadBtnInstall))
{ {
_hideWad(true); _hideWad(true);
m_btnMgr.setText(m_wbfsLblMessage, _t("wad4", L"Installing WAD, please wait...")); m_btnMgr.setProgress(m_wbfsPBar, 0.f);
m_btnMgr.show(m_wbfsLblMessage, true); m_btnMgr.setText(m_wbfsLblMessage, L"");
/* who cares about making a thread, just refresh a second */ m_btnMgr.setText(m_wbfsLblDialog, L"");
for(u8 i = 0; i < 60; ++i) m_btnMgr.show(m_wbfsPBar);
_mainLoopCommon(); m_btnMgr.show(m_wbfsLblMessage);
m_btnMgr.show(m_wbfsLblDialog);
/* mios is real nand, chans are emu */ /* mios is real nand, chans are emu */
if(mios == false) if(mios == false)
{ {
const char *emu_char = m_cfg.getString(CHANNEL_DOMAIN, "path", "/").c_str(); const char *emu_char = m_cfg.getString(CHANNEL_DOMAIN, "path", "/").c_str();
NandHandle.SetPaths(emu_char, DeviceName[currentPartition]); NandHandle.SetPaths(emu_char, DeviceName[currentPartition]);
} }
_start_pThread();
m_thrdMessage = _t("wad4", L"Installing WAD, please wait...");
m_thrdMessageAdded = true;
int result = installWad(wad_path); int result = installWad(wad_path);
_stop_pThread();
if(result < 0) if(result < 0)
m_btnMgr.setText(m_wbfsLblMessage, wfmt(_fmt("wad5", L"Installation error %i!"), result)); m_btnMgr.setText(m_wbfsLblDialog, wfmt(_fmt("wad5", L"Installation error %i!"), result));
else else
m_btnMgr.setText(m_wbfsLblMessage, wfmt(_fmt("wad6", L"Installation finished with %i hash fails."), result)); m_btnMgr.setText(m_wbfsLblDialog, wfmt(_fmt("wad6", L"Installation finished with %i hash fails."), result));
} }
else if((m_btnMgr.selected(m_configBtnPartitionP) || m_btnMgr.selected(m_configBtnPartitionM))) else if((m_btnMgr.selected(m_configBtnPartitionP) || m_btnMgr.selected(m_configBtnPartitionM)))
{ {
@ -413,6 +488,8 @@ void CMenu::_Wad(const char *wad_path)
_hideWad(); _hideWad();
/* onscreen message might be onscreen still */ /* onscreen message might be onscreen still */
m_btnMgr.hide(m_wbfsLblMessage); m_btnMgr.hide(m_wbfsLblMessage);
m_btnMgr.hide(m_wbfsLblDialog);
m_btnMgr.hide(m_wbfsPBar);
} }
void CMenu::_initWad() void CMenu::_initWad()

View File

@ -111,10 +111,7 @@ void CMenu::GC_Messenger(int message, int info, char *cinfo)
m_thrdMessage = _t("wbfsop25", L"Disc read error!! Please clean the disc"); m_thrdMessage = _t("wbfsop25", L"Disc read error!! Please clean the disc");
else if(message == 11) else if(message == 11)
m_thrdMessage = _t("wbfsop26", L"Disc ejected!! Please insert disc again"); m_thrdMessage = _t("wbfsop26", L"Disc ejected!! Please insert disc again");
m_thrdMessageAdded = true;
if(!m_thrdMessage.empty())
m_btnMgr.setText(m_wbfsLblDialog, m_thrdMessage);
_mainLoopCommon();
} }
int CMenu::_gameInstaller(void *obj) int CMenu::_gameInstaller(void *obj)
@ -364,14 +361,16 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op)
break; break;
} }
strncpy(cfPos, GameID, 6); strncpy(cfPos, GameID, 6);
m_btnMgr.setText(m_wbfsLblDialog, wfmt(_fmt("wbfsop6", L"Installing [%s] %s..."), GameID, gc_hdr.title));
done = true; done = true;
upd_dml = true; upd_dml = true;
m_thrdWorking = true; m_thrdWorking = true;
m_thrdProgress = 0.f; m_thrdProgress = 0.f;
m_thrdMessageAdded = false;
//LWP_CreateThread(&thread, (void *(*)(void *))_GCgameInstaller, (void *)this, 0, 8 * 1024, 64); //LWP_CreateThread(&thread, (void *(*)(void *))_GCgameInstaller, (void *)this, 0, 8 * 1024, 64);
_start_pThread();
m_thrdMessage = wfmt(_fmt("wbfsop6", L"Installing [%s] %s..."), GameID, gc_hdr.title);
m_thrdMessageAdded = true;
_GCgameInstaller(); _GCgameInstaller();
_stop_pThread();
} }
else else
{ {
@ -535,16 +534,3 @@ void CMenu::_textWBFS(void)
{ {
m_btnMgr.setText(m_wbfsBtnGo, _t("wbfsop5", L"Go")); m_btnMgr.setText(m_wbfsBtnGo, _t("wbfsop5", L"Go"));
} }
void CMenu::GC_Refresh(int status, int total)
{
m_progress = (float)status / (float)total;
// Don't synchronize too often
if(m_progress - m_thrdProgress >= 0.01f)
{
m_thrdProgress = m_progress;
m_btnMgr.setProgress(m_wbfsPBar, m_thrdProgress);
m_btnMgr.setText(m_wbfsLblMessage, wfmt(L"%i%%", (int)(m_thrdProgress * 100.f)));
_mainLoopCommon();
}
}