您可以在安裝之前卸載以前的版本:
如果你不能做一個完整的卸載,你就必須實現部分卸載。
理想的做法是對卸載程序日誌(unins000.dat
)進行逆向工程,只提取安裝到lib
子文件夾並處理(撤消)它們。但由於這是一個未公開的二進制文件,因此很難做到。
如果您維護被安裝在[Files]
部分文件的顯式列表,像
[Files]
Source: "lib\dependency-A-1.2.3.jar"; Dest: "{app}\lib"
Source: "lib\dependency-B-2.3.4.jar"; Dest: "{app}\lib"
那麼無論什麼時候依賴的變化,將以前的版本到[InstallDelete]
部分:
[Files]
Source: "lib\dependency-A-1.3.0.jar"; Dest: "{app}"
Source: "lib\dependency-B-2.3.4.jar"; Dest: "{app}"
[InstallDelete]
{app}\lib\dependency-A-1.2.3.jar
如果您使用通配符安裝依賴,
[Files]
Source: "lib\*.jar"; Dest: "{app}\lib"
並且您無法對卸載程序日誌進行逆向工程,您將不得不通過自己的方式複製其功能。
可以使用preprocessor產生與安裝的依賴關係的文件。將該文件安裝到{app}
文件夾並在安裝之前處理該文件。
[Files]
Source: "MyApp.jar"; DestDir: "{app}"
Source: "lib\*.jar"; DestDir: "{app}\lib"
#define ProcessFile(Source, FindResult, FindHandle) \
Local[0] = FindGetFileName(FindHandle), \
Local[1] = Source + "\\" + Local[0], \
Local[2] = FindNext(FindHandle), \
"'" + Local[0] + "'#13#10" + \
(Local[2] ? ProcessFile(Source, Local[2], FindHandle) : "")
#define ProcessFolder(Source) \
Local[0] = FindFirst(Source + "\\*.jar", faAnyFile), \
ProcessFile(Source, Local[0], Local[0])
#define DepedenciesToInstall ProcessFolder("lib")
#define DependenciesLog "{app}\dependencies.log"
[UninstallDelete]
Type: files; Name: "{#DependenciesLog}"
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
AppPath, DependenciesLogPath: string;
Dependencies: TArrayOfString;
Count, I: Integer;
begin
DependenciesLogPath := ExpandConstant('{#DependenciesLog}');
if CurStep = ssInstall then
begin
{ If dependencies log already exists, remove the previously installed dependencies }
if LoadStringsFromFile(DependenciesLogPath, Dependencies) then
begin
Count := GetArrayLength(Dependencies);
Log(Format('Loaded %d dependencies, deleting...', [Count]));
for I := 0 to Count - 1 do
DeleteFile(ExpandConstant('{app}\lib\' + Dependencies[I]));
end;
end
else
if CurStep = ssPostInstall then
begin
{ Now that the app folder already exists, }
{ save dependencies log (to be processed by future upgrade) }
if SaveStringToFile(DependenciesLogPath, {#DepedenciesToInstall}, False) then
begin
Log('Created dependencies log');
end
else
begin
Log('Failed to create dependencies log');
end;
end;
end;
謝謝你很多。它工作正常,除了第一次安裝,因爲在安裝之前{app} \ lib'不存在,所以我試圖解決這個問題。 –
是的,我已經修復了我的答案。 –