Skip to content

Commit

Permalink
custom mod dir selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Sisah2 committed Mar 25, 2024
1 parent b5a515d commit 011bdf3
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/mods/ModsDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.jetbrains.anko.db.*
import constants.Constants

class ModsDatabaseOpenHelper private constructor(ctx: Context)
: ManagedSQLiteOpenHelper(ctx, Constants.USER_FILE_STORAGE + "/ModsDatabase", null, 1) {
: ManagedSQLiteOpenHelper(ctx, Constants.USER_FILE_STORAGE + "/launcher/ModsDatabase", null, 1) {

init {
instance = this
Expand Down
32 changes: 19 additions & 13 deletions app/src/main/java/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ class MainActivity : AppCompatActivity() {
if (prefs.getString("bugsnag_consent", "")!! == "") {
askBugsnagConsent()
}

// create user custom icon folder as a hint and create launcher folder
File(Constants.USER_FILE_STORAGE + "/launcher/icons").mkdirs()
if (!File(Constants.USER_FILE_STORAGE + "/launcher/icons/paste custom icons here.txt").exists())
File(Constants.USER_FILE_STORAGE + "/launcher/icons/paste custom icons here.txt").writeText(
"attack.png \ninventory.png \njournal.png \njump.png \nkeyboard.png \nmouse.png \npause.png \npointer_arrow.png \nrun.png \nsave.png \nsneak.png \nthird_person.png \ntoggle_magic.png \ntoggle_weapon.png \ntoggle.png \nuse.png \nwait.png")

if(!File(Constants.USER_FILE_STORAGE + "/launcher/modsdir.cfg").exists())
File(Constants.USER_FILE_STORAGE + "/launcher/modsdir.cfg").writeText(GameInstaller.getDataFiles(this).dropLast(10))
}

/**
Expand Down Expand Up @@ -192,9 +201,10 @@ class MainActivity : AppCompatActivity() {
var dataFilesList = ArrayList<String>()
dataFilesList.add(inst.findDataFiles())

File(inst.findDataFiles().dropLast(10)).listFiles().forEach {
val modsDir = File(Constants.USER_FILE_STORAGE + "/launcher/modsdir.cfg").readText()
File(modsDir).listFiles().forEach {
if (!it.isFile())
dataFilesList.add(inst.findDataFiles().dropLast(10) + it.getName())
dataFilesList.add(modsDir + it.getName())
}

val plugins = ModsCollection(ModType.Plugin, dataFilesList,
Expand Down Expand Up @@ -282,16 +292,18 @@ class MainActivity : AppCompatActivity() {
return
}

val modsDir = File(Constants.USER_FILE_STORAGE + "/launcher/modsdir.cfg").readText()

val db = ModsDatabaseOpenHelper.getInstance(this)

var dataFilesList = ArrayList<String>()
var dataDirsPath = ArrayList<String>()
dataFilesList.add(GameInstaller.getDataFiles(this))
dataDirsPath.add(GameInstaller.getDataFiles(this).dropLast(10))
dataDirsPath.add(modsDir)

File(GameInstaller.getDataFiles(this).dropLast(10)).listFiles().forEach {
File(modsDir).listFiles().forEach {
if (!it.isFile())
dataFilesList.add(GameInstaller.getDataFiles(this).dropLast(10) + it.getName())
dataFilesList.add(modsDir + it.getName())
}

val resources = ModsCollection(ModType.Resource, dataFilesList, db)
Expand All @@ -311,7 +323,7 @@ class MainActivity : AppCompatActivity() {
// output data dirs
dirs.mods
.filter { it.enabled }
.forEach { output += "data=" + '"' + GameInstaller.getDataFiles(this).dropLast(10) + it.filename + '"' + "\n" }
.forEach { output += "data=" + '"' + modsDir + it.filename + '"' + "\n" }

// output plugins
plugins.mods
Expand Down Expand Up @@ -367,12 +379,6 @@ class MainActivity : AppCompatActivity() {
if (!File(Constants.USER_OPENMW_CFG).exists())
File(Constants.USER_OPENMW_CFG).writeText("# This is the user openmw.cfg. Feel free to modify it as you wish.\n")

// create user custom icon folder as a hint
File(Constants.USER_FILE_STORAGE + "/icons").mkdirs()
if (!File(Constants.USER_FILE_STORAGE + "/icons/paste custom icons here.txt").exists())
File(Constants.USER_FILE_STORAGE + "/icons/paste custom icons here.txt").writeText(
"attack.png \ninventory.png \njournal.png \njump.png \nkeyboard.png \nmouse.png \npause.png \npointer_arrow.png \nrun.png \nsave.png \nsneak.png \nthird_person.png \ntoggle_magic.png \ntoggle_weapon.png \ntoggle.png \nuse.png \nwait.png")

// set version stamp
File(Constants.VERSION_STAMP).writeText(BuildConfig.VERSION_CODE.toString())
}
Expand Down Expand Up @@ -594,8 +600,8 @@ class MainActivity : AppCompatActivity() {
writeSetting("Navigator", "async nav mesh updater threads", prefs.getString("gs_navmesh_threads", "1").toString())
writeSetting("Physics", "async num threads", prefs.getString("gs_physics_threads", "1").toString())
writeSetting("Cells", "preload num threads", prefs.getString("gs_preload_threads", "1").toString())

}

private fun startGame() {
// Get scaling factor from config; if invalid or not provided, generate one
var scaling = 0f
Expand Down
49 changes: 43 additions & 6 deletions app/src/main/java/ui/activity/ModsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import mods.*
import android.view.MenuItem
import java.io.File

import android.view.Menu
import com.codekidlabs.storagechooser.StorageChooser
import constants.Constants

class ModsActivity : AppCompatActivity() {

val mPluginAdapter = ModsAdapter()
Expand Down Expand Up @@ -90,20 +94,22 @@ class ModsActivity : AppCompatActivity() {
var dataFilesList = ArrayList<String>()
dataFilesList.add(GameInstaller.getDataFiles(this))

val modsDir = File(Constants.USER_FILE_STORAGE + "/launcher/modsdir.cfg").readText()

// Get list of enabled data directories
var dataDirs = ArrayList<String>()
var enabledDataDirs = ArrayList<String>()
enabledDataDirs.add(GameInstaller.getDataFiles(this))
dataDirs.add(GameInstaller.getDataFiles(this).dropLast(10))
dataDirs.add(modsDir)
val availableDirs = ModsCollection(ModType.Dir, dataDirs, database)

availableDirs.mods
.filter { it.enabled }
.forEach { enabledDataDirs.add(it.filename) }

File(GameInstaller.getDataFiles(this).dropLast(10)).listFiles().forEach {
File(modsDir).listFiles().forEach {
if (!it.isFile() && enabledDataDirs.contains(it.getName()) )
dataFilesList.add(GameInstaller.getDataFiles(this).dropLast(10) + it.getName())
dataFilesList.add(modsDir + it.getName())
}

mPluginAdapter.collection = ModsCollection(ModType.Plugin, dataFilesList, database)
Expand All @@ -121,14 +127,16 @@ class ModsActivity : AppCompatActivity() {
// This is here just to auto-enable basic plugins (morrowind.esp...) it somehow dont work in updateModList :(
var dataFilesList = ArrayList<String>()

val modsDir = File(Constants.USER_FILE_STORAGE + "/launcher/modsdir.cfg").readText()

if (type == ModType.Dir)
dataFilesList.add(GameInstaller.getDataFiles(this).dropLast(10))
dataFilesList.add(modsDir)
else {
dataFilesList.add(GameInstaller.getDataFiles(this))

File(GameInstaller.getDataFiles(this).dropLast(10)).listFiles().forEach {
File(modsDir).listFiles().forEach {
if (!it.isFile())
dataFilesList.add(GameInstaller.getDataFiles(this).dropLast(10) + it.getName())
dataFilesList.add(modsDir + it.getName())
}
}

Expand Down Expand Up @@ -170,6 +178,14 @@ class ModsActivity : AppCompatActivity() {
}
}

override fun onPrepareOptionsMenu(menu: Menu): Boolean {
menu.clear()
val inflater = menuInflater
inflater.inflate(R.menu.mod_manager_settings, menu)

return super.onPrepareOptionsMenu(menu)
}

/**
* Makes the "back" icon in the actionbar perform the back operation
*/
Expand All @@ -180,7 +196,28 @@ class ModsActivity : AppCompatActivity() {
true
}

R.id.action_set_mods_dir -> {

val chooser = StorageChooser.Builder()
.withActivity(this)
.withFragmentManager(fragmentManager)
.withMemoryBar(true)
.allowCustomPath(true)
.setType(StorageChooser.DIRECTORY_CHOOSER)
.build()

chooser.show()

chooser.setOnSelectListener { path -> setupData(path) }
true
}

else -> super.onOptionsItemSelected(item)
}
}

private fun setupData(path: String) {
File(Constants.USER_FILE_STORAGE + "/launcher/modsdir.cfg").writeText(path + "/")
this.recreate()
}
}
14 changes: 14 additions & 0 deletions app/src/main/res/menu/mod_manager_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ModsActivity">
<group android:id="@+id/mod_menu_group">

<item
android:id="@+id/action_set_mods_dir"
android:title="@string/action_set_mods_dir"
app:showAsAction="never"
/>

</group>
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
<string name="action_theme_dark">Dark</string>

<string name="action_generate_navmesh">Generate NavMesh cache</string>
<string name="action_set_mods_dir">Set Custom Mods Dir</string>

<string name="activity_settings">Settings</string>
<string name="game_mechanics_activity_settings">Game Mechanics</string>
Expand Down

0 comments on commit 011bdf3

Please sign in to comment.