From: Ketmar Dark Date: Sun, 13 Oct 2019 00:21:38 +0000 (+0300) Subject: utils: added `GetDiskFileInfo()` function X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=7ddf228d373859083726fdead73c4d84c8f05716;p=d2df-sdl.git utils: added `GetDiskFileInfo()` function --- diff --git a/src/shared/utils.pas b/src/shared/utils.pas index 5ef5884..867f0dc 100644 --- a/src/shared/utils.pas +++ b/src/shared/utils.pas @@ -18,7 +18,7 @@ unit utils; interface uses - SysUtils, Classes; + SysUtils, Classes, md5; // ////////////////////////////////////////////////////////////////////////// // @@ -277,6 +277,21 @@ procedure CopyMemory (Dest: Pointer; Src: Pointer; Len: LongWord); inline; procedure ZeroMemory (Dest: Pointer; Len: LongWord); inline; +type + TDiskFileInfo = record + diskName: AnsiString; + size: LongInt; + age: LongInt; + // not changed by info getter; used in other parts of the code + userName: AnsiString; + tag: Integer; + hash: TMD5Digest; + udata: Pointer; + end; + +function GetDiskFileInfo (fname: AnsiString; var info: TDiskFileInfo): Boolean; + + implementation uses @@ -1997,6 +2012,32 @@ begin end; +function GetDiskFileInfo (fname: AnsiString; var info: TDiskFileInfo): Boolean; +var + age: LongInt; + size: LongInt; + handle: THandle; +begin + result := false; + if (length(fname) = 0) then exit; + if not findFileCI(fname) then exit; + // get age + age := FileAge(fname); + if (age = -1) then exit; + // get size + handle := FileOpen(fname, fmOpenRead or fmShareDenyNone); + if (handle = THandle(-1)) then exit; + size := FileSeek(handle, 0, fsFromEnd); + FileClose(handle); + if (size = -1) then exit; + // fill info + info.diskName := fname; + info.size := size; + info.age := age; + result := true; +end; + + (* var ss: ShortString;