Skip to content

Commit

Permalink
gzdoom: launcher add extra file chooser button
Browse files Browse the repository at this point in the history
  • Loading branch information
glKarin committed Dec 13, 2024
1 parent b233a74 commit 69261b5
Show file tree
Hide file tree
Showing 16 changed files with 1,079 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android.changelog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gles
gzdoom launcher add extra file chooser button
11 changes: 11 additions & 0 deletions Q3E/src/main/java/com/n0n3m4/q3e/karin/KStr.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ public static String CmdStr(String str)
return str;
}

public static String UnEscapeQuotes( String arg )
{
if(IsBlank(arg))
return arg;
arg = arg.trim();
if(arg.startsWith("\"") && arg.endsWith("\""))
return KidTechCommand.UnEscapeQuotes(arg);
else
return arg;
}

public static String ucfirst(String str)
{
if(IsBlank(str))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ public static boolean IsUriPermissionGrantPrefix(Context context, String path)
{
Uri uri = FileUtility.PathUri(path);
//Log.e("TAG", "IsUriPermissionGrantPrefix: " +uri + "|" + persistedUriPermission.getUri()+"="+persistedUriPermission.getUri().equals(uri));
if(uri.toString().startsWith(persistedUriPermission.getUri().toString()))
if((uri.toString() + "%2F").startsWith(persistedUriPermission.getUri().toString() + "%2F"))
return true;
}
return false;
Expand All @@ -636,7 +636,7 @@ public static Uri GetPermissionGrantedUri(Context context, String path)
Uri uri = FileUtility.PathUri(path);
//Log.e("TAG", "IsUriPermissionGrantPrefix: " +uri + "|" + persistedUriPermission.getUri()+"="+persistedUriPermission.getUri().equals(uri));
Uri grantedUri = persistedUriPermission.getUri();
if(uri.toString().startsWith(grantedUri.toString()))
if((uri.toString() + "%2F").startsWith(grantedUri.toString() + "%2F"))
return grantedUri;
}
return null;
Expand Down
107 changes: 95 additions & 12 deletions idTech4Amm/src/main/java/com/karin/idTech4Amm/lib/FileUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
* Local file IO utility
Expand Down Expand Up @@ -218,32 +220,109 @@ public static boolean mv(String src, String target)
}
}

public static String GetRealPath(String path)
{
Path p = Paths.get(path);
if(!Files.exists(p))
return null;

while(Files.isSymbolicLink(p))
{
try
{
p = Files.readSymbolicLink(p);
}
catch(IOException e)
{
e.printStackTrace();
break;
}
}
return p.toAbsolutePath().toString();
}

public static List<String> GetSymbolPaths(String path)
{
Path p = Paths.get(path);
if(!Files.exists(p))
return null;

List<String> list = new ArrayList<>();
list.add(p.toAbsolutePath().toString());
while(Files.isSymbolicLink(p))
{
try
{
p = Files.readSymbolicLink(p);
list.add(p.toAbsolutePath().toString());
}
catch(IOException e)
{
e.printStackTrace();
break;
}
}
return list;
}

public static List<String> GetSDCardPaths()
{
Set<String> set = new LinkedHashSet<>();
List<String> strings = GetSymbolPaths("/sdcard");
if(null != strings)
set.addAll(strings);
set.add(GetSDCardRoot());
set.add("/sdcard");
set.add("/storage/self/primary");
return new ArrayList<>(set);
}

public static boolean IsSDCardPath(String path)
{
if (path.startsWith("/sdcard"))
return true;
else
List<String> paths = GetSDCardPaths();
for(String p : paths)
{
final String emuPath = Environment.getExternalStorageDirectory().getAbsolutePath();
if (path.startsWith(emuPath))
if (path.startsWith(p))
return true;
}
return false;
}

public static String GetSDCardRelativePath(String path)
{
if (path.startsWith("/sdcard"))
path = path.substring("/sdcard".length());
else
List<String> paths = GetSDCardPaths();
for(String p : paths)
{
final String emuPath = Environment.getExternalStorageDirectory().getAbsolutePath();
if (path.startsWith(emuPath))
path = path.substring(emuPath.length());
if (path.startsWith(p))
{
path = path.substring(p.length());
break;
}
}
return path;
}

public static String GetSDCardRoot()
{
return Environment.getExternalStorageDirectory().getAbsolutePath();
}

// /storage/self/primary
public static String NormalizeSDCardPath(String target)
{
String sdcard = GetSDCardRoot();
List<String> paths = GetSDCardPaths();
for(String p : paths)
{
if (target.startsWith(p))
{
target = sdcard + target.substring(p.length());
break;
}
}
return target;
}

public static Uri PathGrantUri(String dir)
{
dir = GetSDCardRelativePath(dir);
Expand Down Expand Up @@ -292,7 +371,11 @@ public static String ParentPath(String path)
public static String GetPathFromUri(Uri uri)
{
String path = uri.toString();
path = path.replaceAll("content://com\\.android\\.externalstorage\\.documents/tree/primary%3A", "/storage/emulated/0/");
final String DocPathPrefix = "content://com.android.externalstorage.documents/tree/primary%3A";
if(path.startsWith(DocPathPrefix))
path = GetSDCardRoot() + "/" + path.substring(DocPathPrefix.length());
else
path = path.replaceAll("content://com\\.android\\.externalstorage\\.documents/tree/primary%3A", GetSDCardRoot() + "/");
path = path.replaceAll("%2F", "/");
//Log.e("TAG", "GetPathFromUri: " + path);
return path;
Expand Down
24 changes: 24 additions & 0 deletions idTech4Amm/src/main/java/com/karin/idTech4Amm/lib/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
* Common utility
Expand Down Expand Up @@ -69,6 +70,29 @@ public static boolean ArrayContains(String[] arr, String target, boolean cs)
return ArrayIndexOf(arr, target, cs) >= 0;
}

public static int IndexOf(List<String> arr, String target, boolean cs)
{
for(int i = 0; i < arr.size(); i++)
{
if(cs)
{
if(target.equals(arr.get(i)))
return i;
}
else
{
if(target.equalsIgnoreCase(arr.get(i)))
return i;
}
}
return -1;
}

public static boolean Contains(List<String> arr, String target, boolean cs)
{
return IndexOf(arr, target, cs) >= 0;
}

public static int Step(int a, int step)
{
return (int)Math.round((float)a / (float)step) * step;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class FileBrowser
private boolean m_showHidden = true;
private boolean m_ignoreDotDot = false;
private boolean m_dirNameWithSeparator = true;
private boolean m_followSymbol = false;
private Listener m_callback = null;

public interface Listener
Expand Down Expand Up @@ -83,6 +84,8 @@ protected boolean ListFiles(String path)
if (path == null || path.isEmpty())
return false;

path = RealPath(path);

dir = new File(path);
if (!dir.isDirectory())
return false;
Expand Down Expand Up @@ -194,7 +197,8 @@ else if(ContextUtility.NeedUsingDocumentFile(m_context, path))
{
DocumentFile parentDocumentFile = DocumentFile.fromTreeUri(m_context, uri);
String parentPath = FileUtility.GetPathFromUri(uri);
String subPath = FileUtility.GetRelativePath(path, parentPath);
String normalizePath = FileUtility.NormalizeSDCardPath(path);
String subPath = FileUtility.GetRelativePath(normalizePath, parentPath);
res = ListDocumentFiles(path, parentDocumentFile, subPath);
}
else
Expand Down Expand Up @@ -343,6 +347,8 @@ public boolean ListVirtualFiles(String path, String[] files)
if (path == null || path.isEmpty())
return false;

path = RealPath(path);

if (files == null)
{
if (!path.equals(m_currentPath))
Expand Down Expand Up @@ -410,6 +416,8 @@ public boolean ListGivenFiles(String path, String[] files)
if (path == null || path.isEmpty())
return false;

path = RealPath(path);

dir = new File(path);
if (!dir.isDirectory())
return false;
Expand Down Expand Up @@ -489,6 +497,8 @@ public boolean ListDocumentFiles(String path, DocumentFile dir)
if (path == null || path.isEmpty())
return false;

path = RealPath(path);

if (dir == null)
{
if (!path.equals(m_currentPath))
Expand Down Expand Up @@ -563,6 +573,8 @@ public boolean ListDocumentFiles(String path, DocumentFile dirDoc, String subPat
if (path == null || path.isEmpty())
return false;

path = RealPath(path);

String[] parts = FileUtility.SplitPathParts(subPath);
if(null == parts || parts.length == 0)
return false;
Expand Down Expand Up @@ -658,6 +670,13 @@ private void SetupEmptyList(String path)
}
}

private String RealPath(String path)
{
if(m_followSymbol)
return FileUtility.GetRealPath(path);
return path;
}

public boolean IsDirectory(String path)
{
return GetFileType(path) == FileModel.ID_FILE_TYPE_DIRECTORY;
Expand Down Expand Up @@ -698,7 +717,8 @@ else if(documentFile.exists())
{
DocumentFile parentDocumentFile = DocumentFile.fromTreeUri(m_context, uri);
String parentPath = FileUtility.GetPathFromUri(uri);
String subPath = FileUtility.GetRelativePath(path, parentPath);
String normalizePath = FileUtility.NormalizeSDCardPath(path);
String subPath = FileUtility.GetRelativePath(normalizePath, parentPath);

String[] parts = FileUtility.SplitPathParts(subPath);
DocumentFile dir = parentDocumentFile;
Expand Down
Loading

0 comments on commit 69261b5

Please sign in to comment.