Inno Setup在Uninstallable = no时记住选择的安装类型

时间:2016-02-29 22:26:38

标签: inno-setup pascalscript

我正在创建一个有点非传统的Inno Setup安装程序。我正在设置Uninstallable=no但是我仍然需要能够记住用户在将来重新安装时选择的安装类型。我想把类型输出到我能够做的文件中。我不确定如何在下次运行安装程序时设置类型。这是我存储类型的代码。

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if (CurStep = ssDone) then
    SaveStringToFile('{app}\type.dat', WizardSetupType(false), false);
end;

我知道怎么读这个,但我不知道如何设置类型。

编辑:

这是新代码

procedure CurPageChanged(CurPageID: Integer);
begin
  //We need to manually store and restore the install type since Uninstallable=no
  if (CurPageID = wpSelectComponents) then
    WizardForm.TypesCombo.ItemIndex := GetIniInt('Settings', 'InstallType', 0, 0, 3, ExpandConstant('{app}\settings.ini'));
  if (CurPageID = wpInstalling) then
    SetIniInt('Settings', 'InstallType', WizardForm.TypesCombo.ItemIndex, ExpandConstant('{app}\settings.ini'));
end;

1 个答案:

答案 0 :(得分:2)

保存WizardSetupType而不是WizardForm.TypesCombo.ItemIndex,并在恢复选择时将其设置回来。

恢复WizardForm.TypesCombo.OnChange后,您必须致电SaveStringToFile以更新组件选择。

我还建议您使用INI文件函数SetIniIntGetIniInt而不是SetIniInt('Settings', 'InstallType', WizardForm.TypesCombo.ItemIndex, ExpandConstant('{app}\settings.ini'));

商店:

WizardForm.TypesCombo.ItemIndex :=
  GetIniInt('Settings', 'InstallType', 0, 0, 3, ExpandConstant('{app}\settings.ini'));
{ The OnChange is not called automatically when ItemIndex is set programmatically. }
{ We have to call it to update components selection. }
WizardForm.TypesCombo.OnChange(WizardForm.TypesCombo);

还原:

#include <algorithm>
#include <iostream>
#include <string>

bool isVowel(char c)
{
    // A simple function that returns true if the character passed in matches
    // any of the list of vowels, and returns false on any other input.
    if ( 'a' == c ||
         'e' == c ||
         'i' == c ||
         'o' == c ||
         'u' == c ||
         'A' == c ||
         'E' == c ||
         'I' == c ||
         'O' == c ||
         'U' == c) {
        return true; // return true if it's a vowel
    }

    return false; // remember to return false if it isn't
}

std::size_t countVowels(std::string const& sentence)
{
    // Use the standard count_if algorithm to loop over the string and count
    // all characters that the predicate returns true for.
    // Note that we return the resulting total.
    return std::count_if(std::begin(sentence),
                         std::end  (sentence),
                         isVowel);
}

int main() {
    std::string sentence;
    std::cout << "Please enter a sentence, or q to quit: ";
    std::getline(std::cin, sentence);

    if ( "q" == sentence ||
         "Q" == sentence) {
        // Quit if the user entered a string containing just a single letter q.
        // Note we compare against a string literal, not a single character.
        return 0;
    }

    // Call the counting function and print the result.
    std::cout << "There are "
              << countVowels(sentence) // Call the function on the input.
              << " vowels in your sentence\n";
    return 0;
}