DEADSOFTWARE

Engine: Fix e_UpperDir() leaving a trailing backslash
authorDmitry D. Chernov <blackdoomer@yandex.ru>
Mon, 15 May 2023 12:21:33 +0000 (22:21 +1000)
committerDmitry D. Chernov <blackdoomer@yandex.ru>
Mon, 15 May 2023 12:21:33 +0000 (22:21 +1000)
This fixes a bug with broken folder navigation in file lists.

src/engine/e_res.pas
src/game/g_gui.pas

index e48cc32ed5746264150eb419cbf14ee36db99135..69adb6e6eb5faa6b5e4fd98c0d919b270cb50501 100644 (file)
@@ -79,9 +79,9 @@ implementation
   function e_UpperDir (path: AnsiString): AnsiString;
     var i: Integer;
   begin
-    i := High(path);
+    i := High(path);  // consider possible cases: '\a\', '\a', '\abc\'
     while (i >= 1) and (path[i] <> '/') and (path[i] <> '\') do Dec(i);
-    result := Copy(path, 1, i)
+    result := Copy(path, 1, i-1)  // exclude the trailing separator
   end;
 
   function HasRelativeDirs (name: AnsiString): Boolean;
index b8b19999fb4728c9edcbe2b880d1373e98d455aa..2200703437db6be9fc693d2bdfbd83dc76a55b31 100644 (file)
@@ -3232,13 +3232,13 @@ begin
                   begin
                     if FItems[FIndex] = #29 + '..' then
                     begin
-                      e_LogWritefln('TGUIFileListBox: Upper dir "%s" -> "%s"', [FSubPath, e_UpperDir(FSubPath)]);
+                      //e_LogWritefln('TGUIFileListBox: Upper dir "%s" -> "%s"', [FSubPath, e_UpperDir(FSubPath)]);
                       FSubPath := e_UpperDir(FSubPath)
                     end
                     else
                     begin
                       s := Copy(AnsiString(FItems[FIndex]), 2);
-                      e_LogWritefln('TGUIFileListBox: Enter dir "%s" -> "%s"', [FSubPath, e_CatPath(FSubPath, s)]);
+                      //e_LogWritefln('TGUIFileListBox: Enter dir "%s" -> "%s"', [FSubPath, e_CatPath(FSubPath, s)]);
                       FSubPath := e_CatPath(FSubPath, s);
                     end;
                     ScanDirs;