Android: Fix opening games with extensionless URI

This commit is contained in:
JosJuice 2020-11-08 15:39:17 +01:00
parent e60665da94
commit 525268f043
6 changed files with 39 additions and 0 deletions

View File

@ -99,6 +99,12 @@ public class ContentHandler
return -1;
}
@Nullable @Keep
public static String getDisplayName(String uri)
{
return getDisplayName(Uri.parse(uri));
}
@Nullable
public static String getDisplayName(@NonNull Uri uri)
{

View File

@ -112,6 +112,15 @@ jlong GetAndroidContentSizeAndIsDirectory(const std::string& uri)
ToJString(env, uri));
}
std::string GetAndroidContentDisplayName(const std::string& uri)
{
JNIEnv* env = IDCache::GetEnvForThread();
jobject display_name =
env->CallStaticObjectMethod(IDCache::GetContentHandlerClass(),
IDCache::GetContentHandlerGetDisplayName(), ToJString(env, uri));
return display_name ? GetJString(env, reinterpret_cast<jstring>(display_name)) : "";
}
int GetNetworkIpAddress()
{
JNIEnv* env = IDCache::GetEnvForThread();

View File

@ -28,6 +28,12 @@ bool DeleteAndroidContent(const std::string& uri);
// Returns -1 if not found, -2 if directory, file size otherwise.
jlong GetAndroidContentSizeAndIsDirectory(const std::string& uri);
// An unmangled URI (one which the C++ code has not appended anything to) can't be relied on
// to contain a file name at all. If a file name is desired, this function is the most reliable
// way to get it, but the display name is not guaranteed to always actually be like a file name.
// An empty string will be returned for files which do not exist.
std::string GetAndroidContentDisplayName(const std::string& uri);
int GetNetworkIpAddress();
int GetNetworkPrefixLength();
int GetNetworkGateway();

View File

@ -45,6 +45,7 @@ static jclass s_content_handler_class;
static jmethodID s_content_handler_open_fd;
static jmethodID s_content_handler_delete;
static jmethodID s_content_handler_get_size_and_is_directory;
static jmethodID s_content_handler_get_display_name;
static jclass s_network_helper_class;
static jmethodID s_network_helper_get_network_ip_address;
@ -216,6 +217,11 @@ jmethodID GetContentHandlerGetSizeAndIsDirectory()
return s_content_handler_get_size_and_is_directory;
}
jmethodID GetContentHandlerGetDisplayName()
{
return s_content_handler_get_display_name;
}
jclass GetNetworkHelperClass()
{
return s_network_helper_class;
@ -315,6 +321,8 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
env->GetStaticMethodID(s_content_handler_class, "delete", "(Ljava/lang/String;)Z");
s_content_handler_get_size_and_is_directory = env->GetStaticMethodID(
s_content_handler_class, "getSizeAndIsDirectory", "(Ljava/lang/String;)J");
s_content_handler_get_display_name = env->GetStaticMethodID(
s_content_handler_class, "getDisplayName", "(Ljava/lang/String;)Ljava/lang/String;");
const jclass network_helper_class =
env->FindClass("org/dolphinemu/dolphinemu/utils/NetworkHelper");

View File

@ -45,6 +45,7 @@ jclass GetContentHandlerClass();
jmethodID GetContentHandlerOpenFd();
jmethodID GetContentHandlerDelete();
jmethodID GetContentHandlerGetSizeAndIsDirectory();
jmethodID GetContentHandlerGetDisplayName();
jclass GetNetworkHelperClass();
jmethodID GetNetworkHelperGetNetworkIpAddress();

View File

@ -158,6 +158,15 @@ BootParameters::GenerateFromFile(std::vector<std::string> paths,
if (paths.size() == 1)
paths.clear();
#ifdef ANDROID
if (extension.empty() && IsPathAndroidContent(path))
{
const std::string display_name = GetAndroidContentDisplayName(path);
SplitPath(display_name, nullptr, nullptr, &extension);
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
}
#endif
static const std::unordered_set<std::string> disc_image_extensions = {
{".gcm", ".iso", ".tgc", ".wbfs", ".ciso", ".gcz", ".wia", ".rvz", ".dol", ".elf"}};
if (disc_image_extensions.find(extension) != disc_image_extensions.end() || is_drive)