mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-04-10 03:11:29 -06:00
Fixed a possible app crash when calling AndroidStorage::GetUserDirectory
This commit is contained in:
parent
96485a22f8
commit
8e1ffc1bdc
@ -698,7 +698,7 @@ object NativeLibrary {
|
||||
|
||||
val dirSep = "/"
|
||||
|
||||
val pathSegment = uri.lastPathSegment!!
|
||||
val pathSegment = uri.lastPathSegment ?: return ""
|
||||
val virtualPath = pathSegment.substringAfter(":")
|
||||
|
||||
if (pathSegment.startsWith("primary:")) { // User directory is located in primary storage
|
||||
@ -723,7 +723,8 @@ object NativeLibrary {
|
||||
fun getUserDirectory(): String {
|
||||
val preferences: SharedPreferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(CitraApplication.appContext)
|
||||
return getNativePath(preferences.getString("CITRA_DIRECTORY", "")!!.toUri())
|
||||
val userDirectoryUri = preferences.getString("CITRA_DIRECTORY", "")!!.toUri()
|
||||
return getNativePath(userDirectoryUri)
|
||||
}
|
||||
|
||||
@Keep
|
||||
|
||||
@ -163,13 +163,27 @@ std::optional<std::string> GetUserDirectory() {
|
||||
throw std::runtime_error(
|
||||
"Unable to locate user directory: Function with ID 'get_user_directory' is missing");
|
||||
}
|
||||
|
||||
auto env = GetEnvForThread();
|
||||
auto j_user_directory =
|
||||
(jstring)(env->CallStaticObjectMethod(native_library, get_user_directory, nullptr));
|
||||
auto result = env->GetStringUTFChars(j_user_directory, nullptr);
|
||||
if (result == "") {
|
||||
|
||||
jstring j_user_directory =
|
||||
(jstring)env->CallStaticObjectMethod(native_library, get_user_directory);
|
||||
|
||||
if (env->ExceptionCheck() || j_user_directory == nullptr) {
|
||||
env->ExceptionClear();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const char* chars = env->GetStringUTFChars(j_user_directory, nullptr);
|
||||
|
||||
std::string result = chars ? chars : "";
|
||||
|
||||
env->ReleaseStringUTFChars(j_user_directory, chars);
|
||||
|
||||
if (result.empty()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -296,7 +310,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 "";
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user