2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* ProgressWindow
|
|
|
|
* USB Loader GX 2009
|
|
|
|
*
|
|
|
|
* ProgressWindow.cpp
|
|
|
|
***************************************************************************/
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "menu.h"
|
|
|
|
#include "language/gettext.h"
|
|
|
|
#include "libwiigui/gui.h"
|
|
|
|
#include "prompts/ProgressWindow.h"
|
|
|
|
#include "usbloader/wbfs.h"
|
2009-11-15 20:52:58 +01:00
|
|
|
#include "usbloader/utils.h"
|
2010-09-24 19:58:56 +02:00
|
|
|
#include "themes/CTheme.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/*** Variables used only in this file ***/
|
|
|
|
static lwp_t progressthread = LWP_THREAD_NULL;
|
|
|
|
static char progressTitle[100];
|
|
|
|
static char progressMsg1[150];
|
|
|
|
static char progressMsg2[150];
|
|
|
|
static char progressTime[80];
|
|
|
|
static char progressSizeLeft[80];
|
|
|
|
static char progressSpeed[15];
|
|
|
|
static char *dyn_message;
|
|
|
|
static int showProgress = 0;
|
|
|
|
static f32 progressDone = 0.0;
|
|
|
|
static bool showTime = false;
|
|
|
|
static bool showSize = false;
|
2009-10-20 01:09:27 +02:00
|
|
|
static bool changed = true;
|
2010-02-25 13:08:03 +01:00
|
|
|
static s64 gameinstalldone = 0;
|
|
|
|
static s64 gameinstalltotal = -1;
|
2009-10-01 01:10:58 +02:00
|
|
|
static time_t start;
|
|
|
|
|
|
|
|
/*** Extern variables ***/
|
|
|
|
extern GuiWindow * mainWindow;
|
|
|
|
extern float gamesize;
|
|
|
|
|
2010-01-19 11:48:50 +01:00
|
|
|
/*** Extern functions ***/
|
|
|
|
extern void ResumeGui();
|
|
|
|
extern void HaltGui();
|
|
|
|
|
2010-02-25 13:08:03 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* ProgressCallback mainly for gameinstallation. Can be used for other C app.
|
2010-09-24 02:48:03 +02:00
|
|
|
***************************************************************************/
|
|
|
|
extern "C" void ProgressCallback(s64 done, s64 total)
|
2010-02-25 13:08:03 +01:00
|
|
|
{
|
|
|
|
gameinstalldone = done;
|
|
|
|
gameinstalltotal = total;
|
|
|
|
}
|
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* GameInstallProgress
|
|
|
|
* GameInstallValue updating function
|
2010-09-24 02:48:03 +02:00
|
|
|
***************************************************************************/
|
2010-02-25 13:08:03 +01:00
|
|
|
static void GameInstallProgress()
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (gameinstalltotal <= 0) return;
|
2009-10-20 01:09:27 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (gameinstalldone > gameinstalltotal) gameinstalldone = gameinstalltotal;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
static u32 expected = 300;
|
|
|
|
|
|
|
|
u32 elapsed, h, m, s;
|
|
|
|
f32 speed = 0;
|
|
|
|
|
|
|
|
//Elapsed time
|
2010-09-24 02:48:03 +02:00
|
|
|
elapsed = time(0) - start;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
//Calculate speed in MB/s
|
2010-09-24 02:48:03 +02:00
|
|
|
if (elapsed > 0) speed = KB_SIZE * gamesize * gameinstalldone / (gameinstalltotal * elapsed);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (gameinstalldone != gameinstalltotal)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
//Expected time
|
2010-09-24 02:48:03 +02:00
|
|
|
if (elapsed) expected = (expected * 3 + elapsed * gameinstalltotal / gameinstalldone) / 4;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
//Remaining time
|
2010-09-24 02:48:03 +02:00
|
|
|
elapsed = (expected > elapsed) ? (expected - elapsed) : 0;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Calculate time values
|
2010-09-24 02:48:03 +02:00
|
|
|
h = elapsed / 3600;
|
|
|
|
m = (elapsed / 60) % 60;
|
|
|
|
s = elapsed % 60;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
progressDone = 100.0 * gameinstalldone / gameinstalltotal;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
snprintf(progressTime, sizeof(progressTime), "%s %d:%02d:%02d", tr( "Time left:" ), h, m, s);
|
|
|
|
snprintf(progressSizeLeft, sizeof(progressSizeLeft), "%.2fGB/%.2fGB",
|
|
|
|
gamesize * gameinstalldone / gameinstalltotal, gamesize);
|
|
|
|
snprintf(progressSpeed, sizeof(progressSpeed), "%.1fMB/s", speed);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2009-10-20 01:09:27 +02:00
|
|
|
changed = true;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* SetupGameInstallProgress
|
2010-09-24 02:48:03 +02:00
|
|
|
***************************************************************************/
|
|
|
|
void SetupGameInstallProgress(char * title, char * game)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(progressTitle, title, sizeof(progressTitle));
|
|
|
|
strlcpy(progressMsg1, game, sizeof(progressMsg1));
|
2009-10-01 01:10:58 +02:00
|
|
|
gameinstalltotal = 1;
|
|
|
|
showProgress = 1;
|
|
|
|
showSize = true;
|
|
|
|
showTime = true;
|
2010-09-24 02:48:03 +02:00
|
|
|
LWP_ResumeThread(progressthread);
|
|
|
|
start = time(0);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* ProgressWindow
|
|
|
|
*
|
|
|
|
* Opens a window, which displays progress to the user. Can either display a
|
|
|
|
* progress bar showing % completion, or a throbber that only shows that an
|
|
|
|
* action is in progress.
|
|
|
|
***************************************************************************/
|
2010-09-24 02:48:03 +02:00
|
|
|
static void ProgressWindow(const char *title, const char *msg1, const char *msg2)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiWindow promptWindow(472, 320);
|
|
|
|
promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
|
|
|
promptWindow.SetPosition(0, -10);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png"));
|
|
|
|
GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png"));
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
GuiTrigger trigA;
|
2010-09-24 02:48:03 +02:00
|
|
|
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiImage dialogBoxImg(&dialogBox);
|
|
|
|
if (Settings.wsprompt == yes)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
dialogBoxImg.SetWidescreen(Settings.widescreen);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
GuiImageData progressbarOutline(Resources::GetFile("progressbar_outline.png"), Resources::GetFileSize("progressbar_outline.png"));
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiImage progressbarOutlineImg(&progressbarOutline);
|
|
|
|
if (Settings.wsprompt == yes)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
progressbarOutlineImg.SetWidescreen(Settings.widescreen);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
progressbarOutlineImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
progressbarOutlineImg.SetPosition(25, 40);
|
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
GuiImageData progressbarEmpty(Resources::GetFile("progressbar_empty.png"), Resources::GetFileSize("button_dialogue_box.png"));
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiImage progressbarEmptyImg(&progressbarEmpty);
|
|
|
|
progressbarEmptyImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
progressbarEmptyImg.SetPosition(25, 40);
|
|
|
|
progressbarEmptyImg.SetTile(100);
|
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
GuiImageData progressbar(Resources::GetFile("progressbar.png"), Resources::GetFileSize("progressbar.png"));
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiImage progressbarImg(&progressbar);
|
|
|
|
progressbarImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
progressbarImg.SetPosition(25, 40);
|
|
|
|
|
2010-09-24 19:58:56 +02:00
|
|
|
GuiText titleTxt(title, 26, Theme.prompttext);
|
2010-09-24 02:48:03 +02:00
|
|
|
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
|
|
|
titleTxt.SetPosition(0, 60);
|
|
|
|
|
2010-09-24 19:58:56 +02:00
|
|
|
GuiText msg1Txt(msg1, 22, Theme.prompttext);
|
2010-09-24 02:48:03 +02:00
|
|
|
msg1Txt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
|
|
|
if (msg2)
|
|
|
|
msg1Txt.SetPosition(0, 120);
|
|
|
|
else msg1Txt.SetPosition(0, 100);
|
|
|
|
msg1Txt.SetMaxWidth(430, DOTTED);
|
|
|
|
|
2010-09-24 19:58:56 +02:00
|
|
|
GuiText msg2Txt(msg2, 22, Theme.prompttext);
|
2010-09-24 02:48:03 +02:00
|
|
|
msg2Txt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
|
|
|
msg2Txt.SetPosition(0, 125);
|
|
|
|
msg2Txt.SetMaxWidth(430, DOTTED);
|
|
|
|
|
2010-09-24 19:58:56 +02:00
|
|
|
GuiText prsTxt("%", 22, Theme.prompttext);
|
2010-09-24 02:48:03 +02:00
|
|
|
prsTxt.SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE);
|
|
|
|
prsTxt.SetPosition(-188, 40);
|
|
|
|
|
2010-09-24 19:58:56 +02:00
|
|
|
GuiText timeTxt((char*) NULL, 22, Theme.prompttext);
|
2010-09-24 02:48:03 +02:00
|
|
|
timeTxt.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
|
|
|
|
timeTxt.SetPosition(280, -50);
|
|
|
|
|
2010-09-24 19:58:56 +02:00
|
|
|
GuiText sizeTxt((char*) NULL, 22, Theme.prompttext);
|
2010-09-24 02:48:03 +02:00
|
|
|
sizeTxt.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
|
|
|
|
sizeTxt.SetPosition(50, -50);
|
|
|
|
|
2010-09-24 19:58:56 +02:00
|
|
|
GuiText speedTxt((char*) NULL, 22, Theme.prompttext);
|
2010-09-24 02:48:03 +02:00
|
|
|
speedTxt.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
|
|
|
|
speedTxt.SetPosition(50, -74);
|
|
|
|
|
2010-09-24 19:58:56 +02:00
|
|
|
GuiText prTxt((char*) NULL, 26, Theme.prompttext);
|
2010-09-24 02:48:03 +02:00
|
|
|
prTxt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
prTxt.SetPosition(200, 40);
|
|
|
|
|
|
|
|
if ((Settings.wsprompt == yes) && (Settings.widescreen)) /////////////adjust for widescreen
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
progressbarOutlineImg.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
|
|
|
progressbarOutlineImg.SetPosition(0, 40);
|
|
|
|
progressbarEmptyImg.SetPosition(80, 40);
|
|
|
|
progressbarEmptyImg.SetTile(78);
|
|
|
|
progressbarImg.SetPosition(80, 40);
|
|
|
|
msg1Txt.SetMaxWidth(380, DOTTED);
|
|
|
|
msg2Txt.SetMaxWidth(380, DOTTED);
|
|
|
|
|
|
|
|
timeTxt.SetPosition(250, -50);
|
|
|
|
timeTxt.SetFontSize(20);
|
|
|
|
speedTxt.SetPosition(90, -74);
|
|
|
|
speedTxt.SetFontSize(20);
|
|
|
|
sizeTxt.SetPosition(90, -50);
|
|
|
|
sizeTxt.SetFontSize(20);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
usleep(400000); // wait to see if progress flag changes soon
|
|
|
|
if (!showProgress) return;
|
|
|
|
|
|
|
|
promptWindow.Append(&dialogBoxImg);
|
|
|
|
promptWindow.Append(&progressbarEmptyImg);
|
|
|
|
promptWindow.Append(&progressbarImg);
|
|
|
|
promptWindow.Append(&progressbarOutlineImg);
|
|
|
|
promptWindow.Append(&prTxt);
|
|
|
|
promptWindow.Append(&prsTxt);
|
|
|
|
if (title) promptWindow.Append(&titleTxt);
|
|
|
|
if (msg1) promptWindow.Append(&msg1Txt);
|
|
|
|
if (msg2) promptWindow.Append(&msg2Txt);
|
|
|
|
if (showTime) promptWindow.Append(&timeTxt);
|
|
|
|
if (showSize)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
promptWindow.Append(&sizeTxt);
|
|
|
|
promptWindow.Append(&speedTxt);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HaltGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50);
|
|
|
|
mainWindow->SetState(STATE_DISABLED);
|
|
|
|
mainWindow->Append(&promptWindow);
|
|
|
|
mainWindow->ChangeFocus(&promptWindow);
|
2009-10-01 01:10:58 +02:00
|
|
|
ResumeGui();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
while (promptWindow.GetEffect() > 0)
|
|
|
|
usleep(100);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
int tmp;
|
2010-09-24 02:48:03 +02:00
|
|
|
while (showProgress)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2009-12-13 10:26:34 +01:00
|
|
|
VIDEO_WaitVSync();
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
GameInstallProgress();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (changed)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2009-10-20 01:09:27 +02:00
|
|
|
changed = false;
|
2009-10-17 22:48:52 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
tmp = static_cast<int> (progressbarImg.GetWidth() * progressDone);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (Settings.widescreen && Settings.wsprompt == yes)
|
|
|
|
progressbarImg.SetSkew(0, 0, static_cast<int> (progressbarImg.GetWidth() * progressDone * 0.8)
|
|
|
|
- progressbarImg.GetWidth(), 0, static_cast<int> (progressbarImg.GetWidth() * progressDone
|
|
|
|
* 0.8) - progressbarImg.GetWidth(), 0, 0, 0);
|
|
|
|
else progressbarImg.SetSkew(0, 0, static_cast<int> (progressbarImg.GetWidth() * progressDone)
|
|
|
|
- progressbarImg.GetWidth(), 0, static_cast<int> (progressbarImg.GetWidth() * progressDone)
|
|
|
|
- progressbarImg.GetWidth(), 0, 0, 0);
|
2009-10-20 01:09:27 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
prTxt.SetTextf("%.2f", progressDone);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (showSize)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
sizeTxt.SetText(progressSizeLeft);
|
|
|
|
speedTxt.SetText(progressSpeed);
|
2009-10-20 01:09:27 +02:00
|
|
|
}
|
2009-10-17 22:48:52 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (showTime) timeTxt.SetText(progressTime);
|
2009-10-20 01:09:27 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (msg2) msg2Txt.SetText(dyn_message);
|
2009-10-20 01:09:27 +02:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50);
|
|
|
|
while (promptWindow.GetEffect() > 0)
|
|
|
|
usleep(100);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
HaltGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
mainWindow->Remove(&promptWindow);
|
|
|
|
mainWindow->SetState(STATE_DEFAULT);
|
2009-10-01 01:10:58 +02:00
|
|
|
ResumeGui();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* ProgressThread
|
2010-09-24 02:48:03 +02:00
|
|
|
***************************************************************************/
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
static void * ProgressThread(void *arg)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
while (1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!showProgress) LWP_SuspendThread(progressthread);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
ProgressWindow(progressTitle, progressMsg1, progressMsg2);
|
|
|
|
usleep(100);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* ProgressStop
|
|
|
|
***************************************************************************/
|
2010-09-19 01:16:05 +02:00
|
|
|
void ProgressStop()
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
showProgress = 0;
|
2010-02-25 13:08:03 +01:00
|
|
|
gameinstalltotal = -1;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
// wait for thread to finish
|
2010-09-24 02:48:03 +02:00
|
|
|
while (!LWP_ThreadIsSuspended(progressthread))
|
|
|
|
usleep(100);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* ShowProgress
|
|
|
|
*
|
|
|
|
* Callbackfunction for updating the progress values
|
|
|
|
* Use this function as standard callback
|
|
|
|
***************************************************************************/
|
2010-09-24 02:48:03 +02:00
|
|
|
void ShowProgress(const char *title, const char *msg1, char *dynmsg2, f32 done, f32 total, bool swSize, bool swTime)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (total <= 0)
|
2009-10-01 01:10:58 +02:00
|
|
|
return;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (done > total) done = total;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
showSize = swSize;
|
|
|
|
showTime = swTime;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (title) strlcpy(progressTitle, title, sizeof(progressTitle));
|
|
|
|
if (msg1) strlcpy(progressMsg1, msg1, sizeof(progressMsg1));
|
|
|
|
if (dynmsg2) dyn_message = dynmsg2;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2009-12-12 19:04:35 +01:00
|
|
|
static u32 expected;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2009-12-12 19:04:35 +01:00
|
|
|
u32 elapsed, h, m, s, speed = 0;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!done)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
start = time(0);
|
2009-12-12 19:04:35 +01:00
|
|
|
expected = 300;
|
2010-09-24 02:48:03 +02:00
|
|
|
LWP_ResumeThread(progressthread);
|
2009-12-12 19:04:35 +01:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2009-12-12 19:04:35 +01:00
|
|
|
//Elapsed time
|
2010-09-24 02:48:03 +02:00
|
|
|
elapsed = time(0) - start;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2009-12-12 19:04:35 +01:00
|
|
|
//Calculate speed in KB/s
|
2010-09-24 02:48:03 +02:00
|
|
|
if (elapsed > 0) speed = done / (elapsed * KB_SIZE);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (done != total)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-12-12 19:04:35 +01:00
|
|
|
//Expected time
|
2010-09-24 02:48:03 +02:00
|
|
|
if (elapsed) expected = (expected * 3 + elapsed * total / done) / 4;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2009-12-12 19:04:35 +01:00
|
|
|
//Remaining time
|
2010-09-24 02:48:03 +02:00
|
|
|
elapsed = (expected > elapsed) ? (expected - elapsed) : 0;
|
2009-12-12 19:04:35 +01:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2009-12-12 19:04:35 +01:00
|
|
|
//Calculate time values
|
2010-09-24 02:48:03 +02:00
|
|
|
h = elapsed / 3600;
|
|
|
|
m = (elapsed / 60) % 60;
|
|
|
|
s = elapsed % 60;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (swTime == true)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
snprintf(progressTime, sizeof(progressTime), "%s %d:%02d:%02d", tr( "Time left:" ), h, m, s);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (swSize == true)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (total < MB_SIZE)
|
|
|
|
snprintf(progressSizeLeft, sizeof(progressSizeLeft), "%0.2fKB/%0.2fKB", done * done / total / KB_SIZE,
|
|
|
|
total / KB_SIZE);
|
|
|
|
else if (total > MB_SIZE && total < GB_SIZE)
|
|
|
|
snprintf(progressSizeLeft, sizeof(progressSizeLeft), "%0.2fMB/%0.2fMB", done * done / total / MB_SIZE,
|
|
|
|
total / MB_SIZE);
|
|
|
|
else snprintf(progressSizeLeft, sizeof(progressSizeLeft), "%0.2fGB/%0.2fGB", done * done / total / GB_SIZE,
|
|
|
|
total / GB_SIZE);
|
|
|
|
|
|
|
|
snprintf(progressSpeed, sizeof(progressSpeed), "%dKB/s", speed);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
showProgress = 1;
|
2010-09-19 01:16:05 +02:00
|
|
|
progressDone = 100.0 * done / total;
|
2009-10-20 01:09:27 +02:00
|
|
|
changed = true;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* InitProgressThread
|
|
|
|
*
|
|
|
|
* Startup Progressthread in idle prio
|
|
|
|
***************************************************************************/
|
2010-09-19 01:16:05 +02:00
|
|
|
void InitProgressThread()
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
LWP_CreateThread(&progressthread, ProgressThread, NULL, NULL, 16384, 80);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* ExitProgressThread
|
|
|
|
*
|
|
|
|
* Shutdown Progressthread
|
|
|
|
***************************************************************************/
|
2010-09-19 01:16:05 +02:00
|
|
|
void ExitProgressThread()
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
LWP_JoinThread(progressthread, NULL);
|
2009-10-01 01:10:58 +02:00
|
|
|
progressthread = LWP_THREAD_NULL;
|
|
|
|
}
|