More NewUI, bugfix in ParamSFO where strings were created to include the trailing zero.

This commit is contained in:
Henrik Rydgard 2013-06-09 12:41:12 +02:00
parent cf2422002c
commit 645e8a7705
9 changed files with 195 additions and 32 deletions

View File

@ -123,7 +123,7 @@ bool ParamSFOData::ReadSFO(const u8 *paramsfo, size_t size)
{
const char *utfdata = (const char *)(data_start + indexTables[i].data_table_offset);
DEBUG_LOG(LOADER, "%s %s", key, utfdata);
SetValue(key,std::string(utfdata,indexTables[i].param_len),indexTables[i].param_max_len);
SetValue(key,std::string(utfdata /*, indexTables[i].param_len*/), indexTables[i].param_max_len);
}
break;
}

View File

@ -27,6 +27,7 @@
#include "Core/FileSystems/ISOFileSystem.h"
#include "Core/FileSystems/DirectoryFileSystem.h"
#include "Core/ELF/PBPReader.h"
#include "Core/System.h"
#include "Core/Config.h"
@ -59,36 +60,55 @@ u64 GameInfo::GetGameSizeInBytes() {
}
}
std::string GameInfo::GetSaveDataDirectory() {
std::string id = paramSFO.GetValueString("ID");
return g_Config.memCardDirectory + "/PSP/GAME/" + id;
std::vector<std::string> GameInfo::GetSaveDataDirectories() {
std::string id = paramSFO.GetValueString("DISC_ID");
std::string memc, flash;
GetSysDirectories(memc, flash);
std::vector<FileInfo> dirs;
getFilesInDir((memc + "PSP/SAVEDATA/").c_str(), &dirs);
std::vector<std::string> directories;
for (size_t i = 0; i < dirs.size(); i++) {
if (startsWith(dirs[i].name, id)) {
directories.push_back(dirs[i].fullName);
}
}
return directories;
}
u64 GameInfo::GetSaveDataSizeInBytes() {
std::string saveDataDir = GetSaveDataDirectory();
std::vector<FileInfo> fileInfo;
getFilesInDir(saveDataDir.c_str(), &fileInfo);
std::vector<std::string> saveDataDir = GetSaveDataDirectories();
u64 totalSize = 0;
for (size_t i = 0; i < fileInfo.size(); i++) {
totalSize += fileInfo[i].size;
for (size_t j = 0; j < saveDataDir.size(); j++) {
std::vector<FileInfo> fileInfo;
getFilesInDir(saveDataDir[j].c_str(), &fileInfo);
// Note: getFileInDir does not fill in fileSize properly.
for (size_t i = 0; i < fileInfo.size(); i++) {
FileInfo finfo;
getFileInfo(fileInfo[i].fullName.c_str(), &finfo);
if (!finfo.isDirectory)
totalSize += finfo.size;
}
}
return totalSize;
}
bool GameInfo::DeleteAllSaveData() {
std::string saveDataDir = GetSaveDataDirectory();
std::vector<std::string> saveDataDir = GetSaveDataDirectories();
for (size_t j = 0; j < saveDataDir.size(); j++) {
std::vector<FileInfo> fileInfo;
getFilesInDir(saveDataDir[j].c_str(), &fileInfo);
std::vector<FileInfo> fileInfo;
getFilesInDir(saveDataDir.c_str(), &fileInfo);
u64 totalSize = 0;
for (size_t i = 0; i < fileInfo.size(); i++) {
deleteFile(fileInfo[i].fullName.c_str());
}
u64 totalSize = 0;
for (size_t i = 0; i < fileInfo.size(); i++) {
deleteFile(fileInfo[i].fullName.c_str());
deleteDir(saveDataDir[j].c_str());
}
deleteDir(saveDataDir.c_str());
return true;
}

View File

@ -45,7 +45,7 @@ public:
void LoadParamSFO();
std::string GetSaveDataDirectory();
std::vector<std::string> GetSaveDataDirectories();
// Hold this when reading or writing from the GameInfo.

View File

@ -15,13 +15,17 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "gfx_es2/draw_buffer.h"
#include "base/colorutil.h"
#include "base/timeutil.h"
#include "math/curves.h"
#include "ui/ui_context.h"
#include "ui/view.h"
#include "ui/viewgroup.h"
#include "UI/EmuScreen.h"
#include "UI/GameScreen.h"
#include "UI/GameSettingsScreen.h"
#include "UI/GameInfoCache.h"
#include "UI/MenuScreens.h"
void GameScreen::CreateViews() {
GameInfo *info = g_gameInfoCache.GetInfo(gamePath_, true);
@ -38,8 +42,11 @@ void GameScreen::CreateViews() {
ViewGroup *leftColumn = new AnchorLayout(new LinearLayoutParams(1.0f));
root_->Add(leftColumn);
leftColumn->Add(new Choice("Back", "", new AnchorLayoutParams(150, WRAP_CONTENT, 10, NONE, NONE, 10)))->OnClick.Handle(this, &GameScreen::OnSwitchBack);
if (info) {
tvTitle_ = leftColumn->Add(new TextView(0, info->title, ALIGN_LEFT, 1.0f, new AnchorLayoutParams(10, 10, NONE, NONE)));
tvGameSize_ = leftColumn->Add(new TextView(0, "...", ALIGN_LEFT, 1.0f, new AnchorLayoutParams(10, 50, NONE, NONE)));
tvSaveDataSize_ = leftColumn->Add(new TextView(0, "...", ALIGN_LEFT, 1.0f, new AnchorLayoutParams(10, 90, NONE, NONE)));
}
ViewGroup *rightColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(300, FILL_PARENT, actionMenuMargins));
@ -55,9 +62,32 @@ void GameScreen::CreateViews() {
void DrawBackground(float alpha);
void GameScreen::DrawBackground() {
GameInfo *info = g_gameInfoCache.GetInfo(gamePath_, true);
void GameScreen::DrawBackground(UIContext &dc) {
GameInfo *ginfo = g_gameInfoCache.GetInfo(gamePath_, true);
dc.Flush();
dc.RebindTexture();
::DrawBackground(1.0f);
dc.Flush();
if (ginfo && ginfo->pic1Texture) {
ginfo->pic1Texture->Bind(0);
uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0;
dc.Draw()->DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1,color);
dc.Flush();
dc.RebindTexture();
}
/*
if (ginfo && ginfo->pic0Texture) {
ginfo->pic0Texture->Bind(0);
// Pic0 is drawn in the bottom right corner, overlaying pic1.
float sizeX = dp_xres / 480 * ginfo->pic0Texture->Width();
float sizeY = dp_yres / 272 * ginfo->pic0Texture->Height();
uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 2)) & 0xFFc0c0c0;
ui_draw2d.DrawTexRect(dp_xres - sizeX, dp_yres - sizeY, dp_xres, dp_yres, 0,0,1,1,color);
ui_draw2d.Flush();
dc.RebindTexture();
}*/
}
void GameScreen::update(InputState &input) {
@ -66,6 +96,18 @@ void GameScreen::update(InputState &input) {
GameInfo *info = g_gameInfoCache.GetInfo(gamePath_, true);
if (tvTitle_)
tvTitle_->SetText(info->title);
if (info->gameSize) {
char temp[256];
sprintf(temp, "Game: %1.1f MB", (float)(info->gameSize) / 1024.f / 1024.f);
tvGameSize_->SetText(temp);
sprintf(temp, "SaveData: %1.1f MB", (float)(info->saveDataSize) / 1024.f / 1024.f);
tvSaveDataSize_->SetText(temp);
}
}
UI::EventReturn GameScreen::OnSwitchBack(UI::EventParams &e) {
screenManager()->switchScreen(new MenuScreen());
return UI::EVENT_DONE;
}
UI::EventReturn GameScreen::OnPlay(UI::EventParams &e) {
@ -85,21 +127,78 @@ UI::EventReturn GameScreen::OnGameSettings(UI::EventParams &e) {
UI::EventReturn GameScreen::OnDeleteSaveData(UI::EventParams &e) {
GameInfo *info = g_gameInfoCache.GetInfo(gamePath_, true);
if (info) {
// VERY DANGEROUS, must add confirmation dialog before enabling.
// info->DeleteAllSaveData();
screenManager()->push(
new PromptScreen("Do you really want to delete all\nyour save data for this game?", "Delete Savedata", "Cancel",
std::bind(&GameScreen::CallbackDeleteSaveData, this, placeholder::_1)));
}
RecreateViews();
return UI::EVENT_DONE;
}
void GameScreen::CallbackDeleteSaveData(bool yes) {
GameInfo *info = g_gameInfoCache.GetInfo(gamePath_, false);
if (yes) {
info->DeleteAllSaveData();
}
}
UI::EventReturn GameScreen::OnDeleteGame(UI::EventParams &e) {
GameInfo *info = g_gameInfoCache.GetInfo(gamePath_, true);
if (info) {
// VERY DANGEROUS
// info->DeleteGame();
screenManager()->push(
new PromptScreen("Do you really want to delete all\nthis game entirely? You can't undo this.", "Delete Game", "Cancel",
std::bind(&GameScreen::CallbackDeleteGame, this, placeholder::_1)));
}
RecreateViews();
return UI::EVENT_DONE;
}
void GameScreen::CallbackDeleteGame(bool yes) {
GameInfo *info = g_gameInfoCache.GetInfo(gamePath_, false);
if (yes) {
info->DeleteGame();
g_gameInfoCache.Clear();
screenManager()->switchScreen(new MenuScreen());
}
}
void DrawBackground(float alpha);
void PromptScreen::DrawBackground(UIContext &dc) {
::DrawBackground(1.0f);
}
void PromptScreen::CreateViews() {
// Information in the top left.
// Back button to the bottom left.
// Scrolling action menu to the right.
using namespace UI;
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(0, message_, ALIGN_LEFT, 1.0f, new AnchorLayoutParams(10, 10, NONE, NONE)));
ViewGroup *rightColumnItems = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(300, FILL_PARENT, actionMenuMargins));
root_->Add(rightColumnItems);
rightColumnItems->Add(new Choice(yesButtonText_))->OnClick.Handle(this, &PromptScreen::OnYes);
if (noButtonText_ != "")
rightColumnItems->Add(new Choice(noButtonText_))->OnClick.Handle(this, &PromptScreen::OnNo);
}
UI::EventReturn PromptScreen::OnYes(UI::EventParams &e) {
callback_(true);
screenManager()->finishDialog(this, DR_OK);
return UI::EVENT_DONE;
}
UI::EventReturn PromptScreen::OnNo(UI::EventParams &e) {
callback_(false);
screenManager()->finishDialog(this, DR_CANCEL);
return UI::EVENT_DONE;
}

View File

@ -17,6 +17,7 @@
#pragma once
#include "base/functional.h"
#include "ui/ui_screen.h"
// Game screen: Allows you to start a game, delete saves, delete the game,
@ -31,7 +32,9 @@ public:
protected:
virtual void CreateViews();
virtual void DrawBackground();
virtual void DrawBackground(UIContext &dc);
void CallbackDeleteSaveData(bool yes);
void CallbackDeleteGame(bool yes);
private:
// Event handlers
@ -39,10 +42,34 @@ private:
UI::EventReturn OnGameSettings(UI::EventParams &e);
UI::EventReturn OnDeleteSaveData(UI::EventParams &e);
UI::EventReturn OnDeleteGame(UI::EventParams &e);
UI::EventReturn OnSwitchBack(UI::EventParams &e);
std::string gamePath_;
// As we load metadata in the background, we need to be able to update these after the fact.
UI::TextView *tvTitle_;
UI::TextView *tvGameSize_;
};
UI::TextView *tvSaveDataSize_;
};
inline void NoOpVoidBool(bool) {}
class PromptScreen : public UIScreen {
public:
PromptScreen(std::string message, std::string yesButtonText, std::string noButtonText, std::function<void(bool)> callback)
: message_(message), yesButtonText_(yesButtonText), noButtonText_(noButtonText), callback_(callback) {}
virtual void CreateViews();
protected:
virtual void DrawBackground(UIContext &dc);
private:
UI::EventReturn OnYes(UI::EventParams &e);
UI::EventReturn OnNo(UI::EventParams &e);
std::string message_;
std::string yesButtonText_;
std::string noButtonText_;
std::function<void(bool)> callback_;
};

View File

@ -72,6 +72,21 @@ void GameSettingsScreen::CreateViews() {
audioSettings->Add(new CheckBox(&g_Config.bEnableSound, "Enable Sound"));
audioSettings->Add(new CheckBox(&g_Config.bEnableAtrac3plus, "Enable Atrac3+"));
audioSettings->Add(new Choice("Download Atrac3+ plugin"))->OnClick.Handle(this, &GameSettingsScreen::OnDownloadPlugin);
ViewGroup *controlsSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT));
ViewGroup *controlsSettings = new LinearLayout(ORIENT_VERTICAL);
controlsSettingsScroll->Add(controlsSettings);
tabHolder->AddTab("Controls", controlsSettingsScroll);
controlsSettings->Add(new CheckBox(&g_Config.bShowTouchControls, "Show Touch Controls"));
controlsSettings->Add(new CheckBox(&g_Config.bShowAnalogStick, "Show analog stick"));
controlsSettings->Add(new CheckBox(&g_Config.bAccelerometerToAnalogHoriz, "Horizontal tilt to analog"));
ViewGroup *systemSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT));
ViewGroup *systemSettings = new LinearLayout(ORIENT_VERTICAL);
systemSettingsScroll->Add(systemSettings);
tabHolder->AddTab("System", systemSettingsScroll);
systemSettings->Add(new CheckBox(&g_Config.bJit, "Enable JIT (dynarec)"));
systemSettings->Add(new CheckBox(&g_Config.bFastMemory, "Fast Memory (unstable)"));
}
UI::EventReturn GameSettingsScreen::OnDownloadPlugin(UI::EventParams &e) {
@ -81,7 +96,7 @@ UI::EventReturn GameSettingsScreen::OnDownloadPlugin(UI::EventParams &e) {
void DrawBackground(float alpha);
void GameSettingsScreen::DrawBackground() {
void GameSettingsScreen::DrawBackground(UIContext &dc) {
GameInfo *info = g_gameInfoCache.GetInfo(gamePath_, true);
::DrawBackground(1.0f);
}

View File

@ -28,7 +28,7 @@ public:
protected:
virtual void CreateViews();
virtual void DrawBackground();
virtual void DrawBackground(UIContext &dc);
private:
// Event handlers

View File

@ -337,6 +337,8 @@ void NativeInit(int argc, const char *argv[],
if (!gfxLog)
logman->SetLogLevel(LogTypes::G3D, LogTypes::LERROR);
INFO_LOG(BOOT, "Logger inited.");
#else
g_Config.memCardDirectory = "MemStick/";
#endif
i18nrepo.LoadIni(g_Config.languageIni);

2
native

@ -1 +1 @@
Subproject commit bc2a18eeeef66c5ab37d3efd08d5c2e0001cfa4a
Subproject commit 976ef3b7140cb14ef2cdaba59a12d767abd37483