1
0
mirror of https://bitbucket.org/Dennis07/lina-components.git synced 2025-08-24 21:49:04 +02:00

Version 1.0 DEV 1.07a

Signed-off-by: Dennis07 <den.goehlert@t-online.de>
This commit is contained in:
Dennis07
2014-09-16 03:14:30 +02:00
parent 271b68d229
commit 898d52e080
15 changed files with 177 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
These statistics cover the official repository of Lina Components.
Total lines of code (LoC): 3800+
Total visual components (VC): 9
Total lines of code (LoC): 4000+
Total visual components (VC): 11

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -6,11 +6,15 @@ unit uFileTools;
/// (c) 2014 Dennis G�hlert a.o. ///
//////////////////////////////////////
{$IFNDEF MSWINDOWS}
{$MESSAGE ERROR 'The "uFileTools" unit is only available under MS-Windows OS'}
{$ENDIF}
interface
uses
{ Standard-Units }
Classes, SysUtils, ShellAPI, Forms, Windows, Dialogs,
Classes, SysUtils, ShellAPI, Forms, Windows, Math,
{$IFNDEF NO_GENERIC}
Generics.Collections,
{$ENDIF}
@@ -24,6 +28,7 @@ type
EMissingTypeDesc = class(Exception);
EMissingExts = class(Exception);
EInvalidStyle = class(Exception);
ENoGetFileOwner = class(Exception);
type
{ Hilfsklassen }
@@ -33,6 +38,23 @@ type
type
{ Hauptklassen }
TWinFileInfo = class
private
{ Private-Deklarationen }
FFileName: String;
public
{ Public-Deklarationen }
constructor Create(AFileName: String);
destructor Destroy; override;
property FileName: String read FFileName;
{ function GetSignature: String;
function GetVersionStructure: Integer;
function GetVersionFileMS: Integer;
function GetVersionFileLS: Integer;
function GetVersionProductMS: Integer;
function GetVersionProductLS: Integer; }
end;
TWinDrive = class
private
{ Private-Deklarationen }
@@ -52,6 +74,7 @@ type
FFileName: String;
FExecuteMode: TFileExecuteMode;
FDrive: TWinDrive;
FInfo: TWinFileInfo;
public
{ Public-Deklarationen }
constructor Create(AFileName: String);
@@ -59,15 +82,16 @@ type
property FileName: String read FFileName;
property ExecuteMode: TFileExecuteMode read FExecuteMode write FExecuteMode;
property Drive: TWinDrive read FDrive write FDrive;
property Info: TWinFileInfo read FInfo write FInfo;
function GetExtension(WithDot: Boolean = True): String; //ExtractFileExt()
function GetPath: String; //ExtractFilePath()
function GetDir: String; //ExtractFileDir()
function GetFileName(WithExt: Boolean = True): String; //ExtractFileName()
function GetFolderName: String; //ExtractFileFolder()
function GetSize: Int64; //GetFileSize()
// GetVersion: Extended //GetFileVerion()
//function GetVersion: Extended;
function GetAttributes: TFileAttributes; //GetFileAttributes();
// GetOwner: String
function GetOwner: String;
function GetModified: TDateTime; //GetFileModified()
function GetCreated: TDateTime; //GetFileCreated()
function GetAccessed: TDateTime; //GetFileAccessed()
@@ -93,13 +117,36 @@ type
function ExtractDriveChar(const FileName: String): Char;
function DriveCharToFileDir(DriveChar: Char): ShortString;
function DriveCharToFilePath(DriveChar: Char): ShortString;
function FileTimeToDateTime(FileTime: TFileTime): TDateTime;
function ConvertFileSize(const InputSize: Int64; ConvertFactor: ShortInt = 2): Extended;
function GetFileSize(FileName: String): Int64;
function GetFileModified(FileName: String): TDateTime;
function GetFileCreated(FileName: String): TDateTime;
function GetFileAccessed(FileName: String): TDateTime;
function GetFileAttributes(FileName: String): TFileAttributes;
//const
const
{ Umrechnungs-Faktoren }
TB_TO_B = 4;
GB_TO_B = 3;
TB_TO_KB = 3;
MB_TO_B = 2;
GB_TO_KB = 2;
TB_TO_MB = 2;
KB_TO_B = 1;
MB_TO_KB = 1;
GB_TO_MB = 1;
TB_TO_GB = 1;
B_TO_KB = -1;
KB_TO_MB = -1;
MB_TO_GB = -1;
GB_TO_TB = -1;
B_TO_MB = -2;
KB_TO_GB = -2;
MB_TO_TB = -2;
B_TO_GB = -3;
KB_TO_TB = -3;
B_TO_TB = -4;
{ Dateierweiterungen f�r ListFiles() }
{FXT_ANY = '*.*'
FXT_EXE = ('*.exe');
@@ -272,6 +319,13 @@ begin
Result := SystemTimeToDateTime(SysTime);
end;
function ConvertFileSize(const InputSize: Int64; ConvertFactor: ShortInt = 2): Extended;
begin
{ Sollte verwendet werden mit den Umrechnungs-Faktoren, die in der globalen
"const"-Section deklariert wurden. }
Result := InputSize * Power(1024,ConvertFactor);
end;
function GetFileSize(FileName: String): Int64;
var
FileHandle: THandle;
@@ -381,6 +435,25 @@ begin
end;
end;
{ ----------------------------------------------------------------------------
TWinFileInfo
---------------------------------------------------------------------------- }
constructor TWinFileInfo.Create(AFileName: String);
begin
FFileName := AFileName;
if FileExists(FFileName) = False then
begin
raise EFileNoExist.Create('File not found: "' + FFileName + '"');
end;
end;
destructor TWinFileInfo.Destroy;
begin
//...
inherited;
end;
{ ----------------------------------------------------------------------------
TWinDrive
---------------------------------------------------------------------------- }
@@ -388,9 +461,9 @@ end;
constructor TWinDrive.Create(ADriveChar: Char);
begin
FDriveChar := ADriveChar;
if DirectoryExists(ADriveChar) = False then
if DirectoryExists(DriveCharToFileDir(FDriveChar)) = False then
begin
raise EDriveNoExist.Create('Drive not found: "' + DriveChar + '"');
raise EDriveNoExist.Create('Drive not found: "' + FDriveChar + '"');
end;
end;
@@ -454,16 +527,18 @@ constructor TWinFile.Create(AFileName: String);
begin
ExecuteMode := feOpen;
FFileName := AFileName;
Drive := TWinDrive.Create(ExtractDriveChar(FFileName));
if FileExists(AFileName) = False then
FDrive := TWinDrive.Create(ExtractDriveChar(FFileName));
FInfo := TWinFileInfo.Create(FFileName);
if FileExists(FFileName) = False then
begin
raise EFileNoExist.Create('File not found: "' + AFileName + '"');
raise EFileNoExist.Create('File not found: "' + FFileName + '"');
end;
end;
destructor TWinFile.Destroy;
begin
Drive.Free;
FDrive.Free;
FInfo.Free;
inherited;
end;
@@ -529,6 +604,48 @@ begin
Result := GetFileAttributes(FFileName);
end;
function TWinFile.GetOwner: String;
var
SecDescr: PSecurityDescriptor;
SizeNeeded, SizeNeeded2: DWORD;
OwnerSID: PSID;
OwnerDefault: BOOL;
OwnerName, DomainName: PChar;
OwnerType: SID_NAME_USE;
begin
GetMem(SecDescr, 1024);
GetMem(OwnerSID, SizeOf(PSID));
GetMem(OwnerName, 1024);
GetMem(DomainName, 1024);
try
if GetFileSecurity(PChar(FFileName),OWNER_SECURITY_INFORMATION,SecDescr,1024,SizeNeeded) = True then
begin
if GetSecurityDescriptorOwner(SecDescr,OwnerSID,OwnerDefault) = True then
begin
SizeNeeded := 1024;
SizeNeeded2 := 1024;
if LookupAccountSID(nil,OwnerSID,OwnerName,SizeNeeded,DomainName,SizeNeeded2,OwnerType) = True then
begin
Result := OwnerName + '@' + DomainName;
end else
begin
raise ENoGetFileOwner.Create('Could not determine the file owner');
end;
end else
begin
raise ENoGetFileOwner.Create('Could not determine the file owner');
end;
end else
begin
raise ENoGetFileOwner.Create('Could not determine the file owner');
end;
finally
FreeMem(SecDescr);
FreeMem(OwnerName);
FreeMem(DomainName);
end;
end;
function TWinFile.Execute: Boolean;
begin
Result := ExecuteFile(FFileName,ExecuteMode);

View File

@@ -78,13 +78,17 @@ type
function WinUserDirectory: String;
function WinUserAdmin: Boolean;
function WinUserExists(UsrNme: String): Boolean;
{ Sonstige }
function SecToTime(const Sec: Cardinal): TTime;
function SystemLanguage: String;
{ Array-Position }
function ArrayPos(const AValue: Variant; const AArray: array of Variant): Integer; overload;
function ArrayPos(const AValue: String; const AArray: array of String): Integer; overload;
function ArrayPos(const AValue: Integer; const AArray: array of Integer): Integer; overload;
function ArrayPos(const AValue: Extended; const AArray: array of Extended): Integer; overload;
{ Sonstige }
function SecToTime(const Sec: Cardinal): TTime;
function SystemLanguage: String;
function ExtractUserName(const Owner: String): String;
function ExtractUserDomain(const Owner: String): String;
function RoundPos(Number: Extended; Pos: Byte): Extended;
const
Spaces = [#9,#10,#13,#32,#160];
@@ -220,6 +224,47 @@ begin
end;
end;
function ExtractUserName(const Owner: String): String;
var
Index: Integer;
begin
for Index := 1 to Length(Owner) do
begin
if Owner[Index] = '@' then
begin
Break;
end else
begin
Result := Result + Owner[Index];
end;
end;
end;
function ExtractUserDomain(const Owner: String): String;
var
Index: Integer;
begin
for Index := Length(Owner) downto 0 do
begin
if Owner[Index] = '@' then
begin
Break;
end else
begin
Result := Result + Owner[Index];
end;
end;
end;
function RoundPos(Number: Extended; Pos: Byte): Extended;
var
Factor: Extended;
begin
Factor := IntPower(10,Pos);
Number := Round(Number * Factor);
Result := Number / Factor;
end;
function WinUserName: String;
var
Buffer: array [0..255] of Char;