-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSW2GZ.iss
More file actions
163 lines (151 loc) · 7.46 KB
/
Copy pathSW2GZ.iss
File metadata and controls
163 lines (151 loc) · 7.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
; SW2GZ installer — auto-removes previous install, kills SolidWorks if running,
; deploys + registers in one click.
; Build: ISCC.exe /DMyAppVersion=<version> installer\SW2GZ.iss (see BUILD.md)
#define MyAppName "SW2GZ"
; MyAppVersion drives AppVersion + the output filename. Pass it explicitly at
; build time so it tracks the git tag being released, e.g.:
; ISCC.exe /DMyAppVersion=2.8.0 installer\SW2GZ.iss
; (BUILD.md and .github/workflows/release.yml derive this from `git describe
; --tags`.) The fallback below is only for ad-hoc local builds without /D —
; bump it when it drifts too far behind the latest tag.
#ifndef MyAppVersion
#define MyAppVersion "2.8.0"
#endif
#define MyAppPublisher "Aryan Arlikar"
; SW2GZ COM addin GUID (matches HKLM\SOFTWARE\SolidWorks\Addins\{...}).
#define AddinGuid "{34fad620-2a46-4ba6-9f5f-1dfefde894c7}"
[Setup]
; {{#AddinGuid} -> literal {GUID}: the leading {{ escapes to one {, the preprocessor
; emits the brace-wrapped GUID, giving a clean AppId of {GUID} (NOT {GUID}}). The
; uninstall key is then {GUID}_is1, which GetUninstallerPath below looks up correctly.
AppId={{#AddinGuid}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName={autopf}\SW2GZ
DefaultGroupName=SW2GZ
DisableProgramGroupPage=yes
OutputDir=Output
OutputBaseFilename=SW2GZ-Setup-{#MyAppVersion}
Compression=lzma
SolidCompression=yes
ArchitecturesInstallIn64BitMode=x64compatible
PrivilegesRequired=admin
; Close SolidWorks automatically if it's running — DLL is locked while SW holds the addin.
; The [Code] InitializeSetup hook also runs taskkill /F as a hard backstop.
CloseApplications=force
RestartApplications=no
[Files]
Source: "..\SW2GZ\bin\x64\Release\SW2GZ.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\SW2GZ\bin\x64\Release\SW2GZ.dll.config"; DestDir: "{app}"; Flags: ignoreversion skipifsourcedoesntexist
; Ship runtime dependency DLLs, but NEVER redistribute:
; solidworkstools.dll -> Dassault Systemes' property, already present on every machine that has SolidWorks.
; xunit* / Moq / Castle.Core / *TestPlatform* -> test-only deps, not needed at runtime.
Source: "..\SW2GZ\bin\x64\Release\*.dll"; DestDir: "{app}"; Flags: ignoreversion; Excludes: "solidworkstools.dll,xunit*.dll,Moq.dll,Castle.Core.dll,Microsoft.VisualStudio.TestPlatform*.dll"
; Ribbon icon set (PNG strip + per-size icons) generated by
; scripts\GenerateIcons.ps1. Sw2gzIconList() / Sw2gzStripIconList() in
; SwAddin.cs return paths under {app}\images\ - without these the ribbon
; falls back to the generic blue (i) placeholder for every command.
Source: "..\SW2GZ\bin\x64\Release\images\*"; DestDir: "{app}\images"; Flags: ignoreversion
; Browser preview assets (three.js + urdf-loader SPA). PreviewServer.cs
; reads "{app}\preview\index.html" at runtime and hosts it on a random
; 127.0.0.1 port. No node / npm install — three.js + urdf-loader load
; from unpkg.com via the page's importmap on first browser open, then
; cache locally. Only external requirement is internet access for that
; first load on each machine.
Source: "..\SW2GZ\bin\x64\Release\preview\*"; DestDir: "{app}\preview"; Flags: ignoreversion recursesubdirs createallsubdirs
[InstallDelete]
; Wipe stale binaries from the install dir before laying down the new build.
Type: filesandordirs; Name: "{app}\*"
; RegAsm registration runs in [Code] (CurStepChanged/ssPostInstall) — it must execute
; AFTER solidworkstools.dll is copied next to SW2GZ.dll (see CopyLocalSolidWorksTools).
; RegAsm has to load the assembly to register it, and the assembly references SolidWorksTools.
[UninstallRun]
Filename: "{win}\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe"; Parameters: "/u ""{app}\SW2GZ.dll"""; Flags: runhidden runascurrentuser; RunOnceId: "Sw2gzRegasmUnregister"
[UninstallDelete]
; Remove the locally-copied solidworkstools.dll and the (now-empty) install dir.
Type: filesandordirs; Name: "{app}"
[Code]
{ ---------- Detect + silently uninstall any previous SW2GZ install. ---------- }
function GetUninstallerPath: string;
var
sUnInstPath: string;
sUnInstallString: string;
begin
Result := '';
// Literal Pascal string -- NO ExpandConstant. The #AddinGuid substitution
// happens at compile time; passing the resulting brace-wrapped GUID through
// ExpandConstant would make Inno try to parse it as a runtime constant.
sUnInstPath := 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#AddinGuid}_is1';
sUnInstallString := '';
if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
Result := sUnInstallString;
end;
function StopSolidWorks: Integer;
var
iResult: Integer;
begin
Result := 0;
{ Try to close SOLIDWORKS gracefully via taskkill; ignore failures (it may not be running). }
Exec(ExpandConstant('{cmd}'), '/C taskkill /IM SLDWORKS.exe /T /F >NUL 2>NUL', '', SW_HIDE, ewWaitUntilTerminated, iResult);
end;
function InitializeSetup: Boolean;
var
sUninstaller: string;
iResult: Integer;
begin
Result := True;
{ Kill any running SolidWorks (DLL is locked while it loads the addin). }
StopSolidWorks;
{ Find any prior SW2GZ install registered under our AppId and silently uninstall it. }
sUninstaller := GetUninstallerPath;
if sUninstaller <> '' then
begin
{ Strip surrounding quotes Inno records around the path. }
sUninstaller := RemoveQuotes(sUninstaller);
if FileExists(sUninstaller) then
begin
Exec(sUninstaller,
'/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /NOCANCEL',
'', SW_HIDE, ewWaitUntilTerminated, iResult);
{ Give regasm /u a moment to release any handles before we lay down new bits. }
Sleep(800);
end;
end;
end;
{ ---------- Locate the machine's own solidworkstools.dll (Dassault's). ----------
We never ship this DLL. RegAsm must load SW2GZ.dll to register it, and SW2GZ.dll
references the SolidWorksTools assembly, so the DLL has to be resolvable. Every
target machine already has SolidWorks installed, so we source it from there. }
function GetSolidWorksToolsDll: string;
var
sRegPath: string;
begin
Result := '';
if FileExists(ExpandConstant('{commonpf}\SOLIDWORKS Corp\SOLIDWORKS\solidworkstools.dll')) then
Result := ExpandConstant('{commonpf}\SOLIDWORKS Corp\SOLIDWORKS\solidworkstools.dll')
else if FileExists(ExpandConstant('{commonpf32}\SOLIDWORKS Corp\SOLIDWORKS\solidworkstools.dll')) then
Result := ExpandConstant('{commonpf32}\SOLIDWORKS Corp\SOLIDWORKS\solidworkstools.dll')
else if RegQueryStringValue(HKLM, 'SOFTWARE\SOLIDWORKS\Setup', 'SolidWorks Folder', sRegPath) then
if FileExists(AddBackslash(sRegPath) + 'solidworkstools.dll') then
Result := AddBackslash(sRegPath) + 'solidworkstools.dll';
end;
procedure CurStepChanged(CurStep: TSetupStep);
var
sApp, sTools: string;
iResult: Integer;
begin
if CurStep = ssPostInstall then
begin
sApp := ExpandConstant('{app}');
{ Copy the local (already-licensed) solidworkstools.dll next to SW2GZ.dll so RegAsm
can resolve it. This is a local copy of the user's own file, not redistribution. }
sTools := GetSolidWorksToolsDll;
if sTools <> '' then
CopyFile(sTools, sApp + '\solidworkstools.dll', False);
{ Register the COM add-in. Must run AFTER the copy above. }
Exec(ExpandConstant('{win}\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe'),
'/codebase "' + sApp + '\SW2GZ.dll"', '', SW_HIDE, ewWaitUntilTerminated, iResult);
end;
end;