使用用户输入的输入替换已安装的文本文件中的占位符

时间:2017-07-24 20:01:30

标签: inno-setup pascalscript

作为Inno Setup内置安装程序的一部分,我想将用户输入安装程序的文本字段输出到文本文件。

到目前为止,我有以下内容:

const images = ['https://placeimg.com/200/200/nature','https://placeimg.com/200/200/tech','https://placeimg.com/200/200/animals','https://placeimg.com/200/200/nature','https://placeimg.com/200/200/tech','https://placeimg.com/200/200/animals','https://placeimg.com/200/200/nature','https://placeimg.com/200/200/tech','https://placeimg.com/200/200/animals','https://placeimg.com/200/200/nature'];

function getPeople() {
   const endpoint = "https://swapi.co/api/people/";
   return fetch(endpoint)
      .then(function(blob) {
         return blob.json();
      })
      .then(function(data) {
         return data.results;
      });
}

getPeople().then(peopleObject => { 
    displayPerson(peopleObject)
});

function displayPerson(peopleObject) {
  
      const people = peopleObject.map((person, index) => {
        return `
          <div class="card">
            <p> ${person.name} </p>
            <p> ${person.height}cm </p>
            <p><img src=${images[index]}</p>
          </div>
        `
   }).join('');
  const cardContainer = document.createElement('div');
  cardContainer.className += "card-container";
  cardContainer.innerHTML = people;
  document.body.appendChild(cardContainer);
}

但是,当我运行安装程序并输入字段时,它不会输出到文本文件。

如果我用数字替换[Code] var PrimaryServerPage: TInputQueryWizardPage; PrimaryAddress: String; procedure InitializeWizard; begin PrimaryServerPage := CreateInputQueryPage(wpWelcome, 'Primary Server Details', 'Where is you application installed?', 'Please specify the IP address or hostname of your Primary Server, ' + 'then click Next.'); PrimaryServerPage.Add('Primary Server IP/Hostname:', false); PrimaryAddress := PrimaryServerPage.Values[0]; SaveStringToFile('c:\filename.txt', PrimaryAddress, True); end; ,则会成功输出到文本文件。

任何人都可以帮助或提供我可能出错的地方的建议吗?

另外,在此之后我实际上想将此值输出到现有文本文件的中间,这可能吗? 例如,这里是我希望将其插入的配置文件。要添加到“输入值此处”的值! 这可以作为安装的最后一步添加吗?安装完成后,配置文件才会存在?

PrimaryServerPage.Values[0]

正在进行中工作,在我看到替换之前,我一直在努力让文本文件输出工作(我想我可能会误解这个帖子),尽管任何指导都会很好,因为我确信我的经验不足Inno也会把我赶出去。

###############################################################################
#
#    Configuration File.
#
###############################################################################

#
# This file is intended for advanced users. Please consult the documentation
# before modifying this file.
#
# NOTE: The hash (#) represents a comment.
#

#
# Define the name or IP address of the primary server.
# On secondary server installs, this value should be changed to point to the
# primary server.
#   Default: 127.0.0.1
#   Examples:  mainserver.localdomain.com, win2003, 1.2.3.4
#
# IMPORTANT: Please restart the Service" after
# changing this value.
#
ApplicationServer=ENTER VALUE HERE!

1 个答案:

答案 0 :(得分:0)

结合这两个问题的答案:

您将获得如下代码:

var
  PrimaryServerPage: TInputQueryWizardPage;

function FileReplaceString(ReplaceString: string):boolean;
var
  MyFile : TStrings;
  MyText : string;
begin
  Log('Replacing in file');
  MyFile := TStringList.Create;

  try
    Result := true;

    try
      MyFile.LoadFromFile(ExpandConstant('{app}' + '\thefile.txt'));
      Log('File loaded');
      MyText := MyFile.Text;

      { Only save if text has been changed. }
      if StringChangeEx(MyText, 'REPLACE_WITH_IP', ReplaceString, True) > 0 then
      begin;
        Log('IP address inserted');
        MyFile.Text := MyText;
        MyFile.SaveToFile(ExpandConstant('{app}' + '\thefile.txt'));
        Log('File saved');
      end;
    except
      Result := false;
    end;
  finally
    MyFile.Free;
  end;

  Result := True;
end;

procedure InitializeWizard;
begin
  PrimaryServerPage :=
    CreateInputQueryPage(
      wpWelcome, 'PaperCut Application Server Details', 'Where is PaperCut installed?',
      'Please specify the IP address or hostname of your ' +
        'Primary PaperCut Application Server, then click Next.');
  PrimaryServerPage.Add('Primary Application Server IP/Hostname:', False);
end;   

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    Log('File installed, replacing IP address');
    FileReplaceString(PrimaryServerPage.Values[0]);
  end;
end;