///////////////////////////////////////////////////////////////////////////////
//                            Lisaac OS Library                              //
//                                                                           //
//                   LSIIT - ULP - CNRS - INRIA - FRANCE                     //
//                                                                           //
//   This program is free software: you can redistribute it and/or modify    //
//   it under the terms of the GNU General Public License as published by    //
//   the Free Software Foundation, either version 3 of the License, or       //
//   (at your option) any later version.                                     //
//                                                                           //
//   This program is distributed in the hope that it will be useful,         //
//   but WITHOUT ANY WARRANTY; without even the implied warranty of          //
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
//   GNU General Public License for more details.                            //
//                                                                           //
//   You should have received a copy of the GNU General Public License       //
//   along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
//                                                                           //
//                     http://isaacproject.u-strasbg.fr/                     //
///////////////////////////////////////////////////////////////////////////////
Section Header
  
  + name        := ENTRY;

  - copyright   := "2003-2005 Jérome Boutet, 2003-2007 Benoit Sonntag";
    
  - bibliography:= "http://IsaacOS.com";

  - author      := "Benoit Sonntag (bsonntag@loria.fr), Jerome Boutet (boutet@loria.fr)";  

  - comment     := "Entry ANSI";
  
  - external := 
`
SYSTEMTIME systime;
WIN32_FIND_DATA data2;
HANDLE hfile2;
`;
  
Section Inherit
  
  + parent_abstract_entry:Expanded ABSTRACT_ENTRY;
    
Section Public  
    
  //
  // Physical implementation.
  //

  - physical_make:BOOLEAN <-
  ( + pe:NATIVE_ARRAY[CHARACTER];
    + result:BOOLEAN;
    
    pe := path.to_external;
    `hfile2 = FindFirstFile(@pe,&data2)`;
    result := `hfile2 != INVALID_HANDLE_VALUE`:BOOLEAN(TRUE,FALSE);
    (result).if {
      is_directory := `(data2.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0`:BOOLEAN(TRUE,FALSE);
      `FileTimeToSystemTime(&data2.ftLastAccessTime,&systime)`;
      access_date := to_date;
      access_time := to_time;
      `FileTimeToSystemTime(&data2.ftLastWriteTime,&systime)`;
      update_date := to_date;
      update_time := to_time;
      size := `(data2.nFileSizeHigh << 16)|data2.nFileSizeLow`:UINTEGER_32;
      `FindClose(hfile2)`;
    };
    result
  );
  
  - physical_remove_directory:BOOLEAN <-
  ( + p:NATIVE_ARRAY[CHARACTER];
    p := path.to_external;
    `rmdir(@p)`:(INTEGER) = 0
  );
  
  - physical_remove_file:BOOLEAN <-
  ( + p:NATIVE_ARRAY[CHARACTER];
    p := path.to_external;
    `remove(@p)`:(INTEGER) = 0
  );
  
  - physical_rename old_path:ABSTRACT_STRING with new_path:ABSTRACT_STRING :BOOLEAN <-
  ( + old_p,new_p:NATIVE_ARRAY[CHARACTER];
    old_p := old_path.to_external;
    new_p := new_path.to_external;
    `rename(@old_p,@new_p)`:(INTEGER) = 0
  );
  
Section Private
  
  - to_date:DATE <-
  ( + y:UINTEGER_16;
    + m,d,wd:UINTEGER_8;
    
    y  := `systime.wYear`:UINTEGER_16;
    m  := `systime.wMonth`:UINTEGER_8;
    d  := `systime.wDay`:UINTEGER_8;
    wd := `systime.wDayOfWeek`:UINTEGER_8;
    DATE.create (y,m,d,wd)
  );
  
  - to_time:TIME <-
  ( + h,m,s,cs:UINTEGER_8;
    
    h  := `systime.wHour`:UINTEGER_8;
    m  := `systime.wMinute`:UINTEGER_8;
    s  := `systime.wSecond`:UINTEGER_8;
    cs := `systime.wMilliseconds/10`:UINTEGER_8;
    TIME.create (h,m,s,cs) 
  );