From d6c8c6cfa016a4f6eb24f48b489480ec5d141f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 5 Dec 2013 14:14:15 +0100 Subject: [PATCH] If the user opens a ZIP file, offer to install it (it will show up in Homebrew & Demos). No progress bar yet, it just freezes during install. --- CMakeLists.txt | 1 + UI/EmuScreen.cpp | 18 +++++++---- UI/InstallZipScreen.cpp | 66 +++++++++++++++++++++++++++++++++++++++++ UI/InstallZipScreen.h | 41 +++++++++++++++++++++++++ UI/MiscScreens.cpp | 3 +- UI/UI.vcxproj | 4 ++- UI/UI.vcxproj.filters | 8 ++++- android/jni/Android.mk | 1 + lang | 2 +- native | 2 +- 10 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 UI/InstallZipScreen.cpp create mode 100644 UI/InstallZipScreen.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 591ff2f60f..d16079e919 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1160,6 +1160,7 @@ set(NativeAppSource UI/ControlMappingScreen.cpp UI/Store.cpp UI/CwCheatScreen.cpp + UI/InstallZipScreen.cpp UI/ui_atlas.cpp) if(ANDROID AND ARM) set(NativeAppSource ${NativeAppSource} android/jni/ArmEmitterTest.cpp) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index c02400416d..99fa87811d 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -44,11 +44,10 @@ #include "Core/MIPS/JitCommon/JitCommon.h" #include "Core/SaveState.h" -#include "UI/OnScreenDisplay.h" #include "UI/ui_atlas.h" +#include "UI/OnScreenDisplay.h" #include "UI/GamepadEmu.h" #include "UI/UIShader.h" - #include "UI/MainScreen.h" #include "UI/EmuScreen.h" #include "UI/DevScreens.h" @@ -56,7 +55,7 @@ #include "UI/MiscScreens.h" #include "UI/ControlMappingScreen.h" #include "UI/GameSettingsScreen.h" - +#include "UI/InstallZipScreen.h" EmuScreen::EmuScreen(const std::string &filename) : booted_(false), gamePath_(filename), invalid_(true), pauseTrigger_(false) { @@ -459,13 +458,20 @@ void EmuScreen::update(InputState &input) { UpdateUIState(UISTATE_INGAME); if (errorMessage_.size()) { + // Special handling for ZIP files. It's not very robust to check an error message but meh, + // at least it's pre-translation. + if (errorMessage_.find("ZIP") != std::string::npos) { + screenManager()->push(new InstallZipScreen(gamePath_)); + errorMessage_ = ""; + return; + } I18NCategory *g = GetI18NCategory("Error"); - std::string errLoadingFile = g->T("Error loading file"); + std::string errLoadingFile = g->T("Error loading file", "Could not load game"); + errLoadingFile.append(" "); errLoadingFile.append(g->T(errorMessage_.c_str())); - screenManager()->push(new PromptScreen( - errLoadingFile, "OK", "")); + screenManager()->push(new PromptScreen(errLoadingFile, "OK", "")); errorMessage_ = ""; return; } diff --git a/UI/InstallZipScreen.cpp b/UI/InstallZipScreen.cpp new file mode 100644 index 0000000000..24a8fbfc69 --- /dev/null +++ b/UI/InstallZipScreen.cpp @@ -0,0 +1,66 @@ +// 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 "UI/ui_atlas.h" +#include "file/file_util.h" + +#include "Core/Util/GameManager.cpp" +#include "UI/InstallZipScreen.h" + +void InstallZipScreen::CreateViews() { + using namespace UI; + + FileInfo fileInfo; + bool success = getFileInfo(zipPath_.c_str(), &fileInfo); + + I18NCategory *di = GetI18NCategory("Dialog"); + + Margins actionMenuMargins(0, 100, 15, 0); + + root_ = new LinearLayout(ORIENT_HORIZONTAL); + + 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(zipPath_, ALIGN_LEFT, false, new AnchorLayoutParams(10, 60, NONE, 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_->OnClick.Handle(this, &InstallZipScreen::OnInstall); + rightColumnItems->Add(new Choice(di->T("Back")))->OnClick.Handle(this, &UIScreen::OnBack); + rightColumnItems->Add(new CheckBox(&deleteZipFile_, di->T("Delete ZIP file"))); +} + +UI::EventReturn InstallZipScreen::OnInstall(UI::EventParams ¶ms) { + installChoice_->SetEnabled(false); + if (g_GameManager.InstallGameOnThread(zipPath_)) { + screenManager()->finishDialog(this, DR_OK); + } + return UI::EVENT_DONE; +} + +void InstallZipScreen::update(InputState &input) { + UIScreen::update(input); +} diff --git a/UI/InstallZipScreen.h b/UI/InstallZipScreen.h new file mode 100644 index 0000000000..7f362bf1a4 --- /dev/null +++ b/UI/InstallZipScreen.h @@ -0,0 +1,41 @@ +// 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/. + +#pragma once + +#include "base/functional.h" +#include "ui/view.h" +#include "ui/ui_screen.h" + +#include "UI/MiscScreens.h" + +class InstallZipScreen : public UIDialogScreenWithBackground { +public: + InstallZipScreen(std::string zipPath) : installChoice_(0), zipPath_(zipPath), deleteZipFile_(false) {} + virtual void update(InputState &input); + +protected: + virtual void CreateViews(); + +private: + UI::EventReturn OnInstall(UI::EventParams ¶ms); + + UI::Choice *installChoice_; + std::string zipPath_; + bool deleteZipFile_; +}; + diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index 0452772d03..ce0316c94b 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -269,7 +269,6 @@ void NewLanguageScreen::OnCompleted(DialogResult result) { if (result != DR_OK) return; std::string oldLang = g_Config.sLanguageIni; - std::string iniFile = langs_[listView_->GetSelected()].name; size_t dot = iniFile.find('.'); @@ -281,7 +280,7 @@ void NewLanguageScreen::OnCompleted(DialogResult result) { return; g_Config.sLanguageIni = code; - + if (i18nrepo.LoadIni(g_Config.sLanguageIni)) { // Dunno what else to do here. if (langValuesMapping.find(code) == langValuesMapping.end()) { diff --git a/UI/UI.vcxproj b/UI/UI.vcxproj index 8a8909f26d..0a6faf934b 100644 --- a/UI/UI.vcxproj +++ b/UI/UI.vcxproj @@ -35,6 +35,7 @@ + @@ -54,6 +55,7 @@ + @@ -186,4 +188,4 @@ - \ No newline at end of file + diff --git a/UI/UI.vcxproj.filters b/UI/UI.vcxproj.filters index 45103142d2..818693e77a 100644 --- a/UI/UI.vcxproj.filters +++ b/UI/UI.vcxproj.filters @@ -40,6 +40,9 @@ Screens + + Screens + @@ -81,6 +84,9 @@ Screens + + Screens + @@ -88,4 +94,4 @@ {faee5dce-633b-4ba6-b19d-ea70ee3c1c38} - \ No newline at end of file + diff --git a/android/jni/Android.mk b/android/jni/Android.mk index b92c3f244c..f82259caf0 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -280,6 +280,7 @@ LOCAL_SRC_FILES := \ $(SRC)/UI/TouchControlLayoutScreen.cpp \ $(SRC)/UI/TouchControlVisibilityScreen.cpp \ $(SRC)/UI/CwCheatScreen.cpp \ + $(SRC)/UI/InstallZipScreen.cpp \ $(SRC)/UI/NativeApp.cpp include $(BUILD_SHARED_LIBRARY) diff --git a/lang b/lang index 2afe063659..6eb6c50d59 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 2afe06365967319795f799c468ea0b35b7fc1f77 +Subproject commit 6eb6c50d59aa6a7fed418126f806a8cbbeb8a64c diff --git a/native b/native index 1e03cd84c3..4caec3871c 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 1e03cd84c31e30e26ea9c82c89184938734cf863 +Subproject commit 4caec3871c71df3d8d2440cc772171523fbea182