From 820bbaede5806cd3e3d8f305dc98b123e8f7c5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=97=B1=20PixelyIon?= Date: Mon, 30 Mar 2020 00:37:11 +0530 Subject: [PATCH] Fix occurrence of multiple headers in game list + Make TinyXML2 Static This commit mainly fixes multiple headers in the game list, which was caused by using the wrong variable for the recursive function. In addition, it makes TinyXML2 statically linked to libskyline which makes it the lone shared objects present in APKs. --- app/CMakeLists.txt | 4 +- app/src/main/java/emu/skyline/MainActivity.kt | 48 +++++++++---------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index dba03a11..5275abd8 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -3,9 +3,11 @@ project(Skyline LANGUAGES CXX ASM VERSION 0.3) set(BUILD_TESTS OFF) set(BUILD_TESTING OFF) -set(BUILD_SHARED_LIBS OFF) +set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build Shared Libraries" FORCE) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) + set(source_DIR ${CMAKE_SOURCE_DIR}/src/main/cpp) set(CMAKE_CXX_FLAGS_RELEASE "-Ofast -flto=full -Wno-unused-command-line-argument") if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt index b262e6c1..78341cb3 100644 --- a/app/src/main/java/emu/skyline/MainActivity.kt +++ b/app/src/main/java/emu/skyline/MainActivity.kt @@ -38,32 +38,32 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { Snackbar.make(findViewById(android.R.id.content), text, Snackbar.LENGTH_SHORT).show() } - private fun findFile(ext: String, loader: BaseLoader, directory: DocumentFile, entries: Int = 0): Int { - var entryCount = entries + private fun findFile(ext: String, loader: BaseLoader, directory: DocumentFile, found: Boolean = false): Boolean { + var foundCurrent = found directory.listFiles() - .forEach { file -> - if (file.isDirectory) { - entryCount = findFile(ext, loader, file, entries) - } else { - if (ext.equals(file.name?.substringAfterLast("."), ignoreCase = true)) { - val document = RandomAccessDocument(this, file) - if (loader.verifyFile(document)) { - val entry = loader.getTitleEntry(document, file.uri) - val header = (entryCount == 0) - runOnUiThread { - if (header) - adapter.addHeader(getString(R.string.nro)) - adapter.addItem(GameItem(entry)) + .forEach { file -> + if (file.isDirectory) { + foundCurrent = findFile(ext, loader, file, foundCurrent) + } else { + if (ext.equals(file.name?.substringAfterLast("."), ignoreCase = true)) { + val document = RandomAccessDocument(this, file) + if (loader.verifyFile(document)) { + val entry = loader.getTitleEntry(document, file.uri) + runOnUiThread { + if (!foundCurrent) { + adapter.addHeader(getString(R.string.nro)) + foundCurrent = true + } + adapter.addItem(GameItem(entry)) + } } - entryCount++ + document.close() } - document.close() } } - } - return entryCount + return foundCurrent } private fun refreshFiles(tryLoad: Boolean) { @@ -77,12 +77,12 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { } thread(start = true) { val snackbar = Snackbar.make(findViewById(android.R.id.content), getString(R.string.searching_roms), Snackbar.LENGTH_INDEFINITE) - runOnUiThread {snackbar.show()} + runOnUiThread { snackbar.show() } try { - runOnUiThread{adapter.clear()} - val entries = findFile("nro", NroLoader(this), DocumentFile.fromTreeUri(this, Uri.parse(sharedPreferences.getString("search_location", "")))!!) + runOnUiThread { adapter.clear() } + val foundNros = findFile("nro", NroLoader(this), DocumentFile.fromTreeUri(this, Uri.parse(sharedPreferences.getString("search_location", "")))!!) runOnUiThread { - if (entries == 0) + if (!foundNros) adapter.addHeader(getString(R.string.no_rom)) try { adapter.save(File("${applicationInfo.dataDir}/roms.bin")) @@ -103,7 +103,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { notifyUser(e.message!!) } } - runOnUiThread {snackbar.dismiss()} + runOnUiThread { snackbar.dismiss() } } }