{$F+,I-,O-,R-,S-,V-,G+,N+,X+}

{$IFDEF Ver70}

{$T-}                                                                  {!!.10}

{$ENDIF}



{---

  Vor dem Benutzen dieser Unit oder ndern eines DEFINE's LFN.GER lesen!

  Ein deutscher Interfaceteils ist in LFNINT.GER verfgbar.

  Eine deutsche FILE_ID.DIZ ist in LFN_IDG.DIZ verfgbar.

  Siehe WHATSNEW.GER fr die nderungen nach der letzten Version.



  Before integrate this unit or changing any DEFINE's read LFN.ENG!

  An english interfacepart is in LFNINT.ENG avaible.

  An english FILE_ID.DIZ is in LFN_IDE.DIZ avaible.

  See WHATSNEW.ENG for the changes after the last version.

---}



{-Conditional DEFINE's that affect this unit}

{$I LFN.IN0}



{$IFDEF Dpmi}

  {$C FIXED PRELOAD PERMANENT}

{$ENDIF}



{$IFDEF Windows}

  {$C FIXED PRELOAD PERMANENT}

{$ENDIF}



unit

  LFN;



  {--------------------------------------------------------------------}

  {-                   LFN.PAS v1.10 Final Release                    -}

  {-          Support of long filenames under Win95/98 for            -}

  {-              TP6, TP/BP7 und compatible compilers.               -}

  {-             Written by Andreas Killer, Germany, NRW              -}

  {-      homepage: http://home.t-online.de/home/andreas.killer       -}

  {--------------------------------------------------------------------}



interface

uses

{$IFDEF UseOpro}

  OpString, OpInline,

{$ENDIF}

{$IFDEF Windows}

  WinProcs,

{$ENDIF}

{$IFDEF UseDos}

  Dos

  {$IFDEF UseWinDos} , {$ELSE}

    {$IFDEF Ver70} , Strings ; {$ELSE} ; {$ENDIF}

  {$ENDIF}

{$ENDIF}

{$IFDEF UseWinDos}

  WinDos, Strings;

{$ENDIF}



{$IFDEF Ver60}

type

  PChar = ^Char;                                                       {!!.07}

{$ENDIF}



const

  {-It's possible to create filenames with a clear alias (the number after

    the ~ i.E.: ABCDEF~1) to make it easier identificate the file under MSDOS.

    0 = set/get alias automatically.}

  FileAlias : Byte = 0;



{$IFDEF AssignLongName}

type

  {-Note: In "var F" will have the respective filevariable.}

  AssignNewProc = procedure(var F; FName : PChar);                     {!!.07}

  AssignGetNameFunc = function(var F) : Pointer;

  AssignDisposeProc = procedure(var F);

var

  {-This procedure is used to put the filename on the heap}

  AssignNew : AssignNewProc;

  {-Returns a pointer to the filename}

  AssignGetName : AssignGetNameFunc;

  {-Deallocates the filename on heap}

  AssignDispose : AssignDisposeProc;

{$ENDIF}



{.F-}

const

  {-Avaible flags for Filemode:}

  fmDenyAll    = $0010;  {-file sharing mode}

  fmDenyWrite  = $0020;  {-file sharing mode}

  fmDenyRead   = $0030;  {-file sharing mode}

  fmDenyNone   = $0040;  {-file sharing mode}

  fmNoInherit  = $0080;  {-no-inherit flag}

  fmNoBuffer   = $0100;  {-do not buffer data (requires that all reads/writes be exact physical sectors)}

  fmNoCompress = $0200;  {-do not compress file even if volume normally compresses files}

  fmUseAlias   = $0400;  {-use alias hint in DI as numeric tail for short-name alias}

  {-Anmerkung: fmUseAlias wird automatisch gesetzt wenn FileAlias einen Wert <> 0 hat.}

  fmError24    = $2000;  {-return error code instead of generating INT 24h if critical error while opening file}

  fmCommit     = $4000;  {-commit file after every write operation}

{.F+}



const

  {-Avaible delimiters in the commandline (see LFN.ENG)}

  ParamDelims : set of Char = ['"'];

var

  {-Points to the commandline (see EXREDIR.PAS)}

  ParamPtr : ^String;



function ParamLine : String;

  {-Returns the complete commandline}

function ParamPosition(Index : Word) : Word;

  {-Returns the position of a parameter in the commandline}



  {=============================== Section 1: ==============================}

  {================ Alternate routines that replaces others ================}

  {=========================================================================}



type

  {-This record must be expanded, because DOS.SearchRec can hold filename of

    12 chars long only.}

  SearchRec =

    record

      Fill : array[1..21] of Byte;

      Attr : Byte;

      Time : LongInt;

      Size : LongInt;

      {$IFDEF CompatToDos}

      Name : String;              {-String of the long filename}

      {$ELSE}

      Name : array[0..259] of Char; {-AsciiZ of the long filename}

      {$ENDIF}

      Handle : Word;              {-Filehandle for Find-First,-Next,-Close}

    end;



{$IFDEF CompatToDos}

procedure FindFirst(Path : String; Attr : Word; var F : SearchRec);

  {-Search a directory for the first entry of a filename}

{$ELSE}

type

  TSearchRec = SearchRec;



procedure FindFirst(Path : PChar; Attr : Word; var F : TSearchRec);

  {-Search a directory for the first entry of a filename}

{$ENDIF}



procedure FindNext(var F : SearchRec);

  {-Continues a search started with FindFirst}

procedure FindClose(var F : SearchRec);

  {-Closes a search started with FindFirst. FindClose will be called automatically

    from FindNext if no more files are found. Attention: If this condition will

    NOT be happen, than FindClose MUST called to free the filehandle taken by

    FindFirst. Under MSDOS this proc does nothing.}



type

  PathStr = String;               {!!.05}

  DirStr = String;

  NameStr = String;

  ExtStr = String;



{$IFDEF UseDos}

procedure FSplit(Path : String; var Dir : DirStr; var Name : NameStr;

                 var Ext : ExtStr);

  {-Splits a pathname in it's 3 components}

function FExpand(Path : PathStr) : PathStr;

  {-Expands a filename with it path}

{$ENDIF}



function DiskFree(Drive : Byte) :

  {$IFDEF DFSReturnComp} Comp ; {$ELSE} LongInt; {$ENDIF}

  {-Returns the free size of a drive}

function DiskSize(Drive : Byte) :

  {$IFDEF DFSReturnComp} Comp ; {$ELSE} LongInt; {$ENDIF}

  {-Returns the size of a drive}



{---

  Note: DiskFree/DiskSize use the AX=$7303/INT $21 call. These function

  will work properly under Windows/DOS7.x, but if you develop a program in the

  IDE (Turbo or BP), then the correct result is only returned on the first run

  of the program. I dont know why this happens.

---}



  {=============================== Section 2: ==============================}

  {====== Extended routines, can be used under DOS also (see LFN.ENG): =====}

  {=========================================================================}



procedure SetCreateFTime(var F; Time : LongInt);

  {-Sets date and time of creation of a file}

procedure GetCreateFTime(var F; var Time : LongInt);

  {-Gets date and time of creation of a file}



{$IFDEF UseDos}

function TruePathName(PathName : String) : String;

  {-Returns the shortest path to a file or expand the filename with the

    current directory}

function GetShortName(PathName : String) : String;

  {-Change a long filename in a short one}

function GetLongName(PathName : String) : String;

  {-Change a short filename in a long one. (Under MSDOS allways a short name

    is returned)}

{$ENDIF}



{$IFDEF UseWinDos}

function TruePathNamePChar(Dest, PathName : PChar) : PChar;

  {-Returns the shortest path to a file or expand the filename with the

    current directory}

function GetShortNamePChar(Dest, PathName : PChar) : PChar;

  {-Change a long filename in a short one}

function GetLongNamePChar(Dest, PathName : PChar) : PChar;

  {-Change a short filename in a long one. (Under MSDOS allways a short name

    is returned)}

{$ENDIF}



procedure FlushDrive(Drive : Byte);

  {-Force to write the buffer and cache to disk.

      Drive can be: 0 = current drive, 1 = drive A, etc.}

procedure ResetDrive(Drive : Byte);

  {-Force to write and clear the buffer and cache to disk.

      Drive can be: 0 = current drive, 1 = drive A, etc.}

function IsNetworkDrive(Drive : Char) : Boolean;

  {-True if drive is a remote drive}



  {========================================================================}



function Win95_Aktiv : Boolean;

  {-True if Win95 or above is running}

procedure EnableLFN;

  {-Activiates the support for long filenames}

procedure DisableLFN;

  {-Deactiviates the support for long filenames}



  {========================================================================}



implementation

