mirror of
https://github.com/izzy2lost/2ship2harkinian-Android.git
synced 2026-06-19 01:20:08 -07:00
GUI Scaling fixes
This commit is contained in:
@@ -38,6 +38,12 @@
|
||||
#define UNREACHABLE __builtin_unreachable();
|
||||
#endif
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <SDL2/SDL.h>
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <SDL2/SDL_messagebox.h>
|
||||
@@ -95,6 +101,28 @@ enum class ButtonId : int {
|
||||
FIND,
|
||||
};
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
||||
const char* javaRomPath = NULL;
|
||||
bool fileDialogOpen = false;
|
||||
|
||||
//function to be called from C
|
||||
void openFilePickerFromC(JNIEnv* env, jobject javaObject) {
|
||||
fileDialogOpen = true;
|
||||
jclass javaClass = env->GetObjectClass(javaObject);
|
||||
jmethodID openFilePickerMethod = env->GetMethodID(javaClass, "openFilePicker", "()V");
|
||||
env->CallVoidMethod(javaObject, openFilePickerMethod);
|
||||
}
|
||||
// Define the native method to handle the selected file path
|
||||
extern "C" void JNICALL Java_com_dishii_mm_MainActivity_nativeHandleSelectedFile(JNIEnv* env, jobject obj, jstring filePath) {
|
||||
const char* filePathStr = env->GetStringUTFChars(filePath, 0);
|
||||
javaRomPath = strdup(filePathStr); // save filepath to string
|
||||
fileDialogOpen = false;
|
||||
env->ReleaseStringUTFChars(filePath, filePathStr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void Extractor::ShowErrorBox(const char* title, const char* text) {
|
||||
#ifdef _WIN32
|
||||
MessageBoxA(nullptr, text, title, MB_OK | MB_ICONERROR);
|
||||
@@ -297,8 +325,20 @@ bool Extractor::GetRomPathFromBox() {
|
||||
}
|
||||
mCurrentRomPath = nameBuffer;
|
||||
#else
|
||||
#ifndef __ANDROID__
|
||||
auto selection = pfd::open_file("Select a file", ".", { "N64 Roms", "*.z64 *.n64 *.v64" }).result();
|
||||
|
||||
#else
|
||||
JNIEnv* javaEnv = (JNIEnv*)SDL_AndroidGetJNIEnv();
|
||||
jobject javaObject = (jobject)SDL_AndroidGetActivity();
|
||||
std::vector<std::string> selection;
|
||||
openFilePickerFromC(javaEnv, javaObject);
|
||||
while(fileDialogOpen){
|
||||
//Do nothing until it's chosen
|
||||
SDL_Delay(250);
|
||||
}
|
||||
SDL_Log("%s",javaRomPath);
|
||||
selection.push_back(javaRomPath);
|
||||
#endif
|
||||
if (selection.empty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -306,6 +346,12 @@ bool Extractor::GetRomPathFromBox() {
|
||||
mCurrentRomPath = selection[0];
|
||||
#endif
|
||||
mCurRomSize = GetCurRomSize();
|
||||
#ifdef __ANDROID__
|
||||
if (javaRomPath) {
|
||||
free((void*)javaRomPath);
|
||||
javaRomPath = NULL;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -520,7 +566,11 @@ const char* Extractor::GetZapdVerStr() const {
|
||||
}
|
||||
|
||||
std::string Extractor::Mkdtemp() {
|
||||
#ifndef __ANDROID__
|
||||
std::string temp_dir = std::filesystem::temp_directory_path().string();
|
||||
#else
|
||||
std::string temp_dir = SDL_AndroidGetExternalStoragePath();
|
||||
#endif
|
||||
|
||||
// create 6 random alphanumeric characters
|
||||
static const char charset[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
@@ -560,7 +610,12 @@ bool Extractor::CallZapd(std::string installPath, std::string exportdir) {
|
||||
std::filesystem::copy(installPath + "/assets", tempdir + "/assets",
|
||||
std::filesystem::copy_options::recursive | std::filesystem::copy_options::update_existing);
|
||||
#else
|
||||
#ifndef __ANDROID__
|
||||
std::filesystem::create_symlink(installPath + "/assets", tempdir + "/assets");
|
||||
#else
|
||||
std::filesystem::copy(installPath + "/assets", tempdir + "/assets",
|
||||
std::filesystem::copy_options::recursive | std::filesystem::copy_options::update_existing);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
std::filesystem::current_path(tempdir);
|
||||
|
||||
Reference in New Issue
Block a user