Work on the new experience

This commit is contained in:
Henrik Rydgård committed 2021-08-04 23:22:43 +02:00
1 parent 793e79945f
commit 87bcdb7b88
6 files changed
+141 -98

No files matched your search

+97 -67
View File
@@ -25,23 +25,26 @@
#include "Common/UI/ViewGroup.h"
#include "Common/StringUtils.h"
#include "Common/File/FileUtil.h"
#include "Common/File/Path.h"
#include "Common/System/System.h"
#include "Common/System/NativeApp.h"
#include "Common/Data/Text/I18n.h"
#include "Common/System/Display.h"
#include "Common/Data/Text/I18n.h"
#include "Common/File/AndroidStorage.h"
#include "Common/File/FileUtil.h"
#include "Common/File/Path.h"
#include "Core/Util/GameManager.h"
#include "Core/System.h"
#include "Core/Config.h"
#include "UI/MemStickScreen.h"
#include "UI/MainScreen.h"
#include "UI/MiscScreens.h"
#include "Core/Config.h"
MemStickScreen::~MemStickScreen() { }
MemStickScreen::~MemStickScreen() {
pendingMemStickFolder_ = g_Config.memStickDirectory;
}
void MemStickScreen::CreateViews() {
using namespace UI;
@@ -51,45 +54,68 @@ void MemStickScreen::CreateViews() {
Margins actionMenuMargins(15, 15, 15, 0);
root_ = new AnchorLayout();
root_ = new LinearLayout(ORIENT_HORIZONTAL, new AnchorLayoutParams(FILL_PARENT, FILL_PARENT));
ViewGroup *columns = new LinearLayout(ORIENT_HORIZONTAL, new AnchorLayoutParams(FILL_PARENT, FILL_PARENT));
root_->Add(columns);
ViewGroup *leftColumn = new AnchorLayout(new LinearLayoutParams(1.0));
Spacer *spacerColumn = new Spacer(new LinearLayoutParams(20.0, FILL_PARENT, 0.0f));
ViewGroup *leftColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0));
ViewGroup *rightColumnItems = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(300, FILL_PARENT, actionMenuMargins));
columns->Add(leftColumn);
columns->Add(rightColumnItems);
root_->Add(spacerColumn);
root_->Add(leftColumn);
root_->Add(rightColumnItems);
Path path = g_Config.memStickDirectory;
int64_t freeSpaceAtMemStick = -1;
#if PPSSPP_PLATFORM(ANDROID)
if (Android_IsContentUri(path.ToString())) {
freeSpaceAtMemStick = Android_GetFreeSpaceByContentUri(path.ToString());
} else {
freeSpaceAtMemStick = Android_GetFreeSpaceByFilePath(path.ToString());
if (initialSetup_) {
leftColumn->Add(new TextView(iz->T("Welcome to PPSSPP!"), ALIGN_LEFT, false));
leftColumn->Add(new Spacer(new LinearLayoutParams(FILL_PARENT, 12.0f, 0.0f)));
}
leftColumn->Add(new TextView(iz->T("MemoryStickDescription", "Choose PSP data storage (Memory Stick)"), ALIGN_LEFT, false));
#if !PPSSPP_PLATFORM(WINDOWS)
if (!pendingMemStickFolder_.empty()) {
int64_t freeSpaceAtMemStick = -1;
if (Android_IsContentUri(pendingMemStickFolder_.ToString())) {
freeSpaceAtMemStick = Android_GetFreeSpaceByContentUri(pendingMemStickFolder_.ToString());
} else {
freeSpaceAtMemStick = Android_GetFreeSpaceByFilePath(pendingMemStickFolder_.ToString());
}
leftColumn->Add(new TextView(pendingMemStickFolder_.ToVisualString(), ALIGN_LEFT, false));
std::string freeSpaceText = "Free space: N/A";
if (freeSpaceAtMemStick >= 0) {
freeSpaceText = StringFromFormat("free space: %lld MB", freeSpaceAtMemStick / (1024 * 1024));
leftColumn->Add(new TextView(freeSpaceText, ALIGN_LEFT, false));
}
}
if (!g_Config.memStickDirectory.empty()) {
TextView *view = leftColumn->Add(new TextView(g_Config.memStickDirectory.ToVisualString(), ALIGN_LEFT, false));
view->SetShadow(true);
}
#endif
int leftSide = 100;
settingInfo_ = new SettingInfoMessage(ALIGN_CENTER | FLAG_WRAP_TEXT, new AnchorLayoutParams(dp_xres - leftSide - 40.0f, WRAP_CONTENT, leftSide, dp_yres - 80.0f - 40.0f, NONE, NONE));
settingInfo_->SetBottomCutoff(dp_yres - 200.0f);
leftColumn->Add(new Choice(iz->T("Create or Choose a PSP folder")))->OnClick.Handle(this, &MemStickScreen::OnBrowse);
leftColumn->Add(new TextView(iz->T("ChooseFolderDesc", "* Data will stay even if you uninstall PPSSPP.\n* Data can be shared with PPSSPP Gold\n* Easy USB access"), ALIGN_LEFT, false));
root_->Add(settingInfo_);
leftColumn->Add(new Choice(iz->T("Use App Private Directory")))->OnClick.Handle(this, &MemStickScreen::OnUseInternalStorage);
leftColumn->Add(new TextView(iz->T("InternalStorageDesc", "* Warning! Data will be deleted if you uninstall PPSSPP!\n* Data cannot be shared with PPSSPP Gold\n* USB access through Android/data/org.ppsspp.ppsspp/files"), ALIGN_LEFT, false));
leftColumn->Add(new TextView(iz->T("Memory Stick Storage"), ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
leftColumn->Add(new TextView(iz->T("MemoryStickDescription", "Choose where your PSP memory stick data (savegames, etc) is stored"), ALIGN_LEFT, false, new AnchorLayoutParams(10, 50, NONE, NONE)));
leftColumn->Add(new TextView(g_Config.memStickDirectory.ToVisualString(), ALIGN_LEFT, false, new AnchorLayoutParams(10, 140, NONE, NONE)));
leftColumn->Add(new Spacer(new LinearLayoutParams(FILL_PARENT, 12.0f, 0.0f)));
std::string freeSpaceText = "Free space: N/A";
if (freeSpaceAtMemStick >= 0) {
freeSpaceText = StringFromFormat("free space: %lld MB", freeSpaceAtMemStick / (1024 * 1024));
Choice *confirmButton = rightColumnItems->Add(new Choice(iz->T("Confirm")));
confirmButton->OnClick.Handle(this, &MemStickScreen::OnConfirm);
confirmButton->SetEnabled(!pendingMemStickFolder_.empty());
if (!initialSetup_) {
rightColumnItems->Add(new CheckBox(&moveData_, iz->T("Move Data")));
rightColumnItems->Add(new Choice(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK);
}
leftColumn->Add(new TextView(freeSpaceText, ALIGN_LEFT, false, new AnchorLayoutParams(10, 240, NONE, NONE)));
INFO_LOG(SYSTEM, "MemStickScreen: initialSetup=%d", (int)initialSetup_);
}
rightColumnItems->Add(new Choice(iz->T("Browse")))->OnClick.Handle(this, &MemStickScreen::OnBrowse);
rightColumnItems->Add(new Choice(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK);
UI::EventReturn MemStickScreen::OnUseInternalStorage(UI::EventParams &params) {
pendingMemStickFolder_ = Path(g_extFilesDir);
return UI::EVENT_DONE;
}
UI::EventReturn MemStickScreen::OnBrowse(UI::EventParams &params) {
@@ -108,48 +134,52 @@ void MemStickScreen::sendMessage(const char *message, const char *value) {
filename = value;
INFO_LOG(SYSTEM, "Got folder: '%s'", filename.c_str());
pendingMemStickFolder_ = Path(filename);
CallbackMemStickFolder(true);
RecreateViews();
}
}
}
void MemStickScreen::CallbackMemStickFolder(bool yes) {
UI::EventReturn MemStickScreen::OnConfirm(UI::EventParams &params) {
auto sy = GetI18NCategory("System");
if (yes) {
Path memStickDirFile = g_Config.internalDataDirectory / "memstick_dir.txt";
Path testWriteFile = pendingMemStickFolder_ / ".write_verify_file";
Path memStickDirFile = g_Config.internalDataDirectory / "memstick_dir.txt";
Path testWriteFile = pendingMemStickFolder_ / ".write_verify_file";
// Doesn't already exist, create.
// Should this ever happen?
if (pendingMemStickFolder_.Type() == PathType::NATIVE) {
if (!File::Exists(pendingMemStickFolder_)) {
File::CreateFullPath(pendingMemStickFolder_);
}
if (!File::WriteDataToFile(true, "1", 1, testWriteFile)) {
settingInfo_->Show(sy->T("ChangingMemstickPathInvalid", "That path couldn't be used to save Memory Stick files."), nullptr);
return;
}
File::Delete(testWriteFile);
} else {
// TODO: Do the same but with scoped storage? Not really necessary, right? If it came from a browse
// for folder, we can assume it exists, barring wacky race conditions like the user being connected
// by USB and deleting it.
// Doesn't already exist, create.
// Should this ever happen?
if (pendingMemStickFolder_.Type() == PathType::NATIVE) {
if (!File::Exists(pendingMemStickFolder_)) {
File::CreateFullPath(pendingMemStickFolder_);
}
// This doesn't need the storage API - this path is accessible the normal way.
std::string str = pendingMemStickFolder_.ToString();
if (!File::WriteDataToFile(true, str.c_str(), (unsigned int)str.size(), memStickDirFile)) {
ERROR_LOG(SYSTEM, "Failed to write memstick path '%s' to '%s'", pendingMemStickFolder_.c_str(), memStickDirFile.c_str());
// Not sure what to do if this file.
if (!File::WriteDataToFile(true, "1", 1, testWriteFile)) {
// settingInfo_->Show(sy->T("ChangingMemstickPathInvalid", "That path couldn't be used to save Memory Stick files."), nullptr);
return UI::EVENT_DONE;
}
// Save so the settings, at least, are transferred.
g_Config.memStickDirectory = pendingMemStickFolder_;
g_Config.SetSearchPath(GetSysDirectory(DIRECTORY_SYSTEM));
g_Config.UpdateIniLocation();
g_Config.Save("MemstickPathChanged");
screenManager()->RecreateAllViews();
File::Delete(testWriteFile);
} else {
// TODO: Do the same but with scoped storage? Not really necessary, right? If it came from a browse
// for folder, we can assume it exists and is writable, barring wacky race conditions like the user
// being connected by USB and deleting it.
}
// This doesn't need the storage API - this path is accessible the normal way.
std::string str = pendingMemStickFolder_.ToString();
if (!File::WriteDataToFile(true, str.c_str(), (unsigned int)str.size(), memStickDirFile)) {
ERROR_LOG(SYSTEM, "Failed to write memstick path '%s' to '%s'", pendingMemStickFolder_.c_str(), memStickDirFile.c_str());
// Not sure what to do if this file.
}
// Save so the settings, at least, are transferred.
g_Config.memStickDirectory = pendingMemStickFolder_;
g_Config.SetSearchPath(GetSysDirectory(DIRECTORY_SYSTEM));
g_Config.UpdateIniLocation();
if (g_Config.Save("MemstickPathChanged")) {
TriggerFinish(DialogResult::DR_OK);
} else {
error_ = sy->T("Failed to save config");
RecreateViews();
}
return UI::EVENT_DONE;
}