Fix Android internal storage, issue #365

This commit is contained in:
Milan Nikolic 2024-05-09 08:27:51 +02:00
parent c09c9462b4
commit 9b53342ac0
No known key found for this signature in database
GPG key ID: 9229D0EAA3AA4E75
2 changed files with 12 additions and 18 deletions

View file

@ -1,12 +0,0 @@
// +build android
#include "_cgo_export.h"
struct android_app *GetAndroidApp();
void android_init() {
struct android_app *app;
app = GetAndroidApp();
asset_manager = app->activity->assetManager;
internal_storage_path = app->activity->internalDataPath;
}

View file

@ -9,10 +9,17 @@ package rl
#include <android/asset_manager.h>
#include <android_native_app_glue.h>
extern void android_init();
extern struct android_app* GetAndroidApp();
static AAssetManager* asset_manager;
static const char* internal_storage_path;
static AAssetManager* GetAssetManager() {
struct android_app* app = GetAndroidApp();
return app->activity->assetManager;
}
static const char* GetInternalStoragePath() {
struct android_app* app = GetAndroidApp();
return app->activity->internalDataPath;
}
*/
import "C"
@ -33,7 +40,6 @@ func InitWindow(width int32, height int32, title string) {
defer C.free(unsafe.Pointer(ctitle))
C.InitWindow(cwidth, cheight, ctitle)
C.android_init()
}
// SetCallbackFunc - Sets callback function
@ -98,7 +104,7 @@ func OpenAsset(name string) (Asset, error) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
a := &asset{C.AAssetManager_open(C.asset_manager, cname, C.AASSET_MODE_UNKNOWN)}
a := &asset{C.AAssetManager_open(C.GetAssetManager(), cname, C.AASSET_MODE_UNKNOWN)}
if a.ptr == nil {
return nil, fmt.Errorf("asset file could not be opened")
@ -136,5 +142,5 @@ func (a *asset) Close() error {
}
func getInternalStoragePath() string {
return C.GoString(C.internal_storage_path)
return C.GoString(C.GetInternalStoragePath())
}