hedgewars/uFLData.pas
author unc0rr
Thu, 02 Oct 2014 00:48:14 +0400
branchqmlfrontend
changeset 10438 50ed968e4fee
parent 10436 084e046f6bd5
child 10448 4cb727e029fa
permissions -rw-r--r--
Filter out garbage from themes list
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     1
unit uFLData;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     2
interface
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     3
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     4
function getThemesList: PPChar; cdecl;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     5
procedure freeThemesList(list: PPChar); cdecl;
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
     6
function getThemeIcon(themeName: PChar; buffer: PChar; buflen: Longword): Longword; cdecl;
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     7
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     8
implementation
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     9
uses uPhysFSLayer;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    10
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    11
function getThemesList: PPChar; cdecl;
10438
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    12
var list, res, tmp: PPChar;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    13
    i, size: Longword;
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    14
begin
10438
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    15
    list:= pfsEnumerateFiles('Themes');
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    16
    size:= 0;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    17
    tmp:= list;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    18
    while tmp^ <> nil do
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    19
    begin
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    20
        inc(size);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    21
        inc(tmp)
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    22
    end;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    23
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    24
    res:= GetMem((3 + size) * sizeof(PChar));
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    25
    res^:= PChar(list);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    26
    inc(res);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    27
    res^:= PChar(res + size + 2);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    28
    inc(res);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    29
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    30
    getThemesList:= res;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    31
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    32
    for i:= 1 to size do
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    33
    begin
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    34
        if pfsExists('/Themes/' + shortstring(list^) + '/icon.png') then
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    35
        begin
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    36
            res^:= list^;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    37
            inc(res)
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    38
        end;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    39
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    40
        inc(list)
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    41
    end;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    42
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    43
    res^:= nil
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    44
end;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    45
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    46
procedure freeThemesList(list: PPChar); cdecl;
10438
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    47
var listEnd: PPChar;
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    48
begin
10438
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    49
    dec(list);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    50
    listEnd:= PPChar(list^);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    51
    dec(list);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    52
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    53
    pfsFreeList(PPChar(list^));
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    54
    freeMem(list, (listEnd - list) * sizeof(PChar))
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    55
end;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    56
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    57
function getThemeIcon(themeName: PChar; buffer: PChar; buflen: Longword): Longword; cdecl;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    58
var s: shortstring;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    59
    f: PFSFile;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    60
begin
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    61
    s:= '/Themes/' + shortstring(themeName) + '/icon@2x.png';
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    62
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    63
    f:= pfsOpenRead(s);
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    64
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    65
    if f = nil then
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    66
        getThemeIcon:= 0
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    67
    else
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    68
    begin
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    69
        getThemeIcon:= pfsBlockRead(f, buffer, buflen);
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    70
        pfsClose(f)
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    71
    end;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    72
end;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    73
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    74
end.