From 6567881ce5555e800444b3aadff5b1bc2c3bae89 Mon Sep 17 00:00:00 2001
From: Persephone Bubblegum-Holiday <kawaiizenbo@noreply.local>
Date: Fri, 28 Feb 2025 22:13:55 -0700
Subject: [PATCH] fix bug with symbolic links

---
 AFCExplorer/MainWindow.xaml.cs | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/AFCExplorer/MainWindow.xaml.cs b/AFCExplorer/MainWindow.xaml.cs
index c64b8b7..c486870 100644
--- a/AFCExplorer/MainWindow.xaml.cs
+++ b/AFCExplorer/MainWindow.xaml.cs
@@ -59,9 +59,12 @@ namespace AFCExplorer
                 {
                     if (fn == "." || fn == "..") continue;
                     afc.afc_get_file_info(afcHandle, path + fn, out ReadOnlyCollection<string> fileInfo).ThrowOnError();
-                    string readableSize = FormatBytes(ulong.Parse(fileInfo[1]));
-                    string readableType = fileInfo[7] == "S_IFDIR" ? "Directory" : "File";
-                    int unixSeconds = (int)(((long.Parse(fileInfo[9]) / 1000) / 1000) / 1000);
+                    Dictionary<string, string> fileInfoD = new Dictionary<string, string>();
+                    for (int i = 0; i < fileInfo.Count; i += 2) fileInfoD.Add(fileInfo[i], fileInfo[i+1]);
+                    //MessageBox.Show(string.Join("\n", fileInfo));
+                    string readableSize = FormatBytes(ulong.Parse(fileInfoD["st_size"]));
+                    string readableType = ReadableTypes[fileInfoD["st_ifmt"]];
+                    int unixSeconds = (int)(((long.Parse(fileInfoD["st_mtime"]) / 1000) / 1000) / 1000);
                     string readableTime = DateTimeOffset.FromUnixTimeSeconds(unixSeconds).DateTime.ToString();
                     afcDirectory.Add(new AFCFileType(fn, readableType, readableTime, readableSize));
                 }
@@ -359,5 +362,12 @@ namespace AFCExplorer
 
             return string.Format("{0:0.##} {1}", dblSByte, Suffix[i]);
         }
+
+        public static Dictionary<string, string> ReadableTypes = new Dictionary<string, string>
+        {
+            { "S_IFDIR", "Directory" },
+            { "S_IFREG", "File" },
+            { "S_IFLNK", "Symbolic Link" },
+        };
     }
 }