mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
android: try to automatically create .nomedia file in directory where games are located
This commit is contained in:
@@ -12,6 +12,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import su.xash.engine.model.Game
|
||||
import su.xash.engine.util.Nomedia
|
||||
import java.io.File
|
||||
|
||||
class LibraryViewModel(application: Application) : AndroidViewModel(application) {
|
||||
@@ -39,6 +40,8 @@ class LibraryViewModel(application: Application) : AndroidViewModel(application)
|
||||
?: (Environment.getExternalStorageDirectory().absolutePath + "/xash")
|
||||
val root = File(rootPath)
|
||||
|
||||
Nomedia.ensureNomedia(root)
|
||||
|
||||
_installedGames.postValue(Game.getGames(ctx, root))
|
||||
_isReloading.postValue(false)
|
||||
}
|
||||
|
||||
42
android/app/src/main/java/su/xash/engine/util/Nomedia.kt
Normal file
42
android/app/src/main/java/su/xash/engine/util/Nomedia.kt
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Nomedia.kt - ensure that .nomedia file exists in directory
|
||||
Copyright (C) 2025 Alibek Omarov
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
package su.xash.engine.util
|
||||
import java.io.File
|
||||
|
||||
object Nomedia {
|
||||
fun ensureNomedia(directory: File): Boolean {
|
||||
try {
|
||||
// ensure paths exists
|
||||
if (!directory.exists() && !directory.mkdirs()) {
|
||||
return false
|
||||
}
|
||||
|
||||
// check if it's a directory
|
||||
if (!directory.isDirectory) {
|
||||
return false
|
||||
}
|
||||
|
||||
val nomediaFile = File(directory, ".nomedia")
|
||||
|
||||
// it returns false if file already exists, which is fine for us
|
||||
nomediaFile.createNewFile()
|
||||
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user