mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-02-17 03:15:39 +00:00
Android: Fix filenames for SAF paths showing incorrectly
This commit is contained in:
parent
c3f914565f
commit
f9fb4c2d16
|
@ -1003,10 +1003,10 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||||
(s_EmulationActivity_method_setInputDeviceVibration =
|
(s_EmulationActivity_method_setInputDeviceVibration =
|
||||||
env->GetMethodID(s_EmulationActivity_class, "setInputDeviceVibration", "(IFF)V")) == nullptr ||
|
env->GetMethodID(s_EmulationActivity_class, "setInputDeviceVibration", "(IFF)V")) == nullptr ||
|
||||||
(s_PatchCode_constructor = env->GetMethodID(s_PatchCode_class, "<init>", "(ILjava/lang/String;Z)V")) == nullptr ||
|
(s_PatchCode_constructor = env->GetMethodID(s_PatchCode_class, "<init>", "(ILjava/lang/String;Z)V")) == nullptr ||
|
||||||
(s_GameListEntry_constructor = env->GetMethodID(
|
(s_GameListEntry_constructor =
|
||||||
s_GameListEntry_class, "<init>",
|
env->GetMethodID(s_GameListEntry_class, "<init>",
|
||||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JLjava/lang/String;Ljava/lang/"
|
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JLjava/lang/String;Ljava/lang/"
|
||||||
"String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V")) == nullptr ||
|
"String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V")) == nullptr ||
|
||||||
(s_SaveStateInfo_constructor = env->GetMethodID(
|
(s_SaveStateInfo_constructor = env->GetMethodID(
|
||||||
s_SaveStateInfo_class, "<init>",
|
s_SaveStateInfo_class, "<init>",
|
||||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZII[B)V")) ==
|
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZII[B)V")) ==
|
||||||
|
@ -1345,13 +1345,11 @@ static jobject CreateGameListEntry(JNIEnv* env, AndroidHostInterface* hi, const
|
||||||
{
|
{
|
||||||
const Timestamp modified_ts(
|
const Timestamp modified_ts(
|
||||||
Timestamp::FromUnixTimestamp(static_cast<Timestamp::UnixTimestampValue>(entry.last_modified_time)));
|
Timestamp::FromUnixTimestamp(static_cast<Timestamp::UnixTimestampValue>(entry.last_modified_time)));
|
||||||
const std::string file_title_str(FileSystem::GetFileTitleFromPath(entry.path));
|
|
||||||
const std::string cover_path_str(hi->GetGameList()->GetCoverImagePathForEntry(&entry));
|
const std::string cover_path_str(hi->GetGameList()->GetCoverImagePathForEntry(&entry));
|
||||||
|
|
||||||
jstring path = env->NewStringUTF(entry.path.c_str());
|
jstring path = env->NewStringUTF(entry.path.c_str());
|
||||||
jstring code = env->NewStringUTF(entry.code.c_str());
|
jstring code = env->NewStringUTF(entry.code.c_str());
|
||||||
jstring title = env->NewStringUTF(entry.title.c_str());
|
jstring title = env->NewStringUTF(entry.title.c_str());
|
||||||
jstring file_title = env->NewStringUTF(file_title_str.c_str());
|
|
||||||
jstring region = env->NewStringUTF(DiscRegionToString(entry.region));
|
jstring region = env->NewStringUTF(DiscRegionToString(entry.region));
|
||||||
jstring type = env->NewStringUTF(GameList::EntryTypeToString(entry.type));
|
jstring type = env->NewStringUTF(GameList::EntryTypeToString(entry.type));
|
||||||
jstring compatibility_rating =
|
jstring compatibility_rating =
|
||||||
|
@ -1360,9 +1358,8 @@ static jobject CreateGameListEntry(JNIEnv* env, AndroidHostInterface* hi, const
|
||||||
jstring modified_time = env->NewStringUTF(modified_ts.ToString("%Y/%m/%d, %H:%M:%S"));
|
jstring modified_time = env->NewStringUTF(modified_ts.ToString("%Y/%m/%d, %H:%M:%S"));
|
||||||
jlong size = entry.total_size;
|
jlong size = entry.total_size;
|
||||||
|
|
||||||
jobject entry_jobject =
|
jobject entry_jobject = env->NewObject(s_GameListEntry_class, s_GameListEntry_constructor, path, code, title, size,
|
||||||
env->NewObject(s_GameListEntry_class, s_GameListEntry_constructor, path, code, title, file_title, size,
|
modified_time, region, type, compatibility_rating, cover_path);
|
||||||
modified_time, region, type, compatibility_rating, cover_path);
|
|
||||||
|
|
||||||
env->DeleteLocalRef(modified_time);
|
env->DeleteLocalRef(modified_time);
|
||||||
if (cover_path)
|
if (cover_path)
|
||||||
|
@ -1370,7 +1367,6 @@ static jobject CreateGameListEntry(JNIEnv* env, AndroidHostInterface* hi, const
|
||||||
env->DeleteLocalRef(compatibility_rating);
|
env->DeleteLocalRef(compatibility_rating);
|
||||||
env->DeleteLocalRef(type);
|
env->DeleteLocalRef(type);
|
||||||
env->DeleteLocalRef(region);
|
env->DeleteLocalRef(region);
|
||||||
env->DeleteLocalRef(file_title);
|
|
||||||
env->DeleteLocalRef(title);
|
env->DeleteLocalRef(title);
|
||||||
env->DeleteLocalRef(code);
|
env->DeleteLocalRef(code);
|
||||||
env->DeleteLocalRef(path);
|
env->DeleteLocalRef(path);
|
||||||
|
|
|
@ -712,7 +712,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
|
|
||||||
CharSequence[] items = new CharSequence[numPaths + 1];
|
CharSequence[] items = new CharSequence[numPaths + 1];
|
||||||
for (int i = 0; i < numPaths; i++)
|
for (int i = 0; i < numPaths; i++)
|
||||||
items[i] = GameListEntry.getFileNameForPath(paths[i]);
|
items[i] = FileHelper.getFileNameForPath(paths[i]);
|
||||||
items[numPaths] = getString(R.string.emulation_activity_change_disc_select_new_file);
|
items[numPaths] = getString(R.string.emulation_activity_change_disc_select_new_file);
|
||||||
|
|
||||||
builder.setSingleChoiceItems(items, (currentPath < numPaths) ? currentPath : -1, (dialogInterface, i) -> {
|
builder.setSingleChoiceItems(items, (currentPath < numPaths) ? currentPath : -1, (dialogInterface, i) -> {
|
||||||
|
|
|
@ -242,6 +242,29 @@ public class FileHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the file name component of a path or URI.
|
||||||
|
* @param path Path/URI to examine.
|
||||||
|
* @return File name component of path/URI.
|
||||||
|
*/
|
||||||
|
public static String getFileNameForPath(String path) {
|
||||||
|
if (path.startsWith("content:/") || path.startsWith("file:/")) {
|
||||||
|
try {
|
||||||
|
final Uri uri = Uri.parse(path);
|
||||||
|
final String lastPathSegment = uri.getLastPathSegment();
|
||||||
|
if (lastPathSegment != null)
|
||||||
|
path = lastPathSegment;
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int lastSlash = path.lastIndexOf('/');
|
||||||
|
if (lastSlash > 0 && lastSlash < path.length() - 1)
|
||||||
|
return path.substring(lastSlash + 1);
|
||||||
|
else
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a file descriptor for a content URI string. Called by native code.
|
* Retrieves a file descriptor for a content URI string. Called by native code.
|
||||||
*
|
*
|
||||||
|
|
|
@ -27,7 +27,6 @@ public class GameListEntry {
|
||||||
private String mPath;
|
private String mPath;
|
||||||
private String mCode;
|
private String mCode;
|
||||||
private String mTitle;
|
private String mTitle;
|
||||||
private String mFileTitle;
|
|
||||||
private long mSize;
|
private long mSize;
|
||||||
private String mModifiedTime;
|
private String mModifiedTime;
|
||||||
private DiscRegion mRegion;
|
private DiscRegion mRegion;
|
||||||
|
@ -35,12 +34,11 @@ public class GameListEntry {
|
||||||
private CompatibilityRating mCompatibilityRating;
|
private CompatibilityRating mCompatibilityRating;
|
||||||
private String mCoverPath;
|
private String mCoverPath;
|
||||||
|
|
||||||
public GameListEntry(String path, String code, String title, String fileTitle, long size, String modifiedTime, String region,
|
public GameListEntry(String path, String code, String title, long size, String modifiedTime, String region,
|
||||||
String type, String compatibilityRating, String coverPath) {
|
String type, String compatibilityRating, String coverPath) {
|
||||||
mPath = path;
|
mPath = path;
|
||||||
mCode = code;
|
mCode = code;
|
||||||
mTitle = title;
|
mTitle = title;
|
||||||
mFileTitle = fileTitle;
|
|
||||||
mSize = size;
|
mSize = size;
|
||||||
mModifiedTime = modifiedTime;
|
mModifiedTime = modifiedTime;
|
||||||
mCoverPath = coverPath;
|
mCoverPath = coverPath;
|
||||||
|
@ -76,10 +74,6 @@ public class GameListEntry {
|
||||||
return mTitle;
|
return mTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileTitle() {
|
|
||||||
return mFileTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSize() { return mSize; }
|
public long getSize() { return mSize; }
|
||||||
|
|
||||||
public String getModifiedTime() {
|
public String getModifiedTime() {
|
||||||
|
@ -102,11 +96,4 @@ public class GameListEntry {
|
||||||
|
|
||||||
public void setCoverPath(String coverPath) { mCoverPath = coverPath; }
|
public void setCoverPath(String coverPath) { mCoverPath = coverPath; }
|
||||||
|
|
||||||
public static String getFileNameForPath(String path) {
|
|
||||||
int lastSlash = path.lastIndexOf('/');
|
|
||||||
if (lastSlash > 0 && lastSlash < path.length() - 1)
|
|
||||||
return path.substring(lastSlash + 1);
|
|
||||||
else
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,10 @@ package com.github.stenzek.duckstation;
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.PopupMenu;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -74,7 +70,7 @@ public class GameListFragment extends Fragment implements GameList.OnRefreshList
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSubTitle() {
|
private String getSubTitle() {
|
||||||
String fileName = GameListEntry.getFileNameForPath(mEntry.getPath());
|
String fileName = FileHelper.getFileNameForPath(mEntry.getPath());
|
||||||
String sizeString = String.format("%.2f MB", (double) mEntry.getSize() / 1048576.0);
|
String sizeString = String.format("%.2f MB", (double) mEntry.getSize() / 1048576.0);
|
||||||
return String.format("%s (%s)", fileName, sizeString);
|
return String.format("%s (%s)", fileName, sizeString);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ public class GamePropertiesActivity extends AppCompatActivity {
|
||||||
|
|
||||||
mPropertiesListAdapter = new PropertyListAdapter(this);
|
mPropertiesListAdapter = new PropertyListAdapter(this);
|
||||||
mPropertiesListAdapter.addItem("title", "Title", mGameListEntry.getTitle());
|
mPropertiesListAdapter.addItem("title", "Title", mGameListEntry.getTitle());
|
||||||
mPropertiesListAdapter.addItem("filetitle", "File Title", mGameListEntry.getFileTitle());
|
|
||||||
mPropertiesListAdapter.addItem("serial", "Serial", mGameListEntry.getCode());
|
mPropertiesListAdapter.addItem("serial", "Serial", mGameListEntry.getCode());
|
||||||
mPropertiesListAdapter.addItem("type", "Type", mGameListEntry.getType().toString());
|
mPropertiesListAdapter.addItem("type", "Type", mGameListEntry.getType().toString());
|
||||||
mPropertiesListAdapter.addItem("path", "Path", mGameListEntry.getPath());
|
mPropertiesListAdapter.addItem("path", "Path", mGameListEntry.getPath());
|
||||||
|
|
Loading…
Reference in a new issue