Filter out garbage from themes list qmlfrontend
authorunc0rr
Thu, 02 Oct 2014 00:48:14 +0400
branchqmlfrontend
changeset 10438 50ed968e4fee
parent 10436 084e046f6bd5
child 10440 b74a7bbe224e
Filter out garbage from themes list
hedgewars/uFLData.pas
--- a/hedgewars/uFLData.pas	Wed Oct 01 01:20:05 2014 +0400
+++ b/hedgewars/uFLData.pas	Thu Oct 02 00:48:14 2014 +0400
@@ -9,13 +9,49 @@
 uses uPhysFSLayer;
 
 function getThemesList: PPChar; cdecl;
+var list, res, tmp: PPChar;
+    i, size: Longword;
 begin
-    getThemesList:= pfsEnumerateFiles('Themes')
+    list:= pfsEnumerateFiles('Themes');
+    size:= 0;
+    tmp:= list;
+    while tmp^ <> nil do
+    begin
+        inc(size);
+        inc(tmp)
+    end;
+
+    res:= GetMem((3 + size) * sizeof(PChar));
+    res^:= PChar(list);
+    inc(res);
+    res^:= PChar(res + size + 2);
+    inc(res);
+
+    getThemesList:= res;
+
+    for i:= 1 to size do
+    begin
+        if pfsExists('/Themes/' + shortstring(list^) + '/icon.png') then
+        begin
+            res^:= list^;
+            inc(res)
+        end;
+
+        inc(list)
+    end;
+
+    res^:= nil
 end;
 
 procedure freeThemesList(list: PPChar); cdecl;
+var listEnd: PPChar;
 begin
-    pfsFreeList(list)
+    dec(list);
+    listEnd:= PPChar(list^);
+    dec(list);
+
+    pfsFreeList(PPChar(list^));
+    freeMem(list, (listEnd - list) * sizeof(PChar))
 end;
 
 function getThemeIcon(themeName: PChar; buffer: PChar; buflen: Longword): Longword; cdecl;