mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-21 08:19:33 +00:00
add testing library load
This commit is contained in:
3 files changed
+63
-6
No files matched your search
@@ -2,12 +2,14 @@ package dev.xyze.geodelauncher
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
|
import android.os.FileUtils
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@@ -25,6 +27,11 @@ import org.cocos2dx.lib.Cocos2dxGLSurfaceView
|
|||||||
import org.cocos2dx.lib.Cocos2dxHelper
|
import org.cocos2dx.lib.Cocos2dxHelper
|
||||||
import org.cocos2dx.lib.Cocos2dxRenderer
|
import org.cocos2dx.lib.Cocos2dxRenderer
|
||||||
import org.fmod.FMOD
|
import org.fmod.FMOD
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
|
|
||||||
|
|
||||||
class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperListener {
|
class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperListener {
|
||||||
@@ -68,10 +75,8 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
System.load("$gdNativeLibraryPath/lib${GJConstants.FMOD_LIB_NAME}.so")
|
System.load("$gdNativeLibraryPath/lib${GJConstants.FMOD_LIB_NAME}.so")
|
||||||
System.load("$gdNativeLibraryPath/lib${GJConstants.COCOS_LIB_NAME}.so")
|
System.load("$gdNativeLibraryPath/lib${GJConstants.COCOS_LIB_NAME}.so")
|
||||||
|
|
||||||
try {
|
if (getLoadTesting()) {
|
||||||
System.loadLibrary(GJConstants.MOD_CORE_LIB_NAME)
|
loadTestingLibraries()
|
||||||
} catch (e: UnsatisfiedLinkError) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FMOD.init(this)
|
FMOD.init(this)
|
||||||
@@ -249,4 +254,57 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
Log.d(sTag, "isEmulator=$isEmulator")
|
Log.d(sTag, "isEmulator=$isEmulator")
|
||||||
return isEmulator
|
return isEmulator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getLoadTesting(): Boolean {
|
||||||
|
val preferences = getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
return preferences.getBoolean(getString(R.string.preference_load_testing), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadTestingLibraries() {
|
||||||
|
// clear data dir
|
||||||
|
val testDirPath = File(filesDir.path + File.separator + "testlib" + File.separator)
|
||||||
|
if (testDirPath.exists()) {
|
||||||
|
testDirPath.deleteRecursively()
|
||||||
|
}
|
||||||
|
testDirPath.mkdir()
|
||||||
|
|
||||||
|
getExternalFilesDir(null)?.let { dir ->
|
||||||
|
val testingPath = dir.path + File.separator + "test" + File.separator
|
||||||
|
|
||||||
|
File(testingPath).walk().forEach {
|
||||||
|
if (it.isFile) {
|
||||||
|
// welcome to the world of Android classloader permissions
|
||||||
|
val outputFile = File(testDirPath.path + File.separator + it.name)
|
||||||
|
copyFile(FileInputStream(it), FileOutputStream(outputFile))
|
||||||
|
|
||||||
|
try {
|
||||||
|
println("Loading test library ${outputFile.name}")
|
||||||
|
System.load(outputFile.path)
|
||||||
|
} catch (e: UnsatisfiedLinkError) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun copyFile(inputStream: InputStream, outputStream: OutputStream) {
|
||||||
|
// gotta love copying
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
FileUtils.copy(inputStream, outputStream)
|
||||||
|
} else {
|
||||||
|
inputStream.use { input ->
|
||||||
|
outputStream.use { output ->
|
||||||
|
val buffer = ByteArray(4 * 1024)
|
||||||
|
while (true) {
|
||||||
|
val byteCount = input.read(buffer)
|
||||||
|
if (byteCount < 0) break
|
||||||
|
output.write(buffer, 0, byteCount)
|
||||||
|
}
|
||||||
|
output.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -185,7 +185,7 @@ fun TestingUtils() {
|
|||||||
onCheckedChange = null
|
onCheckedChange = null
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "Load testing libraries",
|
text = "Load files in /test",
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
modifier = Modifier.padding(start = 16.dp)
|
modifier = Modifier.padding(start = 16.dp)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ object GJConstants {
|
|||||||
|
|
||||||
const val COCOS_LIB_NAME = "cocos2dcpp"
|
const val COCOS_LIB_NAME = "cocos2dcpp"
|
||||||
const val FMOD_LIB_NAME = "fmod"
|
const val FMOD_LIB_NAME = "fmod"
|
||||||
const val MOD_CORE_LIB_NAME = "geode"
|
|
||||||
const val LAUNCHER_FIX_LIB_NAME = "launcherfix"
|
const val LAUNCHER_FIX_LIB_NAME = "launcherfix"
|
||||||
|
|
||||||
// this value is hardcoded into GD
|
// this value is hardcoded into GD
|
||||||
|
|||||||
Reference in new issue
Block a user