mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-05-04 11:14:48 +12:00
Bonk v1
This commit is contained in:
parent
5ec6d8a5d5
commit
c8db0098f5
12 changed files with 51 additions and 55 deletions
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class AndroidUtils {
|
namespace AndroidUtils {
|
||||||
public:
|
int openDocument(const char* directory, const char* mode);
|
||||||
static int openDocument(const char* directory, const char* mode);
|
}
|
||||||
};
|
|
|
@ -41,7 +41,8 @@ bool IOFile::open(const char* filename, const char* permissions) {
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
std::string path(filename);
|
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);
|
handle = fdopen(AndroidUtils::openDocument(filename, permissions), permissions);
|
||||||
} else {
|
} else {
|
||||||
handle = std::fopen(filename, permissions);
|
handle = std::fopen(filename, permissions);
|
||||||
|
@ -49,6 +50,7 @@ bool IOFile::open(const char* filename, const char* permissions) {
|
||||||
#else
|
#else
|
||||||
handle = std::fopen(filename, permissions);
|
handle = std::fopen(filename, permissions);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return isOpen();
|
return isOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,6 @@ public class AlberDriver {
|
||||||
|
|
||||||
public static native void setShaderJitEnabled(boolean enable);
|
public static native void setShaderJitEnabled(boolean enable);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static int openDocument(String path, String mode) {
|
public static int openDocument(String path, String mode) {
|
||||||
try {
|
try {
|
||||||
mode = FileUtils.parseNativeMode(mode);
|
mode = FileUtils.parseNativeMode(mode);
|
||||||
|
@ -42,7 +40,7 @@ public class AlberDriver {
|
||||||
ParcelFileDescriptor parcel;
|
ParcelFileDescriptor parcel;
|
||||||
if (Objects.equals(uri.getScheme(), "game")) {
|
if (Objects.equals(uri.getScheme(), "game")) {
|
||||||
if (mode.contains("w")) {
|
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());
|
uri = FileUtils.obtainUri(GameUtils.getCurrentGame().getRealPath());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.panda3ds.pandroid.app;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
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.SearchFragment;
|
||||||
import com.panda3ds.pandroid.app.main.SettingsFragment;
|
import com.panda3ds.pandroid.app.main.SettingsFragment;
|
||||||
|
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity implements NavigationBarView.OnItemSelectedListener {
|
public class MainActivity extends BaseActivity implements NavigationBarView.OnItemSelectedListener {
|
||||||
private final GamesFragment gamesFragment = new GamesFragment();
|
private final GamesFragment gamesFragment = new GamesFragment();
|
||||||
private final SearchFragment searchFragment = new SearchFragment();
|
private final SearchFragment searchFragment = new SearchFragment();
|
||||||
|
|
|
@ -21,10 +21,8 @@ import com.panda3ds.pandroid.utils.Constants;
|
||||||
import com.panda3ds.pandroid.utils.FileUtils;
|
import com.panda3ds.pandroid.utils.FileUtils;
|
||||||
import com.panda3ds.pandroid.utils.GameUtils;
|
import com.panda3ds.pandroid.utils.GameUtils;
|
||||||
import com.panda3ds.pandroid.view.gamesgrid.GamesGridView;
|
import com.panda3ds.pandroid.view.gamesgrid.GamesGridView;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
public class GamesFragment extends Fragment implements ActivityResultCallback<Uri> {
|
public class GamesFragment extends Fragment implements ActivityResultCallback<Uri> {
|
||||||
private final ActivityResultContracts.OpenDocument openRomContract = new ActivityResultContracts.OpenDocument();
|
private final ActivityResultContracts.OpenDocument openRomContract = new ActivityResultContracts.OpenDocument();
|
||||||
private ActivityResultLauncher<String[]> pickFileRequest;
|
private ActivityResultLauncher<String[]> pickFileRequest;
|
||||||
|
@ -62,21 +60,21 @@ public class GamesFragment extends Fragment implements ActivityResultCallback<Ur
|
||||||
|
|
||||||
String extension = FileUtils.extension(uri);
|
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")) {
|
if (extension.equals("elf") || extension.endsWith("axf")) {
|
||||||
importELF(uri);
|
importELF(uri);
|
||||||
} else {
|
} else {
|
||||||
FileUtils.makeUriPermanent(uri, FileUtils.MODE_READ);
|
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));
|
GameMetadata game = new GameMetadata(uri, FileUtils.getName(uri).split("\\.")[0], getString(R.string.unknown));
|
||||||
GameUtils.addGame(game);
|
GameUtils.addGame(game);
|
||||||
GameUtils.launch(requireActivity(), game);
|
GameUtils.launch(requireActivity(), game);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void importELF(String uri) {
|
private void importELF(String uri) {
|
||||||
AlertDialog dialog = new LoadingAlertDialog(requireActivity(), R.string.loading).create();
|
AlertDialog dialog = new LoadingAlertDialog(requireActivity(), R.string.loading).create();
|
||||||
|
|
|
@ -12,6 +12,7 @@ class PatternUtils {
|
||||||
builder.append("|");
|
builder.append("|");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append(")\\b");
|
builder.append(")\\b");
|
||||||
return Pattern.compile(builder.toString());
|
return Pattern.compile(builder.toString());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue