Skip to content

Commit

Permalink
Merge pull request #2261 from ivan-mogilko/361--iossafetyfixes
Browse files Browse the repository at this point in the history
Small fixes for Android and iOS
  • Loading branch information
ivan-mogilko authored Dec 16, 2023
2 parents ce2045d + 8fa906c commit 2cd2771
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 73 deletions.
41 changes: 11 additions & 30 deletions Engine/platform/android/acpland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@

#if AGS_PLATFORM_OS_ANDROID
#include <ctype.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <SDL.h>
#include <allegro.h>
#include <jni.h>
#include <android/log.h>
#include <android/asset_manager_jni.h>
#include "platform/base/agsplatformdriver.h"
#include "platform/base/mobile_base.h"
#include "ac/runtime_defines.h"
#include "game/main_game_file.h"
#include "platform/base/mobile_base.h"
#include "plugin/agsplugin.h"
#include "util/android_file.h"
#include "util/directory.h"
#include "util/file.h"
#include "util/path.h"
#include "util/string_compat.h"
#include "util/file.h"

using namespace AGS::Common;

Expand Down Expand Up @@ -272,33 +271,13 @@ JNIEXPORT void JNICALL
JNIEXPORT jint JNICALL
Java_uk_co_adventuregamestudio_runtime_PreferencesActivity_getAvailableTranslations(JNIEnv* env, jobject object, jobjectArray translations)
{
int i = 0;
int length;
DIR* dir;
struct dirent* entry;
char buffer[200];

dir = opendir(".");
if (dir)
{
while ((entry = readdir(dir)) != 0)
int count = 0;
for (FindFile ff = FindFile::OpenFiles(".", "*.tra"); !ff.AtEnd(); ff.Next())
{
length = strlen(entry->d_name);
if (length > 4)
{
if (ags_stricmp(&entry->d_name[length - 4], ".tra") == 0)
{
memset(buffer, 0, 200);
strncpy(buffer, entry->d_name, length - 4);
env->SetObjectArrayElement(translations, i, env->NewStringUTF(&buffer[0]));
i++;
}
}
String filename = Path::RemoveExtension(Path::GetFilename(ff.Current()));
env->SetObjectArrayElement(translations, count++, env->NewStringUTF(filename.GetCStr()));
}
closedir(dir);
}

return i;
return count;
}

JNIEXPORT void JNICALL
Expand Down Expand Up @@ -423,8 +402,10 @@ void AGSAndroid::DisplayAlert(const char *text, ...) {
va_list args;
va_start(args, text);
vsprintf(displbuf, text, args);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "AGSNative",displbuf, nullptr);
va_end(args);

Debug::Printf(kDbgMsg_Warn, "%s", displbuf);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "AGSNative", displbuf, nullptr);
}

void AGSAndroid::Delay(int millis) {
Expand Down
58 changes: 15 additions & 43 deletions Engine/platform/ios/acplios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@

#if AGS_PLATFORM_OS_IOS
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <ctype.h>
#include <SDL.h>

#include <allegro.h>
#include "platform/base/agsplatformdriver.h"
#include "platform/base/mobile_base.h"
#include "ac/gamesetup.h"
#include "ac/runtime_defines.h"
#include "main/config.h"
#include "plugin/agsplugin.h"
#include "util/string_utils.h"
#include "util/string_compat.h"
#include "ac/gamesetup.h"
#include "util/path.h"
#include "util/directory.h"
#include "util/file.h"
#include "util/path.h"
#include "util/string_compat.h"
#include "util/string_utils.h"


using namespace AGS::Common;
Expand Down Expand Up @@ -238,37 +236,18 @@ void setStringConfigValue(int id, const char* value)

int getAvailableTranslations(char* translations)
{
int i = 0;
size_t length;
DIR* dir;
struct dirent* entry;
char buffer[200];

dir = opendir(".");
if (dir)
{
while ((entry = readdir(dir)) != 0)
int count = 0;
for (FindFile ff = FindFile::OpenFiles(".", "*.tra"); !ff.AtEnd(); ff.Next())
{
length = strlen(entry->d_name);
if (length > 4)
{
if (ags_stricmp(&entry->d_name[length - 4], ".tra") == 0)
{
memset(buffer, 0, 200);
strncpy(buffer, entry->d_name, length - 4);
//env->SetObjectArrayElement(translations, i, env->NewStringUTF(&buffer[0])); // figure out how to pass the string to iOS back
i++;
}
}
String filename = Path::RemoveExtension(Path::GetFilename(ff.Current()));
// FIXME: figure out how to pass the string to iOS back!
//env->SetObjectArrayElement(translations, count++, env->NewStringUTF(filename.GetCStr()));
}
closedir(dir);
}

return i;
return count;
}


void startEngine(char* filename, char* directory, int loadLastSave)
void startEngine(const char* filename, const char* directory, int loadLastSave)
{
auto &setup = AGSIOS::GetMobileSetup();
setup.game_file_name = filename;
Expand All @@ -283,15 +262,8 @@ void startEngine(char* filename, char* directory, int loadLastSave)
ReadConfiguration(setup, IOS_CONFIG_FILENAME, true);

// Get the games path.
char path[256];
strcpy(path, setup.game_file_name.GetCStr());
size_t lastindex = strlen(path) - 1;
while (path[lastindex] != '/')
{
path[lastindex] = 0;
lastindex--;
}
chdir(path);
String gamepath = Path::GetParent(setup.game_file_name);
chdir(gamepath.GetCStr());

setenv("ULTRADIR", "..", 1);

Expand Down Expand Up @@ -358,7 +330,7 @@ void AGSIOS::DisplayAlert(const char *text, ...) {
va_end(ap);

Debug::Printf(kDbgMsg_Warn, "%s", displbuf);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, nullptr, displbuf, nullptr);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "AGSNative", displbuf, nullptr);
}

void AGSIOS::Delay(int millis) {
Expand Down

0 comments on commit 2cd2771

Please sign in to comment.