|
| 1 | +#define BuildDir SourcePath + "RetailCoder.VBE\bin\Debug" |
| 2 | +#define AppName "RubberDuck" |
| 3 | +#define AddinDLL "Rubberduck.dll" |
| 4 | +#define AppVersion GetFileVersion(SourcePath + "RetailCoder.VBE\bin\Debug\Rubberduck.dll") |
| 5 | +#define AppPublisher "RubberDuck" |
| 6 | +#define AppURL "http://rubberduck-vba.com" |
| 7 | +#define License SourcePath + "\License.rtf" |
| 8 | +#define OutputDirectory SourcePath + "\Installers" |
| 9 | +#define AddinProgId "Rubberduck.Extension" |
| 10 | +#define AddinCLSID "8D052AD8-BBD2-4C59-8DEC-F697CA1F8A66" |
| 11 | + |
| 12 | +[Setup] |
| 13 | +; TODO this CLSID should match the one used by the current installer. |
| 14 | +AppId={{979AFF96-DD9E-4FC2-802D-9E0C36A60D09} |
| 15 | +AppName={#AppName} |
| 16 | +AppVersion={#AppVersion} |
| 17 | +AppPublisher={#AppPublisher} |
| 18 | +AppPublisherURL={#AppURL} |
| 19 | +AppSupportURL={#AppURL} |
| 20 | +AppUpdatesURL={#AppURL} |
| 21 | +; use the local appdata folder instead of the program files dir. |
| 22 | +DefaultDirName={localappdata}\{#AppName} |
| 23 | +DefaultGroupName=Rubberduck |
| 24 | +AllowNoIcons=yes |
| 25 | +LicenseFile={#License} |
| 26 | +OutputDir={#OutputDirectory} |
| 27 | +OutputBaseFilename=Rubberduck.Setup.{#AppVersion} |
| 28 | +Compression=lzma |
| 29 | +SolidCompression=yes |
| 30 | + |
| 31 | +ArchitecturesAllowed=x86 x64 |
| 32 | +ArchitecturesInstallIn64BitMode=x64 |
| 33 | + |
| 34 | +[Languages] |
| 35 | +; TODO add additional installation languages here. |
| 36 | +Name: "English"; MessagesFile: "compiler:Default.isl" |
| 37 | + |
| 38 | +[Files] |
| 39 | +; We are taking everything from the Build directory and adding it to the installer. This |
| 40 | +; might not be what we want to do. |
| 41 | +Source: "{#BuildDir}\*"; DestDir: "{app}"; Flags: ignoreversion; Excludes: "{#AddinDLL}"; Check: Is64BitOfficeInstalled |
| 42 | +Source: "{#BuildDir}\NativeBinaries\amd64\*"; DestDir: "{app}"; Flags: ignoreversion; Excludes: "{#AddinDLL}"; Check: Is64BitOfficeInstalled |
| 43 | +Source: "{#BuildDir}\{#AddinDLL}"; DestDir: "{app}"; Flags: ignoreversion; Check: Is64BitOfficeInstalled; AfterInstall: RegisterAddin |
| 44 | + |
| 45 | +Source: "{#BuildDir}\*"; DestDir: "{app}"; Flags: ignoreversion; Excludes: "{#AddinDLL}"; Check: Is32BitOfficeInstalled |
| 46 | +Source: "{#BuildDir}\NativeBinaries\x86\*"; DestDir: "{app}"; Flags: ignoreversion; Excludes: "{#AddinDLL}"; Check: Is32BitOfficeInstalled |
| 47 | +Source: "{#BuildDir}\{#AddinDLL}"; DestDir: "{app}"; Flags: ignoreversion; Check: Is32BitOfficeInstalled; AfterInstall: RegisterAddin |
| 48 | + |
| 49 | +[UninstallDelete] |
| 50 | +; TODO we may not want to delete everything?... |
| 51 | +Name: {app}; Type: filesandordirs |
| 52 | + |
| 53 | +[Run] |
| 54 | +; http://stackoverflow.com/questions/5618337/how-to-register-a-net-dll-using-inno-setup |
| 55 | +Filename: "{dotnet4032}\RegAsm.exe"; Parameters: "/codebase {#AddinDLL}"; WorkingDir: "{app}"; Flags: runascurrentuser runminimized; StatusMsg: "Registering Controls..."; Check: Is32BitOfficeInstalled |
| 56 | +Filename: "{dotnet4064}\RegAsm.exe"; Parameters: "/codebase {#AddinDLL}"; WorkingDir: "{app}"; Flags: runascurrentuser runminimized; StatusMsg: "Registering Controls..."; Check: Is64BitOfficeInstalled |
| 57 | + |
| 58 | +[UninstallRun] |
| 59 | +Filename: "{dotnet4032}\RegAsm.exe"; Parameters: "/u {#AddinDLL}"; WorkingDir: "{app}"; StatusMsg: "Unregistering Controls..."; Flags: runascurrentuser runminimized; Check: Is32BitOfficeInstalled |
| 60 | +Filename: "{dotnet4064}\RegAsm.exe"; Parameters: "/u {#AddinDLL}"; WorkingDir: "{app}"; StatusMsg: "Unregistering Controls..."; Flags: runascurrentuser runminimized; Check: Is64BitOfficeInstalled |
| 61 | + |
| 62 | +[CustomMessages] |
| 63 | +; TODO add additional languages here. |
| 64 | +English.NETFramework40NotInstalled=Microsoft .NET Framework 4.0 installation was not detected. |
| 65 | + |
| 66 | +[Icons] |
| 67 | +Name: "{group}\{cm:ProgramOnTheWeb,{#AppName}}"; Filename: "{#AppURL}" |
| 68 | +Name: "{group}\{cm:UninstallProgram,{#AppName}}"; Filename: "{uninstallexe}" |
| 69 | + |
| 70 | +[Code] |
| 71 | +// The following code is adapted from: http://stackoverflow.com/a/11651515/2301065 |
| 72 | +const |
| 73 | + SCS_32BIT_BINARY = 0; |
| 74 | + SCS_64BIT_BINARY = 6; |
| 75 | + // There are other values that GetBinaryType can return, but we're |
| 76 | + // not interested in them. |
| 77 | +var |
| 78 | + HasCheckedOfficeBitness: Boolean; |
| 79 | + OfficeIs64Bit: Boolean; |
| 80 | +
|
| 81 | +function GetBinaryType(lpApplicationName: AnsiString; var lpBinaryType: Integer): Boolean; |
| 82 | +external 'GetBinaryTypeA@kernel32.dll stdcall'; |
| 83 | +
|
| 84 | +// TODO this only checks for Excel's bitness, but what if they don't have it installed? |
| 85 | +function Is64BitExcelFromRegisteredExe(): Boolean; |
| 86 | +var |
| 87 | + excelPath: String; |
| 88 | + binaryType: Integer; |
| 89 | +begin |
| 90 | + Result := False; // Default value - assume 32-bit unless proven otherwise. |
| 91 | + // RegQueryStringValue second param is '' to get the (default) value for the key |
| 92 | + // with no sub-key name, as described at |
| 93 | + // http://stackoverflow.com/questions/913938/ |
| 94 | + if IsWin64() and RegQueryStringValue(HKEY_LOCAL_MACHINE, |
| 95 | + 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe', |
| 96 | + '', excelPath) then begin |
| 97 | + // We've got the path to Excel. |
| 98 | + try |
| 99 | + if GetBinaryType(excelPath, binaryType) then begin |
| 100 | + Result := (binaryType = SCS_64BIT_BINARY); |
| 101 | + end; |
| 102 | + except |
| 103 | + // Ignore - better just to assume it's 32-bit than to let the installation |
| 104 | + // fail. This could fail because the GetBinaryType function is not |
| 105 | + // available. I understand it's only available in Windows 2000 |
| 106 | + // Professional onwards. |
| 107 | + end; |
| 108 | + end; |
| 109 | +end; |
| 110 | +
|
| 111 | +function Is64BitOfficeInstalled(): Boolean; |
| 112 | +begin |
| 113 | + if (not HasCheckedOfficeBitness) then |
| 114 | + OfficeIs64Bit := Is64BitExcelFromRegisteredExe(); |
| 115 | + Result := OfficeIs64Bit; |
| 116 | +end; |
| 117 | +
|
| 118 | +function Is32BitOfficeInstalled(): Boolean; |
| 119 | +begin |
| 120 | + Result := (not Is64BitOfficeInstalled()); |
| 121 | +end; |
| 122 | +
|
| 123 | +function InitializeSetup(): Boolean; |
| 124 | +var |
| 125 | + iErrorCode: Integer; |
| 126 | +begin |
| 127 | + // MS .NET Framework 4.0 must be installed for this application to work. |
| 128 | + if Not RegKeyExists(HKLM, 'SOFTWARE\Microsoft\.NETFramework\v4.0.30319') then |
| 129 | + begin |
| 130 | + MsgBox(ExpandConstant('{cm:NETFramework40NotInstalled}'), mbCriticalError, mb_Ok); |
| 131 | + ShellExec('open', 'http://msdn.microsoft.com/en-us/netframework/aa731542', '', '', SW_SHOW, ewNoWait, iErrorCode) |
| 132 | + Result := False; |
| 133 | + end |
| 134 | + else |
| 135 | + Result := True; |
| 136 | +end; |
| 137 | +
|
| 138 | +procedure RegisterAddinForIDE(const iRootKey: Integer; const sAddinSubKey: String; const sProgIDConnect: String); |
| 139 | +begin |
| 140 | + RegWriteStringValue(iRootKey, sAddinSubKey + '\' + sProgIDConnect, 'FriendlyName', '{#AppName}'); |
| 141 | + RegWriteStringValue(iRootKey, sAddinSubKey + '\' + sProgIDConnect, 'Description' , '{#AppName}'); |
| 142 | + RegWriteDWordValue (iRootKey, sAddinSubKey + '\' + sProgIDConnect, 'LoadBehavior', 3); |
| 143 | +end; |
| 144 | +
|
| 145 | +procedure UnregisterAddinForIDE(const iRootKey: Integer; const sAddinSubKey: String; const sProgIDConnect: String); |
| 146 | +begin |
| 147 | + if RegKeyExists(iRootKey, sAddinSubKey + '\' + sProgIDConnect) then |
| 148 | + RegDeleteKeyIncludingSubkeys(iRootKey, sAddinSubKey + '\' + sProgIDConnect); |
| 149 | +end; |
| 150 | +
|
| 151 | +procedure RegisterAddin(); |
| 152 | +begin |
| 153 | + if Is32BitOfficeInstalled() then |
| 154 | + RegisterAddinForIDE(HKCU32, 'Software\Microsoft\VBA\VBE\6.0\Addins', '{#AddinProgId}'); |
| 155 | +
|
| 156 | + if Is64BitOfficeInstalled() then |
| 157 | + RegisterAddinForIDE(HKCU64, 'Software\Microsoft\VBA\VBE\6.0\Addins64', '{#AddinProgId}'); |
| 158 | +end; |
| 159 | +
|
| 160 | +procedure UnregisterAddin(); |
| 161 | +begin |
| 162 | + UnregisterAddinForIDE(HKCU32, 'Software\Microsoft\VBA\VBE\6.0\Addins', '{#AddinProgId}'); |
| 163 | + if IsWin64() then |
| 164 | + UnregisterAddinForIDE(HKCU64, 'Software\Microsoft\VBA\VBE\6.0\Addins64', '{#AddinProgId}'); |
| 165 | +end; |
| 166 | +
|
| 167 | +procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); |
| 168 | +begin |
| 169 | + if CurUninstallStep = usUninstall then UnregisterAddin(); |
| 170 | +end; |
0 commit comments