Skip to content

Commit 11c7039

Browse files
committed
2 parents 6aaa3c1 + eb7bc92 commit 11c7039

File tree

1 file changed

+95
-25
lines changed

1 file changed

+95
-25
lines changed

Installer Build Script.iss

Lines changed: 95 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ Source: "{#BuildDir}\NativeBinaries\x86\*"; DestDir: "{app}"; Flags: ignoreversi
4747
Source: "{#BuildDir}\{#AddinDLL}"; DestDir: "{app}"; Flags: ignoreversion; Check: Is32BitOfficeInstalled; AfterInstall: RegisterAddin
4848

4949
[UninstallDelete]
50-
; TODO we may not want to delete everything?...
51-
Name: {app}; Type: filesandordirs
50+
; Removing all application files (except for configuration).
51+
Name: "{app}\*.dll"; Type: filesandordirs
52+
Name: "{app}\*.xml"; Type: filesandordirs
53+
Name: "{app}\*.pdb"; Type: filesandordirs
5254

5355
[Run]
5456
; http://stackoverflow.com/questions/5618337/how-to-register-a-net-dll-using-inno-setup
@@ -72,46 +74,60 @@ Name: "{group}\{cm:UninstallProgram,{#AppName}}"; Filename: "{uninstallexe}"
7274
const
7375
SCS_32BIT_BINARY = 0;
7476
SCS_64BIT_BINARY = 6;
75-
// There are other values that GetBinaryType can return, but we're
76-
// not interested in them.
77+
// There are other values that GetBinaryType can return, but we're not interested in them.
78+
OfficeNotFound = -1;
79+
7780
var
7881
HasCheckedOfficeBitness: Boolean;
7982
OfficeIs64Bit: Boolean;
8083
8184
function GetBinaryType(lpApplicationName: AnsiString; var lpBinaryType: Integer): Boolean;
8285
external 'GetBinaryTypeA@kernel32.dll stdcall';
8386
84-
// TODO this only checks for Excel's bitness, but what if they don't have it installed?
85-
function Is64BitExcelFromRegisteredExe(): Boolean;
87+
function GetOfficeAppBitness(exeName: string): Integer;
8688
var
87-
excelPath: String;
89+
appPath: String;
8890
binaryType: Integer;
8991
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.
92+
Result := OfficeNotFound; // Default value.
93+
94+
if RegQueryStringValue(HKEY_LOCAL_MACHINE,
95+
'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\' + exeName,
96+
'', appPath) then begin
9897
try
99-
if GetBinaryType(excelPath, binaryType) then begin
100-
Result := (binaryType = SCS_64BIT_BINARY);
101-
end;
98+
if GetBinaryType(appPath, binaryType) then Result := binaryType;
10299
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.
107100
end;
108101
end;
109102
end;
110103
104+
function GetOfficeBitness(): Integer;
105+
var
106+
appBitness: Integer;
107+
officeExeNames: array[0..4] of String;
108+
i: Integer;
109+
begin
110+
officeExeNames[0] := 'excel.exe';
111+
officeExeNames[1] := 'msaccess.exe';
112+
officeExeNames[2] := 'winword.exe';
113+
officeExeNames[3] := 'outlook.exe';
114+
officeExeNames[4] := 'powerpnt.exe';
115+
116+
for i := 0 to 4 do begin
117+
appBitness := GetOfficeAppBitness(officeExeNames[i]);
118+
if appBitness <> OfficeNotFound then begin
119+
Result := appBitness;
120+
exit;
121+
end;
122+
end;
123+
// Note if we get to here then we haven't found any Office versions. Should
124+
// we fail the installation?
125+
end;
126+
111127
function Is64BitOfficeInstalled(): Boolean;
112128
begin
113129
if (not HasCheckedOfficeBitness) then
114-
OfficeIs64Bit := Is64BitExcelFromRegisteredExe();
130+
OfficeIs64Bit := (GetOfficeBitness() = SCS_64BIT_BINARY);
115131
Result := OfficeIs64Bit;
116132
end;
117133
@@ -120,12 +136,66 @@ begin
120136
Result := (not Is64BitOfficeInstalled());
121137
end;
122138
139+
// http://kynosarges.org/DotNetVersion.html
140+
function IsDotNetDetected(version: string; service: cardinal): boolean;
141+
// Indicates whether the specified version and service pack of the .NET Framework is installed.
142+
//
143+
// version -- Specify one of these strings for the required .NET Framework version:
144+
// 'v1.1.4322' .NET Framework 1.1
145+
// 'v2.0.50727' .NET Framework 2.0
146+
// 'v3.0' .NET Framework 3.0
147+
// 'v3.5' .NET Framework 3.5
148+
// 'v4\Client' .NET Framework 4.0 Client Profile
149+
// 'v4\Full' .NET Framework 4.0 Full Installation
150+
// 'v4.5' .NET Framework 4.5
151+
//
152+
// service -- Specify any non-negative integer for the required service pack level:
153+
// 0 No service packs required
154+
// 1, 2, etc. Service pack 1, 2, etc. required
155+
var
156+
key: string;
157+
install, release, serviceCount: cardinal;
158+
check45, success: boolean;
159+
begin
160+
// .NET 4.5 installs as update to .NET 4.0 Full
161+
if version = 'v4.5' then begin
162+
version := 'v4\Full';
163+
check45 := true;
164+
end else
165+
check45 := false;
166+
167+
// installation key group for all .NET versions
168+
key := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\' + version;
169+
170+
// .NET 3.0 uses value InstallSuccess in subkey Setup
171+
if Pos('v3.0', version) = 1 then begin
172+
success := RegQueryDWordValue(HKLM, key + '\Setup', 'InstallSuccess', install);
173+
end else begin
174+
success := RegQueryDWordValue(HKLM, key, 'Install', install);
175+
end;
176+
177+
// .NET 4.0/4.5 uses value Servicing instead of SP
178+
if Pos('v4', version) = 1 then begin
179+
success := success and RegQueryDWordValue(HKLM, key, 'Servicing', serviceCount);
180+
end else begin
181+
success := success and RegQueryDWordValue(HKLM, key, 'SP', serviceCount);
182+
end;
183+
184+
// .NET 4.5 uses additional value Release
185+
if check45 then begin
186+
success := success and RegQueryDWordValue(HKLM, key, 'Release', release);
187+
success := success and (release >= 378389);
188+
end;
189+
190+
result := success and (install = 1) and (serviceCount >= service);
191+
end;
192+
123193
function InitializeSetup(): Boolean;
124194
var
125195
iErrorCode: Integer;
126196
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
197+
// MS .NET Framework 4.5 must be installed for this application to work.
198+
if not IsDotNetDetected('v4.5', 0) then
129199
begin
130200
MsgBox(ExpandConstant('{cm:NETFramework40NotInstalled}'), mbCriticalError, mb_Ok);
131201
ShellExec('open', 'http://msdn.microsoft.com/en-us/netframework/aa731542', '', '', SW_SHOW, ewNoWait, iErrorCode)

0 commit comments

Comments
 (0)