aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-02-20 03:34:43 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-02-20 03:34:43 +0000
commit1a94097c5baccf831bc85befa159b2b02c3c0bc3 (patch)
tree482ac562e421185626208518dcec015dab33fd1b
parent2c57e4b07526db9a959174d6f91688f34608824d (diff)
downloadusdx-1a94097c5baccf831bc85befa159b2b02c3c0bc3.tar.gz
usdx-1a94097c5baccf831bc85befa159b2b02c3c0bc3.tar.xz
usdx-1a94097c5baccf831bc85befa159b2b02c3c0bc3.zip
Fixed a bug in the directory-handling routine.
USDX tried to close directories that might not have been opened (TheDir=nil) before. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@867 b956fd51-792f-4845-bead-9b4dfca2ff2c
-rw-r--r--Game/Code/Classes/UPlatformLinux.pas93
1 files changed, 49 insertions, 44 deletions
diff --git a/Game/Code/Classes/UPlatformLinux.pas b/Game/Code/Classes/UPlatformLinux.pas
index b3c78a10..71a75a6b 100644
--- a/Game/Code/Classes/UPlatformLinux.pas
+++ b/Game/Code/Classes/UPlatformLinux.pas
@@ -44,6 +44,7 @@ uses
oldlinux,
{$ENDIF}
SysUtils,
+ ULog,
UConfig;
{$IFDEF FPC_VERSION_2_2_0_PLUS}
@@ -61,32 +62,34 @@ begin
TheDir := FpOpenDir( Dir );
if Assigned(TheDir) then
- repeat
- ADirent := FpReadDir(TheDir^);
+ begin
+ repeat
+ ADirent := FpReadDir(TheDir^);
- If Assigned(ADirent) and (ADirent^.d_name <> '.') and (ADirent^.d_name <> '..') then
- begin
- lAttrib := FileGetAttr(Dir + ADirent^.d_name);
- if ReturnAllSubDirs and ((lAttrib and faDirectory) <> 0) then
- begin
- SetLength( Result, i + 1);
- Result[i].Name := ADirent^.d_name;
- Result[i].IsDirectory := true;
- Result[i].IsFile := false;
- i := i + 1;
- end
- else if (Length(Filter) = 0) or (Pos( Filter, LowerCase(ADirent^.d_name)) > 0) then
+ If Assigned(ADirent) and (ADirent^.d_name <> '.') and (ADirent^.d_name <> '..') then
begin
- SetLength( Result, i + 1);
- Result[i].Name := ADirent^.d_name;
- Result[i].IsDirectory := false;
- Result[i].IsFile := true;
- i := i + 1;
+ lAttrib := FileGetAttr(Dir + ADirent^.d_name);
+ if ReturnAllSubDirs and ((lAttrib and faDirectory) <> 0) then
+ begin
+ SetLength( Result, i + 1);
+ Result[i].Name := ADirent^.d_name;
+ Result[i].IsDirectory := true;
+ Result[i].IsFile := false;
+ i := i + 1;
+ end
+ else if (Length(Filter) = 0) or (Pos( Filter, LowerCase(ADirent^.d_name)) > 0) then
+ begin
+ SetLength( Result, i + 1);
+ Result[i].Name := ADirent^.d_name;
+ Result[i].IsDirectory := false;
+ Result[i].IsFile := true;
+ i := i + 1;
+ end;
end;
- end;
- Until ADirent = nil;
+ until (ADirent = nil);
- FpCloseDir(TheDir^);
+ FpCloseDir(TheDir^);
+ end;
end;
{$ELSE}
Function TPlatformLinux.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray;
@@ -103,32 +106,34 @@ begin
TheDir := oldlinux.opendir( Dir );
if Assigned(TheDir) then
- repeat
- ADirent := oldlinux.ReadDir(TheDir);
+ begin
+ repeat
+ ADirent := oldlinux.ReadDir(TheDir);
- If Assigned(ADirent) and (ADirent^.name <> '.') and (ADirent^.name <> '..') then
- begin
- lAttrib := FileGetAttr(Dir + ADirent^.name);
- if ReturnAllSubDirs and ((lAttrib and faDirectory) <> 0) then
- begin
- SetLength( Result, i + 1);
- Result[i].Name := ADirent^.name;
- Result[i].IsDirectory := true;
- Result[i].IsFile := false;
- i := i + 1;
- end
- else if (Length(Filter) = 0) or (Pos( Filter, LowerCase(ADirent^.name)) > 0) then
+ If Assigned(ADirent) and (ADirent^.name <> '.') and (ADirent^.name <> '..') then
begin
- SetLength( Result, i + 1);
- Result[i].Name := ADirent^.name;
- Result[i].IsDirectory := false;
- Result[i].IsFile := true;
- i := i + 1;
+ lAttrib := FileGetAttr(Dir + ADirent^.name);
+ if ReturnAllSubDirs and ((lAttrib and faDirectory) <> 0) then
+ begin
+ SetLength( Result, i + 1);
+ Result[i].Name := ADirent^.name;
+ Result[i].IsDirectory := true;
+ Result[i].IsFile := false;
+ i := i + 1;
+ end
+ else if (Length(Filter) = 0) or (Pos( Filter, LowerCase(ADirent^.name)) > 0) then
+ begin
+ SetLength( Result, i + 1);
+ Result[i].Name := ADirent^.name;
+ Result[i].IsDirectory := false;
+ Result[i].IsFile := true;
+ i := i + 1;
+ end;
end;
- end;
- Until ADirent = nil;
+ until (ADirent = nil);
- oldlinux.CloseDir(TheDir);
+ oldlinux.CloseDir(TheDir);
+ end;
end;
{$ENDIF}