1 // Copyright (c) 2013- PPSSPP Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
18 #include "base/logging.h"
19 #include "i18n/i18n.h"
22 #include "ui/viewgroup.h"
23 #include "UI/ui_atlas.h"
24 #include "file/file_util.h"
26 #include "Core/Util/GameManager.h"
27 #include "UI/InstallZipScreen.h"
28 #include "UI/MainScreen.h"
30 void InstallZipScreen::CreateViews() {
34 bool success
= getFileInfo(zipPath_
.c_str(), &fileInfo
);
36 I18NCategory
*di
= GetI18NCategory("Dialog");
37 I18NCategory
*iz
= GetI18NCategory("InstallZip");
39 Margins
actionMenuMargins(0, 100, 15, 0);
41 root_
= new LinearLayout(ORIENT_HORIZONTAL
);
43 ViewGroup
*leftColumn
= new AnchorLayout(new LinearLayoutParams(1.0f
));
44 root_
->Add(leftColumn
);
46 leftColumn
->Add(new TextView(iz
->T("Install game from ZIP file?"), ALIGN_LEFT
, false, new AnchorLayoutParams(10, 10, NONE
, NONE
)));
47 leftColumn
->Add(new TextView(zipPath_
, ALIGN_LEFT
, false, new AnchorLayoutParams(10, 60, NONE
, NONE
)));
49 doneView_
= leftColumn
->Add(new TextView("", new AnchorLayoutParams(10, 120, NONE
, NONE
)));
50 progressBar_
= leftColumn
->Add(new ProgressBar(new AnchorLayoutParams(10, 200, 200, NONE
)));
52 ViewGroup
*rightColumnItems
= new LinearLayout(ORIENT_VERTICAL
, new LinearLayoutParams(300, FILL_PARENT
, actionMenuMargins
));
53 root_
->Add(rightColumnItems
);
55 installChoice_
= rightColumnItems
->Add(new Choice(iz
->T("Install")));
56 installChoice_
->OnClick
.Handle(this, &InstallZipScreen::OnInstall
);
57 backChoice_
= rightColumnItems
->Add(new Choice(di
->T("Back")));
58 backChoice_
->OnClick
.Handle
<UIScreen
>(this, &UIScreen::OnOK
); // OK so that EmuScreen will handle it right
60 rightColumnItems
->Add(new CheckBox(&deleteZipFile_
, iz
->T("Delete ZIP file")));
63 bool InstallZipScreen::key(const KeyInput
&key
) {
64 // Ignore all key presses during installation to avoid user escape
65 if (!g_GameManager
.IsInstallInProgress()) {
66 return UIScreen::key(key
);
71 UI::EventReturn
InstallZipScreen::OnInstall(UI::EventParams
¶ms
) {
72 if (g_GameManager
.InstallGameOnThread(zipPath_
, deleteZipFile_
)) {
73 installStarted_
= true;
74 installChoice_
->SetEnabled(false);
76 return UI::EVENT_DONE
;
79 void InstallZipScreen::update(InputState
&input
) {
80 I18NCategory
*iz
= GetI18NCategory("InstallZip");
83 if (g_GameManager
.IsInstallInProgress()) {
84 progressBar_
->SetVisibility(V_VISIBLE
);
85 progressBar_
->SetProgress(g_GameManager
.GetCurrentInstallProgress());
86 backChoice_
->SetEnabled(false);
88 progressBar_
->SetVisibility(V_GONE
);
89 backChoice_
->SetEnabled(true);
90 std::string err
= g_GameManager
.GetInstallError();
92 doneView_
->SetText(iz
->T(err
.c_str()));
93 } else if (installStarted_
) {
94 doneView_
->SetText(iz
->T("Installed!"));
95 MainScreen::showHomebrewTab
= true;
98 UIScreen::update(input
);