2013-12-05 13:14:15 +00:00
|
|
|
// Copyright (c) 2013- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "i18n/i18n.h"
|
|
|
|
#include "ui/ui.h"
|
|
|
|
#include "ui/view.h"
|
|
|
|
#include "ui/viewgroup.h"
|
|
|
|
#include "file/file_util.h"
|
|
|
|
|
2019-02-10 14:55:00 +00:00
|
|
|
#include "Common/StringUtils.h"
|
2013-12-05 15:04:50 +00:00
|
|
|
#include "Core/Util/GameManager.h"
|
2013-12-05 13:14:15 +00:00
|
|
|
#include "UI/InstallZipScreen.h"
|
2013-12-06 11:29:27 +00:00
|
|
|
#include "UI/MainScreen.h"
|
2013-12-05 13:14:15 +00:00
|
|
|
|
|
|
|
void InstallZipScreen::CreateViews() {
|
|
|
|
using namespace UI;
|
|
|
|
|
|
|
|
FileInfo fileInfo;
|
|
|
|
bool success = getFileInfo(zipPath_.c_str(), &fileInfo);
|
|
|
|
|
2020-01-26 18:43:18 +00:00
|
|
|
auto di = GetI18NCategory("Dialog");
|
|
|
|
auto iz = GetI18NCategory("InstallZip");
|
2013-12-05 13:14:15 +00:00
|
|
|
|
|
|
|
Margins actionMenuMargins(0, 100, 15, 0);
|
|
|
|
|
|
|
|
root_ = new LinearLayout(ORIENT_HORIZONTAL);
|
|
|
|
|
|
|
|
ViewGroup *leftColumn = new AnchorLayout(new LinearLayoutParams(1.0f));
|
|
|
|
ViewGroup *rightColumnItems = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(300, FILL_PARENT, actionMenuMargins));
|
2019-07-08 21:03:27 +00:00
|
|
|
root_->Add(leftColumn);
|
2013-12-05 13:14:15 +00:00
|
|
|
root_->Add(rightColumnItems);
|
|
|
|
|
2019-07-08 21:03:27 +00:00
|
|
|
std::string shortFilename = GetFilenameFromPath(zipPath_);
|
|
|
|
|
|
|
|
// TODO: Do in the background?
|
|
|
|
ZipFileInfo zipInfo;
|
|
|
|
ZipFileContents contents = DetectZipFileContents(zipPath_, &zipInfo);
|
|
|
|
|
|
|
|
if (contents == ZipFileContents::ISO_FILE || contents == ZipFileContents::PSP_GAME_DIR) {
|
|
|
|
std::string question = iz->T("Install game from ZIP file?");
|
|
|
|
leftColumn->Add(new TextView(question, ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
|
|
|
|
leftColumn->Add(new TextView(shortFilename, ALIGN_LEFT, false, new AnchorLayoutParams(10, 60, NONE, NONE)));
|
|
|
|
|
|
|
|
doneView_ = leftColumn->Add(new TextView("", new AnchorLayoutParams(10, 120, NONE, NONE)));
|
|
|
|
progressBar_ = leftColumn->Add(new ProgressBar(new AnchorLayoutParams(10, 200, 200, NONE)));
|
|
|
|
|
|
|
|
installChoice_ = rightColumnItems->Add(new Choice(iz->T("Install")));
|
|
|
|
installChoice_->OnClick.Handle(this, &InstallZipScreen::OnInstall);
|
|
|
|
backChoice_ = rightColumnItems->Add(new Choice(di->T("Back")));
|
|
|
|
rightColumnItems->Add(new CheckBox(&deleteZipFile_, iz->T("Delete ZIP file")));
|
2019-07-15 00:43:51 +00:00
|
|
|
|
|
|
|
returnToHomebrew_ = true;
|
|
|
|
} else if (contents == ZipFileContents::TEXTURE_PACK) {
|
|
|
|
std::string question = iz->T("Install textures from ZIP file?");
|
|
|
|
leftColumn->Add(new TextView(question, ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
|
|
|
|
leftColumn->Add(new TextView(shortFilename, ALIGN_LEFT, false, new AnchorLayoutParams(10, 60, NONE, NONE)));
|
|
|
|
|
|
|
|
doneView_ = leftColumn->Add(new TextView("", new AnchorLayoutParams(10, 120, NONE, NONE)));
|
|
|
|
progressBar_ = leftColumn->Add(new ProgressBar(new AnchorLayoutParams(10, 200, 200, NONE)));
|
|
|
|
|
|
|
|
installChoice_ = rightColumnItems->Add(new Choice(iz->T("Install")));
|
|
|
|
installChoice_->OnClick.Handle(this, &InstallZipScreen::OnInstall);
|
|
|
|
backChoice_ = rightColumnItems->Add(new Choice(di->T("Back")));
|
|
|
|
rightColumnItems->Add(new CheckBox(&deleteZipFile_, iz->T("Delete ZIP file")));
|
|
|
|
|
|
|
|
returnToHomebrew_ = false;
|
2019-07-08 21:03:27 +00:00
|
|
|
} else {
|
|
|
|
leftColumn->Add(new TextView(iz->T("Zip file does not contain PSP software"), ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
|
|
|
|
backChoice_ = rightColumnItems->Add(new Choice(di->T("Back")));
|
|
|
|
}
|
2019-07-15 00:43:51 +00:00
|
|
|
|
|
|
|
// OK so that EmuScreen will handle it right.
|
|
|
|
backChoice_->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK);
|
2013-12-05 16:49:37 +00:00
|
|
|
}
|
|
|
|
|
2014-06-15 11:04:59 +00:00
|
|
|
bool InstallZipScreen::key(const KeyInput &key) {
|
2017-03-06 14:43:38 +00:00
|
|
|
// Ignore all key presses during download and installation to avoid user escape
|
|
|
|
if (g_GameManager.GetState() == GameManagerState::IDLE) {
|
2014-06-15 11:04:59 +00:00
|
|
|
return UIScreen::key(key);
|
2013-12-05 16:49:37 +00:00
|
|
|
}
|
2014-06-15 11:04:59 +00:00
|
|
|
return false;
|
2013-12-05 13:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn InstallZipScreen::OnInstall(UI::EventParams ¶ms) {
|
2019-07-10 21:37:10 +00:00
|
|
|
if (g_GameManager.InstallGameOnThread(zipPath_, zipPath_, deleteZipFile_)) {
|
2013-12-05 16:49:37 +00:00
|
|
|
installStarted_ = true;
|
|
|
|
installChoice_->SetEnabled(false);
|
2013-12-05 13:14:15 +00:00
|
|
|
}
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
2017-03-15 05:01:18 +00:00
|
|
|
void InstallZipScreen::update() {
|
2020-01-26 18:43:18 +00:00
|
|
|
auto iz = GetI18NCategory("InstallZip");
|
2013-12-06 11:49:57 +00:00
|
|
|
|
2013-12-05 16:49:37 +00:00
|
|
|
using namespace UI;
|
2017-03-06 14:43:38 +00:00
|
|
|
if (g_GameManager.GetState() != GameManagerState::IDLE) {
|
2019-09-27 20:56:06 +00:00
|
|
|
if (progressBar_) {
|
|
|
|
progressBar_->SetVisibility(V_VISIBLE);
|
|
|
|
progressBar_->SetProgress(g_GameManager.GetCurrentInstallProgressPercentage());
|
|
|
|
}
|
2013-12-05 16:49:37 +00:00
|
|
|
backChoice_->SetEnabled(false);
|
|
|
|
} else {
|
2019-09-27 20:56:06 +00:00
|
|
|
if (progressBar_) {
|
2019-07-08 21:03:27 +00:00
|
|
|
progressBar_->SetVisibility(V_GONE);
|
2019-09-27 20:56:06 +00:00
|
|
|
}
|
2013-12-05 16:49:37 +00:00
|
|
|
backChoice_->SetEnabled(true);
|
2013-12-06 11:49:57 +00:00
|
|
|
std::string err = g_GameManager.GetInstallError();
|
|
|
|
if (!err.empty()) {
|
2019-07-08 21:03:27 +00:00
|
|
|
if (doneView_)
|
|
|
|
doneView_->SetText(iz->T(err.c_str()));
|
2013-12-06 14:29:14 +00:00
|
|
|
} else if (installStarted_) {
|
2019-07-08 21:03:27 +00:00
|
|
|
if (doneView_)
|
|
|
|
doneView_->SetText(iz->T("Installed!"));
|
2019-07-15 00:43:51 +00:00
|
|
|
MainScreen::showHomebrewTab = returnToHomebrew_;
|
2013-12-06 11:49:57 +00:00
|
|
|
}
|
2013-12-05 16:49:37 +00:00
|
|
|
}
|
2017-03-15 05:01:18 +00:00
|
|
|
UIScreen::update();
|
2013-12-05 13:14:15 +00:00
|
|
|
}
|