Setting task value based on active file type associations when upgrading

跟風遠走 提交于 2020-06-13 08:49:26

问题


I have the following tasks as part of my installer:

[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; 

By design, Inno Setup has UsePreviousTasks set to Yes. However, my software installs both bit editions and the user may subsequently override the installer default via application settings.

Therefore, when my installer is upgrading, can it determine which bit edition is actively registered and leave it set as that value?


回答1:


Based on your previous question, I know that your registrations look like:

[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\""

So you can query the registered command and look for a respective executable name in the command.

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;

You may want to modify this to change the task selection only the first time the user enters the tasks page.

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;


来源:https://stackoverflow.com/questions/61724825/setting-task-value-based-on-active-file-type-associations-when-upgrading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!