]> uap-core.de Git - rssreader.git/commitdiff
add Toolkit getConfigPath and getConfigFilePath
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 9 Sep 2025 14:20:53 +0000 (16:20 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 9 Sep 2025 14:20:53 +0000 (16:20 +0200)
ui-java/src/main/java/de/unixwork/ui/Toolkit.java
ui-java/src/main/java/de/unixwork/ui/ToolkitFuncs.java

index 8a8dbc5143c7488a26007c1ae4a99cbd51f2fc0b..abf7868bc973977896029c4c3c94c4a89da40e67 100644 (file)
@@ -620,4 +620,35 @@ public class Toolkit {
             throw new RuntimeException(e);
         }
     }
+
+    public static String getConfigPath() {
+        ToolkitFuncs ui = ToolkitFuncs.getInstance();
+        try {
+            MemorySegment cstr = (MemorySegment)ui.getappdir.invoke();
+            if(cstr == MemorySegment.NULL) {
+                return null;
+            }
+            long len = (long)ui.strlen.invoke(cstr);
+            cstr = cstr.reinterpret(len+1);
+            return cstr.getString(0);
+        } catch (Throwable e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static String getConfigFilePath(String fileName) {
+        ToolkitFuncs ui = ToolkitFuncs.getInstance();
+        try(Arena arena = Arena.ofConfined()) {
+            MemorySegment fileNameCstr = arena.allocateFrom(fileName);
+            MemorySegment cstr = (MemorySegment)ui.configfile.invoke(fileNameCstr);
+            if(cstr == MemorySegment.NULL) {
+                return null;
+            }
+            long len = (long)ui.strlen.invoke(cstr);
+            cstr = cstr.reinterpret(len+1);
+            return cstr.getString(0);
+        } catch (Throwable e) {
+            throw new RuntimeException(e);
+        }
+    }
 }
index 19a4bcbf0605aacec381d5919715d0e5ed2d195e..4eabb3bcecf78dd5fee9493f0db9398546ebfca2 100644 (file)
@@ -78,6 +78,9 @@ public class ToolkitFuncs {
     public MethodHandle ui_malloc;
     public MethodHandle ui_free;
 
+    public MethodHandle getappdir;
+    public MethodHandle configfile;
+
     // some libc stuff
     public MethodHandle malloc;
     public MethodHandle free;
@@ -170,6 +173,9 @@ public class ToolkitFuncs {
         MemorySegment ui_malloc_addr = lib.find("ui_malloc").orElseThrow();
         MemorySegment ui_free_addr = lib.find("ui_free").orElseThrow();
 
+        MemorySegment getappdir_addr = lib.find("getappdir").orElseThrow();
+        MemorySegment configfile_addr = lib.find("configfile").orElseThrow();
+
         MemorySegment malloc_addr = lib.find("malloc").orElseThrow();
         MemorySegment free_addr = lib.find("free").orElseThrow();
         MemorySegment strlen_addr = lib.find("strlen").orElseThrow();
@@ -244,6 +250,9 @@ public class ToolkitFuncs {
 
         call_mainthread = linker.downcallHandle(call_mainthread_addr, sigv_mm);
 
+        getappdir = linker.downcallHandle(getappdir_addr, sigm);
+        configfile = linker.downcallHandle(configfile_addr, sigm_m);
+
         ui_malloc = linker.downcallHandle(ui_malloc_addr, sigm_ml);
         ui_free = linker.downcallHandle(ui_free_addr, sigv_mm);