Show simple progress bars at the top of the screen during downloads.

Should do something more practical eventually.
This commit is contained in:
Henrik Rydgård 2013-11-29 16:33:17 +01:00
parent 29bbb826a1
commit eaed2e516b
5 changed files with 46 additions and 26 deletions

View File

@ -51,7 +51,7 @@ bool GameManager::DownloadAndInstall(std::string storeZipUrl) {
}
std::string filename = GetTempFilename();
curDownload_ = downloader_.StartDownload(storeZipUrl, filename);
curDownload_ = g_DownloadManager.StartDownload(storeZipUrl, filename);
return true;
}
@ -93,8 +93,8 @@ void GameManager::Update() {
// Doesn't matter if the install succeeds or not, we delete the temp file to not squander space.
// TODO: Handle disk full?
deleteFile(zipName.c_str());
curDownload_.reset();
}
curDownload_.reset();
}
}
@ -162,7 +162,6 @@ void GameManager::InstallGame(std::string zipfile) {
// Note that we do NOT write files that are not in a directory, to avoid random
// README files etc.
if (strstr(fn, "/") != 0) {
INFO_LOG(HLE, "File: %i: %s", i, fn);
struct zip_stat zstat;
int x = zip_stat_index(z, i, 0, &zstat);
size_t size = zstat.size;
@ -174,7 +173,9 @@ void GameManager::InstallGame(std::string zipfile) {
std::string outFilename = pspGame + fn;
bool isDir = outFilename.back() == '/';
if (!isDir) {
INFO_LOG(HLE, "Writing %i bytes to %s", (int)size, outFilename.c_str());
if (i < 10) {
INFO_LOG(HLE, "Writing %i bytes to %s", (int)size, outFilename.c_str());
}
FILE *f = fopen(outFilename.c_str(), "wb");
if (f) {
fwrite(buffer, 1, size, f);
@ -186,6 +187,7 @@ void GameManager::InstallGame(std::string zipfile) {
}
}
}
INFO_LOG(HLE, "Extracted %i files.", numFiles);
zip_close(z);
}

View File

@ -37,8 +37,6 @@ public:
private:
void InstallGame(std::string zipfile);
std::string GetTempFilename() const;
http::Downloader downloader_;
std::shared_ptr<http::Download> curDownload_;
};

View File

@ -189,28 +189,24 @@ std::string boot_filename = "";
void NativeHost::InitSound(PMixer *mixer) {
g_mixer = mixer;
#ifdef IOS
iOSCoreAudioInit();
iOSCoreAudioInit();
#endif
}
void NativeHost::ShutdownSound() {
#ifdef IOS
iOSCoreAudioShutdown();
iOSCoreAudioShutdown();
#endif
g_mixer = 0;
}
int NativeMix(short *audio, int num_samples) {
// ILOG("Entering mixer");
if (g_mixer) {
num_samples = g_mixer->Mix(audio, num_samples);
} else {
memset(audio, 0, num_samples * 2 * sizeof(short));
}
// ILOG("Leaving mixer");
return num_samples;
}
@ -305,7 +301,7 @@ void NativeInit(int argc, const char *argv[],
#ifdef ANDROID
// On Android, create a PSP directory tree in the external_directory,
// to hopefully reduce confusion a bit.
// to hopefully reduce confusion a bit.
ILOG("Creating %s", (g_Config.memCardDirectory + "PSP").c_str());
mkDir((g_Config.memCardDirectory + "PSP").c_str());
mkDir((g_Config.memCardDirectory + "PSP/SAVEDATA").c_str());
@ -388,12 +384,12 @@ void NativeInit(int argc, const char *argv[],
if (!gfxLog)
logman->SetLogLevel(LogTypes::G3D, LogTypes::LERROR);
INFO_LOG(BOOT, "Logger inited.");
#endif
#endif
i18nrepo.LoadIni(g_Config.sLanguageIni);
I18NCategory *d = GetI18NCategory("DesktopUI");
// Note to translators: do not translate this/add this to PPSSPP-lang's files.
// It's intended to be custom for every user.
// Note to translators: do not translate this/add this to PPSSPP-lang's files.
// It's intended to be custom for every user.
// Only add it to your own personal copies of PPSSPP.
#ifdef _WIN32
// TODO: Could allow a setting to specify a font file to load?
@ -407,9 +403,7 @@ void NativeInit(int argc, const char *argv[],
g_gameInfoCache.Init();
screenManager = new ScreenManager();
if (skipLogo) {
screenManager->switchScreen(new EmuScreen(boot_filename));
} else {
@ -550,10 +544,9 @@ void TakeScreenshot() {
memcpy(flipbuffer + y * pixel_xres * 4, buffer + (pixel_yres - y - 1) * pixel_xres * 4, pixel_xres * 4);
}
if(g_Config.bScreenshotsAsPNG)
if (g_Config.bScreenshotsAsPNG) {
stbi_write_png(temp, pixel_xres, pixel_yres, 4, flipbuffer, pixel_xres * 4);
else
{
} else {
jpge::params params;
params.m_quality = 90;
compress_image_to_jpeg_file(temp, pixel_xres, pixel_yres, 4, flipbuffer, params);
@ -566,6 +559,33 @@ void TakeScreenshot() {
#endif
}
void DrawDownloadsOverlay(UIContext &ctx) {
// Thin bar at the top of the screen like Chrome.
std::vector<float> progress = g_DownloadManager.GetCurrentProgress();
if (progress.empty()) {
return;
}
static const uint32_t colors[4] = {
0xFFFFFFFF,
0xFFCCCCCC,
0xFFAAAAAA,
0xFF777777,
};
ctx.Begin();
int h = 5;
for (int i = 0; i < progress.size(); i++) {
float barWidth = 10 + (dp_xres - 10) * progress[i];
Bounds bounds(0, h * i, barWidth, h);
INFO_LOG(HLE, "Bar");
UI::Drawable solid(colors[i & 3]);
ctx.FillRect(solid, bounds);
}
ctx.End();
ctx.Flush();
}
void NativeRender() {
g_GameManager.Update();
@ -589,6 +609,8 @@ void NativeRender() {
screenManager->getUIContext()->Text()->OncePerFrame();
}
DrawDownloadsOverlay(*screenManager->getUIContext());
if (g_TakeScreenshot) {
TakeScreenshot();
}

View File

@ -112,18 +112,18 @@ StoreScreen::StoreScreen() : loading_(true), connectionError_(false) {
std::string indexPath = storeBaseUrl + "index.json";
listing_ = downloader_.StartDownload(indexPath, "");
listing_ = g_DownloadManager.StartDownload(indexPath, "");
}
StoreScreen::~StoreScreen() {
downloader_.CancelAll();
g_DownloadManager.CancelAll();
}
// Handle async download tasks
void StoreScreen::update(InputState &input) {
UIDialogScreenWithBackground::update(input);
downloader_.Update();
g_DownloadManager.Update();
if (listing_.get() != 0 && listing_->Done()) {
if (listing_->ResultCode() == 200) {

View File

@ -77,8 +77,6 @@ private:
std::string GetStoreJsonURL(std::string storePath) const;
std::string GetTranslatedString(const json_value *json, std::string key, const char *fallback = 0) const;
http::Downloader downloader_;
std::shared_ptr<http::Download> listing_;
std::shared_ptr<http::Download> image_;