Skip to content

Commit

Permalink
use base directory for geode libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 8, 2024
1 parent f8d7f7f commit a139cc7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 78 deletions.
105 changes: 40 additions & 65 deletions app/src/main/java/com/geode/launcher/GeometryDashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,29 +146,6 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
return "$sourceDir!/lib/$architecture/"
}

@SuppressLint("UnsafeDynamicallyLoadedCode")
private fun loadLibraryFromAssetsCopy(libraryName: String) {
// loads a library loaded in assets
// this copies the library to a non-compressed directory

val arch = LaunchUtils.getApplicationArchitecture()
val libraryFd = try {
assets.openNonAssetFd("lib/$arch/lib$libraryName.so")
} catch (_: Exception) {
throw UnsatisfiedLinkError("Could not find library lib$libraryName.so for abi $arch")
}

// copy the library to a path we can access
// there doesn't seem to be a way to load a library from a file descriptor
val libraryCopy = File(cacheDir, "lib$libraryName.so")
val libraryOutput = libraryCopy.outputStream()
DownloadUtils.copyFile(libraryFd.createInputStream(), libraryOutput)

System.load(libraryCopy.path)

return
}

@SuppressLint("UnsafeDynamicallyLoadedCode")
private fun loadGeodeLibrary(): Boolean {
// Load Geode if exists
Expand All @@ -189,34 +166,31 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
// you know zmx i have 0 clue what this does so im
// just gonna like copy the binary from external
// also i get 20 million permission denied errors
getExternalFilesDir(null)?.let { dir ->
val externalGeodePath = LaunchUtils.getInstalledGeodePath(this) ?: return false
val externalGeodePath = LaunchUtils.getInstalledGeodePath(this) ?: return false

val copiedPath = File(filesDir.path, "copied")
if (copiedPath.exists()) {
copiedPath.deleteRecursively()
}
copiedPath.mkdir()

val geodePath = File(copiedPath.path, "Geode.so")

if (externalGeodePath.exists()) {
DownloadUtils.copyFile(
FileInputStream(externalGeodePath),
FileOutputStream(geodePath)
)

if (geodePath.exists()) {
try {
println("Loading Geode from ${externalGeodePath.name}")
System.load(geodePath.path)
} catch (e: UnsatisfiedLinkError) {
e.printStackTrace()
}
val copiedPath = File(filesDir.path, "copied")
if (copiedPath.exists()) {
copiedPath.deleteRecursively()
}
copiedPath.mkdir()

val copiedGeodePath = File(copiedPath.path, "Geode.so")

if (externalGeodePath.exists()) {
DownloadUtils.copyFile(
FileInputStream(externalGeodePath),
FileOutputStream(copiedGeodePath)
)

if (copiedGeodePath.exists()) {
try {
println("Loading Geode from ${externalGeodePath.name}")
System.load(copiedGeodePath.path)
} catch (e: UnsatisfiedLinkError) {
e.printStackTrace()
}
}
}

}

return false
Expand Down Expand Up @@ -257,6 +231,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
hideSystemUi()
}

@Suppress("DEPRECATION")
private fun hideSystemUi() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
// window compat is dumb!!
Expand All @@ -275,6 +250,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
}
}

@Suppress("DEPRECATION")
private fun setLegacyVisibility() {
// setDecorFitsSystemWindows doesn't hide anything
window.decorView.systemUiVisibility =
Expand Down Expand Up @@ -401,24 +377,23 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
}
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)
DownloadUtils.copyFile(
FileInputStream(it),
FileOutputStream(outputFile)
)

try {
println("Loading test library ${outputFile.name}")
System.load(outputFile.path)
} catch (e: UnsatisfiedLinkError) {
e.printStackTrace()
}
val dir = LaunchUtils.getBaseDirectory(this)
val testingPath = File(dir, "test")

testingPath.walk().forEach {
if (it.isFile) {
// welcome to the world of Android classloader permissions
val outputFile = File(testDirPath, it.name)
DownloadUtils.copyFile(
FileInputStream(it),
FileOutputStream(outputFile)
)

try {
println("Loading test library ${outputFile.name}")
System.load(outputFile.path)
} catch (e: UnsatisfiedLinkError) {
e.printStackTrace()
}
}
}
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/java/com/geode/launcher/utils/LaunchUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@ object LaunchUtils {
fun getInstalledGeodePath(context: Context): File? {
val geodeName = getGeodeFilename()

val internalGeodePath = File(context.filesDir.path, "launcher/$geodeName")
val internalGeodePath = File(context.filesDir, "launcher/$geodeName")
if (internalGeodePath.exists()) {
return internalGeodePath
}
context.getExternalFilesDir(null)?.let { dir->
val updateGeodePath = File(dir.path, "game/geode/update/$geodeName")
if (updateGeodePath.exists()) {
return updateGeodePath
}

val externalGeodePath = File(dir.path, geodeName)
if (externalGeodePath.exists()) {
return externalGeodePath
}
val externalGeodeDir = getBaseDirectory(context)

val updateGeodePath = File(externalGeodeDir, "launcher/$geodeName")
if (updateGeodePath.exists()) {
return updateGeodePath
}

val externalGeodePath = File(externalGeodeDir, geodeName)
if (externalGeodePath.exists()) {
return externalGeodePath
}

return null
}

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/geode/launcher/utils/ReleaseManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ class ReleaseManager private constructor(

private fun getGeodeOutputPath(): File {
val geodeName = LaunchUtils.getGeodeFilename()

val fallbackPath = File(applicationContext.filesDir, "launcher")
val geodeDirectory = applicationContext.getExternalFilesDir("") ?: fallbackPath
val geodeDirectory = LaunchUtils.getBaseDirectory(applicationContext)

return File(geodeDirectory, geodeName)
}
Expand Down

0 comments on commit a139cc7

Please sign in to comment.