This commit is contained in:
wheremyfoodat 2024-02-17 11:33:58 +02:00
parent 5ec6d8a5d5
commit c8db0098f5
12 changed files with 51 additions and 55 deletions

View file

@ -1,6 +1,5 @@
#pragma once
class AndroidUtils {
public:
static int openDocument(const char* directory, const char* mode);
};
namespace AndroidUtils {
int openDocument(const char* directory, const char* mode);
}

View file

@ -41,7 +41,8 @@ bool IOFile::open(const char* filename, const char* permissions) {
#ifdef __ANDROID__
std::string path(filename);
if(path.find("://") != std::string::npos){ //IF SAF URI
// Check if this is a URI directory, which will need special handling due to SAF
if (path.find("://") != std::string::npos ) {
handle = fdopen(AndroidUtils::openDocument(filename, permissions), permissions);
} else {
handle = std::fopen(filename, permissions);
@ -49,6 +50,7 @@ bool IOFile::open(const char* filename, const char* permissions) {
#else
handle = std::fopen(filename, permissions);
#endif
return isOpen();
}

View file

@ -32,8 +32,6 @@ public class AlberDriver {
public static native void setShaderJitEnabled(boolean enable);
public static int openDocument(String path, String mode) {
try {
mode = FileUtils.parseNativeMode(mode);
@ -42,7 +40,7 @@ public class AlberDriver {
ParcelFileDescriptor parcel;
if (Objects.equals(uri.getScheme(), "game")) {
if (mode.contains("w")) {
throw new IllegalArgumentException("Cannot write to rom-fs");
throw new IllegalArgumentException("Cannot open ROM file as writable");
}
uri = FileUtils.obtainUri(GameUtils.getCurrentGame().getRealPath());
}

View file

@ -2,7 +2,6 @@ package com.panda3ds.pandroid.app;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
@ -13,7 +12,6 @@ import com.panda3ds.pandroid.app.main.GamesFragment;
import com.panda3ds.pandroid.app.main.SearchFragment;
import com.panda3ds.pandroid.app.main.SettingsFragment;
public class MainActivity extends BaseActivity implements NavigationBarView.OnItemSelectedListener {
private final GamesFragment gamesFragment = new GamesFragment();
private final SearchFragment searchFragment = new SearchFragment();

View file

@ -21,10 +21,8 @@ import com.panda3ds.pandroid.utils.Constants;
import com.panda3ds.pandroid.utils.FileUtils;
import com.panda3ds.pandroid.utils.GameUtils;
import com.panda3ds.pandroid.view.gamesgrid.GamesGridView;
import java.util.UUID;
public class GamesFragment extends Fragment implements ActivityResultCallback<Uri> {
private final ActivityResultContracts.OpenDocument openRomContract = new ActivityResultContracts.OpenDocument();
private ActivityResultLauncher<String[]> pickFileRequest;
@ -62,21 +60,21 @@ public class GamesFragment extends Fragment implements ActivityResultCallback<Ur
String extension = FileUtils.extension(uri);
// For ELF and AXF files the emulator core uses the C++ iostreams API to be compatible with elfio unlike other file types
// As such, instead of writing more SAF code for operating with iostreams we just copy the ELF/AXF file to our own private directory
// And use it without caring about SAF
if (extension.equals("elf") || extension.endsWith("axf")) {
importELF(uri);
} else {
FileUtils.makeUriPermanent(uri, FileUtils.MODE_READ);
importGame(uri);
}
}
}
}
private void importGame(String uri){
GameMetadata game = new GameMetadata(uri, FileUtils.getName(uri).split("\\.")[0], getString(R.string.unknown));
GameUtils.addGame(game);
GameUtils.launch(requireActivity(), game);
}
}
}
}
private void importELF(String uri) {
AlertDialog dialog = new LoadingAlertDialog(requireActivity(), R.string.loading).create();

View file

@ -12,6 +12,7 @@ class PatternUtils {
builder.append("|");
}
}
builder.append(")\\b");
return Pattern.compile(builder.toString());
}