mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-27 02:10:34 +00:00
Install zip file screen: Add working progress bar for install.
This commit is contained in:
parent
804ddf03f2
commit
3ab1aeb9ef
@ -16,7 +16,8 @@
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include "file/file_util.h"
|
||||
#include "native/ext/libzip/zip.h"
|
||||
#include "ext/libzip/zip.h"
|
||||
#include "thread/thread.h"
|
||||
#include "util/text/utf8.h"
|
||||
|
||||
#include "Common/Log.h"
|
||||
@ -109,8 +110,7 @@ void GameManager::Update() {
|
||||
}
|
||||
}
|
||||
|
||||
// Does NOT delete the zip file, that is done by the function calling this, if applicable.
|
||||
bool GameManager::InstallGame(std::string zipfile) {
|
||||
bool GameManager::InstallGame(std::string zipfile, bool deleteAfter) {
|
||||
if (installInProgress_) {
|
||||
ERROR_LOG(HLE, "Cannot have two installs in progress at the same time");
|
||||
return false;
|
||||
@ -253,15 +253,25 @@ bool GameManager::InstallGame(std::string zipfile) {
|
||||
zip_close(z);
|
||||
installProgress_ = 1.0f;
|
||||
installInProgress_ = false;
|
||||
if (deleteAfter) {
|
||||
deleteFile(zipfile.c_str());
|
||||
}
|
||||
InstallDone();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GameManager::InstallGameOnThread(std::string zipFile) {
|
||||
bool GameManager::InstallGameOnThread(std::string zipFile, bool deleteAfter) {
|
||||
if (installInProgress_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Actually launch a thread
|
||||
InstallGame(zipFile);
|
||||
installThread_.reset(new std::thread(std::bind(&GameManager::InstallGame, this, zipFile, deleteAfter)));
|
||||
installThread_->detach();
|
||||
return true;
|
||||
}
|
||||
|
||||
void GameManager::InstallDone() {
|
||||
if (installThread_.get() != 0) {
|
||||
installThread_.reset();
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "thread/thread.h"
|
||||
#include "net/http_client.h"
|
||||
|
||||
class GameManager {
|
||||
@ -47,13 +48,15 @@ public:
|
||||
}
|
||||
|
||||
// Only returns false if there's already an installation in progress.
|
||||
bool InstallGameOnThread(std::string zipFile);
|
||||
bool InstallGameOnThread(std::string zipFile, bool deleteAfter);
|
||||
|
||||
private:
|
||||
bool InstallGame(std::string zipfile);
|
||||
bool InstallGame(std::string zipfile, bool deleteAfter = false);
|
||||
void InstallDone();
|
||||
|
||||
std::string GetTempFilename() const;
|
||||
std::shared_ptr<http::Download> curDownload_;
|
||||
|
||||
std::shared_ptr<std::thread> installThread_;
|
||||
bool installInProgress_;
|
||||
float installProgress_;
|
||||
};
|
||||
|
@ -33,6 +33,7 @@ void InstallZipScreen::CreateViews() {
|
||||
bool success = getFileInfo(zipPath_.c_str(), &fileInfo);
|
||||
|
||||
I18NCategory *di = GetI18NCategory("Dialog");
|
||||
I18NCategory *iz = GetI18NCategory("InstallZip");
|
||||
|
||||
Margins actionMenuMargins(0, 100, 15, 0);
|
||||
|
||||
@ -41,26 +42,45 @@ void InstallZipScreen::CreateViews() {
|
||||
ViewGroup *leftColumn = new AnchorLayout(new LinearLayoutParams(1.0f));
|
||||
root_->Add(leftColumn);
|
||||
|
||||
leftColumn->Add(new TextView(di->T("Install game from ZIP file?"), ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
|
||||
leftColumn->Add(new TextView(iz->T("Install game from ZIP file?"), ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
|
||||
leftColumn->Add(new TextView(zipPath_, ALIGN_LEFT, false, new AnchorLayoutParams(10, 60, NONE, NONE)));
|
||||
progressBar_ = leftColumn->Add(new ProgressBar(new AnchorLayoutParams(10, 200, 200, NONE)));
|
||||
|
||||
ViewGroup *rightColumnItems = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(300, FILL_PARENT, actionMenuMargins));
|
||||
root_->Add(rightColumnItems);
|
||||
|
||||
installChoice_ = rightColumnItems->Add(new Choice(di->T("Install")));
|
||||
installChoice_ = rightColumnItems->Add(new Choice(iz->T("Install")));
|
||||
installChoice_->OnClick.Handle(this, &InstallZipScreen::OnInstall);
|
||||
rightColumnItems->Add(new Choice(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK); // OK so that EmuScreen will handle it right
|
||||
rightColumnItems->Add(new CheckBox(&deleteZipFile_, di->T("Delete ZIP file")));
|
||||
backChoice_ = rightColumnItems->Add(new Choice(di->T("Back")));
|
||||
backChoice_->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK); // OK so that EmuScreen will handle it right
|
||||
|
||||
rightColumnItems->Add(new CheckBox(&deleteZipFile_, iz->T("Delete ZIP file")));
|
||||
}
|
||||
|
||||
void InstallZipScreen::key(const KeyInput &key) {
|
||||
// Ignore all key presses during installation to avoid user escape
|
||||
if (!g_GameManager.IsInstallInProgress()) {
|
||||
UIScreen::key(key);
|
||||
}
|
||||
}
|
||||
|
||||
UI::EventReturn InstallZipScreen::OnInstall(UI::EventParams ¶ms) {
|
||||
installChoice_->SetEnabled(false);
|
||||
if (g_GameManager.InstallGameOnThread(zipPath_)) {
|
||||
screenManager()->finishDialog(this, DR_OK);
|
||||
if (g_GameManager.InstallGameOnThread(zipPath_, deleteZipFile_)) {
|
||||
installStarted_ = true;
|
||||
installChoice_->SetEnabled(false);
|
||||
}
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
void InstallZipScreen::update(InputState &input) {
|
||||
using namespace UI;
|
||||
if (g_GameManager.IsInstallInProgress()) {
|
||||
progressBar_->SetVisibility(V_VISIBLE);
|
||||
progressBar_->SetProgress(g_GameManager.GetCurrentInstallProgress());
|
||||
backChoice_->SetEnabled(false);
|
||||
} else {
|
||||
progressBar_->SetVisibility(V_GONE);
|
||||
backChoice_->SetEnabled(true);
|
||||
}
|
||||
UIScreen::update(input);
|
||||
}
|
||||
|
@ -25,8 +25,9 @@
|
||||
|
||||
class InstallZipScreen : public UIDialogScreenWithBackground {
|
||||
public:
|
||||
InstallZipScreen(std::string zipPath) : installChoice_(0), zipPath_(zipPath), deleteZipFile_(false) {}
|
||||
InstallZipScreen(std::string zipPath) : installChoice_(0), zipPath_(zipPath), installStarted_(false), deleteZipFile_(false) {}
|
||||
virtual void update(InputState &input);
|
||||
virtual void key(const KeyInput &key);
|
||||
|
||||
protected:
|
||||
virtual void CreateViews();
|
||||
@ -35,7 +36,11 @@ private:
|
||||
UI::EventReturn OnInstall(UI::EventParams ¶ms);
|
||||
|
||||
UI::Choice *installChoice_;
|
||||
UI::Choice *backChoice_;
|
||||
UI::ProgressBar *progressBar_;
|
||||
UI::TextView *doneView_;
|
||||
std::string zipPath_;
|
||||
bool installStarted_;
|
||||
bool deleteZipFile_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user