升级时根据活动文件类型关联设置任务值
Setting task value based on active file type associations when upgrading
作为安装程序的一部分,我有以下任务:
[Tasks]
Name: register32; Description: "Meeting Schedule Assistant (32 bit)"; \
GroupDescription: "{cm:FileAssociations}"; flags: unchecked exclusive;
Name: register64; Description: "Meeting Schedule Assistant (64 bit)"; \
GroupDescription: "{cm:FileAssociations}"; Check: IsWin64; Flags: exclusive;
根据设计,Inno Setup 将 UsePreviousTasks
设置为 Yes
。但是,我的软件安装了两个位版本,用户随后可以通过应用程序设置覆盖默认安装程序。
因此,当我的安装程序升级时,它能否确定哪个位版本正在积极注册并将其设置为该值?
根据你的,我知道你的注册是这样的:
[HKEY_CLASSES_ROOT\MeetSchedAssist.MWB\Shell\Open\Command]
@="\"C:\Program Files (x86)\MeetSchedAssist\MeetSchedAssist.exe\" \"%1\""
[HKEY_CLASSES_ROOT\MeetSchedAssist.MWB\Shell\Open\Command]
@="\"C:\Program Files\MeetSchedAssist\MeetSchedAssist_x64.exe\" \"%1\""
所以你可以查询注册的命令,在命令中寻找相应的可执行文件名。
procedure InitDefaultFileAssociationsTaskValue;
var
SubKeyName, Command: string;
begin
SubKeyName := 'MeetSchedAssist.MWB\Shell\Open\Command';
if not RegQueryStringValue(HKCR, SubKeyName, '', Command) then
begin
Log('MWB registration not found');
end
else
begin
Log(Format('Command registered for MWB is [%s]', [Command]));
Command := Lowercase(Command);
if Pos('meetschedassist_x64.exe', Command) > 0 then
begin
Log('Detected 64-bit registration');
WizardSelectTasks('register64');
end
else
if Pos('meetschedassist.exe', Command) > 0 then
begin
Log('Detected 32-bit registration');
WizardSelectTasks('register32');
end
else
begin
Log('Registration not recognised');
end;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectTasks then
begin
{ Only now is the task list initialized. }
InitDefaultFileAssociationsTaskValue;
end;
end;
您可能需要修改它以仅在用户第一次进入任务页面时更改任务选择。
var
SelectTasksVisited: Boolean;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectTasks then
begin
{ Only now is the task list initialized. }
if not SelectTasksVisited then
begin
InitDefaultFileAssociationsTaskValue;
SelectTasksVisited := True;
end;
end;
end;
作为安装程序的一部分,我有以下任务:
[Tasks]
Name: register32; Description: "Meeting Schedule Assistant (32 bit)"; \
GroupDescription: "{cm:FileAssociations}"; flags: unchecked exclusive;
Name: register64; Description: "Meeting Schedule Assistant (64 bit)"; \
GroupDescription: "{cm:FileAssociations}"; Check: IsWin64; Flags: exclusive;
根据设计,Inno Setup 将 UsePreviousTasks
设置为 Yes
。但是,我的软件安装了两个位版本,用户随后可以通过应用程序设置覆盖默认安装程序。
因此,当我的安装程序升级时,它能否确定哪个位版本正在积极注册并将其设置为该值?
根据你的
[HKEY_CLASSES_ROOT\MeetSchedAssist.MWB\Shell\Open\Command]
@="\"C:\Program Files (x86)\MeetSchedAssist\MeetSchedAssist.exe\" \"%1\""
[HKEY_CLASSES_ROOT\MeetSchedAssist.MWB\Shell\Open\Command]
@="\"C:\Program Files\MeetSchedAssist\MeetSchedAssist_x64.exe\" \"%1\""
所以你可以查询注册的命令,在命令中寻找相应的可执行文件名。
procedure InitDefaultFileAssociationsTaskValue;
var
SubKeyName, Command: string;
begin
SubKeyName := 'MeetSchedAssist.MWB\Shell\Open\Command';
if not RegQueryStringValue(HKCR, SubKeyName, '', Command) then
begin
Log('MWB registration not found');
end
else
begin
Log(Format('Command registered for MWB is [%s]', [Command]));
Command := Lowercase(Command);
if Pos('meetschedassist_x64.exe', Command) > 0 then
begin
Log('Detected 64-bit registration');
WizardSelectTasks('register64');
end
else
if Pos('meetschedassist.exe', Command) > 0 then
begin
Log('Detected 32-bit registration');
WizardSelectTasks('register32');
end
else
begin
Log('Registration not recognised');
end;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectTasks then
begin
{ Only now is the task list initialized. }
InitDefaultFileAssociationsTaskValue;
end;
end;
您可能需要修改它以仅在用户第一次进入任务页面时更改任务选择。
var
SelectTasksVisited: Boolean;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectTasks then
begin
{ Only now is the task list initialized. }
if not SelectTasksVisited then
begin
InitDefaultFileAssociationsTaskValue;
SelectTasksVisited := True;
end;
end;
end;