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/.
|
|
|
|
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/UI/UI.h"
|
|
|
|
#include "Common/UI/View.h"
|
|
|
|
#include "Common/UI/ViewGroup.h"
|
2013-12-05 13:14:15 +00:00
|
|
|
|
2019-02-10 14:55:00 +00:00
|
|
|
#include "Common/StringUtils.h"
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/Data/Text/I18n.h"
|
2024-09-07 13:01:13 +00:00
|
|
|
#include "Common/Data/Text/Parsers.h"
|
2024-09-05 15:12:10 +00:00
|
|
|
#include "Core/System.h"
|
2013-12-05 15:04:50 +00:00
|
|
|
#include "Core/Util/GameManager.h"
|
2024-09-07 13:01:13 +00:00
|
|
|
#include "Core/Loaders.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"
|
2024-09-05 15:12:10 +00:00
|
|
|
#include "UI/OnScreenDisplay.h"
|
|
|
|
#include "UI/SavedataScreen.h"
|
2013-12-05 13:14:15 +00:00
|
|
|
|
2021-10-17 00:53:05 +00:00
|
|
|
InstallZipScreen::InstallZipScreen(const Path &zipPath) : zipPath_(zipPath) {
|
|
|
|
g_GameManager.ResetInstallError();
|
|
|
|
}
|
|
|
|
|
2013-12-05 13:14:15 +00:00
|
|
|
void InstallZipScreen::CreateViews() {
|
|
|
|
using namespace UI;
|
|
|
|
|
2021-04-25 18:38:22 +00:00
|
|
|
File::FileInfo fileInfo;
|
2021-05-09 16:38:48 +00:00
|
|
|
bool success = File::GetFileInfo(zipPath_, &fileInfo);
|
2013-12-05 13:14:15 +00:00
|
|
|
|
2023-04-05 22:34:50 +00:00
|
|
|
auto di = GetI18NCategory(I18NCat::DIALOG);
|
|
|
|
auto iz = GetI18NCategory(I18NCat::INSTALLZIP);
|
2024-09-05 15:12:10 +00:00
|
|
|
auto er = GetI18NCategory(I18NCat::ERRORS);
|
2024-09-07 13:01:13 +00:00
|
|
|
auto ga = GetI18NCategory(I18NCat::GAME);
|
2013-12-05 13:14:15 +00:00
|
|
|
|
|
|
|
Margins actionMenuMargins(0, 100, 15, 0);
|
|
|
|
|
|
|
|
root_ = new LinearLayout(ORIENT_HORIZONTAL);
|
|
|
|
|
2024-09-05 15:12:10 +00:00
|
|
|
ViewGroup *leftColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f, Margins(12)));
|
2013-12-05 13:14:15 +00:00
|
|
|
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);
|
|
|
|
|
2021-05-09 16:38:48 +00:00
|
|
|
std::string shortFilename = zipPath_.GetFilename();
|
2019-07-08 21:03:27 +00:00
|
|
|
|
|
|
|
// TODO: Do in the background?
|
2024-09-05 15:12:10 +00:00
|
|
|
struct zip *z = ZipOpenPath(zipPath_);
|
|
|
|
|
|
|
|
bool showDeleteCheckbox = false;
|
|
|
|
returnToHomebrew_ = false;
|
|
|
|
installChoice_ = nullptr;
|
|
|
|
doneView_ = nullptr;
|
|
|
|
installChoice_ = nullptr;
|
2024-09-07 13:01:13 +00:00
|
|
|
existingSaveView_ = nullptr;
|
2024-09-05 15:12:10 +00:00
|
|
|
if (z) {
|
|
|
|
DetectZipFileContents(z, &zipFileInfo_); // Even if this fails, it sets zipInfo->contents.
|
|
|
|
if (zipFileInfo_.contents == ZipFileContents::ISO_FILE || zipFileInfo_.contents == ZipFileContents::PSP_GAME_DIR) {
|
|
|
|
std::string_view question = iz->T("Install game from ZIP file?");
|
|
|
|
|
|
|
|
leftColumn->Add(new TextView(question));
|
|
|
|
leftColumn->Add(new TextView(shortFilename));
|
2024-09-07 13:01:13 +00:00
|
|
|
if (!zipFileInfo_.contentName.empty()) {
|
|
|
|
leftColumn->Add(new TextView(zipFileInfo_.contentName));
|
|
|
|
}
|
2024-09-05 15:12:10 +00:00
|
|
|
|
|
|
|
doneView_ = leftColumn->Add(new TextView(""));
|
|
|
|
|
|
|
|
installChoice_ = rightColumnItems->Add(new Choice(iz->T("Install")));
|
|
|
|
installChoice_->OnClick.Handle(this, &InstallZipScreen::OnInstall);
|
|
|
|
returnToHomebrew_ = true;
|
|
|
|
showDeleteCheckbox = true;
|
|
|
|
} else if (zipFileInfo_.contents == ZipFileContents::TEXTURE_PACK) {
|
|
|
|
std::string_view question = iz->T("Install textures from ZIP file?");
|
|
|
|
leftColumn->Add(new TextView(question));
|
|
|
|
leftColumn->Add(new TextView(shortFilename));
|
|
|
|
|
|
|
|
doneView_ = leftColumn->Add(new TextView(""));
|
|
|
|
|
|
|
|
installChoice_ = rightColumnItems->Add(new Choice(iz->T("Install")));
|
|
|
|
installChoice_->OnClick.Handle(this, &InstallZipScreen::OnInstall);
|
|
|
|
backChoice_ = rightColumnItems->Add(new Choice(di->T("Back")));
|
|
|
|
|
|
|
|
showDeleteCheckbox = true;
|
|
|
|
} else if (zipFileInfo_.contents == ZipFileContents::SAVE_DATA) {
|
2024-09-07 13:01:13 +00:00
|
|
|
std::string_view question = iz->T("Import savedata from ZIP file");
|
|
|
|
leftColumn->Add(new TextView(question))->SetBig(true);
|
|
|
|
leftColumn->Add(new TextView(zipFileInfo_.gameTitle + ": " + zipFileInfo_.savedataDir));
|
|
|
|
|
|
|
|
Path savedataDir = GetSysDirectory(DIRECTORY_SAVEDATA);
|
|
|
|
bool overwrite = !CanExtractWithoutOverwrite(z, savedataDir, 50);
|
|
|
|
|
|
|
|
leftColumn->Add(new NoticeView(NoticeLevel::WARN, di->T("Confirm Overwrite"), ""));
|
|
|
|
|
|
|
|
int columnWidth = 300;
|
|
|
|
|
|
|
|
LinearLayout *compareColumns = leftColumn->Add(new LinearLayout(UI::ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
|
2024-09-07 13:23:50 +00:00
|
|
|
LinearLayout *leftCompare = new LinearLayout(UI::ORIENT_VERTICAL);
|
|
|
|
leftCompare->Add(new TextView(iz->T("Data to import")));
|
|
|
|
compareColumns->Add(leftCompare);
|
|
|
|
leftCompare->Add(new SavedataView(*screenManager()->getUIContext(), Path(), IdentifiedFileType::PSP_SAVEDATA_DIRECTORY,
|
2024-09-07 13:01:13 +00:00
|
|
|
zipFileInfo_.gameTitle, zipFileInfo_.savedataTitle, zipFileInfo_.savedataDetails, NiceSizeFormat(zipFileInfo_.totalFileSize), zipFileInfo_.mTime, false, new LinearLayoutParams(columnWidth, WRAP_CONTENT)));
|
2024-09-05 15:12:10 +00:00
|
|
|
|
|
|
|
// Check for potential overwrite at destination, and ask the user if it's OK to overwrite.
|
2024-09-07 13:01:13 +00:00
|
|
|
if (overwrite) {
|
|
|
|
savedataToOverwrite_ = savedataDir / zipFileInfo_.savedataDir;
|
|
|
|
std::shared_ptr<GameInfo> ginfo = g_gameInfoCache->GetInfo(screenManager()->getDrawContext(), savedataToOverwrite_, GameInfoFlags::FILE_TYPE | GameInfoFlags::PARAM_SFO | GameInfoFlags::ICON | GameInfoFlags::SIZE);
|
|
|
|
|
|
|
|
LinearLayout *rightCompare = new LinearLayout(UI::ORIENT_VERTICAL);
|
|
|
|
rightCompare->Add(new TextView(iz->T("Existing data")));
|
2024-09-07 13:23:50 +00:00
|
|
|
|
2024-09-07 13:01:13 +00:00
|
|
|
compareColumns->Add(rightCompare);
|
|
|
|
existingSaveView_ = rightCompare->Add(new SavedataView(*screenManager()->getUIContext(), ginfo.get(), IdentifiedFileType::PSP_SAVEDATA_DIRECTORY, false, new LinearLayoutParams(columnWidth, WRAP_CONTENT)));
|
|
|
|
if (System_GetPropertyBool(SYSPROP_CAN_SHOW_FILE)) {
|
|
|
|
rightCompare->Add(new Button(ga->T("Show In Folder")))->OnClick.Add([=](UI::EventParams &) {
|
|
|
|
System_ShowFileInFolder(savedataToOverwrite_);
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
});
|
|
|
|
}
|
2024-09-05 15:12:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
installChoice_ = rightColumnItems->Add(new Choice(iz->T("Install")));
|
|
|
|
installChoice_->OnClick.Handle(this, &InstallZipScreen::OnInstall);
|
|
|
|
|
|
|
|
doneView_ = leftColumn->Add(new TextView(""));
|
|
|
|
showDeleteCheckbox = true;
|
|
|
|
} else {
|
|
|
|
leftColumn->Add(new TextView(iz->T("Zip file does not contain PSP software"), ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
|
|
|
|
}
|
2019-07-08 21:03:27 +00:00
|
|
|
} else {
|
2024-09-05 15:12:10 +00:00
|
|
|
leftColumn->Add(new TextView(er->T("Error reading file"), ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
|
2019-07-08 21:03:27 +00:00
|
|
|
}
|
2019-07-15 00:43:51 +00:00
|
|
|
|
|
|
|
// OK so that EmuScreen will handle it right.
|
2024-09-05 15:12:10 +00:00
|
|
|
backChoice_ = rightColumnItems->Add(new Choice(di->T("Back")));
|
2019-07-15 00:43:51 +00:00
|
|
|
backChoice_->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK);
|
2024-09-05 15:12:10 +00:00
|
|
|
|
|
|
|
if (showDeleteCheckbox) {
|
|
|
|
rightColumnItems->Add(new CheckBox(&deleteZipFile_, iz->T("Delete ZIP file")));
|
|
|
|
}
|
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) {
|
2024-09-07 13:37:24 +00:00
|
|
|
return UIDialogScreen::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) {
|
2024-09-04 15:08:26 +00:00
|
|
|
ZipFileTask task;
|
|
|
|
task.url = zipPath_;
|
|
|
|
task.fileName = zipPath_;
|
|
|
|
task.deleteAfter = deleteZipFile_;
|
|
|
|
task.zipFileInfo = zipFileInfo_;
|
|
|
|
if (g_GameManager.InstallZipOnThread(task)) {
|
2013-12-05 16:49:37 +00:00
|
|
|
installStarted_ = true;
|
2020-07-04 23:49:34 +00:00
|
|
|
if (installChoice_) {
|
|
|
|
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() {
|
2023-04-05 22:34:50 +00:00
|
|
|
auto iz = GetI18NCategory(I18NCat::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) {
|
2020-11-15 22:09:10 +00:00
|
|
|
if (backChoice_) {
|
|
|
|
backChoice_->SetEnabled(false);
|
|
|
|
}
|
2013-12-05 16:49:37 +00:00
|
|
|
} else {
|
2020-11-15 22:09:10 +00:00
|
|
|
if (backChoice_) {
|
|
|
|
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
|
|
|
}
|
2024-09-07 13:01:13 +00:00
|
|
|
|
|
|
|
if (existingSaveView_) {
|
|
|
|
std::shared_ptr<GameInfo> ginfo = g_gameInfoCache->GetInfo(screenManager()->getDrawContext(), savedataToOverwrite_, GameInfoFlags::FILE_TYPE | GameInfoFlags::PARAM_SFO | GameInfoFlags::ICON | GameInfoFlags::SIZE);
|
|
|
|
existingSaveView_->Update(ginfo.get());
|
|
|
|
}
|
2024-09-07 14:17:28 +00:00
|
|
|
UIDialogScreenWithBackground::update();
|
2013-12-05 13:14:15 +00:00
|
|
|
}
|