Skip to content

Commit a4105f9

Browse files
committed
A property winConfig.removeOldLibs
1 parent c23d50f commit a4105f9

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

src/main/java/io/github/fvarrui/javapackager/model/WindowsConfig.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class WindowsConfig implements Serializable {
4545
private SetupMode setupMode = SetupMode.installForAllUsers;
4646
private WindowsSigning signing;
4747
private Registry registry = new Registry();
48+
private boolean removeOldLibs = false;
4849

4950
public File getIcoFile() {
5051
return icoFile;
@@ -269,15 +270,23 @@ public boolean isDisableRunAfterInstall() {
269270
public void setDisableRunAfterInstall(boolean disableRunAfterInstall) {
270271
this.disableRunAfterInstall = disableRunAfterInstall;
271272
}
272-
273+
273274
public void setDisableWelcomePage(boolean disableWelcomePage) {
274275
this.disableWelcomePage = disableWelcomePage;
275276
}
276-
277+
277278
public boolean isDisableWelcomePage() {
278279
return disableWelcomePage;
279280
}
280281

282+
public boolean isRemoveOldLibs() {
283+
return removeOldLibs;
284+
}
285+
286+
public void setRemoveOldLibs(boolean removeOldLibs) {
287+
this.removeOldLibs = removeOldLibs;
288+
}
289+
281290
@Override
282291
public String toString() {
283292
return "WindowsConfig [icoFile=" + icoFile + ", headerType=" + headerType + ", companyName=" + companyName
@@ -290,7 +299,8 @@ public String toString() {
290299
+ ", disableWelcomePage=" + disableWelcomePage + ", createDesktopIconTask=" + createDesktopIconTask
291300
+ ", generateSetup=" + generateSetup + ", generateMsi=" + generateMsi + ", generateMsm=" + generateMsm
292301
+ ", msiUpgradeCode=" + msiUpgradeCode + ", wrapJar=" + wrapJar + ", setupLanguages=" + setupLanguages
293-
+ ", setupMode=" + setupMode + ", signing=" + signing + ", registry=" + registry + "]";
302+
+ ", setupMode=" + setupMode + ", signing=" + signing + ", registry=" + registry + ", removeOldLibs="
303+
+ removeOldLibs + "]";
294304
}
295305

296306
/**

src/main/resources/windows/iss.vtl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,42 @@ Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilen
9292
#if (!$info.winConfig.disableRunAfterInstall)
9393
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent runascurrentuser
9494
#end
95+
96+
[Code]
97+
98+
function GetInstallLocation(): String;
99+
var
100+
unInstPath: String;
101+
installLocation: String;
102+
begin
103+
unInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');
104+
installLocation := '';
105+
if not RegQueryStringValue(HKLM, unInstPath, 'InstallLocation', installLocation) then
106+
RegQueryStringValue(HKCU, unInstPath, 'InstallLocation', installLocation);
107+
Result := RemoveQuotes(installLocation);
108+
end;
109+
110+
#if ($info.winConfig.removeOldLibs)
111+
procedure RemoveOldLibs();
112+
var
113+
installLocation: String;
114+
libsLocation: String;
115+
begin
116+
installLocation := GetInstallLocation();
117+
if installLocation <> '' then
118+
begin
119+
libsLocation := installLocation + 'libs';
120+
DelTree(libsLocation, True, True, True);
121+
end;
122+
end;
123+
#end
124+
125+
procedure CurStepChanged(CurStep: TSetupStep);
126+
begin
127+
if CurStep = ssInstall then
128+
begin
129+
#if ($info.winConfig.removeOldLibs)
130+
RemoveOldLibs();
131+
#end
132+
end;
133+
end;

0 commit comments

Comments
 (0)