Better mode implementation

This commit is contained in:
gabriel 2024-02-15 11:26:13 -04:00
parent 715ce45066
commit 5772516126

View file

@ -32,30 +32,31 @@ 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){
try { public static String parseNativeMode(String mode){
mode = mode.toLowerCase(); mode = mode.toLowerCase();
switch (mode){ switch (mode){
case "rb":
case "rb+":
case "r+b":
mode = "r";
break;
case "wb":
case "wb+":
case "w+b":
mode = "w";
break;
case "rwt":
case "wt":
case "rw":
case "r": case "r":
case "rb":
return "r";
case "r+":
case "r+b":
case "rb+":
return "rw";
case "w+":
return "rwt";
case "w": case "w":
case "wb":
return "wt";
case "wa": case "wa":
break; return "wa";
default:
throw new IllegalArgumentException("Invalid mode: "+mode);
} }
throw new IllegalArgumentException("Invalid file mode: "+mode);
}
public static int openDocument(String path, String mode){
try {
mode = parseNativeMode(mode);
Context context = PandroidApplication.getAppContext(); Context context = PandroidApplication.getAppContext();
Uri uri = FileUtils.obtainUri(path); Uri uri = FileUtils.obtainUri(path);
ParcelFileDescriptor parcel; ParcelFileDescriptor parcel;