The problem is multiplied with languages and versions. So maybe this pseudo-code would help (pseudo-code because my Pascal-knowledge is too low for real code).
First, there are many ways of going about this.
Second, I'd avoid going with normal arrays in Pascal. They need to be declared as static (i.e. you need to state their sizes beforehand), even FreePascal's dynamic arrays need to be adjusted using SetLength (don't know if PascalScript even has this), so any modifications later would mean you'd need to change at least 2 pieces of code. Next you either need to save the array lengths somewhere, or use the Low & High functions to get the start and end indexes.
I'd rather go with a built-in collection of strings, something like
TStringList. Because it allows to simply add to it, it's always a 0 based index, and it contains a Count property.
Then to initialize the variables you'd need something much more verbose than you're used to:
{ Define what should be supported }
var myVersions : TStringList;
myLanguages : TStringList;
myProducts : TStringList;
{ Procedure called by InnoSetup when it starts }
procedure InitializeWizard();
begin
{ Initialize the values of supported versions }
myVersions := TStringList.Create; // Make a new TStringList object reference
myVersions.Add('18.0'); // Add a string into the StringList object
myVersions.Add('18.1');
myVersions.Add('18.2');
myVersions.Add('19.0');
myLanguages := myLanguages.Create;
myLanguages.Add('401');
myLanguages.Add('407');
myLanguages.Add('410');
myLanguages.Add('804');
myProducts := myProducts.Create;
myProducts.Add('9000');
myProducts.Add('9001');
myProducts.Add('A000');
myProducts.Add('A001');
myProducts.Add('A007');
end;
{ Procedure called by InnoSetup when it's closing }
procedure DeinitializeSetup();
begin
myVersions.Free;
myLanguages.Free;
myProducts.Free;
end;
Notice that the object is instantiated through the Create constructor. But this means that you need to release it using the Free destructor. The procedures I've used are standard names called by InnoSetup at specific points during the installer's run, others can be found here:
http://www.jrsoftware.org/ishelp/index.php?topic=scripteventsNext, you'd need to step through those in a similar idea as DanW's code.
procedure AddRegistry();
var v, l, p, root : Integer;
path1, path2 : String;
begin
if IsWin64 then root := HKLM64
else root := HKLM32;
path1 := 'SOFTWARE\Autodesk\AutoCAD\';
path2 := '\Applications\MyCADApp\';
for v := 0 to (myVersions.Count - 1) do
if RegKeyExists(root, path1 + myVersions[v]) then
for l := 0 to (myLanguages.Count - 1) do
for p := 0 to (myProducts.Count - 1) do
if RegKeyExists(root, path1 + myVersions[v] + '\ACAD-' + myProducts[p] + ':' + myLanguages[l]) then begin
RegWriteStringValue(root, path1 + myVersions[v] + '\ACAD-' + myProducts[p] + ':' + myLanguages[l] + path2,
'InstallPath', ExpandConstant('{app}');
end;
end;
Simpler AlternativeRather than save all versions to arrays / collections and then step through all that. do the same principle as DanW's code:
procedure AddACADRegKey (const Version, Language, Product : String);
var root : Integer;
path1, path2 : String;
begin
if IsWin64 then root := HKLM64
else root := HKLM32;
path1 := 'SOFTWARE\Autodesk\AutoCAD\';
path2 := '\Applications\MyCADApp\';
if RegKeyExists(root, path1 + Version + '\ACAD-' + Product + ':' + Language) then begin
RegWriteStringValue(root, path1 + Version + '\ACAD-' + Product + ':' + Language + path2,
'InstallPath', ExpandConstant('{app}');
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep=ssPostInstall
then begin
AddAcadRegKey ('R18.2', '401', '9000');
AddAcadRegKey ('R19.0', '804', 'A000');
end;
end;
No Code AlternativeYou could simply add these things into your Registry section and have a Check parameter for each. E.g.
[Registry]
Root: HKLM; Subkey: "SOFTWARE\Autodesk\AutoCAD\18.0\ACAD-A000:401\Applications\MyCADApp\"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"; Flags: uninsdeletekey; Check: RegKeyExists(HKLM, 'SOFTWARE\Autodesk\AutoCAD\18.0\ACAD-A000:401')
Root: HKLM; Subkey: "SOFTWARE\Autodesk\AutoCAD\18.1\ACAD-9000:407\Applications\MyCADApp\"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"; Flags: uninsdeletekey; Check: RegKeyExists(HKLM, 'SOFTWARE\Autodesk\AutoCAD\18.1\ACAD-9000:407')
Root: HKLM; Subkey: "SOFTWARE\Autodesk\AutoCAD\19.0\ACAD-A007:804\Applications\MyCADApp\"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"; Flags: uninsdeletekey; Check: RegKeyExists(HKLM, 'SOFTWARE\Autodesk\AutoCAD\19.0\ACAD-A007:804')
No need to "code", just call the built-in function. Though now you add the registry path twice. And you might need to do something for the 32/64 bit issue.