Code:
[Code]
//XML module 1.0
type
TTagPoint = record Name: String; BeginPos, EndPos, Level: Integer; end;
const
CP_ACP = 0; CP_UTF8 = 65001;
Function MultiByteToWideChar(CodePage: UINT; dwFlags: DWORD; lpMultiByteStr: PAnsiChar; cbMultiByte: integer; lpWideCharStr: PAnsiChar; cchWideChar: integer): longint; external '[email protected] stdcall';
Function WideCharToMultiByte(CodePage: UINT; dwFlags: DWORD; lpWideCharStr: PAnsiChar; cchWideChar: integer; lpMultiByteStr: PAnsiChar; cbMultiByte: integer; lpDefaultChar: integer; lpUsedDefaultChar: integer): longint; external '[email protected] stdcall';
function AnsiToUtf8(strSource: string): string;
var
nRet, nRet2: integer; WideCharBuf, MultiByteBuf: AnsiString;
begin
SetLength(WideCharBuf, Length(strSource) * 2);
SetLength(MultiByteBuf, Length(strSource) * 2);
nRet:= MultiByteToWideChar(CP_ACP, 0, strSource, -1, WideCharBuf, Length(WideCharBuf));
nRet2:= WideCharToMultiByte(CP_UTF8, 0, WideCharBuf, -1, MultiByteBuf, Length(MultiByteBuf), 0, 0);
MultiByteBuf:=Copy(MultiByteBuf, 1, nRet2-1);
Result:= MultiByteBuf;
end;
function GetExists(TagArr: array of TTagPoint): Boolean;
var Part1, Part2, Temp: Boolean; n: integer;
begin
if (GetArrayLength(TagArr) > 1) then begin
Temp:= True;
for n:= GetArrayLength(TagArr)-1 downto 1 do begin
Part1:=False; If TagArr[n].BeginPos > TagArr[n-1].BeginPos then Part1:=True;
Part2:=False; If TagArr[n].EndPos < TagArr[n-1].EndPos then Part2:=True;
Temp:=Temp and (Part1 and Part2);
end;
If Temp then Result:= True;
end else begin
Result:=False; if (TagArr[0].BeginPos > 0) and (TagArr[0].EndPos > 0) then Result:= true;
end;
end;
function ExpandTags(const sFileText, sTagName: string): array of TTagPoint;
var i: integer; sTags: array of TTagPoint;
begin
SetArrayLength(Result, 0);
If Pos('\', STagName) > 0 then try
repeat
i:= GetArrayLength(sTags); SetArrayLength(sTags, i+1);
sTags[i].Name:= Copy(sTagName, 1, Pos('\', sTagName)-1);
sTags[i].Level:= i; Delete(sTagName, 1, Pos('\', sTagName));
until Pos('\', STagName) = 0;
finally begin i:= GetArrayLength(sTags); SetArrayLength(sTags, i+1); sTags[i].Level:= i;
sTags[i].Name:= Copy(sTagName, 1, Length(sTagName));
end;
end else begin
SetArrayLength(sTags, 1); sTags[0].Name:= sTagName;
end;
Result:= sTags;
end;
function XMLChangeValue(sFileName, sTagName, sTagParam: string): Boolean;
var sFileText: Ansistring; i: Integer; Tags: array of TTagPoint;
begin
Result:= False
if LoadStringFromFile(sFileName, sFileText) then begin
Tags:= Expandtags(sFileText, sTagName);
for i:=0 to GetArrayLength(Tags)-1 do begin
Tags[i].BeginPos:= Pos('<'+Tags[i].Name, sFileText);
if (Tags[i].BeginPos <> 0) then while sFileText[Tags[i].BeginPos] <> '>' do Tags[i].BeginPos:=Tags[i].BeginPos+1;
Tags[i].EndPos:= Pos('</'+Tags[i].Name+'>', sFileText)
end;
If GetExists(Tags) then begin
i:= GetArrayLength(Tags)-1;
Result:= SaveStringToFile(sFileName, Copy(sFileText,1,Tags[i].BeginPos) + AnsiToUtf8(sTagParam) + Copy(sFileText,Tags[i].EndPos,Length(sFileText)), False);
end;
end;
end;
function XMLWriteValue(sFileName, sTagname, sTagType, sTagParam: string): Boolean;
var sFileText: AnsiString; sSpace, sText: string; i, k, n, CopyPos: Integer; Tags: array of TTagPoint;
begin
Result:= False;
if not FileExists(sFileName) then
SaveStringToFile(sFileName, '<?xml version="1.0" encoding="utf-8" standalone="yes"?>', False);
if LoadStringFromFile(sFileName, sFileText) then begin
Tags:= Expandtags(sFileText, sTagName);
for i:=0 to GetArrayLength(Tags)-1 do begin
Tags[i].BeginPos:= Pos('<'+Tags[i].Name, sFileText);
if (Tags[i].BeginPos <> 0) then while sFileText[Tags[i].BeginPos] <> '>' do Tags[i].BeginPos:=Tags[i].BeginPos+1;
Tags[i].EndPos:= Pos('</'+Tags[i].Name+'>', sFileText)
end;
i:= GetArrayLength(Tags)-1; sText:='';
if ((i-1)<>0) then for n:=0 to i-1 do begin
sSpace:= #13#10; if (Tags[n].Level-1>=0) then for k:=0 to Tags[n].Level-1 do sSpace:=sSpace+#9;
if (Tags[n].BeginPos=0)and(Tags[n].EndPos=0) then sText:= sText+sSpace+'<'+Tags[n].Name+'>';
end;
sSpace:=#13#10; for k:= 0 to Tags[i].Level-1 do sSpace:= sSpace+#9; if (i+1=1) then sSpace:=#13#10;
if (i+1=1)or(Tags[i-1].BeginPos=0) then begin CopyPos:= 1; while sFileText[CopyPos] <> '>' do CopyPos:=CopyPos+1; end else CopyPos:=Tags[i-1].BeginPos;
if (sTagParam <> '')and(sTagType <> '') then sText:= sText+sSpace+'<'+Tags[i].Name+' type="'+sTagType+'">'+AnsiToUtf8(sTagParam)+'</'+Tags[i].Name+'>';
if (sTagParam = '')and(sTagType = '') then sText:= sText+sSpace+'<'+Tags[i].Name+'>'+sSpace+'</'+Tags[i].Name+'>';
if ((i-1)<>0) then for n:=i-1 downto 0 do begin
sSpace:= #13#10; if (Tags[n].Level-1>=0) then for k:=0 to Tags[n].Level-1 do sSpace:=sSpace+#9;
if (Tags[n].BeginPos=0)and(Tags[n].EndPos=0) then sText:= sText+sSpace+'</'+Tags[n].Name+'>';
end;
Result:= SaveStringToFile(sFilename, Copy(sFileText, 1, CopyPos)+sText+Copy(sFileText,CopyPos+1,Length(sFileText)), False)
end;
end;
function XMLReadValue(sFileName, sTagName: string; var sData: string): Boolean;
var sFileText: ansistring; i: Integer; Tags: array of TTagPoint;
begin
Result:= False
if LoadStringFromFile(sFileName, sFileText) then begin
Tags:= ExpandTags(sFileText, sTagName);
for i:=0 to GetArrayLength(Tags)-1 do begin
Tags[i].BeginPos:= Pos('<'+Tags[i].Name, sFileText);
if (Tags[i].BeginPos <> 0) then while sFileText[Tags[i].BeginPos] <> '>' do Tags[i].BeginPos:=Tags[i].BeginPos+1;
Tags[i].EndPos:= Pos('</'+Tags[i].Name+'>', sFileText);
end;
If GetExists(Tags) then begin
i:= GetArrayLength(Tags)-1;
sData:= Copy(sFileText, Tags[i].BeginPos+1, Tags[i].EndPos-Tags[i].BeginPos-1);
Result:= True;
end;
end;
end;
function XMLDeleteValue(sFileName, sTagName: string): Boolean;
var b,e,i: Integer; sFileText: ansistring; Tags: array of TTagPoint;
begin
Result:= False;
if LoadStringFromFile(sFileName, sFileText) then begin
Tags:= ExpandTags(sFileText, sTagName);
for i:=0 to GetArrayLength(Tags)-1 do begin
Tags[i].BeginPos:= Pos('<'+Tags[i].Name, sFileText);
if (Tags[i].BeginPos <> 0) then while sFileText[Tags[i].BeginPos] <> '>' do Tags[i].BeginPos:=Tags[i].BeginPos+1;
Tags[i].EndPos:= Pos('</'+Tags[i].Name+'>', sFileText)
end;
If GetExists(Tags) then begin
i:= GetArrayLength(Tags)-1;
b:= Tags[i].BeginPos-1; e:= Tags[i].EndPos;
while (b-1<>1)and(sFileText[b-1] <> '>') do b:=b-1;
while (e+1<>Length(sFileText))and(sFileText[e-2] <> '>') do e:=e+1;
Result:= SaveStringToFile(sFileName, Copy(sFileText,1,b) + Copy(sFileText,e,Length(sFileText)), False);
end;
end;
end;
//END
function InitializeSetup: Boolean;
var res:integer;
tra,ara,pro,dxv,dxw,vnm:string;
begin
Exec(ExpandConstant('{win}\system32\dxdiag.exe'),'/whql:off /x '+ExpandConstant('{tmp}')+'\dxdiag.xml',ExpandConstant('{tmp}'),0,ewWaitUntilTerminated,res);
XMLReadValue(ExpandConstant('{tmp}\dxdiag.xml'),'DDIVersion',dxv); //video dx
XMLReadValue(ExpandConstant('{tmp}\dxdiag.xml'),'DirectXVersion',dxw); //OS dx
XMLReadValue(ExpandConstant('{tmp}\dxdiag.xml'),'Processor',pro); //Processor
XMLReadValue(ExpandConstant('{tmp}\dxdiag.xml'),'Memory',tra); // All RAM
XMLReadValue(ExpandConstant('{tmp}\dxdiag.xml'),'AvaliableOSMem',ara); //Avaliable RAM
XMLReadValue(ExpandConstant('{tmp}\dxdiag.xml'),'CardName',vnm); //Videocard name
if MsgBox('Processor name: '+pro+#13+'Videocard Name: '+vnm+#13+'OS DirectX Ver: '+dxw+#13+'VideoCard DirectX Ver: DirectX '+dxv+#13+'Ram All/Avaliable: '+tra+'/'+ara,mbInformation,MB_OK) = MB_OK then Result:=False;
end;