inno-setup - 我希望在具有最大可用空间的硬盘驱动器上选择 DefaultDirName
问题描述
我正在使用 Inno Setup 创建安装。我想DefaultDirName
在可用空间最大的硬盘驱动器上被选中。
解决方案
实现一个脚本常量来选择磁盘。使用GetDriveType
WinAPI 函数过滤到固定驱动器 ( DRIVE_FIXED
) 和查询可用磁盘空间的GetSpaceOnDisk64
函数。
[Setup]
DefaultDirName={code:GetDiskWithMostFreeSpace}My Program
[Code]
const
DRIVE_NO_ROOT_DIR = 1;
DRIVE_FIXED = 3;
function GetDriveType(lpRootPathName: string): UInt;
external 'GetDriveTypeW@kernel32.dll stdcall';
function GetDiskWithMostFreeSpace(Param: string): string;
var
I: Integer;
D: string;
MostFree: Int64;
Free, Total: Int64;
T: UInt;
begin
Result := '';
MostFree := -1;
for I := Ord('A') to Ord('Z') do
begin
D := Chr(I) + ':\';
T := GetDriveType(D);
if T = DRIVE_NO_ROOT_DIR then
begin
Log(Format('Disk %s does not exist', [D]));
end
else
begin
Log(Format('Disk %s is of type %d', [D, T]));
if T = DRIVE_FIXED then
begin
if not GetSpaceOnDisk64(D, Free, Total) then
begin
Log(Format('Cannot obtain free disk space on %s', [D]));
end
else
begin
Log(Format('Free disk space on %s is %d', [D, Free]));
if Free > MostFree then
begin
MostFree := Free;
Result := D;
end;
end;
end;
end;
end;
if Result = '' then
begin
RaiseException('Did not find any disk');
end;
Log(Format('Selected disk %s', [Result]));
end;
使用 可以改进代码GetVolumeInformation
,如如何在 Inno Setup 中检查分区类型?
推荐阅读
- azure - 在 Azure ADO 管道任务中获取 azure 服务主体,然后将其传递到管道中的下一步
- laravel - 组前缀内的路由名称不包括前缀
- java - 用于显示错误消息的基于拉取的队列
- html - 如何将语义 HTML 合并到 React 中?
- excel - 检索声明的常量列表?
- angular - angular中自定义图标字体的内容是一个奇怪的字符串
- c++ - CMakeList 排除 INCLUDE_PATH 的子目录
- google-analytics - 查看页面 5 次的用户
- python - Redis Cluster,如何并行迭代大量键
- ruby-on-rails - 如何散列 Rails 中的安全问题?