| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103 |
- {
- Inno Setup Preprocessor
- Copyright (C) 2001-2002 Alex Yackimoff
- Inno Setup
- Copyright (C) 1997-2025 Jordan Russell
- Portions by Martijn Laan
- For conditions of distribution and use, see LICENSE.TXT.
- }
- unit ISPP.Funcs;
- interface
- uses
- Windows, Classes,
- ISPP.VarUtils, ISPP.Intf, ISPP.Preprocessor, ISPP.Parser;
- procedure RegisterFunctions(Preproc: TPreprocessor);
- implementation
- uses
- SysUtils, IniFiles, Registry, Math, DateUtils,
- MD5, SHA1, SHA256, PathFunc, UnsignedFunc,
- Shared.FileClass, Shared.CommonFunc,
- ISPP.Sessions, ISPP.Consts, ISPP.Base, ISPP.IdentMan;
-
- var
- IsWin64: Boolean;
- function PrependPath(const Ext: NativeInt; const Filename: String): String;
- begin
- var Preprocessor := TObject(Ext) as TPreprocessor;
- Result := PathExpand(Preprocessor.PrependDirName(Filename,
- Preprocessor.SourcePath));
- end;
- function CheckParams(const Params: IIsppFuncParams;
- Types: array of TIsppVarType; Minimum: Integer; var Error: TIsppFuncResult): Boolean;
- var
- I: Integer;
- begin
- FillChar(Error, SizeOf(TIsppFuncResult), 0);
- Result := False;
- if Params.GetCount < Minimum then
- begin
- Error.ErrParam := Minimum;
- Error.Error := ISPPFUNC_INSUFARGS;
- Exit;
- end
- else if Params.GetCount > (High(Types) + 1) then
- begin
- Error.ErrParam := High(Types) + 1;
- Error.Error := ISPPFUNC_MANYARGS;
- Exit;
- end
- else
- with IInternalFuncParams(Params) do
- for I := 0 to Params.GetCount - 1 do
- begin
- if (Types[I] = evSpecial) or (Get(I)^.Typ = evNull) then Continue;
- if Types[I] <> Get(I)^.Typ then
- begin
- if Types[I] = evStr then
- Error.Error := ISPPFUNC_STRWANTED
- else
- Error.Error := ISPPFUNC_INTWANTED;
- Error.ErrParam := I;
- Exit;
- end;
- end;
- Result := True;
- end;
- function Int(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- procedure MakeError(E: Exception);
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL;
- end;
- begin
- if CheckParams(Params, [evSpecial, evInt], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- ResPtr^ := ToInt(Get(0)^);
- except
- on E: EConvertError do
- with IInternalFuncParams(Params) do
- begin
- if GetCount > 1 then
- ResPtr^ := Get(1)^
- else
- MakeError(E);
- end;
- on E: Exception do
- MakeError(E);
- end;
- end;
- function Str(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evSpecial], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- ResPtr^ := ToStr(Get(0)^);
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- {FileExists(<filename>)}
- function FileExists(Ext: NativeInt; const Params: IIsppFuncParams; const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- MakeBool(ResPtr^, NewFileExists(PrependPath(Ext, Get(0).AsStr)));
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function DirExists(Ext: NativeInt; const Params: IIsppFuncParams; const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- MakeBool(ResPtr^, Shared.CommonFunc.DirExists(PrependPath(Ext, Get(0).AsStr)));
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function ForceDirectoriesFunc(Ext: NativeInt; const Params: IIsppFuncParams; const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- MakeBool(ResPtr^, ForceDirectories(PrependPath(Ext, Get(0).AsStr)));
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- {FileSize(<filename>)}
- function FileSize(Ext: NativeInt; const Params: IIsppFuncParams; const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- SearchRec: TSearchRec;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- if FindFirst(PrependPath(Ext, Get(0).AsStr), faAnyFile, SearchRec) = 0 then begin
- try
- MakeInt(ResPtr^, SearchRec.Size);
- finally
- FindClose(SearchRec);
- end;
- end else
- MakeInt(ResPtr^, -1);
- end
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- {ReadIni(<file:str>,<section:str>,<name:str>,[<default:str>])}
- function ReadIni(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- Default: string;
- begin
- if CheckParams(Params, [evStr, evStr, evStr, evStr], 3, Result) then
- try
- with IInternalFuncParams(Params) do
- with TIniFile.Create(Get(0).AsStr) do
- try
- if GetCount < 4 then Default := '' else Default := Get(3).AsStr;
- MakeStr(ResPtr^, ReadString(Get(1).AsStr, Get(2).AsStr, Default));
- finally
- Free
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function WriteIni(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr, evStr, evStr, evSpecial], 4, Result) then
- try
- with IInternalFuncParams(Params) do
- with TIniFile.Create(Get(0).AsStr) do
- try
- case Get(3).Typ of
- evInt: WriteInt64(Get(1).AsStr, Get(2).AsStr, Get(3).AsInt64);
- evStr: WriteString(Get(1).AsStr, Get(2).AsStr, Get(3).AsStr);
- else
- WriteString(Get(1).AsStr, Get(2).AsStr, '');
- end;
- ResPtr^ := NULL;
- finally
- Free;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- {ReadReg(<root:int>,<key:str>,[<name:str>,<default:str>])}
- function ReadReg(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- const
- ISPPRootKeyFlagMask = $7F000000;
- ISPPRootKeyFlag64Bit = $02000000;
- ISPPRootKeyValidFlags = ISPPRootKeyFlag64Bit;
- procedure CrackISPPRootKey(const ISPPRootKey: Int64; var RegView64: Boolean;
- var RootKey: HKEY);
- begin
- { Allow only predefined key handles (8xxxxxxx). Can't accept handles to
- open keys because they might have our special flag bits set.
- Also reject unknown flags which may have a meaning in the future. }
- if (ISPPRootKey shr 31 <> 1) or
- ((ISPPRootKey and ISPPRootKeyFlagMask) and not ISPPRootKeyValidFlags <> 0) then
- raise Exception.Create('Invalid root key value');
- if ISPPRootKey and ISPPRootKeyFlag64Bit <> 0 then begin
- if not IsWin64 then
- raise Exception.Create('Cannot access 64-bit registry keys on this version of Windows');
- RegView64 := True
- end
- else
- RegView64 := False;
- RootKey := HKEY(ISPPRootKey and not ISPPRootKeyFlagMask);
- end;
- var
- Name: string;
- Default: TIsppVariant;
- RegView64: Boolean;
- ARootKey: HKEY;
- AAccess: Cardinal;
- begin
- if CheckParams(Params, [evInt, evStr, evStr, evSpecial], 2, Result) then
- try
- with IInternalFuncParams(Params) do begin
- CrackISPPRootKey(Get(0).AsInt64, RegView64, ARootKey);
- AAccess := KEY_QUERY_VALUE;
- if RegView64 then
- AAccess := AAccess or KEY_WOW64_64KEY;
- with TRegistry.Create(AAccess) do
- try
- RootKey := ARootKey;
- if GetCount < 3 then Name := '' else Name := Get(2).AsStr;
- if GetCount < 4 then Default := NULL else Default := Get(3)^;
- if OpenKey(Get(1).AsStr, False) and ((Name = '') or ValueExists(Name)) then
- case GetDataType(Name) of
- rdString, rdExpandString: MakeStr(ResPtr^, ReadString(Name));
- rdInteger: MakeInt(ResPtr^, ReadInteger(Name));
- else
- CopyExpVar(Default, ResPtr^);
- end
- else
- CopyExpVar(Default, ResPtr^);
- finally
- Free
- end;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetEnvFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- MakeStr(ResPtr^, GetEnv(Get(0).AsStr));
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- const
- SSetup = '[Setup]';
- function SetupSetting(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- function Find(L: TStrings; const S: string): string;
- var
- I, J: Integer;
- InSetupSection: Boolean;
- N: string;
- begin
- InSetupSection := False;
- Result := '';
- with L do
- for I := 0 to Count - 1 do
- begin
- if Trim(Strings[I]) = '' then Continue;
- if InSetupSection then
- begin
- if (Trim(Strings[I])[1] = '[') then
- begin
- if not SameText(Trim(Strings[I]), SSetup) then
- InSetupSection := False;
- Continue;
- end;
- J := Pos('=', Strings[I]);
- if J > 0 then N := Trim(Copy(Strings[I], 1, J - 1));
- if CompareText(N, S) = 0 then
- begin
- Result := Trim(Copy(Strings[I], J + 1, MaxInt));
- Break;
- end;
- end
- else
- if SameText(Trim(Strings[I]), SSetup) then
- InSetupSection := True;
- end;
- end;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- MakeStr(ResPtr^, Find(TPreprocessor(Ext).StringList, Get(0).AsStr));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- {SetSetupSetting(<SetupSectionParameterName>,<ParameterValue>)}
- function SetSetupSetting(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- procedure DoSet(L: TStrings; const S, V: string);
- var
- I, J, FirstSetupSectionLine: Integer;
- InSetupSection: Boolean;
- N: string;
- begin
- FirstSetupSectionLine := -1;
- InSetupSection := False;
- with L do
- begin
- for I := 0 to Count - 1 do
- begin
- if Trim(Strings[I]) = '' then Continue;
- if InSetupSection then
- begin
- if (Trim(Strings[I])[1] = '[') then
- begin
- if not SameText(Trim(Strings[I]), SSetup) then
- InSetupSection := False;
- Continue;
- end;
- J := Pos('=', Strings[I]);
- if J > 0 then N := Trim(Copy(Strings[I], 1, J - 1));
- if CompareText(N, S) = 0 then
- begin
- Strings[I] := S + '=' + V;
- Exit;
- end;
- end
- else
- if SameText(Trim(Strings[I]), SSetup) then
- begin
- InSetupSection := True;
- if FirstSetupSectionLine < 0 then
- FirstSetupSectionLine := I;
- end;
- end;
- if FirstSetupSectionLine < 0 then
- FirstSetupSectionLine := L.Add(SSetup);
- L.Insert(FirstSetupSectionLine + 1, S + '=' + V);
- end;
- end;
- begin
- if CheckParams(Params, [evStr, evStr], 2, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- ResPtr^.Typ := evNull;
- DoSet(TPreprocessor(Ext).StringList, Get(0).AsStr, Get(1).AsStr);
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- {EntryCount(<SectionName>)}
- function EntryCountFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- I, J: Integer;
- DoCount: Boolean;
- N, S: string;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- J := 0;
- DoCount := False;
- with IInternalFuncParams(Params), TStringList(TPreprocessor(Ext).StringList) do
- begin
- S := Get(0).AsStr;
- for I := 0 to Count - 1 do
- begin
- N := Trim(Strings[I]);
- if (N <> '') and (N[1] <> ';') and (N[1] = '[') then
- begin
- if DoCount then
- DoCount := False
- else
- if CompareText(Copy(N, 2, Length(N) - 2), S) = 0 then
- DoCount := True;
- Continue;
- end;
- if DoCount and (N <> '') and (N[1] <> ';') then Inc(J);
- end;
- MakeInt(ResPtr^, J);
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- {SaveToFile(<Filename>)}
- function SaveToFile(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- TPreprocessor(Ext).SaveToFile(PrependPath(Ext, Get(0).AsStr));
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- {Find(<what>[,<contains>[,<what>,<contains>[,<what>[,<contains>]]]])}
- function FindLine(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- type
- TFindWhere = (fwMatch, fwBegin, fwEnd, fwContains);
- function Meets(const Str, Substr: string; Sensitive: Boolean; Where: TFindWhere): Boolean;
- begin
- case Where of
- fwMatch: Result := PathStrCompare(PChar(Str), Length(Str), PChar(Substr), Length(Substr), not Sensitive) = 0;
- fwBegin: Result := PathStartsWith(Str, Substr, not Sensitive);
- fwEnd: Result := PathEndsWith(Str, Substr, not Sensitive);
- fwContains: Result := PathStrFind(PChar(Str), Length(Str), PChar(Substr), Length(Substr), not Sensitive) <> -1;
- else
- raise Exception.Create('FindLine Meets: invalid Where');
- end;
- end;
- const
- FIND_WHEREMASK = $01 or $02;
- FIND_SENSITIVE = $04;
- FIND_OR = $08;
- FIND_NOT = $10;
- FIND_TRIM = $20;
- var
- Strs: array[0..2] of string;
- StrCount: Integer;
- Flags: array[0..2] of Integer;
- begin
- if CheckParams(Params, [evInt, evStr, evInt, evStr, evInt, evStr, evInt], 2, Result) then
- try
- FillChar(Flags, SizeOf(Flags), 0);
- with IInternalFuncParams(Params) do
- begin
- var StartFromLine := Get(0).AsInteger;
- if StartFromLine < 0 then
- StartFromLine := 0;
- Strs[0] := Get(1).AsStr;
- StrCount := 1;
- if GetCount > 2 then begin
- Flags[0] := Get(2).AsInteger;
- if GetCount > 3 then begin
- Strs[1] := Get(3).AsStr;
- Inc(StrCount);
- if GetCount > 4 then begin
- Flags[1] := Get(4).AsInteger;
- if GetCount > 5 then begin
- Strs[2] := Get(5).AsStr;
- Inc(StrCount);
- if GetCount > 6 then
- Flags[2] := Get(6).AsInteger;
- end
- end;
- end
- end;
- const Lines = TPreprocessor(Ext).StringList;
- for var I := StartFromLine to Lines.Count-1 do begin
- var Line := Lines[I];
- if Flags[0] and FIND_TRIM <> 0 then
- Line := Trim(Line);
- var Found := Meets(Line, Strs[0], Flags[0] and FIND_SENSITIVE <> 0,
- TFindWhere(Flags[0] and FIND_WHEREMASK)) xor (Flags[0] and FIND_NOT <> 0);
- if (StrCount > 1) and
- (((Flags[1] and FIND_OR <> 0{OR}) and not Found) or
- ((Flags[1] and FIND_OR = 0{AND}) and Found)) then begin
- const MoreFound = Meets(Line, Strs[1], Flags[1] and FIND_SENSITIVE <> 0,
- TFindWhere(Flags[1] and FIND_WHEREMASK)) xor (Flags[1] and FIND_NOT <> 0);
- if Flags[1] and FIND_OR <> 0 then
- Found := Found or MoreFound
- else
- Found := Found and MoreFound;
- end;
- if (StrCount > 2) and
- (((Flags[2] and FIND_OR <> 0{OR}) and not Found) or
- ((Flags[2] and FIND_OR = 0{AND}) and Found)) then begin
- const MoreFound = Meets(Line, Strs[2], Flags[2] and FIND_SENSITIVE <> 0,
- TFindWhere(Flags[2] and FIND_WHEREMASK)) xor (Flags[2] and FIND_NOT <> 0);
- if Flags[2] and FIND_OR <> 0 then
- Found := Found or MoreFound
- else
- Found := Found and MoreFound;
- end;
- if Found then begin
- MakeInt(ResPtr^, I);
- Exit;
- end;
- end;
- MakeInt(ResPtr^, -2);
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function Exec(const Filename, Params: String; WorkingDir: String;
- const WaitUntilTerminated: Boolean; const ShowCmd: Word;
- const Preprocessor: TPreprocessor; const OutputReader: TCreateProcessOutputReader;
- var ResultCode: Integer): Boolean;
- var
- CmdLine: String;
- WorkingDirP: PChar;
- StartupInfo: TStartupInfo;
- ProcessInfo: TProcessInformation;
- begin
- {This function is a combination of InstFuncs' InstExec and Compile's InternalSignCommand }
- if Filename = '>' then
- CmdLine := Params
- else begin
- if (Filename = '') or (Filename[1] <> '"') then
- CmdLine := '"' + Filename + '"'
- else
- CmdLine := Filename;
- if Params <> '' then
- CmdLine := CmdLine + ' ' + Params;
- if SameText(PathExtractExt(Filename), '.bat') or
- SameText(PathExtractExt(Filename), '.cmd') then begin
- { See InstExec for explanation }
- CmdLine := '"' + AddBackslash(GetSystemDir) + 'cmd.exe" /C "' + CmdLine + '"'
- end;
- if WorkingDir = '' then
- WorkingDir := PathExtractDir(Filename);
- end;
- FillChar (StartupInfo, SizeOf(StartupInfo), 0);
- StartupInfo.cb := SizeOf(StartupInfo);
- StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
- StartupInfo.wShowWindow := ShowCmd;
- if WorkingDir <> '' then
- WorkingDirP := PChar(WorkingDir)
- else
- WorkingDirP := nil;
- var InheritHandles := False;
- var dwCreationFlags: DWORD := CREATE_DEFAULT_ERROR_MODE;
- if (OutputReader <> nil) and WaitUntilTerminated then begin
- OutputReader.UpdateStartupInfo(StartupInfo);
- InheritHandles := True;
- dwCreationFlags := dwCreationFlags or CREATE_NO_WINDOW;
- end;
- Result := CreateProcess(nil, PChar(CmdLine), nil, nil, InheritHandles,
- dwCreationFlags, nil, WorkingDirP, StartupInfo, ProcessInfo);
- if not Result then begin
- DWORD(ResultCode) := GetLastError;
- Exit;
- end;
- { Don't need the thread handle, so close it now }
- CloseHandle(ProcessInfo.hThread);
- if OutputReader <> nil then
- OutputReader.NotifyCreateProcessDone;
- try
- if WaitUntilTerminated then begin
- while True do begin
- case WaitForSingleObject(ProcessInfo.hProcess, 50) of
- WAIT_OBJECT_0: Break;
- WAIT_TIMEOUT:
- begin
- if OutputReader <> nil then
- OutputReader.Read(False);
- Preprocessor.CallIdleProc; { Doesn't allow an Abort }
- end;
- else
- Preprocessor.RaiseError('Exec: WaitForSingleObject failed');
- end;
- end;
- if OutputReader <> nil then
- OutputReader.Read(True);
- end;
- { Get the exit code. Will be set to STILL_ACTIVE if not yet available }
- if not GetExitCodeProcess(ProcessInfo.hProcess, DWORD(ResultCode)) then
- ResultCode := -1; { just in case }
- finally
- CloseHandle(ProcessInfo.hProcess);
- end;
- end;
- procedure ExecLog(const S: String; const Error, FirstLine: Boolean; const Data: NativeInt);
- begin
- var Preprocessor := TPreprocessor(Data);
- if Error then
- Preprocessor.WarningMsg(S)
- else
- Preprocessor.StatusMsg('Exec output: %s', [S]);
- end;
- {
- int Exec(str FileName, str Params, str WorkingDir, int Wait, int ShowCmd, int Log)
- }
- function ExecFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr, evStr, evStr, evInt, evInt, evInt], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- var ParamsS, WorkingDir: String;
- var WaitUntilTerminated := True;
- var ShowCmd: Word := SW_SHOWNORMAL;
- if GetCount > 1 then ParamsS := Get(1).AsStr;
- if GetCount > 2 then WorkingDir := PrependPath(Ext, Get(2).AsStr);
- if (GetCount > 3) and (Get(3).Typ <> evNull) then WaitUntilTerminated := Get(3).AsBoolean;
- if (GetCount > 4) and (Get(4).Typ <> evNull) then ShowCmd := Get(4).AsWord;
- var Preprocessor := TPreprocessor(Ext);
- var ResultCode: Integer;
- var OutputReader := TCreateProcessOutputReader.Create(ExecLog, NativeInt(Preprocessor));
- try
- var Success := Exec(Get(0).AsStr, ParamsS, WorkingDir, WaitUntilTerminated,
- ShowCmd, Preprocessor, OutputReader, ResultCode);
- if not WaitUntilTerminated then
- MakeBool(ResPtr^, Success)
- else
- MakeInt(ResPtr^, ResultCode);
- finally
- OutputReader.Free;
- end;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- type
- PExecAndGetFirstLineLogData = ^TExecAndGetFirstLineLogData;
- TExecAndGetFirstLineLogData = record
- Preprocessor: TPreprocessor;
- Line: String;
- end;
- procedure ExecAndGetFirstLineLog(const S: String; const Error, FirstLine: Boolean; const Data: NativeInt);
- begin
- var Data2 := PExecAndGetFirstLineLogData(Data);
- if not Error and (Data2.Line = '') and (S.Trim <> '') then
- Data2.Line := S;
- ExecLog(S, Error, FirstLine, NativeInt(Data2.Preprocessor));
- end;
- {
- str ExecAndGetFirstLine(str FileName, str Params, str WorkingDir,)
- }
- function ExecAndGetFirstLineFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr, evStr, evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- var ParamsS, WorkingDir: String;
- if GetCount > 1 then ParamsS := Get(1).AsStr;
- if GetCount > 2 then WorkingDir := PrependPath(Ext, Get(2).AsStr);
- var Data: TExecAndGetFirstLineLogData;
- Data.Preprocessor := TPreprocessor(Ext);
- Data.Line := '';
- var ResultCode: Integer;
- var OutputReader := TCreateProcessOutputReader.Create(ExecAndGetFirstLineLog, NativeInt(@Data));
- try
- var Success := Exec(Get(0).AsStr, ParamsS, WorkingDir, True,
- SW_SHOWNORMAL, Data.Preprocessor, OutputReader, ResultCode);
- if Success then
- MakeStr(ResPtr^, Data.Line)
- else begin
- Data.Preprocessor.WarningMsg('CreateProcess failed (%d).', [ResultCode]);
- ResPtr^.Typ := evNull;
- end;
- finally
- OutputReader.Free;
- end;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function LenFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- MakeInt(ResPtr^, Length(Get(0).AsStr));
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function CopyFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- S: string;
- B, C: Int64;
- begin
- if CheckParams(Params, [evStr, evInt, evInt], 2, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- S := Get(0).AsStr;
- B := Get(1).AsInt64;
- if GetCount > 2 then C := Get(2).AsInt64 else C := MaxInt;
- { Constrain 64-bit arguments to 32 bits without truncating them }
- if B < 1 then
- B := 1;
- if C > MaxInt then
- C := MaxInt;
- if (B > MaxInt) or (C < 0) then begin
- { Result should be empty in these cases }
- B := 1;
- C := 0;
- end;
- MakeStr(ResPtr^, Copy(S, Integer(B), Integer(C)));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function PosFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr, evStr], 2, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- MakeInt(ResPtr^, Pos(Get(0).AsStr, Get(1).AsStr));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function LowerCaseFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- MakeStr(ResPtr^, LowerCase(Get(0).AsStr));
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function UpperCaseFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- MakeStr(ResPtr^, UpperCase(Get(0).AsStr));
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function RPosFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr, evStr], 2, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- MakeInt(ResPtr^, Get(1).AsStr.LastIndexOf(Get(0).AsStr) + 1);
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetVersionNumbersStringFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- Filename: string;
- VersionHandle: Cardinal;
- SIZE: Cardinal;
- S: UINT;
- Buf: Pointer;
- FI: PVSFixedFileInfo;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- ResPtr^.Typ := evNull;
- Filename := PrependPath(Ext, Get(0).AsStr);
- Size := GetFileVersionInfoSize(PChar(Filename), VersionHandle);
- if Size > 0 then
- begin
- GetMem(Buf, Size);
- try
- GetFileVersionInfo(PChar(Filename), VersionHandle, Size, Buf);
- if VerQueryValue(Buf, '\', Pointer(FI), S) then
- begin
- MakeStr(ResPtr^,
- IntToStr((FI.dwFileVersionMS and $FFFF0000) shr 16) + '.' +
- IntToStr(FI.dwFileVersionMS and $FFFF) + '.' +
- IntToStr((FI.dwFileVersionLS and $FFFF0000) shr 16) + '.' +
- IntToStr(FI.dwFileVersionLS and $FFFF)
- );
- end;
- finally
- FreeMem(Buf)
- end;
- end
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function ComparePackedVersionFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evInt, evInt], 2, Result) then
- try
- with IInternalFuncParams(Params) do
- MakeInt(ResPtr^, CompareInt64(Get(0).AsInt64, Get(1).AsInt64));
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function SamePackedVersionFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evInt, evInt], 2, Result) then
- try
- with IInternalFuncParams(Params) do
- if Get(0).AsInt64 = Get(1).AsInt64 then
- MakeInt(ResPtr^, 1)
- else
- MakeInt(ResPtr^, 0)
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- {str GetStringFileInfo(str FileName, str StringName, int Lang)}
- function GetFileVersionInfoItem(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- Buf: Pointer;
- function GetStringFileInfo(Lang: UINT; const Name: string; var Value: string): Boolean;
- var
- InfoBuf: Pointer;
- InfoBufSize: Cardinal;
- begin
- Result := VerQueryValue(Buf, PChar('\StringFileInfo\' + IntToHex(LoWord(Lang), 4) +
- IntToHex(HiWord(Lang), 4) +
- '\' + Name), InfoBuf, InfoBufSize) and (InfoBufSize > 0);
- if Result then SetString(Value, PChar(InfoBuf), InfoBufSize - 1)
- end;
- type
- TUINTArray = array[0..$100] of UINT;
- PUINTArray = ^TUINTArray;
- var
- Filename: string;
- VersionHandle: Cardinal;
- Langs: PUINTArray;
- Lang, LangsSize: UINT;
- Value: string;
- Success: Boolean;
- begin
- if CheckParams(Params, [evStr, evStr, evInt], 2, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- Success := False;
- ResPtr^.Typ := evNull;
- Filename := PrependPath(Ext, Get(0).AsStr);
- const Size = GetFileVersionInfoSize(PChar(Filename), VersionHandle);
- if Size > 0 then
- begin
- GetMem(Buf, Size);
- try
- GetFileVersionInfo(PChar(Filename), VersionHandle, Size, Buf);
- if GetCount > 2 then
- begin
- Lang := Get(2).AsCardinal;
- Success := GetStringFileInfo(Lang, Get(1).AsStr, Value);
- end
- else
- begin
- if VerQueryValue(Buf, PChar('\VarFileInfo\Translation'), Pointer(Langs),
- LangsSize) then
- begin
- const LangCount = LangsSize div 4;
- for var I := 0 to LangCount - 1 do
- begin
- Success := GetStringFileInfo(Langs[I], Get(1).AsStr, Value);
- if Success then Break;
- end;
- end;
- end;
- if Success then
- MakeStr(ResPtr^, Value);
- finally
- FreeMem(Buf)
- end;
- end;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function DelFileFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- QueueFileForDeletion(PrependPath(Ext, Get(0).AsStr));
- ResPtr^.Typ := evNull;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function DelFileNowFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- DeleteFile(PChar(PrependPath(Ext, Get(0).AsStr)));
- ResPtr^.Typ := evNull;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function CopyFileFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr, evStr], 2, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- CopyFile(PChar(PrependPath(Ext, Get(0).AsStr)), PChar(PrependPath(Ext, Get(1).AsStr)), False);
- ResPtr^.Typ := evNull;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- type
- PSearchRec = ^TSearchRec;
- procedure GarbageCloseFind(Item: Pointer);
- begin
- FindClose(PSearchRec(Item)^);
- Dispose(Item);
- end;
- function FindFirstFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- Filename: string;
- SR: PSearchRec;
- begin
- if CheckParams(Params, [evStr, evInt], 2, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- Filename := PrependPath(Ext, Get(0).AsStr);
- New(SR);
- ResPtr^.Typ := evInt;
- if FindFirst(Filename, Get(1).AsInteger, SR^) = 0 then
- begin
- ResPtr^.AsInt64 := NativeInt(SR);
- TPreprocessor(Ext).CollectGarbage(SR, Addr(GarbageCloseFind));
- end
- else
- begin
- ResPtr^.AsInt64 := 0;
- Dispose(SR);
- end;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function FindNextFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evInt], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- ResPtr.Typ := evInt;
- if FindNext(PSearchRec(Get(0).AsInt64)^) = 0 then
- ResPtr^.AsInt64 := 1
- else
- ResPtr^.AsInt64 := 0;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function FindGetFileName(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evInt], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- MakeStr(ResPtr^, PSearchRec(Get(0).AsInt64)^.Name);
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function FindCloseFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evInt], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- FindClose(PSearchRec(Get(0).AsInt64)^);
- Dispose(PSearchRec(Get(0).AsInt64));
- TPreprocessor(Ext).UncollectGarbage(Pointer(Get(0).AsInt64));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- type
- PTextFile = ^TextFile;
- procedure GarbageCloseFile(Item: Pointer);
- var
- F: PTextFile;
- begin
- F := Item;
- Close(F^);
- Dispose(F);
- end;
- function FileOpenFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- F: PTextFile;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- New(F);
- try
- with IInternalFuncParams(Params) do
- begin
- FileMode := fmOpenRead or fmShareDenyWrite;
- AssignFile(F^, PrependPath(Ext, Get(0).AsStr));
- {$I-}
- Reset(F^);
- {$I+}
- if IOResult <> 0 then
- begin
- Dispose(F);
- MakeInt(ResPtr^, 0)
- end
- else
- begin
- MakeInt(ResPtr^, NativeInt(F));
- TPreprocessor(Ext).CollectGarbage(F, Addr(GarbageCloseFile));
- end;
- end;
- except
- Dispose(F);
- raise
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function FileGetHandle(const Params: IInternalFuncParams; const Index: Integer): PTextFile;
- begin
- Result := PTextFile(Params.Get(Index).AsInt64);
- if Result = nil then
- raise Exception.Create('Invalid file handle');
- end;
- function FileReadFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- S: string;
- begin
- if CheckParams(Params, [evInt], 1, Result) then
- try
- const P = IInternalFuncParams(Params);
- const F = FileGetHandle(P, 0);
- {$I-}
- Readln(F^, S);
- {$I+}
- if IOResult <> 0 then
- P.ResPtr^ := NULL
- else
- MakeStr(P.ResPtr^, S);
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function FileResetFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evInt], 1, Result) then
- try
- const P = IInternalFuncParams(Params);
- const F = FileGetHandle(P, 0);
- {$I-}
- Reset(F^);
- {$I+}
- if IOResult <> 0 then
- raise Exception.Create('Failed to reset a file')
- else
- P.ResPtr^ := NULL
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function FileEofFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- IsEof: Boolean;
- begin
- if CheckParams(Params, [evInt], 1, Result) then
- try
- const P = IInternalFuncParams(Params);
- const F = FileGetHandle(P, 0);
- {$I-}
- IsEof := Eof(F^);
- {$I+}
- if IOResult <> 0 then
- P.ResPtr^ := NULL
- else
- MakeBool(P.ResPtr^, IsEof);
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function FileCloseFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evInt], 1, Result) then
- try
- const P = IInternalFuncParams(Params);
- const F = FileGetHandle(P, 0);
- {$I-}
- Close(F^);
- {$I+}
- P.ResPtr^ := NULL;
- Dispose(F);
- TPreprocessor(Ext).UncollectGarbage(Pointer(F));
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function SaveStringToFileFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- Filename: String;
- F: TextFile;
- DoAppend: Boolean;
- CodePage: Word;
- begin
- if CheckParams(Params, [evStr, evStr, evInt, evInt], 2, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- Filename := PrependPath(Ext, Get(0).AsStr);
- if (GetCount < 3) or Get(2).AsBoolean then DoAppend := True else DoAppend := False;
- if (GetCount < 4) or Get(3).AsBoolean then CodePage := CP_UTF8 else CodePage := 0;
- DoAppend := DoAppend and NewFileExists(Filename);
- AssignFile(F, FileName, CodePage);
- {$I-}
- if DoAppend then
- Append(F)
- else
- Rewrite(F);
- {$I+}
- if IOResult <> 0 then
- MakeInt(ResPtr^, 0)
- else begin
- try
- MakeInt(ResPtr^, 1);
- if not DoAppend and (CodePage = CP_UTF8) then
- Write(F, #$FEFF); //Strings are UTF-16 so this UTF-16 BOM will actually be saved as an UTF-8 BOM
- Write(F, Get(1).AsStr);
- finally
- CloseFile(F);
- end;
- end;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- type
- PDateTime = ^TDateTime;
- procedure GarbageReleaseDateTime(Item: Pointer);
- begin
- Dispose(Item);
- end;
- function FileGetDate(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- FileDate: PDateTime;
- Age: TDateTime;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- if FileAge(PrependPath(Ext, Get(0).AsStr), Age) then
- begin
- New(FileDate);
- FileDate^ := Age;
- TPreprocessor(Ext).CollectGarbage(FileDate, GarbageReleaseDateTime);
- MakeInt(ResPtr^, Int64(FileDate));
- end
- else
- MakeInt(ResPtr^, -1);
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetNow(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- DateTime: PDateTime;
- begin
- if CheckParams(Params, [], 0, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- New(DateTime);
- DateTime^ := Now;
- TPreprocessor(Ext).CollectGarbage(DateTime, GarbageReleaseDateTime);
- MakeInt(ResPtr^, Int64(DateTime));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetDateFromDT(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evInt], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- MakeInt(ResPtr^, DateTimeToTimeStamp(PDateTime(Get(0).AsInt64)^).Date);
- end;
- except
- on E: EAccessViolation do
- begin
- FuncResult.Error('Invalid datetime value');
- Result.Error := ISPPFUNC_FAIL;
- end;
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetTimeFromDT(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evInt], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- MakeInt(ResPtr^, DateTimeToTimeStamp(PDateTime(Get(0).AsInt64)^).Time);
- end;
- except
- on E: EAccessViolation do
- begin
- FuncResult.Error('Invalid datetime value');
- Result.Error := ISPPFUNC_FAIL;
- end;
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetDateTimeString(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- NewDateSeparatorString, NewTimeSeparatorString: String;
- OldDateSeparator, OldTimeSeparator: Char;
- begin
- if CheckParams(Params, [evStr, evStr, evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- OldDateSeparator := FormatSettings.DateSeparator;
- OldTimeSeparator := FormatSettings.TimeSeparator;
- try
- if GetCount > 1 then
- NewDateSeparatorString := Get(1).AsStr;
- if GetCount > 2 then
- NewTimeSeparatorString := Get(2).AsStr;
- if NewDateSeparatorString <> '' then
- FormatSettings.DateSeparator := NewDateSeparatorString[1];
- if NewTimeSeparatorString <> '' then
- FormatSettings.TimeSeparator := NewTimeSeparatorString[1];
- MakeStr(ResPtr^, FormatDateTime(Get(0).AsStr, Now()));
- finally
- FormatSettings.TimeSeparator := OldTimeSeparator;
- FormatSettings.DateSeparator := OldDateSeparator;
- end;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetFileDateTimeString(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- NewDateSeparatorString, NewTimeSeparatorString: String;
- OldDateSeparator, OldTimeSeparator: Char;
- Age: TDateTime;
- begin
- if CheckParams(Params, [evStr, evStr, evStr, evStr], 2, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- OldDateSeparator := FormatSettings.DateSeparator;
- OldTimeSeparator := FormatSettings.TimeSeparator;
- try
- if GetCount > 2 then
- NewDateSeparatorString := Get(2).AsStr;
- if GetCount > 3 then
- NewTimeSeparatorString := Get(3).AsStr;
- if NewDateSeparatorString <> '' then
- FormatSettings.DateSeparator := NewDateSeparatorString[1];
- if NewTimeSeparatorString <> '' then
- FormatSettings.TimeSeparator := NewTimeSeparatorString[1];
- if not FileAge(PrependPath(Ext, Get(0).AsStr), Age) then begin
- FuncResult.Error('Invalid file name');
- Result.Error := ISPPFUNC_FAIL
- end else
- MakeStr(ResPtr^, FormatDateTime(Get(1).AsStr, Age));
- finally
- FormatSettings.TimeSeparator := OldTimeSeparator;
- FormatSettings.DateSeparator := OldDateSeparator;
- end;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetMD5OfFile(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- Buf: array[0..65535] of Byte;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- var Context: TMD5Context;
- MD5Init(Context);
- var F := TFile.Create(PrependPath(Ext, Get(0).AsStr), fdOpenExisting, faRead, fsReadWrite);
- try
- while True do begin
- var NumRead := F.Read(Buf, SizeOf(Buf));
- if NumRead = 0 then
- Break;
- MD5Update(Context, Buf, NumRead);
- end;
- finally
- F.Free;
- end;
- MakeStr(ResPtr^, MD5DigestToString(MD5Final(Context)));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetMD5OfString(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- var S := AnsiString(Get(0).AsStr);
- MakeStr(ResPtr^, MD5DigestToString(MD5Buf(Pointer(S)^, ULength(S)*SizeOf(S[1]))));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetMD5OfUnicodeString(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- var S := Get(0).AsStr;
- MakeStr(ResPtr^, MD5DigestToString(MD5Buf(Pointer(S)^, ULength(S)*SizeOf(S[1]))));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetSHA1OfFile(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- Buf: array[0..65535] of Byte;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- var Context: TSHA1Context;
- SHA1Init(Context);
- var F := TFile.Create(PrependPath(Ext, Get(0).AsStr), fdOpenExisting, faRead, fsReadWrite);
- try
- while True do begin
- var NumRead := F.Read(Buf, SizeOf(Buf));
- if NumRead = 0 then
- Break;
- SHA1Update(Context, Buf, NumRead);
- end;
- finally
- F.Free;
- end;
- MakeStr(ResPtr^, SHA1DigestToString(SHA1Final(Context)));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetSHA1OfString(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- var S := AnsiString(Get(0).AsStr);
- MakeStr(ResPtr^, SHA1DigestToString(SHA1Buf(Pointer(S)^, ULength(S)*SizeOf(S[1]))));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetSHA1OfUnicodeString(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- var S := Get(0).AsStr;
- MakeStr(ResPtr^, SHA1DigestToString(SHA1Buf(Pointer(S)^, ULength(S)*SizeOf(S[1]))));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetSHA256OfFile(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- Buf: array[0..65535] of Byte;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- var Context: TSHA256Context;
- SHA256Init(Context);
- var F := TFile.Create(PrependPath(Ext, Get(0).AsStr), fdOpenExisting, faRead, fsReadWrite);
- try
- while True do begin
- var NumRead := F.Read(Buf, SizeOf(Buf));
- if NumRead = 0 then
- Break;
- SHA256Update(Context, Buf, NumRead);
- end;
- finally
- F.Free;
- end;
- MakeStr(ResPtr^, SHA256DigestToString(SHA256Final(Context)));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetSHA256OfString(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- var S := AnsiString(Get(0).AsStr);
- MakeStr(ResPtr^, SHA256DigestToString(SHA256Buf(Pointer(S)^, ULength(S)*SizeOf(S[1]))));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function GetSHA256OfUnicodeString(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- var S := Get(0).AsStr;
- MakeStr(ResPtr^, SHA256DigestToString(SHA256Buf(Pointer(S)^, ULength(S)*SizeOf(S[1]))));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function TrimFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- MakeStr(ResPtr^, Trim(Get(0).AsStr));
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function StringChangeFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- S: String;
- begin
- if CheckParams(Params, [evStr, evStr, evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- S := Get(0).AsStr;
- StringChangeEx(S, Get(1).AsStr, Get(2).AsStr, True);
- MakeStr(ResPtr^, S);
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function IsWin64Func(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [], 0, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- MakeBool(ResPtr^, IsWin64);
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function MessageFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do begin
- { Also see Pragma in IsppPreprocessor }
- TPreprocessor(Ext).StatusMsg(Get(0).AsStr);
- ResPtr^ := NULL;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function WarningFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do begin
- { Also see Pragma in IsppPreprocessor }
- TPreprocessor(Ext).WarningMsg(Get(0).AsStr);
- ResPtr^ := NULL;
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function ErrorFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- var
- CatchException: Boolean;
- ErrorMsg: String;
- begin
- CatchException := True;
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do begin
- { Also see Pragma and pcErrorDir in IsppPreprocessor }
- ErrorMsg := Get(0).AsStr;
- if ErrorMsg = '' then ErrorMsg := 'Error';
- CatchException := False;
- TPreprocessor(Ext).RaiseError(ErrorMsg);
- end;
- except
- on E: Exception do
- begin
- if CatchException then begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end else
- raise;
- end;
- end;
- end;
- function AddQuotesFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- MakeStr(ResPtr^, AddQuotes(Get(0).AsStr));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function SameStrFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr, evStr], 2, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- MakeBool(ResPtr^, SameStr(Get(0).AsStr, Get(1).AsStr));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- function Is64BitPEImageFunc(Ext: NativeInt; const Params: IIsppFuncParams;
- const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
- begin
- if CheckParams(Params, [evStr], 1, Result) then
- try
- with IInternalFuncParams(Params) do
- begin
- MakeBool(ResPtr^, Is64BitPEImage(Get(0).AsStr));
- end;
- except
- on E: Exception do
- begin
- FuncResult.Error(PChar(E.Message));
- Result.Error := ISPPFUNC_FAIL
- end;
- end;
- end;
- procedure RegisterFunctions(Preproc: TPreprocessor);
- begin
- with Preproc do
- begin
- { -1 as Ext parameter means that function will be called with Ext set to
- preprocessor instance instead of -1. }
- RegisterFunction('Int', Int, -1);
- RegisterFunction('Str', Str, -1);
- RegisterFunction('FileExists', FileExists, -1);
- RegisterFunction('DirExists', DirExists, -1);
- RegisterFunction('ForceDirectories', ForceDirectoriesFunc, -1);
- RegisterFunction('FileSize', FileSize, -1);
- RegisterFunction('ReadIni', ReadIni, -1);
- RegisterFunction('WriteIni', WriteIni, -1);
- RegisterFunction('ReadReg', ReadReg, -1);
- RegisterFunction('Exec', ExecFunc, -1);
- RegisterFunction('ExecAndGetFirstLine', ExecAndGetFirstLineFunc, -1);
- RegisterFunction('Copy', CopyFunc, -1);
- RegisterFunction('Pos', PosFunc, -1);
- RegisterFunction('RPos', RPosFunc, -1);
- RegisterFunction('Len', LenFunc, -1);
- RegisterFunction('GetVersionNumbersString', GetVersionNumbersStringFunc, -1);
- RegisterFunction('ComparePackedVersion', ComparePackedVersionFunc, -1);
- RegisterFunction('SamePackedVersion', SamePackedVersionFunc, -1);
- RegisterFunction('GetStringFileInfo', GetFileVersionInfoItem, -1);
- RegisterFunction('SaveToFile', ISPP.Funcs.SaveToFile, -1);
- RegisterFunction('Find', FindLine, -1);
- RegisterFunction('SetupSetting', SetupSetting, -1);
- RegisterFunction('SetSetupSetting', SetSetupSetting, -1);
- RegisterFunction('LowerCase', LowerCaseFunc, -1);
- RegisterFunction('UpperCase', UpperCaseFunc, -1);
- RegisterFunction('EntryCount', EntryCountFunc, -1);
- RegisterFunction('GetEnv', GetEnvFunc, -1);
- RegisterFunction('DeleteFile', DelFileFunc, -1);
- RegisterFunction('DeleteFileNow', DelFileNowFunc, -1);
- RegisterFunction('CopyFile', CopyFileFunc, -1);
- RegisterFunction('ReadEnv', GetEnvFunc, -1);
- RegisterFunction('FindFirst', FindFirstFunc, -1);
- RegisterFunction('FindNext', FindNextFunc, -1);
- RegisterFunction('FindGetFileName', FindGetFileName, -1);
- RegisterFunction('FindClose', FindCloseFunc, -1);
- RegisterFunction('FileOpen', FileOpenFunc, -1);
- RegisterFunction('FileRead', FileReadFunc, -1);
- RegisterFunction('FileReset', FileResetFunc, -1);
- RegisterFunction('FileEof', FileEofFunc, -1);
- RegisterFunction('FileClose', FileCloseFunc, -1);
- RegisterFunction('SaveStringToFile', SaveStringToFileFunc, -1);
- RegisterFunction('FileGetDateTime', FileGetDate, -1);
- RegisterFunction('Now', GetNow, -1);
- RegisterFunction('DateTimeToDate', GetDateFromDT, -1);
- RegisterFunction('DateTimeToTime', GetTimeFromDT, -1);
- RegisterFunction('GetDateTimeString', GetDateTimeString, -1);
- RegisterFunction('GetFileDateTimeString', GetFileDateTimeString, -1);
- RegisterFunction('GetMD5OfFile', GetMD5OfFile, -1);
- RegisterFunction('GetMD5OfString', GetMD5OfString, -1);
- RegisterFunction('GetMD5OfUnicodeString', GetMD5OfUnicodeString, -1);
- RegisterFunction('GetSHA1OfFile', GetSHA1OfFile, -1);
- RegisterFunction('GetSHA1OfString', GetSHA1OfString, -1);
- RegisterFunction('GetSHA1OfUnicodeString', GetSHA1OfUnicodeString, -1);
- RegisterFunction('GetSHA256OfFile', GetSHA256OfFile, -1);
- RegisterFunction('GetSHA256OfString', GetSHA256OfString, -1);
- RegisterFunction('GetSHA256OfUnicodeString', GetSHA256OfUnicodeString, -1);
- RegisterFunction('Trim', TrimFunc, -1);
- RegisterFunction('StringChange', StringChangeFunc, -1);
- RegisterFunction('IsWin64', IsWin64Func, -1);
- RegisterFunction('Message', MessageFunc, -1);
- RegisterFunction('Warning', WarningFunc, -1);
- RegisterFunction('Error', ErrorFunc, -1);
- RegisterFunction('AddQuotes', AddQuotesFunc, -1);
- RegisterFunction('SameStr', SameStrFunc, -1);
- RegisterFunction('Is64BitPEImage', Is64BitPEImageFunc, -1);
- end;
- end;
- procedure InitIsWin64;
- var
- IsWow64ProcessFunc: function(hProcess: THandle; var Wow64Process: BOOL): BOOL; stdcall;
- Wow64Process: BOOL;
- begin
- IsWow64ProcessFunc := GetProcAddress(GetModuleHandle(kernel32), 'IsWow64Process');
- IsWin64 := Assigned(IsWow64ProcessFunc) and
- IsWow64ProcessFunc(GetCurrentProcess, Wow64Process) and
- Wow64Process;
- end;
- initialization
- InitIsWin64;
- end.
|