Hi,
I have almost finished my installation project with Inno Setup. Setup package is in 32bit mode because it has 32bit dlls to register in Windows environment. Original idea was to detect AutoCAD version and install 3rd addin upon selected version. It also creates AutoCAD profiles and configures them. I don´t know is this a right way to do it but it is a one way. Have a good coding! =)
This is only a part of code because of 20000 characters limit. If someone need rest of it I can put it in .iss file.
[Icons]
Name: "{group}\KHK"; Filename: "{code:GetAutoCADExe}\acad.exe"; WorkingDir: "{app}"; IconFilename: "{app}\Bp.ico"; Parameters: "{code:CheckAutoCADStartupParameters}/p ""KHK"""
[Run]
Filename: "{app}\CopyRegKey.bat"; Parameters: """HKEY_CURRENT_USER\{code:GetTemplateProfileRegKey}"""; WorkingDir: "{app}"; Flags: waituntilterminated; StatusMsg: "Kopioi ja luo AutoCAD profiilit..."; AfterInstall: ModifyKHKProfileRegFile
Filename: "{app}\ImportRegKey.bat"; Parameters: "KHK"; WorkingDir: "{app}"; Flags: waituntilterminated; StatusMsg: "Palauttaa ja muokkaa AutoCAD profiileja..."; AfterInstall: ModifyKHKProfile
[Code]
// Global type definitions
type
AUTOCADINFO = record
location: AnsiString;
productname: AnsiString;
productid: AnsiString;
serialnumber: AnsiString;
registrykey: AnsiString;
end;
AcadInfoArray = array of AUTOCADINFO;
// Global variables
var
SelectAutoCADPage: TInputOptionWizardPage;
AcadInfos: AcadInfoArray;
RootKey: Integer;
// Function declarations
function GetInstalledAutoCADVersions(): Boolean; forward;
function GetAutoCADProductName(Param: String): String; forward;
// Function implementations
function InitializeSetup(): Boolean;
var
bRes: Boolean;
begin;
bRes := False;
Log('InitializeSetup() called');
bRes := GetInstalledAutoCADVersions();
if bRes = False then begin
MsgBox('Koneelta ei löytynyt asennettua AutoCAD -ohjelmaa.' + #13#10 + 'Asennus lopetetaan.', mbInformation, MB_OK);
end;
Result := bRes;
end;
procedure InitializeWizard;
var
iCountAcadProductNames, I: Integer;
button : TButton;
begin
Log('InitializeWizard() called');
// AutoCAD version selection dialog
SelectAutoCADPage := CreateInputOptionPage(wpWelcome, 'AutoCAD version valinta', 'Minkä AutoCAD:n päälle ohjelmisto asennetaan?',
'Valitse AutoCAD versio ja paina Seuraava.', True, False);
iCountAcadProductNames := GetArrayLength(AcadInfos);
for I := 0 to iCountAcadProductNames - 1 do
begin
SelectAutoCADPage.Add(AcadInfos[I].productname);
end;
function GetInstalledAutoCADVersions(): Boolean;
var
S, V, AcadRegKey, sAcadExeLocation, sProductName, sProductId, sSerialNumber, sRegistryKey: String;
I, J, iCountAcadExeLocations: Integer;
AcadVerNames, AcadVerKeysTemp: TArrayOfString;
AcadInfo: AUTOCADINFO;
begin
if IsWin64 then begin
RootKey := HKLM64;
end else begin
RootKey := HKEY_LOCAL_MACHINE;
end;
iCountAcadExeLocations := 0;
AcadRegKey := 'SOFTWARE\Autodesk\AutoCAD';
if RegGetSubkeyNames(RootKey, AcadRegKey, AcadVerNames) then
begin
S := '';
for I := 0 to GetArrayLength(AcadVerNames) - 1 do
begin
//MsgBox(AcadRegKey + '\' + AcadVerNames[I], mbInformation, MB_OK);
if RegGetSubkeyNames(RootKey, AcadRegKey + '\' + AcadVerNames[I], AcadVerKeysTemp) then
begin
for J := 0 to GetArrayLength(AcadVerKeysTemp)-1 do
begin
//SOFTWARE\Autodesk\AutoCAD\R17.2\ACAD-7000:409
//MsgBox(AcadRegKey + '\' + AcadVerNames[I] + '\' + AcadVerKeysTemp[J], mbInformation, MB_OK);
sAcadExeLocation := '';
sRegistryKey := AcadRegKey + '\' + AcadVerNames[I] + '\' + AcadVerKeysTemp[J];
if RegQueryStringValue(RootKey, AcadRegKey + '\' + AcadVerNames[I] + '\' + AcadVerKeysTemp[J], 'Location', sAcadExeLocation) then
begin
sProductName := '';
sProductId := '';
sSerialNumber := '';
SetArrayLength(AcadInfos, iCountAcadExeLocations + 1);
AcadInfo.location := sAcadExeLocation;
if RegQueryStringValue(RootKey, AcadRegKey + '\' + AcadVerNames[I] + '\' + AcadVerKeysTemp[J], 'ProductName', sProductName) then begin
AcadInfo.productname := sProductName;
end;
if RegQueryStringValue(RootKey, AcadRegKey + '\' + AcadVerNames[I] + '\' + AcadVerKeysTemp[J], 'ProductId', sProductId) then begin
AcadInfo.productid := sProductId;
end;
if RegQueryStringValue(RootKey, AcadRegKey + '\' + AcadVerNames[I] + '\' + AcadVerKeysTemp[J], 'SerialNumber', sSerialNumber) then begin
AcadInfo.serialnumber := sSerialNumber;
end;
AcadInfo.registrykey := sRegistryKey;
AcadInfos[iCountAcadExeLocations] := AcadInfo;
//MsgBox('Location = ' + AcadInfo.location + #13#10 + 'ProductName = ' + AcadInfo.productname + #13#10 + 'ProductId = ' + AcadInfo.productid + #13#10 + 'SerialNumber = ' + AcadInfo.serialnumber + #13#10, mbInformation, MB_OK);
iCountAcadExeLocations := iCountAcadExeLocations + 1;
end;
end;
end;
end;
//MsgBox('Founded AutoCAD registry keys:'#13#10#13#10 + S, mbInformation, MB_OK);
end;
if iCountAcadExeLocations > 0 then begin
Result := True;
end else begin
Result := False;
end;
end;
function GetAutoCADProductName(Param: String): String;
var
sRet: String;
begin
// AutoCAD 2012
if Param = 'ACAD-A000:409' then begin
sRet := 'Autodesk Civil 3D 2012';
end else if Param = 'ACAD-A001:409' then begin
sRet := 'AutoCAD 2012';
end else if Param = 'ACAD-A002:409' then begin
sRet := 'Autodesk Map 3D 2012';
// AutoCAD 2013
end else if Param = 'ACAD-B000:409' then begin
sRet := 'Autodesk Civil 3D 2013';
end else if Param = 'ACAD-B001:409' then begin
sRet := 'AutoCAD 2013';
end else if Param = 'ACAD-B002:409' then begin
sRet := 'Autodesk Map 3D 2013';
// AutoCAD 2009
end else if Param = 'ACAD-7000:409' then begin
sRet := 'Autodesk Civil 3D 2009';
end else if Param = 'ACAD-7001:409' then begin
sRet := 'AutoCAD 2009';
end else if Param = 'ACAD-7002:409' then begin
sRet := 'Autodesk Map 3D 2009';
// AutoCAD 2010
end else if Param = 'ACAD-8000:409' then begin
sRet := 'Autodesk Civil 3D 2010';
end else if Param = 'ACAD-8001:409' then begin
sRet := 'AutoCAD 2010';
end else if Param = 'ACAD-8002:409' then begin
sRet := 'Autodesk Map 3D 2010';
// AutoCAD 2011
end else if Param = 'ACAD-9000:409' then begin
sRet := 'Autodesk Civil 3D 2011';
end else if Param = 'ACAD-9001:409' then begin
sRet := 'AutoCAD 2011';
end else if Param = 'ACAD-9002:409' then begin
sRet := 'Autodesk Map 3D 2011';
// AutoCAD 2014
end else if Param = 'ACAD-D000:409' then begin
sRet := 'Autodesk Civil 3D 2014';
end else if Param = 'ACAD-D001:409' then begin
sRet := 'AutoCAD 2014';
end else if Param = 'ACAD-D002:409' then begin
sRet := 'Autodesk Map 3D 2014';
// AutoCAD 2015
end else if Param = 'ACAD-E000:409' then begin
sRet := 'Autodesk Civil 3D 2015';
end else if Param = 'ACAD-E001:409' then begin
sRet := 'AutoCAD 2015';
end else if Param = 'ACAD-E002:409' then begin
sRet := 'Autodesk Map 3D 2015';
// AutoCAD 2016
end else if Param = 'ACAD-F000:409' then begin
sRet := 'Autodesk Civil 3D 2016';
end else if Param = 'ACAD-F001:409' then begin
sRet := 'AutoCAD 2016';
end else if Param = 'ACAD-F002:409' then begin
sRet := 'Autodesk Map 3D 2016';
// Something other AutoCAD version
end else begin
sRet := 'Tuntematon AutoCAD versio: ' + Param;
end;
//MsgBox('GetAutoCADProductName(' + Param + ') = ' + sRet, mbInformation, MB_OK);
Result := sRet;
end;
function GetAutoCADExe(Param: String): String;
begin
Result := AcadInfos[SelectAutoCADPage.SelectedValueIndex].location;
end;
function GetTemplateProfileRegKey(Param: String): String;
var
prodId, regkey: String;
begin
prodId := AcadInfos[SelectAutoCADPage.SelectedValueIndex].productid;
regkey := AcadInfos[SelectAutoCADPage.SelectedValueIndex].registrykey;
Log('CheckAutoCADStartupParameters prodId: ' + prodId);
if prodId = 'F000' then begin // Civil 3D 2016
Result := regkey + '\Profiles\<<C3D_Metric>>';
end else if prodId = 'E000' then begin // Civil 3D 2015
Result := regkey + '\Profiles\<<C3D_Metric>>';
end else if prodId = 'D000' then begin // Civil 3D 2014
Result := regkey + '\Profiles\<<C3D_Metric>>';
end else if prodId = 'B000' then begin // Civil 3D 2013
Result := regkey + '\Profiles\<<C3D_Metric>>';
end else if prodId = 'A000' then begin // Civil 3D 2012
Result := regkey + '\Profiles\<<C3D_Metric>>';
end else if prodId = '9000' then begin // Civil 3D 2011
Result := regkey + '\Profiles\<<C3D_Metric>>';
end else if prodId = '8000' then begin // Civil 3D 2010
Result := regkey + '\Profiles\<<C3D_Metric>>';
end else if prodId = '7000' then begin // Civil 3D 2009
Result := regkey + '\Profiles\<<C3D_Metric>>';
end else begin
Result := regkey + '\Profiles\<<Unnamed Profile>>';
end;
end;
function CheckAutoCADStartupParameters(Param: String): String;
var
prodId, path: String;
begin
prodId := AcadInfos[SelectAutoCADPage.SelectedValueIndex].productid;
path := AcadInfos[SelectAutoCADPage.SelectedValueIndex].location;
Log('CheckAutoCADStartupParameters prodId: ' + prodId);
Log('CheckAutoCADStartupParameters location: ' + path);
if prodId = 'F000' then begin // Civil 3D 2016
Result := '/ld "' + path + '\AecBase.dbx" /product "C3D" ';
end else if prodId = 'F002' then begin // Map 3D 2016
Result := '/product MAP /language "en-US" ';
end else if prodId = 'E000' then begin // Civil 3D 2015
Result := '/ld "' + path + '\AecBase.dbx" /product "C3D" ';
end else if prodId = 'D000' then begin // Civil 3D 2014
Result := '/ld "' + path + '\AecBase.dbx" ';
end else if prodId = 'B000' then begin // Civil 3D 2013
Result := '/ld "' + path + '\AecBase.dbx" ';
end else if prodId = 'A000' then begin // Civil 3D 2012
Result := '/ld "' + path + '\AecBase.dbx" ';
end else if prodId = '9000' then begin // Civil 3D 2011
Result := '/ld "' + path + '\AecBase.dbx" ';
end else if prodId = '8000' then begin // Civil 3D 2010
Result := '/ld "' + path + '\AecBase.dbx" ';
end else if prodId = '7000' then begin // Civil 3D 2009
Result := '/ld "' + path + '\AecBase.dbx" ';
end else begin
Result := '';
end;
end;
Cheers
Veli