ppsspp/UI/PluginScreen.cpp

176 lines
6.1 KiB
C++
Raw Normal View History

2013-06-01 21:34:50 +00:00
// Copyright (c) 2012- 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/.
2013-06-02 11:43:15 +00:00
#include "base/functional.h"
2013-06-01 21:34:50 +00:00
#include "UI/PluginScreen.h"
#include "ext/vjson/json.h"
#include "i18n/i18n.h"
#include "ui/view.h"
#include "ui/viewgroup.h"
#include "ui/ui_context.h"
2013-06-02 22:42:19 +00:00
#include "UI/ui_atlas.h"
2013-06-02 12:38:22 +00:00
#include "Core/HW/atrac3plus.h"
2013-06-01 21:34:50 +00:00
#ifdef __APPLE__
#include "TargetConditionals.h"
#if TARGET_OS_MAC
#define MACOSX
#endif
#endif
2013-06-02 22:42:19 +00:00
void DrawBackground(float alpha);
2013-06-02 12:38:22 +00:00
void PluginScreen::DrawBackground(UIContext &dc)
2013-06-02 22:42:19 +00:00
{
::DrawBackground(1.0f);
2013-06-01 21:34:50 +00:00
}
PluginScreen::PluginScreen() {
// Let's start by downloading the json. We'll find out in Update when it's finished.
json_ = downloader_.StartDownload("http://www.ppsspp.org/update/at3plusdecoder.json", "");
2013-06-02 12:38:22 +00:00
}
2013-06-01 21:34:50 +00:00
2013-06-02 12:38:22 +00:00
void PluginScreen::CreateViews() {
2013-06-05 14:48:16 +00:00
I18NCategory *p = GetI18NCategory("Plugin");
2013-06-01 21:34:50 +00:00
// Build the UI.
using namespace UI;
root_ = new LinearLayout(ORIENT_VERTICAL);
Margins textMargins(20,17);
2013-06-03 23:25:30 +00:00
Margins buttonMargins(10,10);
2013-06-01 21:34:50 +00:00
2013-06-20 19:51:31 +00:00
root_->Add(new TextView(UBUNTU24, "Atrac3+ Audio Support", ALIGN_HCENTER, 1.5f, new LinearLayoutParams(textMargins)));
2013-06-02 21:46:03 +00:00
ViewGroup *scroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0));
2013-06-03 23:25:30 +00:00
LinearLayout *scrollContents = new LinearLayout(ORIENT_VERTICAL);
2013-06-02 21:46:03 +00:00
root_->Add(scroll);
2013-06-03 23:25:30 +00:00
scroll->Add(scrollContents);
2013-06-02 21:46:03 +00:00
2013-06-03 23:25:30 +00:00
tvDescription_ = scrollContents->Add(new TextView(0, "Looking for download...", ALIGN_LEFT, 1.0f, new LinearLayoutParams(textMargins)));
const char *legalityNotice =
2013-06-05 14:48:16 +00:00
p->T("Origins are dubious", "* Mai's Atrac3+ decoder is currently required\n"
2013-06-20 19:51:31 +00:00
"for background audio and voice in many games.\n"
2013-06-03 23:25:30 +00:00
"Please note that the origins of this code are dubious.\n"
2013-06-05 14:48:16 +00:00
"Choose More Information for more information.");
2013-06-03 23:25:30 +00:00
2013-06-20 19:51:31 +00:00
scrollContents->Add(new TextView(0, legalityNotice, ALIGN_LEFT, 0.65f, new LinearLayoutParams(textMargins) ));
2013-06-01 21:34:50 +00:00
2013-06-02 12:38:22 +00:00
progress_ = root_->Add(new ProgressBar());
2013-06-02 21:46:03 +00:00
progress_->SetVisibility(V_GONE);
2013-06-02 12:38:22 +00:00
2013-06-03 23:25:30 +00:00
ViewGroup *buttonBar = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(buttonMargins));
2013-06-01 21:34:50 +00:00
root_->Add(buttonBar);
2013-06-05 14:48:16 +00:00
buttonBack_ = new Button(p->T("Back"), new LinearLayoutParams(1.0));
2013-06-04 21:54:37 +00:00
buttonBar->Add(buttonBack_)->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
2013-06-05 14:48:16 +00:00
buttonDownload_ = new Button(p->T("Download and install"), new LinearLayoutParams(1.0));
2013-06-02 22:42:19 +00:00
buttonDownload_->SetEnabled(false);
2013-06-04 21:54:37 +00:00
buttonBar->Add(buttonDownload_)->OnClick.Handle(this, &PluginScreen::OnDownload);
2013-06-05 14:48:16 +00:00
buttonBar->Add(new Button(p->T("More Information"), new LinearLayoutParams(1.0)))->OnClick.Handle(this, &PluginScreen::OnInformation);
2013-06-01 21:34:50 +00:00
}
void PluginScreen::update(InputState &input) {
2013-06-02 21:46:03 +00:00
UIScreen::update(input);
2013-06-05 14:48:16 +00:00
I18NCategory *p = GetI18NCategory("Plugin");
2013-06-01 21:34:50 +00:00
downloader_.Update();
if (json_.get() && json_->Done()) {
2013-06-04 20:06:15 +00:00
if (json_->ResultCode() != 200) {
char codeStr[18];
sprintf(codeStr, "%i", json_->ResultCode());
2013-06-05 14:48:16 +00:00
tvDescription_->SetText(p->T("Failed to reach server", "Failed to reach server.\nPlease try again later and check that you have a\nworking internet connection."));
2013-06-04 20:06:15 +00:00
buttonDownload_->SetEnabled(false);
2013-06-05 14:48:16 +00:00
} else {
2013-06-04 20:06:15 +00:00
std::string json;
json_->buffer().TakeAll(&json);
2013-06-01 21:34:50 +00:00
2013-06-04 20:06:15 +00:00
JsonReader reader(json.data(), json.size());
const json_value *root = reader.root();
2013-06-02 11:43:15 +00:00
2013-06-04 20:06:15 +00:00
std::string abi = "";
2013-06-02 21:46:03 +00:00
#if defined(_M_IX86) && defined(_WIN32)
2013-06-04 20:06:15 +00:00
abi = "Win32";
2013-06-02 21:46:03 +00:00
#elif defined(_M_X64) && defined(_WIN32)
2013-06-04 20:06:15 +00:00
abi = "Win64";
2013-06-02 21:46:03 +00:00
#elif defined(ARMEABI)
2013-06-04 20:06:15 +00:00
abi = "armeabi";
2013-06-02 21:46:03 +00:00
#elif defined(ARMEABI_V7A)
2013-06-04 20:06:15 +00:00
abi = "armeabi-v7a";
#elif defined(MACOSX)
abi = "MacOSX64";
2013-06-02 21:46:03 +00:00
#endif
const char *notSupportedText = p->T("SorryNoDownload", "Sorry, there is no automatic download of the decoder\navailable for this platform.");
2013-06-04 20:06:15 +00:00
if (!abi.empty()) {
at3plusdecoderUrl_ = root->getString(abi.c_str(), "");
if (at3plusdecoderUrl_.empty()) {
buttonDownload_->SetEnabled(false);
tvDescription_->SetText(notSupportedText);
2013-06-04 20:06:15 +00:00
} else {
buttonDownload_->SetEnabled(true);
const char *notInstalledText = p->T("To download and install", "To download and install Mai's Atrac3+ decoding\n support, click Download.");
const char *reInstallText = p->T("Already installed", "Mai's Atrac3+ decoder already installed.\nWould you like to redownload and reinstall it?");
2013-06-04 20:06:15 +00:00
tvDescription_->SetText(Atrac3plus_Decoder::IsInstalled() ? reInstallText : notInstalledText);
}
} else {
tvDescription_->SetText(notSupportedText);
2013-06-02 21:46:03 +00:00
}
}
2013-06-04 20:06:15 +00:00
2013-06-01 21:34:50 +00:00
json_.reset();
}
if (at3plusdecoder_.get() && at3plusdecoder_->Done()) {
// Done! yay.
2013-06-02 21:46:03 +00:00
progress_->SetProgress(1.0);
2013-06-04 20:06:15 +00:00
if (at3plusdecoder_->ResultCode() == 200) {
2013-06-02 21:46:03 +00:00
// Yay!
2013-06-05 14:48:16 +00:00
tvDescription_->SetText(p->T("Installed Correctly", "Mai Atrac3plus plugin downloaded and installed.\n"
"Please press Back."));
2013-06-02 21:46:03 +00:00
buttonDownload_->SetVisibility(UI::V_GONE);
} else {
2013-06-02 22:42:19 +00:00
char codeStr[18];
2013-06-04 20:06:15 +00:00
sprintf(codeStr, "%i", at3plusdecoder_->ResultCode());
2013-06-05 14:48:16 +00:00
tvDescription_->SetText(p->T("Failed to download plugin", "Failed to download plugin.\nPlease try again later."));
2013-06-03 23:25:30 +00:00
progress_->SetVisibility(UI::V_GONE);
2013-06-02 21:46:03 +00:00
buttonDownload_->SetEnabled(true);
}
2013-06-02 22:42:19 +00:00
at3plusdecoder_.reset();
2013-06-01 21:34:50 +00:00
}
}
UI::EventReturn PluginScreen::OnDownload(UI::EventParams &e) {
buttonDownload_->SetEnabled(false);
2013-06-02 11:43:15 +00:00
2013-06-02 21:46:03 +00:00
std::string destination = Atrac3plus_Decoder::GetInstalledFilename();
at3plusdecoder_ = downloader_.StartDownload(at3plusdecoderUrl_, destination);
2013-06-03 23:25:30 +00:00
progress_->SetVisibility(UI::V_VISIBLE);
2013-06-01 21:34:50 +00:00
return UI::EVENT_DONE;
}
UI::EventReturn PluginScreen::OnInformation(UI::EventParams &e) {
2013-06-02 22:42:19 +00:00
LaunchBrowser("http://www.ppsspp.org/at3plusdecoder.html");
2013-06-01 21:34:50 +00:00
return UI::EVENT_DONE;
2013-06-02 22:42:19 +00:00
}