Browse Source

* DOS<->Win filetime conversion was fixed.
* FileExists fix from Win32 was applied.

git-svn-id: trunk@1405 -

yury 20 years ago
parent
commit
3239011837
2 changed files with 60 additions and 30 deletions
  1. 45 8
      rtl/wince/dos.pp
  2. 15 22
      rtl/wince/sysutils.pp

+ 45 - 8
rtl/wince/dos.pp

@@ -33,6 +33,9 @@ Type
 
 
 {$i dosh.inc}
 {$i dosh.inc}
 
 
+Function WinToDosTime (Const Wtime : TFileTime; var DTime:longint):longbool;
+Function DosToWinTime (DTime:longint; var Wtime : TFileTime):longbool;
+
 implementation
 implementation
 
 
 {$DEFINE HAS_GETMSCOUNT}
 {$DEFINE HAS_GETMSCOUNT}
@@ -73,16 +76,50 @@ begin
   WinToDosAttr:=Attr;
   WinToDosAttr:=Attr;
 end;
 end;
 
 
-
-Function DosToWinTime (DTime:longint;Var Wtime : TFileTime):longbool;
+type
+  Longrec=packed record
+    lo,hi : word;
+  end;
+  
+Function DosToWinTime (DTime:longint; var Wtime : TFileTime):longbool;
+var
+  FatDate, FatTime: WORD;
+  lft: TFileTime;
+  st: SYSTEMTIME;
 begin
 begin
-  DosToWinTime:=False;  //!!! fixme
+  FatDate:=Longrec(Dtime).Hi;
+  FatTime:=Longrec(Dtime).Lo;
+  with st do
+  begin
+    wDay:=FatDate and $1F;
+    wMonth:=(FatDate shr 5) and $F;
+    wYear:=(FatDate shr 9) + 1980;
+    wSecond:=(FatTime and $1F)*2;
+    wMinute:=(FatTime shr 5) and $1F;
+    wHour:=FatTime shr 11;
+    wMilliseconds:=0;
+    wDayOfWeek:=0;
+  end;
+  DosToWinTime:=SystemTimeToFileTime(@st, @lft) and LocalFileTimeToFileTime(@lft, @Wtime);
 end;
 end;
 
 
 
 
-Function WinToDosTime (Const Wtime : TFileTime;var DTime:longint):longbool;
+Function WinToDosTime (Const Wtime : TFileTime; var DTime:longint):longbool;
+var
+  FatDate, FatTime: WORD;
+  lft: TFileTime;
+  st: SYSTEMTIME;
+  res: longbool;
 begin
 begin
-  WinToDosTime:=False; //!!! fixme
+  res:=FileTimeToLocalFileTime(@WTime, @lft) and FileTimeToSystemTime(@lft, @st);
+  if res then
+  begin
+    FatDate:=st.wDay or (st.wMonth shl 5) or ((st.wYear - 1980) shl 9);
+    FatTime:=(st.wSecond div 2) or (st.wMinute shl 5) or (st.wHour shl 11);
+    Longrec(Dtime).Hi:=FatDate;
+    Longrec(Dtime).Lo:=FatTime;
+  end;
+  WinToDosTime:=res;
 end;
 end;
 
 
 
 
@@ -481,17 +518,17 @@ end;
 
 
 function envcount : longint;
 function envcount : longint;
 begin
 begin
-  envcount:=0; //!!! fixme
+  envcount:=0;
 end;
 end;
 
 
 Function EnvStr (Index: longint): string;
 Function EnvStr (Index: longint): string;
 begin
 begin
-  EnvStr:=''; //!!! fixme
+  EnvStr:='';
 end;
 end;
 
 
 Function  GetEnv(envvar: string): string;
 Function  GetEnv(envvar: string): string;
 begin
 begin
-  GetEnv:=''; //!!! fixme
+  GetEnv:='';
 end;
 end;
 
 
 var
 var

+ 15 - 22
rtl/wince/sysutils.pp

@@ -216,13 +216,13 @@ end;
 
 
 Function DosToWinTime (DTime:longint; out Wtime : TFileTime):longbool;
 Function DosToWinTime (DTime:longint; out Wtime : TFileTime):longbool;
 begin
 begin
-  DosToWinTime:=False;  //!!! fixme
+  DosToWinTime:=dos.DosToWinTime(DTime, Wtime);
 end;
 end;
 
 
 
 
 Function WinToDosTime (Const Wtime : TFileTime; out DTime:longint):longbool;
 Function WinToDosTime (Const Wtime : TFileTime; out DTime:longint):longbool;
 begin
 begin
-  WinToDosTime:=False; //!!! fixme
+  WinToDosTime:=dos.WinToDosTime(Wtime, DTime);
 end;
 end;
 
 
 
 
@@ -248,29 +248,23 @@ end;
 
 
 Function FileExists (Const FileName : String) : Boolean;
 Function FileExists (Const FileName : String) : Boolean;
 var
 var
-  Handle: THandle;
-  FindData: TWin32FindData;
-  fn: PWideChar;
+  Attr:Dword;
 begin
 begin
-  fn:=StringToPWideChar(FileName);
-  Handle := FindFirstFile(PWideChar(widestring(FileName)), FindData);
-  FreeMem(fn);
-  Result:=Handle <> INVALID_HANDLE_VALUE;
-  If Result then
-    Windows.FindClose(Handle);
+  Attr:=FileGetAttr(FileName);
+  if Attr <> $ffffffff then
+    Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0
+  else
+    Result:=False;
 end;
 end;
 
 
 
 
 Function DirectoryExists (Const Directory : String) : Boolean;
 Function DirectoryExists (Const Directory : String) : Boolean;
 var
 var
   Attr:Dword;
   Attr:Dword;
-  fn: PWideChar;
 begin
 begin
-  fn:=StringToPWideChar(Directory);
-  Attr:=GetFileAttributes(fn);
-  FreeMem(fn);
+  Attr:=FileGetAttr(Directory);
   if Attr <> $ffffffff then
   if Attr <> $ffffffff then
-    Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) > 0
+    Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) <> 0
   else
   else
     Result:=False;
     Result:=False;
 end;
 end;
@@ -339,7 +333,7 @@ Var
   FT : TFileTime;
   FT : TFileTime;
 begin
 begin
   If GetFileTime(Handle,nil,nil,@ft) and
   If GetFileTime(Handle,nil,nil,@ft) and
-     WinToDosTime(FT,Result) then
+     WinToDosTime(FT, Result) then
     exit;
     exit;
   Result:=-1;
   Result:=-1;
 end;
 end;
@@ -350,8 +344,7 @@ Var
   FT: TFileTime;
   FT: TFileTime;
 begin
 begin
   Result := 0;
   Result := 0;
-  if DosToWinTime(Age,FT) and
-    SetFileTime(Handle, ft, ft, FT) then
+  if DosToWinTime(Age, FT) and SetFileTime(Handle, FT, FT, FT) then
     Exit;
     Exit;
   Result := GetLastError;
   Result := GetLastError;
 end;
 end;
@@ -651,17 +644,17 @@ end;
 
 
 Function GetEnvironmentVariable(Const EnvVar : String) : String;
 Function GetEnvironmentVariable(Const EnvVar : String) : String;
 begin
 begin
-  Result := ''; //!!! fixme
+  Result := '';
 end;
 end;
 
 
 Function GetEnvironmentVariableCount : Integer;
 Function GetEnvironmentVariableCount : Integer;
 begin
 begin
-  Result := 0; //!!! fixme
+  Result := 0;
 end;
 end;
 
 
 Function GetEnvironmentString(Index : Integer) : String;
 Function GetEnvironmentString(Index : Integer) : String;
 begin
 begin
-  Result := ''; //!!! fixme
+  Result := '';
 end;
 end;