///////////////////////////////////////////////////////////////////////////////
//                             Lisaac 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    := ABSTRACT_FILE_SYSTEM;


  - copyright   := "2003-2005 Jérome Boutet, 2003-2007 Benoit Sonntag";
  
  - comment := "Basic File System manager.";
  
Section Inherit  
  
  - parent_object:OBJECT := OBJECT;
  
Section Public

  //
  // Drives
  //
  
  + current_drive:STRING_CONSTANT;    // Current Drive

  + isaac_drive:STRING_CONSTANT;      // System Drive
  
  - set_drive d:STRING_CONSTANT <-
  (
    ? {d != NULL};
    current_drive := d;    
    current_dir := root;    
    current_dir.open;
  );
  
  //
  // Directories
  //
  
  - root:DIRECTORY <- deferred;
  
  + current_dir:DIRECTORY;  // Current directory
  
  - get_current_directory:DIRECTORY <-
  (
    (current_dir = NULL).if {      // FILE_SYSTEM Not Initialized
      make;
    };
    current_dir
  );
  
  - get_directory n:ABSTRACT_STRING :DIRECTORY <-
  (
    ? {n != NULL};
    (current_dir = NULL).if {      // FILE_SYSTEM Not Initialized
      make;
    };
    current_dir.get_directory n    
  );
  
  - change_directory n:ABSTRACT_STRING <-
  (
    current_dir := get_directory n;
  );
  
  //
  // Files
  //
  
  - new_file n:ABSTRACT_STRING :STD_FILE <-
  (
    ? {n != NULL};
    (current_dir = NULL).if {      // FILE_SYSTEM Not Initialized
      make;
    };
    current_dir.new_file n
  );
  
  - get_file_type n:ABSTRACT_STRING :STD_FILE <-
  // Return file Type Format
  ( + result:STD_FILE;
    ? {n != NULL};
    (AI_FILE.is_type n).if {
      result := AI_FILE;
    }.elseif {BMP_FILE.is_type n} then {
      result := BMP_FILE;
    } else {
      result := STD_FILE;
    };
    result
  );
  
  - get_file n:ABSTRACT_STRING :STD_FILE <-
  (
    ? {n != NULL};
    (current_dir = NULL).if {      // FILE_SYSTEM Not Initialized
      make;
    };
    current_dir.get_file n
  );
  
  - size:INTEGER <-
  // Size of all files of the file system
  ( 
    (current_dir = NULL).if {      // FILE_SYSTEM Not Initialized
      make;
    };
    root.size
  );
  
  //
  // Init
  //
  
  - physical_init <- deferred;
  
  - make <-
  (
    physical_init;
    set_drive isaac_drive;
  );
