Стартовый пул

This commit is contained in:
2024-04-02 08:46:59 +03:00
parent fd57fffd3a
commit 3bb34d000b
5591 changed files with 3291734 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
unit ANBFormatString;
{$MODE Delphi}
{$codepage UTF8}
interface
uses StrUtils, SysUtils, VCLEx;
{stdcalls}
function FormatStr(const AFrmtdStr: String; const AArgs, AArgsValues: array of String): String; STDCALL;
function FormatStrW(const AFrmtdStr: WideString; const AArgs, AArgsValues: array of WideString): WideString; STDCALL;
implementation
function SearchAndReplaceStr(const AStr, ASearchStr, AReplaceStr: String): String;
var CurrDelim, NextDelim: IntEx;
ElemName, s: String;
begin
s:= '';
CurrDelim:= 1;
repeat
NextDelim:= PosEx(ASearchStr, AStr, CurrDelim);
if NextDelim = 0 then
NextDelim:= Length(AStr) + 1;
ElemName:= Copy(AStr, CurrDelim, NextDelim - CurrDelim);
if not (NextDelim > Length(AStr)) then
s:= s + ElemName + AReplaceStr
else
s:= s + ElemName;
CurrDelim:= NextDelim + Length(ASearchStr);
until CurrDelim > Length(AStr);
Result:= s;
end;
{Only for Windows}
function SearchAndReplaceStrW(const AStr, ASearchStr, AReplaceStr: WideString): WideString;
var CurrDelim, NextDelim: IntEx;
ElemName, s: WideString;
begin
s:= '';
CurrDelim:= 1;
repeat
NextDelim:= PosEx(ASearchStr, AStr, CurrDelim);
if NextDelim = 0 then
NextDelim:= Length(AStr) + 1;
ElemName:= Copy(AStr, CurrDelim, NextDelim - CurrDelim);
if not (NextDelim > Length(AStr)) then
s:= s + ElemName + AReplaceStr
else
s:= s + ElemName;
CurrDelim:= NextDelim + Length(ASearchStr);
until CurrDelim > Length(AStr);
Result:= s;
end;
function FormatStr(const AFrmtdStr: string; const AArgs, AArgsValues: array of String): String;
var i: IntEx;
s: String;
begin
s:= AFrmtdStr;
if High(AArgs) <> High(AArgsValues) then
raise Exception.Create('Array of arguments not equal array of its values!');
for i:= 0 to High(AArgs) do
s:= SearchAndReplaceStr(s, AArgs[i], AArgsValues[i]);
Result:= s;
end;
{Only for Windows}
function FormatStrW(const AFrmtdStr: WideString; const AArgs, AArgsValues: array of WideString): WideString;
var i: IntEx;
s: WideString;
begin
s:= AFrmtdStr;
if High(AArgs) <> High(AArgsValues) then
raise Exception.Create('Array of arguments not equal array of its values!');
for i:= 0 to High(AArgs) do
s:= SearchAndReplaceStrW(s, AArgs[i], AArgsValues[i]);
Result:= s;
end;
end.

View File

@@ -0,0 +1,401 @@
unit ANBInputBox;
{$MODE Delphi}
{$codepage UTF8}
interface
uses LCLIntf, LCLType, SysUtils, Graphics, Controls, Forms, StdCtrls, Classes, Types, MaskEdit, Spin, VCLEx;
function ShowInputBox (const ACaption, APrompt, ADefault: String; var isAccept: Boolean): String; OVERLOAD; STDCALL;
function ShowInputBox (const ACaption, APrompt, ADefault: String; const ABtnCaptions: array of String; var isAccept: Boolean): String; OVERLOAD; STDCALL;
function ShowInputBox (const ACaption, APrompt, ADefault: String; const ABtnCaptions: array of String; const AMaxLength: IntEx; var isAccept: Boolean): String; OVERLOAD; STDCALL;
function ShowPasswordInputBox (const ACaption, APrompt, ADefault, APassword: String; var isAccept, isPasswordConfirmed: Boolean; const APasswordChar: Char = '*'): String; OVERLOAD; STDCALL;
function ShowPasswordInputBox (const ACaption, APrompt, ADefault, APassword: String; var isAccept, isPasswordConfirmed: Boolean; const ABtnCaptions: array of String; const APasswordChar: Char = '*'): String; OVERLOAD; STDCALL;
function ShowComboBox (const ACaption, APrompt: String; var Items: TStringList; const ADefaultIndex: IntEx; var isAccept: Boolean): IntEx; OVERLOAD; STDCALL;
function ShowComboBox (const ACaption, APrompt: String; var Items: TStringList; const ADefaultIndex: IntEx; const ABtnsCaption: array of String; var isAccept: Boolean): IntEx; OVERLOAD; STDCALL;
function ShowMaskedBox (const ACaption, APrompt, AMask, ADefault: String; const isIgnoreMask: Boolean; var isAccept: Boolean): String; OVERLOAD; STDCALL;
function ShowMaskedBox (const ACaption, APrompt, AMask, ADefault: String; const isIgnoreMask: Boolean; const ABtnCaptions: array of String; const AMaxLength: IntEx; var isAccept: Boolean): String; OVERLOAD; STDCALL;
function ShowSpinedBox (const ACaption, APrompt: String; const ADefault: IntEx; var isAccept: Boolean): IntEx; STDCALL; OVERLOAD;
function ShowSpinedBox (const ACaption, APrompt: String; const ADefault, AMinValue, AMaxValue: IntEx; const ABtnCaptions: array of String; var isAccept: Boolean): IntEx; STDCALL; OVERLOAD;
const OkBtnDefCaption: String = '&Ok';
CancelBtnDefCaption: String = 'C&ancel';
implementation
function MyGetAveCharSize(Canvas: TCanvas): TPoint;
var I: IntEx;
Buffer: array[0..51] of Char;
begin
with Result do
begin
x:= 0;
y:= 0;
end;
for I:= 0 to 25 do
Buffer[I]:= Chr(I + Ord('A'));
for I:= 0 to 25 do
Buffer[I + 26]:= Chr(I + Ord('a'));
GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
Result.X:= Result.X div 52;
end;
function MyInputQuery(const ACaption, APrompt: String; var Value: String; var APasswordConfirmed: Boolean; const APassword: Boolean; const ANeedPassword: String; const APasswordChar: Char; const AMaxLength: IntEx; const ABtnsCaption: array of String): Boolean;
var Form: TForm;
Prompt: TLabel;
Edit: TEdit;
DialogUnits: TPoint;
ButtonTop, ButtonWidth, ButtonHeight: IntEx;
begin
Result:= false;
Form:= TForm.Create(Application);
with Form do
try
Canvas.Font:= Font;
DialogUnits:= MyGetAveCharSize(Canvas);
BorderStyle:= bsDialog;
Caption:= ACaption;
ClientWidth:= MulDiv(180, DialogUnits.X, 4);
Position:= poScreenCenter;
Color:= clBtnFace;
Prompt:= TLabel.Create(Form);
with Prompt do
begin
Parent:= Form;
Caption:= APrompt;
Left:= MulDiv(8, DialogUnits.X, 4);
Top:= MulDiv(8, DialogUnits.Y, 8);
Constraints.MaxWidth:= MulDiv(164, DialogUnits.X, 4);
WordWrap:= True;
end;
Edit:= TEdit.Create(Form);
with Edit do
begin
Parent:= Form;
Left:= Prompt.Left;
Top:= Prompt.Top + Prompt.Height + 5;
Width:= MulDiv(164, DialogUnits.X, 4);
MaxLength:= AMaxLength;
if APassword then
PasswordChar:= APasswordChar;
Text:= Value;
SelectAll;
end;
ButtonTop:= Edit.Top + Edit.Height + 15;
ButtonWidth:= MulDiv(50, DialogUnits.X, 4);
ButtonHeight:= MulDiv(14, DialogUnits.Y, 8);
with TButton.Create(Form) do
begin
Parent:= Form;
Caption:= ABtnsCaption[0];
ModalResult:= mrOk;
Cursor:= crHandPoint;
Default:= True;
SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth, ButtonHeight);
end;
with TButton.Create(Form) do
begin
Parent:= Form;
Caption:= ABtnsCaption[1];
ModalResult:= mrCancel;
Cursor:= crHandPoint;
Cancel:= True;
SetBounds(MulDiv(92, DialogUnits.X, 4), Edit.Top + Edit.Height + 15, ButtonWidth, ButtonHeight);
Form.ClientHeight:= Top + Height + 13;
end;
if ShowModal = mrOk then
begin
Value:= Edit.Text;
if APassword then
if Value = ANeedPassword then
APasswordConfirmed:= true
else
APasswordConfirmed:= false;
Result:= True;
end;
finally
Form.Free;
end;
end;
function MyInputComboQuery(const ACaption, APrompt: String; const Values: TStringList; const DefIndex: IntEx; var SelectedIndex: IntEx; const ABtnsCaption: array of String): Boolean;
var Form: TForm;
Prompt: TLabel;
Combo: TComboBox;
DialogUnits: TPoint;
ButtonTop, ButtonWidth, ButtonHeight: IntEx;
begin
Result:= false;
Form:= TForm.Create(Application);
with Form do
try
Canvas.Font:= Font;
DialogUnits:= MyGetAveCharSize(Canvas);
BorderStyle:= bsDialog;
Caption:= ACaption;
ClientWidth:= MulDiv(180, DialogUnits.X, 4);
Position:= poScreenCenter;
Color:= clBtnFace;
Prompt:= TLabel.Create(Form);
with Prompt do
begin
Parent:= Form;
Caption:= APrompt;
Left:= MulDiv(8, DialogUnits.X, 4);
Top:= MulDiv(8, DialogUnits.Y, 8);
Constraints.MaxWidth:= MulDiv(164, DialogUnits.X, 4);
WordWrap:= True;
end;
Combo:= TComboBox.Create(Form);
with Combo do
begin
Parent:= Form;
Left:= Prompt.Left;
Top:= Prompt.Top + Prompt.Height + 5;
Width:= MulDiv(164, DialogUnits.X, 4);
Style:= csDropDownList;
Items.Assign(Values);
if DefIndex <= Items.Count - 1 then
ItemIndex:= DefIndex
else
ItemIndex:= -1;
end;
ButtonTop:= Combo.Top + Combo.Height + 15;
ButtonWidth:= MulDiv(50, DialogUnits.X, 4);
ButtonHeight:= MulDiv(14, DialogUnits.Y, 8);
with TButton.Create(Form) do
begin
Parent:= Form;
Caption:= ABtnsCaption[0];
ModalResult:= mrOk;
Cursor:= crHandPoint;
Default:= True;
SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth, ButtonHeight);
end;
with TButton.Create(Form) do
begin
Parent:= Form;
Caption:= ABtnsCaption[1];
ModalResult:= mrCancel;
Cursor:= crHandPoint;
Cancel:= True;
SetBounds(MulDiv(92, DialogUnits.X, 4), Combo.Top + Combo.Height + 15, ButtonWidth, ButtonHeight);
Form.ClientHeight:= Top + Height + 13;
end;
if ShowModal = mrOk then
begin
SelectedIndex:= Combo.ItemIndex;
Result:= True;
end;
finally
Form.Free;
end;
end;
function MyInputMaskQuery(const ACaption, APrompt, AMask: String; var Value: String; const isIgnoreMask: Boolean; const AMaxLength: IntEx; const ABtnsCaption: array of String): Boolean;
var Form: TForm;
Prompt: TLabel;
Edit: TMaskEdit;
DialogUnits: TPoint;
ButtonTop, ButtonWidth, ButtonHeight: IntEx;
begin
Result:= false;
Form:= TForm.Create(Application);
with Form do
try
Canvas.Font:= Font;
DialogUnits:= MyGetAveCharSize(Canvas);
BorderStyle:= bsDialog;
Caption:= ACaption;
ClientWidth:= MulDiv(180, DialogUnits.X, 4);
Position:= poScreenCenter;
Color:= clBtnFace;
Prompt:= TLabel.Create(Form);
with Prompt do
begin
Parent:= Form;
Caption:= APrompt;
Left:= MulDiv(8, DialogUnits.X, 4);
Top:= MulDiv(8, DialogUnits.Y, 8);
Constraints.MaxWidth:= MulDiv(164, DialogUnits.X, 4);
WordWrap:= True;
end;
Edit:= TMaskEdit.Create(Form);
with Edit do
begin
Parent:= Form;
Left:= Prompt.Left;
Top:= Prompt.Top + Prompt.Height + 5;
Width:= MulDiv(164, DialogUnits.X, 4);
MaxLength:= AMaxLength;
EditMask:= AMask;
if isIgnoreMask then
Text:= Value
else
EditText:= Value;
ValidateEdit;
end;
ButtonTop:= Edit.Top + Edit.Height + 15;
ButtonWidth:= MulDiv(50, DialogUnits.X, 4);
ButtonHeight:= MulDiv(14, DialogUnits.Y, 8);
with TButton.Create(Form) do
begin
Parent:= Form;
Caption:= ABtnsCaption[0];
ModalResult:= mrOk;
Cursor:= crHandPoint;
Default:= True;
SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth, ButtonHeight);
end;
with TButton.Create(Form) do
begin
Parent:= Form;
Caption:= ABtnsCaption[1];
ModalResult:= mrCancel;
Cursor:= crHandPoint;
Cancel:= True;
SetBounds(MulDiv(92, DialogUnits.X, 4), Edit.Top + Edit.Height + 15, ButtonWidth, ButtonHeight);
Form.ClientHeight:= Top + Height + 13;
end;
if ShowModal = mrOk then
begin
if isIgnoreMask then
Value:= Edit.Text
else
Value:= Edit.EditText;
Result:= True;
end;
finally
Form.Free;
end;
end;
function MyInputSpinQuery(const ACaption, APrompt: String; var _Value: IntEx; const AMinValue, AMaxValue: IntEx; const ABtnsCaption: array of String): Boolean;
var Form: TForm;
Prompt: TLabel;
Edit: TSpinEdit;
DialogUnits: TPoint;
ButtonTop, ButtonWidth, ButtonHeight: IntEx;
begin
Result:= False;
Form:= TForm.Create(Application);
with Form do
try
Canvas.Font:= Font;
DialogUnits:= MyGetAveCharSize(Canvas);
BorderStyle:= bsDialog;
Caption:= ACaption;
ClientWidth:= MulDiv(180, DialogUnits.X, 4);
Position:= poScreenCenter;
Color:= clBtnFace;
Prompt:= TLabel.Create(Form);
with Prompt do
begin
Parent:= Form;
Caption:= APrompt;
Left:= MulDiv(8, DialogUnits.X, 4);
Top:= MulDiv(8, DialogUnits.Y, 8);
Constraints.MaxWidth:= MulDiv(164, DialogUnits.X, 4);
WordWrap:= True;
end;
Edit:= TSpinEdit.Create(Form);
with Edit do
begin
Parent:= Form;
Left:= Prompt.Left;
Top:= Prompt.Top + Prompt.Height + 5;
Width:= MulDiv(164, DialogUnits.X, 4);
MinValue:= Integer(AMinValue);
MaxValue:= Integer(AMaxValue);
if _Value < AMinValue then
Value:= AMinValue
else
if _Value > AMaxValue then
Value:= AMaxValue
else
Value:= _Value;
SelectAll;
end;
ButtonTop:= Edit.Top + Edit.Height + 15;
ButtonWidth:= MulDiv(50, DialogUnits.X, 4);
ButtonHeight:= MulDiv(14, DialogUnits.Y, 8);
with TButton.Create(Form) do
begin
Parent:= Form;
Caption:= ABtnsCaption[0];
ModalResult:= mrOk;
Cursor:= crHandPoint;
Default:= True;
SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth, ButtonHeight);
end;
with TButton.Create(Form) do
begin
Parent:= Form;
Caption:= ABtnsCaption[1];
ModalResult:= mrCancel;
Cursor:= crHandPoint;
Cancel:= True;
SetBounds(MulDiv(92, DialogUnits.X, 4), Edit.Top + Edit.Height + 15, ButtonWidth, ButtonHeight);
Form.ClientHeight:= Top + Height + 13;
end;
if ShowModal = mrOk then
begin
_Value:= Edit.Value;
Result:= True;
end;
finally
Form.Free;
end;
end;
function ShowInputBox (const ACaption, APrompt, ADefault: String; var isAccept: Boolean): String;
var Pasw: boolean;
begin
Result:= ADefault;
Pasw:= False;
isAccept:= MyInputQuery(ACaption, APrompt, Result, Pasw, False, '', '*', 0, [OkBtnDefCaption, CancelBtnDefCaption]);
end;
function ShowInputBox (const ACaption, APrompt, ADefault: String; const ABtnCaptions: array of String; var isAccept: Boolean): String;
var Pasw: boolean;
begin
Result:= ADefault;
Pasw:= False;
isAccept:= MyInputQuery(ACaption, APrompt, Result, Pasw, False, '', '*', 0, ABtnCaptions);
end;
function ShowInputBox (const ACaption, APrompt, ADefault: String; const ABtnCaptions: array of String; const AMaxLength: IntEx; var isAccept: Boolean): String;
var Pasw: boolean;
begin
Result:= ADefault;
Pasw:= False;
isAccept:= MyInputQuery(ACaption, APrompt, Result, Pasw, false, '', '*', AMaxLength, ABtnCaptions);
end;
function ShowPasswordInputBox (const ACaption, APrompt, ADefault, APassword: String; var isAccept, isPasswordConfirmed: Boolean; const APasswordChar: Char = '*'): String;
begin
Result:= ADefault;
isAccept:= MyInputQuery(ACaption, APrompt, Result, isPasswordConfirmed, True, APassword, APasswordChar, 0, [OkBtnDefCaption, CancelBtnDefCaption]);
end;
function ShowPasswordInputBox (const ACaption, APrompt, ADefault, APassword: String; var isAccept, isPasswordConfirmed: Boolean; const ABtnCaptions: array of String; const APasswordChar: Char = '*'): String;
begin
Result:= ADefault;
isAccept:= MyInputQuery(ACaption, APrompt, Result, isPasswordConfirmed, True, APassword, APasswordChar, 0, ABtnCaptions);
end;
function ShowComboBox (const ACaption, APrompt: string; var Items: TStringList; const ADefaultIndex: IntEx; var isAccept: boolean): IntEx;
begin
Result:= ADefaultIndex;
isAccept:= MyInputComboQuery(ACaption, APrompt, Items, Result, Result, [OkBtnDefCaption, CancelBtnDefCaption]);
end;
function ShowComboBox (const ACaption, APrompt: String; var Items: TStringList; const ADefaultIndex: IntEx; const ABtnsCaption: array of String; var isAccept: Boolean): IntEx;
begin
Result:= ADefaultIndex;
isAccept:= MyInputComboQuery(ACaption, APrompt, Items, Result, Result, ABtnsCaption);
end;
function ShowMaskedBox (const ACaption, APrompt, AMask, ADefault: String; const isIgnoreMask: Boolean; var isAccept: Boolean): String;
begin
Result:= ADefault;
isAccept:= MyInputMaskQuery(ACaption, APrompt, AMask, Result, isIgnoreMask, 0, [OkBtnDefCaption, CancelBtnDefCaption]);
end;
function ShowMaskedBox (const ACaption, APrompt, AMask, ADefault: String; const isIgnoreMask: Boolean; const ABtnCaptions: array of String; const AMaxLength: IntEx; var isAccept: Boolean): String;
begin
Result:= ADefault;
isAccept:= MyInputMaskQuery(ACaption, APrompt, AMask, Result, isIgnoreMask, AMaxLength, ABtnCaptions);
end;
function ShowSpinedBox (const ACaption, APrompt: String; const ADefault: IntEx; var isAccept: Boolean): IntEx;
begin
Result:= ADefault;
isAccept:= MyInputSpinQuery(ACaption, APrompt, Result, 0, 100, [OkBtnDefCaption, CancelBtnDefCaption]);
end;
function ShowSpinedBox (const ACaption, APrompt: String; const ADefault, AMinValue, AMaxValue: IntEx; const ABtnCaptions: array of String; var isAccept: Boolean): IntEx;
begin
Result:= ADefault;
isAccept:= MyInputSpinQuery(ACaption, APrompt, Result, AMinValue, AMaxValue, ABtnCaptions);
end;
end.

View File

@@ -0,0 +1,12 @@
unit ANBRegComp;
{$mode delphi}
{$codepage UTF8}
interface
uses Classes, SysUtils, SkinButton;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('ANB Components', [TSkinBtn]);
end;
end.

View File

@@ -0,0 +1,169 @@
//version 0.31 beta
unit FileUtilsEx;
{$MODE Delphi}
{$codepage UTF8}
interface
uses windows, sysutils, ShellApi, Classes;
type TExePlatform = (expUnknown, exp32Bit, exp64Bit, expOther);
//stdcalls
function FileVersion (AFileName: String): String;
function FileSize2Str (const AFileSize: Int64; AStringNames: Array of String; const ADecimalPlaces: Byte): String; Stdcall; Overload;
function FileSize2Str (const AFileSize: Int64; AStringNames: Array of String): String; Stdcall; Overload;
function FileSize2Str (const AFileSize: Int64; const ADecimalPlaces: Byte): String; Overload;
function FileSize2Str (const AFileSize: Int64): String; Overload;
function FileAccessDateToDateTime (FileTime: TFILETIME): TDateTime; Stdcall;
function RenameDir (const DirName, NewName: String): Boolean; STDCALL;
function GetEXEPlatform (const AFileName: String): TExePlatform; STDCALL;
implementation
const AFileSizeNames: Array[0..4] of String = ('Byte', 'KB', 'MB', 'GB', 'TB');
//Getting version of the file
function FileVersion (AFileName: String): String;
var szName: array[0..255] of Char;
P: Pointer;
Value: Pointer;
Len: UINT;
GetTranslationString: String;
FFileName: PChar;
FValid:boolean;
FSize: DWORD;
FHandle: DWORD;
FBuffer: PChar;
begin
try
FFileName:= StrPCopy(StrAlloc(Length(AFileName) + 1), AFileName);
FValid:= False;
FSize:= GetFileVersionInfoSize(FFileName, FHandle);
if FSize > 0 then
try
GetMem(FBuffer, FSize);
FValid:= GetFileVersionInfo(FFileName, FHandle, FSize, FBuffer);
except
FValid:= False;
raise;
end;
Result:= '';
if FValid then
VerQueryValue(FBuffer, '\VarFileInfo\Translation', P, Len)
else
P:= nil;
if P <> nil then
GetTranslationString:= IntToHex(MakeLong(HiWord(Longint(P^)), LoWord(Longint(P^))), 8);
if FValid then
begin
StrPCopy(szName, '\StringFileInfo\' + GetTranslationString + '\FileVersion');
if VerQueryValue(FBuffer, szName, Value, Len) then
Result:= StrPas(PChar(Value));
end;
finally
try
if FBuffer <> nil then
FreeMem(FBuffer, FSize);
except
end;
try
StrDispose(FFileName);
except
end;
end;
end;
//FileSize2Str
function FileSize2Str (const AFileSize: Int64; AStringNames: Array of String; const ADecimalPlaces: Byte): String; Overload;
function FrmtSize (const ASize, ADelim: Int64; const ADP: Byte): String;
var VDelim: Int64;
Indx: Byte;
begin
VDelim:= 1;
for Indx:= 0 to ADP do
VDelim:= VDelim*10;
Result:= FloatToStr(round((ASize*VDelim)/ADelim)/VDelim);
end;
const AFrmtsStr: String = '%s %s';
begin
//Bytes
if AFileSize < 1024 then
Result:= Format(AFrmtsStr, [IntToStr(AFileSize), AStringNames[0]]);
//KiloBytes
if (AFileSize >= 1024) and (AFileSize < 1048576) then
Result:= Format(AFrmtsStr, [FrmtSize(AFileSize, 1024, ADecimalPlaces), AStringNames[1]]);
//MegaBytes
if (AFileSize >= 1048576) and (AFileSize < 1073741824) then
Result:= Format(AFrmtsStr, [FrmtSize(AFileSize, 1048576, ADecimalPlaces), AStringNames[2]]);
//GigaBytes
if (AFileSize >= 1073741824) and (AFileSize < 1099511627776) then
Result:= Format(AFrmtsStr, [FrmtSize(AFileSize, 1073741824, ADecimalPlaces), AStringNames[3]]);
//TeraBytes
if (AFileSize >= 1099511627776) then
Result:= Format(AFrmtsStr, [FrmtSize(AFileSize, 1073741824, ADecimalPlaces), AStringNames[4]]);
end;
function FileSize2Str (const AFileSize: Int64; AStringNames: Array of String): String; Overload;
begin
Result:= FileSize2Str(AFileSize, AStringNames, 2);
end;
function FileSize2Str (const AFileSize: Int64; const ADecimalPlaces: Byte): String; Overload;
begin
Result:= FileSize2Str(AFileSize, AFileSizeNames, ADecimalPlaces);
end;
function FileSize2Str (const AFileSize: Int64): String; Overload;
begin
Result:= FileSize2Str(AFileSize, AFileSizeNames, 2);
end;
//FileAccessDateToDateTime
//Author: Дураг (http://www.sql.ru/forum/memberinfo.aspx?mid=32731) from http://www.sql.ru/forum/259218/kak-poluchit-datu-i-vremya-sozdaniya-fayla
function FileAccessDateToDateTime (FileTime: TFILETIME): TDateTime;
var LocalTime: TFILETIME;
DOSFileTime: DWORD;
begin
FileTimeToLocalFileTime(FileTime, LocalTime);
FileTimeToDosDateTime(LocalTime, LongRec(DOSFileTime).Hi, LongRec(DOSFileTime).Lo);
Result:= FileDateToDateTime(DOSFileTime);
end;
//RenameDir
function RenameDir (const DirName, NewName: String): Boolean;
var shellinfo: TSHFILEOPSTRUCT;
DirFrom, DirTo: String;
begin
DirFrom:= DirName;
DirTo:= NewName;
with shellinfo do
begin
Wnd:= 0;
wFunc:= FO_RENAME;
pFrom:= PChar(DirFrom);
pTo:= PChar(DirTo);
fFlags:= FOF_FILESONLY or FOF_ALLOWUNDO or FOF_SILENT or FOF_NOCONFIRMATION;
end;
SHFileOperation(shellinfo);
Result:= DirectoryExists(NewName);
end;
//GetEXEPlatform
//Author Dmitry Arefiev (http://www.sql.ru/forum/808857/kak-opredelit-razryadnost-prilozheniya)
function GetEXEPlatform (const AFileName: String): TExePlatform;
var oFS: TFileStream;
iPeOffset: Integer;
iPeHead: LongWord;
iMachineType: Word;
begin
Result:= expUnknown;
try
oFS:= TFileStream.Create(AFileName, fmOpenRead or fmShareDenyNone);
try
oFS.Seek($3C, soFromBeginning);
oFS.Read(iPeOffset, SizeOf(iPeOffset));
oFS.Seek(iPeOffset, soFromBeginning);
oFS.Read(iPeHead, SizeOf(iPeHead));
if iPeHead <> $00004550 then
Exit;
oFS.Read(iMachineType, SizeOf(iMachineType));
case iMachineType of
$8664, $0200: Result:= exp64Bit;
$014C: Result:= exp32Bit;
else
Result:= expOther;
end;
finally
oFS.Free;
end;
except
end;
end;
end.

View File

@@ -0,0 +1,28 @@
unit GraphicsEx;
//version 0.1
{$MODE Delphi}
{$codepage UTF8}
interface
uses Classes, SysUtils, Graphics;
type TRGBByte = 0..255;
TRGBColor = record
R, G, B: TRGBByte;
end;
//stdcalls
function RGB2Color (const ARGB: TRGBColor): TColor;
function Color2RGB (const AColor: TColor): TRGBColor;
implementation
function RGB2Color (const ARGB: TRGBColor): TColor;
begin
Result:= RGBToColor(ARGB.R, ARGB.G, ARGB.B);
end;
function Color2RGB (const AColor: TColor): TRGBColor;
//from http://www.delphisources.ru/pages/faq/base/rgb_tcolor.html
var Color: LongInt;
begin
Color:= ColorToRGB(AColor);
Result.R:= Color;
Result.G:= Color shr 8;
Result.B:= Color shr 16;
end;
end.

View File

@@ -0,0 +1,25 @@
unit MsgBoxes;
{$mode delphi}
{$codepage UTF8}
interface
uses Classes, SysUtils, Forms;
{dialog types for Linux capatability}
const DLG_ASTERISK = $40;
DLG_EXCLAMATION = $30;
DLG_WARNING = $30;
DLG_ERROR = $10;
DLG_QUESTION = $20;
{stdcalls}
function ShowMessageBox (const AText, ATitle: String; const AMessageType: LongInt = 0): Integer; STDCALL;
function ShowMessageBoxA (const AText: String; const AMessageType: LongInt = 0): Integer; STDCALL;
implementation
//Sample Windows MessageDialogs
function ShowMessageBox (const AText, ATitle: String; const AMessageType: LongInt = 0): Integer;
begin
Result:= Application.MessageBox(PChar(AText), PChar(ATitle), AMessageType);
end;
function ShowMessageBoxA (const AText: String; const AMessageType: LongInt = 0): Integer;
begin
Result:= Application.MessageBox(PChar(AText), PChar(Application.Title), AMessageType);
end;
end.

View File

@@ -0,0 +1,96 @@
unit ParamsMngr;
{$MODE Delphi}
{$codepage UTF8}
interface
uses StrUtils, VCLEx;
{stdcalls}
function HasParam (const AParams: String; const AParam: Char): Boolean; OVERLOAD; STDCALL;
function HasParam (const AParams: String; const AParam: String): Boolean; OVERLOAD; STDCALL;
function HasParam (const AParam: String): Boolean; OVERLOAD; STDCALL;
function GetParamValue (const AParams: String; const AParam: Char): String; OVERLOAD; STDCALL;
function GetParamValue (const AParams: String; const AParam: String): String; OVERLOAD; STDCALL;
function GetParamValue (const AParam: string): string; overload; stdcall;
function StartParams: String; STDCALL;
implementation
function HasParam (const AParams: String; const AParam: Char): Boolean;
begin
Result:= False;
if AParams <> '' then
if Pos('/' + AParam, AParams) > 0 then
Result:= True;
end;
function HasParam (const AParams: String; const AParam: String): Boolean;
var PS: IntEx;
NextChr: Char;
begin
Result:= False;
if AParams <> '' then
begin
PS:= Pos('/' + AParam, AParams);
if PS > 0 then
begin
NextChr:= AParams[PS + Length(AParam) + 1];
if (NextChr = '=') or (NextChr = '#') then
Result:= True;
end;
end;
end;
function HasParam (const AParam: String): Boolean;
begin
Result:= HasParam(StartParams, AParam);
end;
function GetParamValue (const AParams: String; const AParam: Char): String;
var i, j, k: IntEx;
begin
Result:= '';
i:= 0;
j:= 0;
k:= 0;
if AParams <> '' then
begin
i:= Pos('/' + AParam, AParams);
if (i > 0) and (AParams[i+2] = '=') then
j:= i+3;
if j > 0 then
begin
k:= PosEx('#', AParams, j);
if k = 0 then
k:= Length(AParams) + 1;
Result:= Copy(AParams, j, k-j);
end;
end;
end;
function GetParamValue (const AParams: String; const AParam: String): String;
var i, j, k: IntEx;
begin
Result:= '';
i:= 0;
j:= 0;
k:= 0;
if AParams <> '' then
begin
i:= Pos('/' + AParam, AParams);
if (i > 0) and (AParams[i + Length(AParam) + 1] = '=') then
j:= i + Length(AParam) + 2;
if j > 0 then
begin
k:= PosEx('#', AParams, j);
if k = 0 then
k:= Length(AParams) + 1;
Result:= Copy(AParams, j, k-j);
end;
end;
end;
function GetParamValue (const AParam: String): String;
begin
Result:= GetParamValue(StartParams, AParam);
end;
function StartParams: String;
var i: IntEx;
begin
Result:= '';
if Paramcount > 0 then
for i:= 1 to Paramcount do
Result:= Result + ParamStr(i) + '#';
end;
end.

View File

@@ -0,0 +1,132 @@
unit SimplyINI;
{$MODE Delphi}
{$codepage UTF8}
interface
uses SysUtils, Classes, IniFiles;
//stdcalls
function INIReadString (const ASection, AKey, ADefault, AFileName: string): string; stdcall;
function INIReadInteger (const ASection, AKey: string; const ADefault: Int64; const AFileName: string): Int64; stdcall;
function INIReadBoolean (const ASection, AKey: string; const ADefault: boolean; const AFileName: string): boolean; stdcall;
procedure INIWriteString (const ASection, AKey, AValue, AFileName: string); stdcall;
procedure INIWriteInteger (const ASection, AKey: string; const AValue: Int64; const AFileName: string); stdcall;
procedure INIWriteBoolean (const ASection, AKey: string; const AValue: boolean; const AFileName: string); stdcall;
procedure INIDeleteKey (const ASection, AKey, AFileName: string); stdcall;
procedure INIDeleteSection (const ASection, AFileName: string); stdcall;
function INISectionExists (const ASection, AFileName: string): boolean; stdcall;
procedure INIReadSections (const AFileName: string; VStrings: TStrings); stdcall;
procedure INIReadSection (const ASection, AFileName: string; VStrings: TStrings); stdcall;
implementation
//Read functions
function INIReadString (const ASection, AKey, ADefault, AFileName: string): string;
var INI: TIniFile;
begin
INI:= TIniFile.Create(AFileName);
try
Result:= INI.ReadString(ASection, AKey, ADefault);
finally
INI.Free;
end;
end;
function INIReadInteger (const ASection, AKey: string; const ADefault: Int64; const AFileName: string): Int64;
var INI: TIniFile;
begin
INI:= TIniFile.Create(AFileName);
try
Result:= INI.ReadInteger(ASection, AKey, ADefault);
finally
INI.Free;
end;
end;
function INIReadBoolean (const ASection, AKey: string; const ADefault: boolean; const AFileName: string): boolean;
var INI: TIniFile;
begin
INI:= TIniFile.Create(AFileName);
try
Result:= INI.ReadBool(ASection, AKey, ADefault);
finally
INI.Free;
end;
end;
//Write procedures
procedure INIWriteString (const ASection, AKey, AValue, AFileName: string);
var INI: TIniFile;
begin
INI:= TIniFile.Create(AFileName);
try
INI.WriteString(ASection, AKey, AValue);
finally
INI.Free;
end;
end;
procedure INIWriteInteger (const ASection, AKey: string; const AValue: Int64; const AFileName: string);
var INI: TIniFile;
begin
INI:= TIniFile.Create(AFileName);
try
INI.WriteInt64(ASection, AKey, AValue);
finally
INI.Free;
end;
end;
procedure INIWriteBoolean (const ASection, AKey: string; const AValue: boolean; const AFileName: string);
var INI: TIniFile;
begin
INI:= TIniFile.Create(AFileName);
try
INI.WriteBool(ASection, AKey, AValue);
finally
INI.Free;
end;
end;
//Delete function
procedure INIDeleteKey (const ASection, AKey, AFileName: string);
var INI: TIniFile;
begin
INI:= TIniFile.Create(AFileName);
try
INI.DeleteKey(ASection, AKey);
finally
INI.Free;
end;
end;
procedure INIDeleteSection (const ASection, AFileName: string);
var INI: TIniFile;
begin
INI:= TIniFile.Create(AFileName);
try
INI.EraseSection(ASection);
finally
INI.Free;
end;
end;
function INISectionExists (const ASection, AFileName: string): boolean;
var INI: TIniFile;
begin
INI:= TIniFile.Create(AFileName);
try
Result:= INI.SectionExists(ASection);
finally
INI.Free;
end;
end;
procedure INIReadSections (const AFileName: string; VStrings: TStrings);
var INI: TIniFile;
begin
INI:= TIniFile.Create(AFileName);
try
INI.ReadSections(VStrings);
finally
INI.Free;
end;
end;
procedure INIReadSection (const ASection, AFileName: string; VStrings: TStrings);
var INI: TIniFile;
begin
INI:= TIniFile.Create(AFileName);
try
INI.ReadSection(ASection, VStrings);
finally
INI.Free;
end;
end;
end.

View File

@@ -0,0 +1,324 @@
unit SimplyJSON;
{$MODE Delphi}
{$codepage UTF8}
{*************************************************************************************************************************************
SimplyJSON
Модуль для парсинга JSON файлов (используется TJSONConfig).
Авторские права (c) 2016 - 2019, Александр Бабаев.
История изменений:
1.3 (01.05.2019) Переработан алгоритм открытия / парсинга JSON файлов при чтении, изменена функция JSReadFont
1.2 (09.05.2017) Добавлены функции чтения/записи шрифтов.
*************************************************************************************************************************************}
interface
uses Classes, SysUtils, Graphics, GraphicsEx, LazFileUtils, fpjson, jsonparser, jsonConf, ANBFormatString;
//stdcalls
function JSReadString (const AKey, ADefault: UnicodeString; const AFileName: String): UnicodeString; STDCALL; OVERLOAD;
function JSReadString (const AKey, ADefault, AFileName: String): String; STDCALL; OVERLOAD;
function JSReadInteger (const AKey: UnicodeString; const ADefault: Int64; const AFileName: String): Int64; STDCALL; OVERLOAD;
function JSReadInteger (const AKey: String; const ADefault: Int64; const AFileName: String): Int64; STDCALL; OVERLOAD;
function JSReadBoolean (const AKey: UnicodeString; const ADefault: Boolean; const AFileName: String): Boolean; STDCALL; OVERLOAD;
function JSReadBoolean (const AKey: String; const ADefault: Boolean; const AFileName: String): Boolean; STDCALL; OVERLOAD;
function JSReadRGBColor (const AKey: UnicodeString; const ADefault: TRGBColor; const AFileName: String): TRGBColor; STDCALL; OVERLOAD;
function JSReadRGBColor (const AKey: String; const ADefault: TRGBColor; const AFileName: String): TRGBColor; STDCALL; OVERLOAD;
procedure JSReadFont (const AKey: UnicodeString; var Font: TFont; const AFileName: String); STDCALL; OVERLOAD;
procedure JSReadFont (const AKey: String; var Font: TFont; const AFileName: String); STDCALL; OVERLOAD;
procedure JSWriteString (const AKey, AValue: UnicodeString; const AFileName: String); STDCALL; OVERLOAD;
procedure JSWriteString (const AKey, AValue, AFileName: String); STDCALL; OVERLOAD;
procedure JSWriteInteger (const AKey: UnicodeString; const AValue: Int64; const AFileName: String); STDCALL; OVERLOAD;
procedure JSWriteInteger (const AKey: String; const AValue: Int64; const AFileName: String); STDCALL; OVERLOAD;
procedure JSWriteBoolean (const AKey: UnicodeString; const AValue: Boolean; const AFileName: String); STDCALL; OVERLOAD;
procedure JSWriteBoolean (const AKey: String; const AValue: Boolean; const AFileName: String); STDCALL; OVERLOAD;
procedure JSWriteRGBColor (const AKey: UnicodeString; const AValue: TRGBColor; const AFileName: String); STDCALL; OVERLOAD;
procedure JSWriteRGBColor (const AKey: String; const AValue: TRGBColor; const AFileName: String); STDCALL; OVERLOAD;
procedure JSWriteFont (const AKey: UnicodeString; const AValue: TFont; const AFileName: String); STDCALL; OVERLOAD;
procedure JSWriteFont (const AKey: String; const AValue: TFont; const AFileName: String); STDCALL; OVERLOAD;
procedure JSDeleteKey (const AKey: UnicodeString; const AFileName: String); STDCALL; OVERLOAD;
procedure JSDeleteKey (const AKey, AFileName: String); STDCALL; OVERLOAD;
procedure JSReadSubKeys (const AKey: UnicodeString; SubkeyList: TStrings; const AFileName: String); STDCALL; OVERLOAD;
procedure JSReadSubKeys (const AKey: String; SubkeyList: TStrings; const AFileName: String); STDCALL; OVERLOAD;
implementation
//Support functions
procedure GetJSData (const AFileName: String; var JSData: TJSONData);
var FS: TFileStream;
SL: TStringList;
begin
if not FileExistsUTF8(AFileName) then
begin
FS:= TFileStream.Create(AFileName, fmOpenWrite);
SL:= TStringList.Create;
SL.Text:= '{}';
SL.SaveToStream(FS);
SL.Free;
FS.Free;
end;
FS:= TFileStream.Create(AFileName, fmOpenRead or fmShareDenyNone);
JSData:= GetJSON(FS, True);
FS.Free;
end;
function FrmtKey (const AKey: UnicodeString): UnicodeString;
var KeyM: UnicodeString;
begin
Result:= AKey;
//Для совместимости с SimplyJSON 1.0 - 1.2 и операциями записи
KeyM:= AKey;
if KeyM[1] = '/' then
Delete(KeyM, 1, 1);
Result:= UnicodeString(FormatStr(KeyM, ['/'], ['.']));
end;
//Read functions
function JSReadString (const AKey, ADefault: UnicodeString; const AFileName: String): UnicodeString; OVERLOAD;
var JD: TJSONData;
begin
GetJSData(AFileName, JD);
try
Result:= JD.FindPath(FrmtKey(AKey)).AsUnicodeString;
except
Result:= ADefault;
end;
JD.Free;
end;
function JSReadString (const AKey, ADefault, AFileName: String): String; OVERLOAD;
var Key, Def, Res: UnicodeString;
begin
Key:= UnicodeString(AKey);
Def:= UnicodeString(ADefault);
Res:= JSReadString(Key, Def, AFileName);
Result:= String(Res);
end;
function JSReadInteger (const AKey: UnicodeString; const ADefault: Int64; const AFileName: String): Int64; OVERLOAD;
var JD: TJSONData;
begin
GetJSData(AFileName, JD);
try
Result:= JD.FindPath(FrmtKey(AKey)).AsInt64;
except
Result:= ADefault;
end;
JD.Free;
end;
function JSReadInteger (const AKey: String; const ADefault: Int64; const AFileName: String): Int64; OVERLOAD;
var Key: UnicodeString;
begin
Key:= UnicodeString(AKey);
Result:= JSReadInteger(Key, ADefault, AFileName);
end;
function JSReadBoolean (const AKey: UnicodeString; const ADefault: Boolean; const AFileName: String): Boolean; OVERLOAD;
var JD: TJSONData;
begin
GetJSData(AFileName, JD);
try
Result:= JD.FindPath(FrmtKey(AKey)).AsBoolean;
except
Result:= ADefault;
end;
JD.Free;
end;
function JSReadBoolean (const AKey: String; const ADefault: Boolean; const AFileName: String): Boolean; OVERLOAD;
var Key: UnicodeString;
begin
Key:= UnicodeString(AKey);
Result:= JSReadBoolean(Key, ADefault, AFileName);
end;
function JSReadRGBColor (const AKey: UnicodeString; const ADefault: TRGBColor; const AFileName: String): TRGBColor; OVERLOAD;
var JD: TJSONData;
KeyM: UnicodeString;
begin
GetJSData(AFileName, JD);
KeyM:= FrmtKey(AKey);
try
Result.R:= JD.FindPath(KeyM + '.r').AsInteger;
Result.G:= JD.FindPath(KeyM + '.g').AsInteger;
Result.B:= JD.FindPath(KeyM + '.b').AsInteger;
except
Result:= ADefault;
end;
JD.Free;
end;
function JSReadRGBColor (const AKey: String; const ADefault: TRGBColor; const AFileName: String): TRGBColor; OVERLOAD;
var Key: UnicodeString;
begin
Key:= UnicodeString(AKey);
Result:= JSReadRGBColor(Key, ADefault, AFileName);
end;
procedure JSReadFont (const AKey: UnicodeString; var Font: TFont; const AFileName: String);
var JD: TJSONData;
FStyle: TFontStyles;
KeyM: UnicodeString;
begin
GetJSData(AFileName, JD);
KeyM:= FrmtKey(AKey);
try
Font.CharSet:= TFontCharSet(JD.FindPath(KeyM + '.charset').AsInteger);
Font.Color:= StringToColor(JD.FindPath(KeyM + '.color').AsString);
Font.Height:= JD.FindPath(KeyM + '.height').AsInteger;
Font.Name:= JD.FindPath(KeyM + '.name').AsString;
Font.Orientation:= JD.FindPath(KeyM + '.orientation').AsInteger;
Font.Pitch:= TFontPitch(JD.FindPath(KeyM + '.pitch').AsInteger);
Font.Quality:= TFontQuality(JD.FindPath(KeyM + '.quality').AsInteger);
Font.Size:= JD.FindPath(KeyM + '.size').AsInteger;
FStyle:= [];
if (JD.FindPath(KeyM + '.style.bold').AsBoolean) then
FStyle:= FStyle + [fsBold];
if (JD.FindPath(KeyM + '.style.italic').AsBoolean) then
FStyle:= FStyle + [fsItalic];
if (JD.FindPath(KeyM + '.style.underline').AsBoolean) then
FStyle:= FStyle + [fsUnderline];
if (JD.FindPath(KeyM + '.style.strikeout').AsBoolean) then
FStyle:= FStyle + [fsStrikeOut];
Font.Style:= FStyle;
except
end;
JD.Free;
end;
procedure JSReadFont (const AKey: String; var Font: TFont; const AFileName: String);
var Key: UnicodeString;
begin
Key:= UnicodeString(AKey);
JSReadFont(Key, Font, AFileName);
end;
//Write procedures
procedure JSWriteString (const AKey, AValue: UnicodeString; const AFileName: String); OVERLOAD;
var JSConf: TJSONConfig;
begin
JSConf:= TJSONConfig.Create(Nil);
with JSConf do
begin
Filename:= AFileName;
Formatted:= True;
SetValue(AKey, AValue);
Flush;
Free;
end;
end;
procedure JSWriteString (const AKey, AValue, AFileName: String); OVERLOAD;
var Key, Val: UnicodeString;
begin
Key:= UnicodeString(AKey);
Val:= UnicodeString(AValue);
JSWriteString(Key, Val, AFileName);
end;
procedure JSWriteInteger (const AKey: UnicodeString; const AValue: Int64; const AFileName: String); OVERLOAD;
var JSConf: TJSONConfig;
begin
JSConf:= TJSONConfig.Create(Nil);
with JSConf do
begin
Filename:= AFileName;
Formatted:= True;
SetValue(AKey, AValue);
Free;
end;
end;
procedure JSWriteInteger (const AKey: String; const AValue: Int64; const AFileName: String); OVERLOAD;
var Key: UnicodeString;
begin
Key:= UnicodeString(AKey);
JSWriteInteger(Key, AValue, AFileName);
end;
procedure JSWriteBoolean (const AKey: UnicodeString; const AValue: Boolean; const AFileName: String); OVERLOAD;
var JSConf: TJSONConfig;
begin
JSConf:= TJSONConfig.Create(Nil);
with JSConf do
begin
Filename:= AFileName;
Formatted:= True;
SetValue(AKey, AValue);
Free;
end;
end;
procedure JSWriteBoolean (const AKey: String; const AValue: Boolean; const AFileName: String); OVERLOAD;
var Key: UnicodeString;
begin
Key:= UnicodeString(AKey);
JSWriteBoolean(Key, AValue, AFileName);
end;
procedure JSWriteRGBColor (const AKey: UnicodeString; const AValue: TRGBColor; const AFileName: String); OVERLOAD;
var JSConf: TJSONConfig;
begin
JSConf:= TJSONConfig.Create(Nil);
with JSConf do
begin
Filename:= AFileName;
Formatted:= True;
SetValue(AKey + '/r', AValue.R);
SetValue(AKey + '/g', AValue.G);
SetValue(AKey + '/b', AValue.B);
Free;
end;
end;
procedure JSWriteRGBColor (const AKey: String; const AValue: TRGBColor; const AFileName: String); OVERLOAD;
var Key: UnicodeString;
begin
Key:= UnicodeString(AKey);
JSWriteRGBColor(Key, AValue, AFileName);
end;
procedure JSWriteFont (const AKey: UnicodeString; const AValue: TFont; const AFileName: String); OVERLOAD;
var JSConf: TJSONConfig;
begin
JSConf:= TJSONConfig.Create(Nil);
with JSConf do
begin
Filename:= AFileName;
Formatted:= True;
SetValue(AKey + '/charset', Integer(AValue.CharSet));
SetValue(AKey + '/color', ColorToString(AValue.Color));
SetValue(AKey + '/height', AValue.Height);
SetValue(AKey + '/name', AValue.Name);
SetValue(AKey + '/orientation', AValue.Orientation);
SetValue(AKey + '/pitch', Integer(AValue.Pitch));
SetValue(AKey + '/quality', Integer(AValue.Quality));
SetValue(AKey + '/size', AValue.Size);
SetValue(AKey + '/style/bold', (fsBold in AValue.Style));
SetValue(AKey + '/style/italic', (fsItalic in AValue.Style));
SetValue(AKey + '/style/underline', (fsUnderline in AValue.Style));
SetValue(AKey + '/style/strikeout', (fsStrikeOut in AValue.Style));
Free;
end;
end;
procedure JSWriteFont (const AKey: String; const AValue: TFont; const AFileName: String); OVERLOAD;
var Key: UnicodeString;
begin
Key:= UnicodeString(AKey);
JSWriteFont(Key, AValue, AFileName);
end;
//Delete function
procedure JSDeleteKey (const AKey: UnicodeString; const AFileName: String); OVERLOAD;
var JSConf: TJSONConfig;
begin
JSConf:= TJSONConfig.Create(Nil);
with JSConf do
begin
Filename:= AFileName;
Formatted:= True;
DeletePath(AKey);
Free;
end;
end;
procedure JSDeleteKey (const AKey, AFileName: String); OVERLOAD;
var Key: UnicodeString;
begin
Key:= UnicodeString(AKey);
JSDeleteKey(Key, AFileName);
end;
//Read subkeys
procedure JSReadSubKeys (const AKey: UnicodeString; SubkeyList: TStrings; const AFileName: String); OVERLOAD;
var JSConf: TJSONConfig;
begin
JSConf:= TJSONConfig.Create(Nil);
with JSConf do
begin
Filename:= AFileName;
Formatted:= True;
SubkeyList.Clear;
EnumSubKeys(AKey, SubkeyList);
Free;
end;
end;
procedure JSReadSubKeys (const AKey: String; SubkeyList: TStrings; const AFileName: String); OVERLOAD;
var Key: UnicodeString;
begin
Key:= UnicodeString(AKey);
JSReadSubKeys(Key, SubkeyList, AFileName);
end;
end.

View File

@@ -0,0 +1,61 @@
unit SkinButton;
{$mode delphi}
{$codepage UTF8}
interface
uses Classes, SysUtils, Buttons, Graphics, Controls;
type TSkinBtn = class(TSpeedButton)
private
FNormalColor, FHighlightColor, FClickColor: TColor;
FTransparent: Boolean;
FOnMouseDown: TMouseEvent;
FOnMouseEnter, FOnMouseLeave: TNotifyEvent;
protected
procedure POnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure POnMouseEnter(Sender: TObject);
procedure POnMouseLeave(Sender: TObject);
public
constructor Create(AOwner: TComponent);
destructor Destroy;
published
property Transparent: Boolean read FTransparent;
property NormalColor: TColor read FNormalColor write FNormalColor;
property OnHighlightColor: TColor read FHighlightColor write FHighlightColor;
property OnClickColor: TColor read FClickColor write FClickColor;
property OnMouseDown: TMouseEvent read FOnMouseDown;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave;
end;
implementation
constructor TSkinBtn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FNormalColor:= clWhite;
FHighlightColor:= FNormalColor;
FClickColor:= FNormalColor;
FTransparent:= False;
inherited Transparent:= FTransparent;
inherited OnMouseEnter:= POnMouseEnter;
inherited OnMouseDown:= POnMouseDown;
inherited OnMouseLeave:= POnMouseLeave;
end;
destructor TSkinBtn.Destroy;
begin
inherited Destroy;
end;
procedure TSkinBtn.POnMouseEnter(Sender: TObject);
begin
(Sender as TSkinBtn).Color:= FHighlightColor;
inherited OnMouseEnter(Sender);
end;
procedure TSkinBtn.POnMouseLeave(Sender: TObject);
begin
(Sender as TSkinBtn).Color:= FNormalColor;
inherited OnMouseLeave(Sender);
end;
procedure TSkinBtn.POnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
(Sender as TSkinBtn).Color:= FClickColor;
inherited OnMouseDown(Sender, Button, Shift, X, Y);
end;
end.

249
ANB ST CP/data/VCLEx.pas Normal file
View File

@@ -0,0 +1,249 @@
unit VCLEx;
{$MODE Delphi}
{$codepage UTF8}
interface
uses ShellApi, windows, sysutils, strutils, LazFileUtils, LazUTF8;
type IntEx = {$IFDEF Win64}Int64{$ELSE}Integer{$ENDIF};
TWaitEvent = procedure;
TOSPlatform = (ospUnknown, ospWin32, ospWin64);
TPrivilegeState = (psError, psLimitedUser, psAdmin);
Percent = 0..100;
TRandomRange = (rrUpperCasesLetters, rrLowerCasesLetters, rrNumbers, rrStandartSymbols);
TRandomRanges = set of TRandomRange;
//stdcalls
function IntToBool (const AInt: IntEx): Boolean; STDCALL;
function BoolToInt (const ABool: Boolean): IntEx; STDCALL;
function CopyDirectory (const AFromDir, AToDir: String; const AFlags: Word = FOF_FILESONLY): Boolean; STDCALL;
function MoveDirectory (const AFromDir, AToDir: String; const AFlags: Word = FOF_FILESONLY): Boolean; STDCALL;
function DelDirectory (const ADir: String; const AFlags: Word = FOF_SILENT or FOF_NOCONFIRMATION): Boolean; STDCALL;
procedure WaitEx (const AMs: Int64; OnWait: TWaitEvent); STDCALL;
procedure Wait (const AMs: Int64); STDCALL;
function GetBuildPlatform: TOSPlatform; STDCALL;
function GetWindowsUserPrivilege: TPrivilegeState; STDCALL;
function ExtractUpDir(const ADir: String; var VSuccess: Boolean): String; STDCALL;
function GetAnyFileType (const AFileName: UTF8String): UTF8String; STDCALL;
function FileSizeToStr (const AFS: Int64; const AScaleCaptions: array of String): String; OVERLOAD; STDCALL;
function FileSizeToStr (const AFS: Int64): String; OVERLOAD; STDCALL;
function GetRandomString (const sLength: Integer; const ARange: TRandomRanges = [rrUpperCasesLetters, rrLowerCasesLetters]; const AIncludedSymbols: String = ''; const AExcludedSymbols: String = ''): String; STDCALL;
implementation
function IntToBool (const AInt: IntEx): Boolean;
begin
if AInt >= 0 then
Result:= True
else
Result:= False;
end;
function BoolToInt (const ABool: Boolean): IntEx;
begin
if ABool then
Result:= 1
else
Result:= -1;
end;
//from http://www.delphiworld.narod.ru/base/copy_del_move_dir.html
function CopyDirectory (const AFromDir, AToDir: String; const AFlags: Word = FOF_FILESONLY): Boolean;
var fos: TSHFileOpStruct;
begin
with fos do
begin
wFunc:= FO_COPY;
fFlags:= AFlags;
pFrom:= PChar(AFromDir + #0);
pTo:= PChar(AToDir);
end;
Result:= (0 = SHFileOperation(fos));
end;
function MoveDirectory (const AFromDir, AToDir: String; const AFlags: Word = FOF_FILESONLY): Boolean;
var fos: TSHFileOpStruct;
begin
with fos do
begin
wFunc:= FO_MOVE;
fFlags:= AFlags;
pFrom:= PChar(AFromDir + #0);
pTo:= PChar(AToDir);
end;
Result:= (0 = SHFileOperation(fos));
end;
function DelDirectory (const ADir: String; const AFlags: Word = FOF_SILENT or FOF_NOCONFIRMATION): Boolean;
var
fos: TSHFileOpStruct;
begin
with fos do
begin
wFunc:= FO_DELETE;
fFlags:= AFlags;
pFrom:= PChar(ADir + #0);
end;
Result:= (0 = SHFileOperation(fos));
end;
//---
procedure WaitEx (const AMs: Int64; OnWait: TWaitEvent);
var STime: Int64;
begin
STime:= GetTickCount64;
repeat
OnWait;
until (GetTickCount64 - STime) = AMs;
end;
procedure Wait (const AMs: Int64);
procedure MyWait;
begin
end;
begin
WaitEx(AMs, @MyWait);
end;
//GetBuildPlatform
function GetBuildPlatform: TOSPlatform;
begin
Result:= ospUnknown;
if LowerCase({$I %FPCTARGETOS%}) = 'win32' then
Result:= ospWin32;
if LowerCase({$I %FPCTARGETOS%}) = 'win64' then
Result:= ospWin64;
end;
//GetWindowsUserPrivilege
function GetWindowsUserPrivilege: TPrivilegeState;
const SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
SECURITY_BUILTIN_DOMAIN_RID = $00000020;
DOMAIN_ALIAS_RID_ADMINS = $00000220;
SECURITY_MANDATORY_HIGH_RID = $00003000;
TokenIntegrityLevel = 25;
var hAccessToken: THandle;
ptgGroups: PTokenGroups;
dwInfoBufferSize: DWORD;
psidAdministrators: PSID;
I: Integer;
SubAuthority: DWORD;
begin
Result:= psError;
if Win32Platform <> VER_PLATFORM_WIN32_NT then
Exit;
if not OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True, hAccessToken) then
if not OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, hAccessToken) then
Exit;
try
GetMem(ptgGroups, 1024);
try
if Win32MajorVersion < 6 then
begin
if not GetTokenInformation(hAccessToken, TokenGroups, ptgGroups, 1024, dwInfoBufferSize) then
Exit;
AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, psidAdministrators);
try
Result:= psLimitedUser;
for I:= 0 to ptgGroups.GroupCount - 1 do
if EqualSid(psidAdministrators, ptgGroups.Groups[I].Sid) then
begin
Result:= psAdmin;
Break;
end;
finally
FreeSid(psidAdministrators);
end;
end
else
begin
if GetTokenInformation(hAccessToken, TTokenInformationClass(TokenIntegrityLevel), ptgGroups, 1024, dwInfoBufferSize) and IsValidSid(PSIDAndAttributes(ptgGroups)^.Sid) then
begin
Result:= psLimitedUser;
SubAuthority:= GetSidSubAuthorityCount(PSIDAndAttributes(ptgGroups)^.Sid)^ - 1;
if GetSidSubAuthority(PSIDAndAttributes(ptgGroups)^.Sid, SubAuthority)^ >= SECURITY_MANDATORY_HIGH_RID then
Result:= psAdmin;
end;
end;
finally
FreeMem(ptgGroups);
end;
finally
CloseHandle(hAccessToken);
end;
end;
function ExtractUpDir (const ADir: String; var VSuccess: Boolean): String;
var CurrDelim, NextDelim: Integer;
s, Str: String;
begin
Str:= ExcludeTrailingBackslash(ADir);
if Length(ADir) < 4 then
begin
VSuccess:= false;
Result:= ADir;
Exit;
end;
s:= '';
CurrDelim:= 1;
repeat
NextDelim:= PosEx('\', Str, CurrDelim);
if NextDelim = 0 then
NextDelim:= Length(Str) + 1;
if NextDelim < Length(Str) then
s:= s + Copy(Str, CurrDelim, NextDelim - CurrDelim) + '\';
CurrDelim:= NextDelim + 1;
until (CurrDelim > Length(Str));
VSuccess:= DirectoryExistsUTF8(s);
Result:= s;
end;
function GetAnyFileType (const AFileName: UTF8String): UTF8String;
var FileInfo: TSHFILEINFO;
begin
Result:= '';
FillChar(FileInfo, SizeOf(FileInfo), 0);
if (SHGetFileInfo(PChar(ExtractFileExt(AFileName)), FILE_ATTRIBUTE_NORMAL, FileInfo, SizeOf(FileInfo), SHGFI_TYPENAME or SHGFI_USEFILEATTRIBUTES) <> 0) then
Result:= AnsiToUtf8(FileInfo.szTypeName);
end;
function FileSizeToStr (const AFS: Int64; const AScaleCaptions: array of String): String;
var ARSize: Real;
begin
if AFS < 1024 then
begin
Result:= Format('%d ' + AScaleCaptions[0], [AFS]);
Exit;
end;
if AFS < 1048576 then
begin
ARSize:= Round((AFS / 1024)*100)/100;
Result:= FloatToStr(ARSize) + ' ' + AScaleCaptions[1];
Exit;
end;
if AFS < 1073741824 then
begin
ARSize:= Round((AFS / 1048576)*100)/100;
Result:= FloatToStr(ARSize) + ' ' + AScaleCaptions[2];
Exit;
end;
ARSize:= Round((AFS / 1073741824)*100)/100;
Result:= FloatToStr(ARSize) + ' ' + AScaleCaptions[3];
end;
function FileSizeToStr (const AFS: Int64): String;
begin
Result:= FileSizeToStr(AFS, ['Byte', 'KB', 'MB', 'GB']);
end;
function GetRandomString (const sLength: Integer; const ARange: TRandomRanges = [rrUpperCasesLetters, rrLowerCasesLetters]; const AIncludedSymbols: String = ''; const AExcludedSymbols: String = ''): String;
const UpperCaseChars = 'ABCDEFGHIKLMNOPQRSTUVWXYZ';
LowerCaseChars = 'abcdefghiklmnopqrstuvwxyz';
NumbersChars = '0123456789';
SymbolsChars = '!"#$%&''()*+,-.:;<=>?@\]^_`{|}~';
var i, j: Integer;
Chars: String;
begin
SetLength (Result, sLength);
Chars:= AIncludedSymbols;
if rrUpperCasesLetters in ARange then
Chars:= Chars + UpperCaseChars;
if rrLowerCasesLetters in ARange then
Chars:= Chars + LowerCaseChars;
if rrNumbers in ARange then
Chars:= Chars + NumbersChars;
if rrStandartSymbols in ARange then
Chars:= Chars + SymbolsChars;
if Length(AExcludedSymbols) > 0 then
for i:= 1 to Length(AExcludedSymbols) do
begin
j:= Pos(AExcludedSymbols[i], Chars);
if j > 0 then
Delete(Chars, j, 1);
end;
for i:= 1 to sLength do
Result[i]:= Chars[Random(Length(Chars))+1];
end;
end.

View File

@@ -0,0 +1,145 @@
unit VersionControl;
{$MODE Delphi}
{$codepage UTF8}
interface
uses LCLIntf, LCLType, LMessages, SysUtils, StrUtils, Forms, Classes,
{$IFDEF WINDOWS}PJVersionInfo{$ENDIF};
type TSmallVersionInfo = record
sviMajor, sviMinor: int64;
end;
type TVersionInfo = record
viMajor, viMinor, viRelease, viBuild: integer;
end;
function SmallVersionInfoToStr (const Value: TSmallVersionInfo): string; stdcall;
function VersionInfoToStr (const Value: TVersionInfo): string; stdcall;
function VersionInfoToSmallVersionInfo (const Value: TVersionInfo): TSmallVersionInfo; stdcall;
function SmallVersionInfoToVersionInfo (const Value: TSmallVersionInfo; const ANilValue: integer = 0): TVersionInfo; stdcall;
function StrToVersionInfo (const AString: string): TVersionInfo; stdcall;
function StrToSmallVersionInfo (const AString: string): TSmallVersionInfo; stdcall;
function CompareVersionInfo (const AVersionInfo1, AVersionInfo2: TVersionInfo): integer; stdcall;
function CompareSmallVersionInfo (const ASmallVersionInfo1, ASmallVersionInfo2: TSmallVersionInfo): integer; stdcall;
{$IFDEF WINDOWS}function GetApplicationVersionInfoStr (const AFileName, AVersionSTR: string): string; STDCALL;{$ENDIF}
const NilVersionInfo: TVersionInfo = (viMajor: 0; viMinor: 0; viRelease: 0; viBuild: 0);
NilSmallVersionInfo: TSmallVersionInfo = (sviMajor: 0; sviMinor: 0);
implementation
function SmallVersionInfoToStr (const Value: TSmallVersionInfo): string;
const Mask: string = '%d.%d';
begin
Result:= Format(Mask, [Value.sviMajor, Value.sviMinor]);
end;
function VersionInfoToStr (const Value: TVersionInfo): string;
const Mask: string = '%d.%d.%d.%d';
begin
Result:= Format(Mask, [Value.viMajor, Value.viMinor, Value.viRelease, Value.viBuild]);
end;
function VersionInfoToSmallVersionInfo (const Value: TVersionInfo): TSmallVersionInfo;
begin
Result.sviMajor:= Value.viMajor;
Result.sviMinor:= Value.viMinor;
end;
function SmallVersionInfoToVersionInfo (const Value: TSmallVersionInfo; const ANilValue: integer = 0): TVersionInfo;
begin
Result.viMajor:= Value.sviMajor;
Result.viMinor:= Value.sviMinor;
Result.viRelease:= ANilValue;
Result.viBuild:= ANilValue;
end;
function StrToVersionInfo (const AString: string): TVersionInfo;
var stringver: string;
CurrDelim, NextDelim, CurrIndex: Integer;
StrArray: array [1..4] of string;
begin
stringver:= AString;
CurrDelim:= 1;
CurrIndex:= 1;
repeat
NextDelim:= PosEx('.', stringver, CurrDelim);
if NextDelim = 0 then
NextDelim:= Length(stringver) + 1;
StrArray[CurrIndex]:= Copy(stringver, CurrDelim, NextDelim - CurrDelim);
CurrDelim:= NextDelim + 1;
CurrIndex:= CurrIndex + 1;
until CurrDelim > Length(stringver);
Result.viMajor:= StrToInt(StrArray[1]);
Result.viMinor:= StrToInt(StrArray[2]);
Result.viRelease:= StrToInt(StrArray[3]);
Result.viBuild:= StrToInt(StrArray[4]);
end;
function StrToSmallVersionInfo (const AString: string): TSmallVersionInfo;
var stringver: string;
CurrDelim, NextDelim: Integer;
StrArray: array [1..2] of string;
begin
stringver:= AString;
NextDelim:= PosEx('.', stringver, 1);
if NextDelim = 0 then
begin
StrArray[1]:= stringver;
Exit;
end;
StrArray[1]:= Copy(stringver, 1, NextDelim - 1);
CurrDelim:= NextDelim + 1;
NextDelim:= PosEx('.', stringver, CurrDelim);
if NextDelim = 0 then
NextDelim:= Length(stringver) + 1;
StrArray[2]:= Copy(stringver, CurrDelim, NextDelim - CurrDelim);
Result.sviMajor:= StrToInt(StrArray[1]);
Result.sviMinor:= StrToInt(StrArray[2]);
end;
function CompareVersionInfo (const AVersionInfo1, AVersionInfo2: TVersionInfo): integer;
//Result:
// 0 - AVersionInfo1 = AVersionInfo2
// -1 - AVersionInfo1 > AVersionInfo2
// 1 - AVersionInfo1 < AVersionInfo2
begin
//by default this versions are equal
Result:= 0;
//equal
if ((AVersionInfo1.viMajor = AVersionInfo2.viMajor) and
(AVersionInfo1.viMinor = AVersionInfo2.viMinor) and
(AVersionInfo1.viRelease = AVersionInfo2.viRelease) and
(AVersionInfo1.viBuild = AVersionInfo2.viBuild)) then
Result:= 0;
//more
if ((AVersionInfo1.viMajor > AVersionInfo2.viMajor) or
((AVersionInfo1.viMajor = AVersionInfo2.viMajor) and
(AVersionInfo1.viMinor > AVersionInfo2.viMinor)) or
((AVersionInfo1.viMajor = AVersionInfo2.viMajor) and
(AVersionInfo1.viMinor = AVersionInfo2.viMinor) and
(AVersionInfo1.viRelease > AVersionInfo2.viRelease)) or
((AVersionInfo1.viMajor = AVersionInfo2.viMajor) and
(AVersionInfo1.viMinor = AVersionInfo2.viMinor) and
(AVersionInfo1.viRelease = AVersionInfo2.viRelease) and
(AVersionInfo1.viBuild > AVersionInfo2.viBuild))) then
Result:= -1;
//less
if ((AVersionInfo1.viMajor < AVersionInfo2.viMajor) or
((AVersionInfo1.viMajor = AVersionInfo2.viMajor) and
(AVersionInfo1.viMinor < AVersionInfo2.viMinor)) or
((AVersionInfo1.viMajor = AVersionInfo2.viMajor) and
(AVersionInfo1.viMinor = AVersionInfo2.viMinor) and
(AVersionInfo1.viRelease < AVersionInfo2.viRelease)) or
((AVersionInfo1.viMajor = AVersionInfo2.viMajor) and
(AVersionInfo1.viMinor = AVersionInfo2.viMinor) and
(AVersionInfo1.viRelease = AVersionInfo2.viRelease) and
(AVersionInfo1.viBuild < AVersionInfo2.viBuild))) then
Result:= 1;
end;
function CompareSmallVersionInfo (const ASmallVersionInfo1, ASmallVersionInfo2: TSmallVersionInfo): integer;
var AVI1, AVI2: TVersionInfo;
begin
AVI1:= SmallVersionInfoToVersionInfo(ASmallVersionInfo1);
AVI2:= SmallVersionInfoToVersionInfo(ASmallVersionInfo2);
Result:= CompareVersionInfo(AVI1, AVI2);
end;
{$IFDEF WINDOWS}
function GetApplicationVersionInfoStr (const AFileName, AVersionSTR: string): string;
var VIC: TPJVersionInfo;
begin
VIC:= TPJVersionInfo.Create(nil);
VIC.FileName:= AFileName;
Result:= VIC.StringFileInfo[AVersionSTR];
VIC.Free;
end;
{$ENDIF WINDOWS}
end.