lets patch it up

This commit is contained in:
izzy2lost
2025-08-13 09:35:23 -04:00
parent 8f3e4a1a1f
commit bcbb81a6fa
2 changed files with 47 additions and 4 deletions
@@ -33,6 +33,8 @@ import android.content.pm.ActivityInfo;
import android.view.KeyEvent;
public class MainActivity extends SDLActivity {
public static native void nativeSetAppDirs(String internal);
static {
System.loadLibrary("Starship");
}
@@ -175,7 +177,9 @@ protected void onCreate(Bundle savedInstanceState) {
userFolderUri = getUserFolderUri();
super.onCreate(savedInstanceState);
setupControllerOverlay();
try { nativeSetAppDirs(getSaveDir()); } catch (Throwable t) { Log.w(TAG, "nativeSetAppDirs failed", t); }
setupControllerOverlay();
attachController();
// Seed internal directory with assets if they exist (optional)
@@ -206,7 +210,9 @@ protected void onCreate(Bundle savedInstanceState) {
out.flush();
out.getFD().sync();
Log.i(TAG, "sf64.o2r copied from user folder to internal storage");
} catch (IOException e) {
try { nativeSetAppDirs(getSaveDir()); } catch (Throwable t) { Log.w(TAG, "nativeSetAppDirs failed", t); }
} catch (IOException e) {
Log.e(TAG, "Failed to copy sf64.o2r from user folder", e);
}
}
@@ -512,7 +518,9 @@ private void handleFolderSelection(Uri treeUri, int returnedFlags) {
out.getFD().sync();
Log.i(TAG, "sf64.o2r copied from user folder to internal storage during folder selection");
// Also sync mods
try { nativeSetAppDirs(getSaveDir()); } catch (Throwable t) { Log.w(TAG, "nativeSetAppDirs failed", t); }
// Also sync mods
syncModsFromUserFolder();
showToast("Files copied. Game should start now.");
@@ -628,7 +636,9 @@ private void handleRomFileSelection(Uri selectedFileUri) {
out.getFD().sync();
Log.i(TAG, "sf64.o2r copied to internal (" + total + " bytes): " + dest.getAbsolutePath());
runOnUiThread(() -> showPortraitDialog("sf64.o2r ready",
try { nativeSetAppDirs(getSaveDir()); } catch (Throwable t) { Log.w(TAG, "nativeSetAppDirs failed", t); }
runOnUiThread(() -> showPortraitDialog("sf64.o2r ready",
"sf64.o2r copied. Restart to load the game.",
DialogActivity.DIALOG_TYPE_FILE_READY));
} catch (IOException e) {
+33
View File
@@ -5,6 +5,8 @@
#ifdef __ANDROID__
#include <thread>
#include <chrono>
#include <jni.h>
#include <SDL.h>
#endif
#include "extractor/GameExtractor.h"
@@ -101,6 +103,20 @@ GameEngine::GameEngine() {
const std::string assets_path = Ship::Context::LocateFileAcrossAppDirs("starship.o2r");
std::vector<std::string> archiveFiles;
#ifdef __ANDROID__
{
const char* sdlInternal = SDL_AndroidGetInternalStoragePath();
if (sdlInternal && *sdlInternal) {
auto* pm = Ship::Context::GetInstance()->GetPathManager();
pm->SetAppDirectoryPath(sdlInternal);
pm->SetUserDirectoryPath(sdlInternal);
SPDLOG_INFO("Android app/user dir set to: {}", sdlInternal);
} else {
SPDLOG_WARN("SDL_AndroidGetInternalStoragePath() returned null; using defaults");
}
}
#endif
#ifdef __SWITCH__
Ship::Switch::Init(Ship::PreInitPhase);
Ship::Switch::Init(Ship::PostInitPhase);
@@ -877,3 +893,20 @@ extern "C" void GameEngine_Free(void* ptr) {
}
}
}
#ifdef __ANDROID__
extern "C" JNIEXPORT void JNICALL
Java_com_starship_android_MainActivity_nativeSetAppDirs(JNIEnv* env, jclass, jstring jpath) {
if (!jpath) return;
const char* p = env->GetStringUTFChars(jpath, nullptr);
if (p) {
auto* pm = Ship::Context::GetInstance()->GetPathManager();
pm->SetAppDirectoryPath(p);
pm->SetUserDirectoryPath(p);
SPDLOG_INFO("JNI set app/user dir to {}", p);
env->ReleaseStringUTFChars(jpath, p);
}
}
#endif