Author Topic: Innosetup: Looping through all versions and verticals and languages ...  (Read 33356 times)

0 Members and 1 Guest are viewing this topic.

civil.eng

  • Newt
  • Posts: 66
Re: Innosetup: Looping through all versions and verticals and languages ...
« Reply #45 on: November 14, 2020, 12:57:26 PM »

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.
Code: [Select]
[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
Hi Veli, this topic is old and I hope you see my post. thank you for your great project of Inno Setup, I could perform a project in inno setup with your functions. now I extremely need to copy a single file like a font to all Locations of Autocad. is it possible?

VVeli

  • Newt
  • Posts: 27
Re: Innosetup: Looping through all versions and verticals and languages ...
« Reply #46 on: January 04, 2021, 04:11:40 AM »
Hi,
I think you can add font to right location to use function GetInstalledAutoCADVersions(): Boolean;
It finds all installed AutoCAD versions on your computer. Just get location and add Fonts folder to copy your file there.
There is a global list (AcadInfos: AcadInfoArray;) where founded AutoCAD versions are readed.
Br. Veli

civil.eng

  • Newt
  • Posts: 66
Re: Innosetup: Looping through all versions and verticals and languages ...
« Reply #47 on: March 06, 2021, 08:48:23 AM »
Thank you for replying, I could do the first part of that, so that now I have an array of all installed Autocad locations, but how can I copy fonts to each location of Autocad?
In another words I have one "Source" and several "DestDir", as far as I know we can use only one destination in "DestDir, while we have multiple location.

d2010

  • Bull Frog
  • Posts: 326
Re: Innosetup: Looping through all versions and verticals and languages ...
« Reply #48 on: March 13, 2021, 01:49:53 AM »
InnoSetup. is very good. The setup-installer.exe develope by InnoSetup5, work fine
inside Reactos, but the windows32application does not work.
 :idea:
Thank you for replying, I could do the first part of that, so that now I have an array of all installed Autocad locations, but how can I copy fonts to each location of Autocad?