Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: Enable text chat #19388

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions Core/Util/GameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ ZipFileContents DetectZipFileContents(struct zip *z, ZipFileInfo *info) {
std::string zippedName = fn;
std::transform(zippedName.begin(), zippedName.end(), zippedName.begin(),
[](unsigned char c) { return asciitolower(c); }); // Not using std::tolower to avoid Turkish I->ı conversion.
// Ignore macos metadata stuff
if (startsWith(zippedName, "__macosx/")) {
continue;
}
if (zippedName.find("eboot.pbp") != std::string::npos) {
int slashCount = 0;
int slashLocation = -1;
Expand All @@ -251,7 +255,12 @@ ZipFileContents DetectZipFileContents(struct zip *z, ZipFileInfo *info) {
if (slashCount <= 1) {
// We only do this if the ISO file is in the root or one level down.
isZippedISO = true;
isoFileIndex = i;
INFO_LOG(Log::HLE, "ISO found in zip: %s", zippedName.c_str());
if (isoFileIndex != -1) {
INFO_LOG(Log::HLE, "More than one ISO file found in zip. Ignoring additional ones.");
} else {
isoFileIndex = i;
}
}
} else if (zippedName.find("textures.ini") != std::string::npos) {
int slashLocation = (int)zippedName.find_last_of('/');
Expand Down Expand Up @@ -493,11 +502,6 @@ bool GameManager::ExtractFile(struct zip *z, int file_index, const Path &outFile
zip_stat_index(z, file_index, 0, &zstat);
size_t size = zstat.size;

// Don't spam the log.
if (file_index < 10) {
INFO_LOG(Log::HLE, "Writing %d bytes to '%s'", (int)size, outFilename.c_str());
}

zip_file *zf = zip_fopen_index(z, file_index, 0);
if (!zf) {
ERROR_LOG(Log::HLE, "Failed to open file by index (%d) (%s)", file_index, outFilename.c_str());
Expand All @@ -506,6 +510,10 @@ bool GameManager::ExtractFile(struct zip *z, int file_index, const Path &outFile

FILE *f = File::OpenCFile(outFilename, "wb");
if (f) {
// Don't spam the log.
if (file_index < 10) {
INFO_LOG(Log::HLE, "Writing %d bytes to '%s'", (int)size, outFilename.c_str());
}
size_t pos = 0;
const size_t blockSize = 1024 * 128;
u8 *buffer = new u8[blockSize];
Expand Down Expand Up @@ -729,7 +737,16 @@ bool GameManager::InstallZippedISO(struct zip *z, int isoFileIndex, const Path &
allBytes += zstat.size;
}

Path outputISOFilename = Path(g_Config.currentDirectory) / fn.substr(nameOffset);
std::string name = fn.substr(nameOffset);

INFO_LOG(Log::IO, "Name in zip: %s size: %d", name.c_str(), (int)zstat.size);

if (startsWith(name, "._")) {
// Not sure why Apple seems to add this when zipping file?
name = name.substr(2);
}

Path outputISOFilename = Path(g_Config.currentDirectory) / name;
size_t bytesCopied = 0;
bool success = false;
auto di = GetI18NCategory(I18NCat::DIALOG);
Expand Down
4 changes: 2 additions & 2 deletions UI/ChatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void ChatMenu::CreateContents(UI::ViewGroup *parent) {
chatEdit_ = bottom->Add(new TextEdit("", n->T("Chat message"), n->T("Chat Here"), new LinearLayoutParams(1.0)));
chatEdit_->OnEnter.Handle(this, &ChatMenu::OnSubmit);

#elif PPSSPP_PLATFORM(ANDROID)
#elif PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(IOS)
bottom->Add(new Button(n->T("Chat Here"),new LayoutParams(FILL_PARENT, WRAP_CONTENT)))->OnClick.Handle(this, &ChatMenu::OnSubmit);
bottom->Add(new Button(n->T("Send")))->OnClick.Handle(this, &ChatMenu::OnSubmit);
#endif
Expand Down Expand Up @@ -95,7 +95,7 @@ UI::EventReturn ChatMenu::OnSubmit(UI::EventParams &e) {
chatEdit_->SetText("");
chatEdit_->SetFocus();
sendChat(chat);
#elif PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(SWITCH)
#elif PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(SWITCH) || PPSSPP_PLATFORM(IOS)
auto n = GetI18NCategory(I18NCat::NETWORKING);
System_InputBoxGetString(token_, n->T("Chat"), "", [](const std::string &value, int) {
sendChat(value);
Expand Down
2 changes: 1 addition & 1 deletion UI/InstallZipScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void InstallZipScreen::CreateViews() {
std::string shortFilename = zipPath_.GetFilename();

// TODO: Do in the background?
ZipFileInfo zipInfo;
ZipFileInfo zipInfo{};
ZipFileContents contents = DetectZipFileContents(zipPath_, &zipInfo);

if (contents == ZipFileContents::ISO_FILE || contents == ZipFileContents::PSP_GAME_DIR) {
Expand Down
12 changes: 11 additions & 1 deletion UI/MainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,12 @@ bool GameBrowser::HasSpecialFiles(std::vector<Path> &filenames) {

void GameBrowser::Update() {
LinearLayout::Update();
if (listingPending_ && path_.IsListingReady()) {
if (refreshPending_) {
path_.Refresh();
}
if ((listingPending_ && path_.IsListingReady()) || refreshPending_) {
Refresh();
refreshPending_ = false;
}
if (searchPending_) {
ApplySearchFilter();
Expand Down Expand Up @@ -1615,6 +1619,12 @@ void MainScreen::dialogFinished(const Screen *dialog, DialogResult result) {
g_BackgroundAudio.SetGame(Path());
}
}
if (tag == "InstallZip") {
INFO_LOG(Log::System, "InstallZip finished, refreshing");
if (gameBrowsers_.size() >= 2) {
gameBrowsers_[1]->RequestRefresh();
}
}
}

void UmdReplaceScreen::CreateViews() {
Expand Down
4 changes: 4 additions & 0 deletions UI/MainScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class GameBrowser : public UI::LinearLayout {
void ApplySearchFilter(const std::string &filter);
void Draw(UIContext &dc) override;
void Update() override;
void RequestRefresh() {
refreshPending_ = true;
}

void SetHomePath(const Path &path) {
homePath_ = path;
Expand Down Expand Up @@ -106,6 +109,7 @@ class GameBrowser : public UI::LinearLayout {
Path focusGamePath_;
bool listingPending_ = false;
bool searchPending_ = false;
bool refreshPending_ = false;
float lastScale_ = 1.0f;
bool lastLayoutWasGrid_ = true;
ScreenManager *screenManager_;
Expand Down