mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-06-08 09:05:02 -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 dirSep = "/"
|
||||||
|
|
||||||
val pathSegment = uri.lastPathSegment!!
|
val pathSegment = uri.lastPathSegment ?: return ""
|
||||||
val virtualPath = pathSegment.substringAfter(":")
|
val virtualPath = pathSegment.substringAfter(":")
|
||||||
|
|
||||||
if (pathSegment.startsWith("primary:")) { // User directory is located in primary storage
|
if (pathSegment.startsWith("primary:")) { // User directory is located in primary storage
|
||||||
@ -723,7 +723,8 @@ object NativeLibrary {
|
|||||||
fun getUserDirectory(): String {
|
fun getUserDirectory(): String {
|
||||||
val preferences: SharedPreferences =
|
val preferences: SharedPreferences =
|
||||||
PreferenceManager.getDefaultSharedPreferences(CitraApplication.appContext)
|
PreferenceManager.getDefaultSharedPreferences(CitraApplication.appContext)
|
||||||
return getNativePath(preferences.getString("CITRA_DIRECTORY", "")!!.toUri())
|
val userDirectoryUri = preferences.getString("CITRA_DIRECTORY", "")!!.toUri()
|
||||||
|
return getNativePath(userDirectoryUri)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
|
|||||||
@ -163,13 +163,27 @@ std::optional<std::string> GetUserDirectory() {
|
|||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"Unable to locate user directory: Function with ID 'get_user_directory' is missing");
|
"Unable to locate user directory: Function with ID 'get_user_directory' is missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto env = GetEnvForThread();
|
auto env = GetEnvForThread();
|
||||||
auto j_user_directory =
|
|
||||||
(jstring)(env->CallStaticObjectMethod(native_library, get_user_directory, nullptr));
|
jstring j_user_directory =
|
||||||
auto result = env->GetStringUTFChars(j_user_directory, nullptr);
|
(jstring)env->CallStaticObjectMethod(native_library, get_user_directory);
|
||||||
if (result == "") {
|
|
||||||
|
if (env->ExceptionCheck() || j_user_directory == nullptr) {
|
||||||
|
env->ExceptionClear();
|
||||||
return std::nullopt;
|
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;
|
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::string TranslateFilePath(const std::string& filepath) {
|
||||||
std::optional<std::string> userDirLocation = GetUserDirectory();
|
std::optional<std::string> userDirLocation = GetUserDirectory();
|
||||||
if (userDirLocation) {
|
if (userDirLocation) {
|
||||||
return *userDirLocation + "/" + filepath;
|
return *userDirLocation + filepath;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user