aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UPlatformWindows.pas
blob: eb4323358298290c6976e90fee6a1d24fe53f8af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
unit UPlatformWindows;

interface

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

{$I switches.inc}

uses Classes, UPlatform;

type

  TPlatform = class(TInterfacedObject, IPlatform)
  public
    Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; 
  end;

implementation

uses SysUtils, Windows;

Function TPlatform.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; 
var
    i : Integer;
    SR : TSearchRecW;
begin
  i := 0;
  Filter := LowerCase(Filter);

  if ReturnAllSubDirs then begin
    if FindFirstW(Dir + '*', faDirectory, SR) = 0 then
    repeat
      if (SR.Name <> '.') and (SR.Name <> '..') then
      begin
        SetLength( Result, i + 1);
        Result[i].Name        := SR.Name;
        Result[i].IsDirectory := true;
        Result[i].IsFile      := false;
        i := i + 1;
      end;
    until FindNextW(SR) <> 0;
    FindCloseW(SR);
  end;
  
  if FindFirstW(Dir + '*' + Filter, 0, SR) = 0 then
  repeat
    SetLength( Result, i + 1);
    Result[i].Name        := SR.Name;
    Result[i].IsDirectory := true;
    Result[i].IsFile      := false;
    i := i + 1;
  until FindNextW(SR) <> 0;
  FindCloseW(SR);
end;

end.