mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-03-27 13:50:22 -06:00
android: Split path resolution logic of getUserDirectory into seperate function
This commit is contained in:
parent
97c9a51015
commit
96485a22f8
@ -693,34 +693,37 @@ object NativeLibrary {
|
||||
|
||||
@Keep
|
||||
@JvmStatic
|
||||
fun getUserDirectory(uriOverride: Uri? = null): String {
|
||||
fun getNativePath(uri: Uri): String {
|
||||
BuildUtil.assertNotGooglePlay()
|
||||
|
||||
val preferences: SharedPreferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(CitraApplication.appContext)
|
||||
|
||||
val dirSep = "/"
|
||||
val udUri = uriOverride ?:
|
||||
preferences.getString("CITRA_DIRECTORY", "")!!.toUri()
|
||||
val udPathSegment = udUri.lastPathSegment!!
|
||||
val udVirtualPath = udPathSegment.substringAfter(":")
|
||||
|
||||
if (udPathSegment.startsWith("primary:")) { // User directory is located in primary storage
|
||||
val pathSegment = uri.lastPathSegment!!
|
||||
val virtualPath = pathSegment.substringAfter(":")
|
||||
|
||||
if (pathSegment.startsWith("primary:")) { // User directory is located in primary storage
|
||||
val primaryStoragePath = Environment.getExternalStorageDirectory().absolutePath
|
||||
return primaryStoragePath + dirSep + udVirtualPath + dirSep
|
||||
return primaryStoragePath + dirSep + virtualPath + dirSep
|
||||
} else { // User directory probably located on a removable storage device
|
||||
val storageIdString = udPathSegment.substringBefore(":")
|
||||
val udRemovablePath = RemovableStorageHelper.getRemovableStoragePath(storageIdString)
|
||||
val storageIdString = pathSegment.substringBefore(":")
|
||||
val removablePath = RemovableStorageHelper.getRemovableStoragePath(storageIdString)
|
||||
|
||||
if (udRemovablePath == null) {
|
||||
if (removablePath == null) {
|
||||
android.util.Log.e("NativeLibrary",
|
||||
"Unknown mount location for storage device '$storageIdString' (URI: $udUri)"
|
||||
"Unknown mount location for storage device '$storageIdString' (URI: $uri)"
|
||||
)
|
||||
return ""
|
||||
}
|
||||
return udRemovablePath + dirSep + udVirtualPath + dirSep
|
||||
return removablePath + dirSep + virtualPath
|
||||
}
|
||||
}
|
||||
|
||||
@Keep
|
||||
@JvmStatic
|
||||
fun getUserDirectory(): String {
|
||||
val preferences: SharedPreferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(CitraApplication.appContext)
|
||||
return getNativePath(preferences.getString("CITRA_DIRECTORY", "")!!.toUri())
|
||||
}
|
||||
|
||||
@Keep
|
||||
|
||||
@ -567,7 +567,7 @@ class SetupFragment : Fragment() {
|
||||
}
|
||||
|
||||
if (!BuildUtil.isGooglePlayBuild) {
|
||||
if (NativeLibrary.getUserDirectory(result) == "") {
|
||||
if (NativeLibrary.getNativePath(result) == "") {
|
||||
SelectUserDirectoryDialogFragment.newInstance(
|
||||
mainActivity,
|
||||
R.string.invalid_selection,
|
||||
|
||||
@ -367,7 +367,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
||||
}
|
||||
|
||||
if (!BuildUtil.isGooglePlayBuild) {
|
||||
if (NativeLibrary.getUserDirectory(result) == "") {
|
||||
if (NativeLibrary.getNativePath(result) == "") {
|
||||
SelectUserDirectoryDialogFragment.newInstance(
|
||||
this,
|
||||
R.string.invalid_selection,
|
||||
|
||||
@ -296,7 +296,7 @@ bool MoveAndRenameFile(const std::string& src_full_path, const std::string& dest
|
||||
std::string TranslateFilePath(const std::string& filepath) {
|
||||
std::optional<std::string> userDirLocation = GetUserDirectory();
|
||||
if (userDirLocation) {
|
||||
return *userDirLocation + filepath;
|
||||
return *userDirLocation + "/" + filepath;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
V(GetFilesName, std::vector<std::string>, (const std::string& filepath), get_files_name, \
|
||||
"getFilesName", "(Ljava/lang/String;)[Ljava/lang/String;") \
|
||||
V(GetUserDirectory, std::optional<std::string>, (), get_user_directory, "getUserDirectory", \
|
||||
"(Landroid/net/Uri;)Ljava/lang/String;") \
|
||||
"()Ljava/lang/String;") \
|
||||
V(CopyFile, bool, \
|
||||
(const std::string& source, const std::string& destination_path, \
|
||||
const std::string& destination_filename), \
|
||||
|
||||
Loading…
Reference in New Issue
Block a user