function CreateLICStopServiceBatch(): boolean;
begin
Result := true;
fileName := ExpandConstant('{code:GetBasicDirectoryValue}\{code:GetInstance}\_Service\Stop_LIC_Service.bat');
SetArrayLength(lines, 3);
lines[0] := ExpandConstant('set wrapdir={code:GetBasicDirectoryValue}\{code:GetInstance}\_Service');
lines[1] := 'cd /d %wrapdir%';
lines[2] := ExpandConstant('commons-daemon\prunsrv.exe //SS//{code:GetLSDVBServiceNameTEdit}');
Result := SaveStringsToFile(filename,lines,false);
exit;
end;
CreateLICStopServiceBatch();
现在我只是将文件写入目录,无论文件是否存在都无关紧要。但我想检查文件是否存在(FileExists
)并且还有机会选择(在对话框中)覆盖或获取已存在的旧文件。
FileExists
function来测试文件是否存在。
见Inno Setup - Check if file exist in destination or else if doesn't abort the installationMsgBox
函数进行确认。
见Inno Setup: Conditionally delete non-empty directory in user's home folderExpandConstant('{code:Function}')
是Pascal代码。这是没有意义的。直接致电Function
。更不用说你的函数可能做了一些微不足道的事情,无论如何你可以内联到代码中。function CreateLICStopServiceBatch(): boolean;
var
FileName: string;
Lines: TArrayOfString;
begin
FileName := GetBasicDirectoryValue + '\' + GetInstance + '\_Service\Stop_LIC_Service.bat';
SetArrayLength(Lines, 3);
Lines[0] := 'set wrapdir=' + GetBasicDirectoryValue + '\' + GetInstance + '\_Service';
Lines[1] := 'cd /d %wrapdir%';
Lines[2] := 'commons-daemon\prunsrv.exe //SS//' + GetLSDVBServiceNameTEdit;
if (not FileExists(FileName)) or
(MsgBox('Overwrite?', mbConfirmation, MB_YESNO) = idYes) then
begin
Result := SaveStringsToFile(FileName, Lines, False);
end
else
begin
{ Not sure what you want to return when user does not confirm overwrite }
Result := False;
end;
end;