将用户输入的用户输入的占位符替换为已安装的文本文件
作为Inno Setup内置安装程序的一部分,我想将用户输入到安装程序的文本字段输出到文本文件。将用户输入的用户输入的占位符替换为已安装的文本文件
到目前为止,我有以下:
[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]
,这将成功输出到文本文件。
任何人都可以帮助或提供建议,我可能会出错哪里?
此外,我实际上想要将此值输出到现有文本文件的中间,这可能吗? 例如这里是我想要插入的配置文件。将值添加到“在此输入值!” 这可以作为安装的最后一步添加吗?直到安装完成后,配置文件才会存在?正在进行
###############################################################################
#
# 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!
工作,不让自己被获取文本文件输出工作(我想我可能会误解这一职位)之前,我看取代,虽然周围的任何指导将是伟大的,因为我肯定我与Inno的经验不足也会让我接触到那里。
[Code]
var
PrimaryServerPage: TInputQueryWizardPage;
PrimaryAddress: String;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if(CurPageID = wpWelcome) then
begin
PrimaryServerPage := CreateInputQueryPage(wpWelcome,
'Application Server Details', 'Where is your app installed?',
'Please specify the IP address or hostname of your Application Server, ' +
'then click Next.');
PrimaryServerPage.Add('Primary Server IP/Hostname:', false);
PrimaryAddress := PrimaryServerPage.Values[0];
SaveStringToFile('c:\filename.txt', PrimaryAddress, True);
end;
Result :=True;
end;
结合回答这两个问题:
-
Replace a text in a file with Inno Setup(
FileReplaceString
功能) -
Inno Setup Compiler: How to modify file content(使用
CurStepChanged(ssPostInstall)
event function)
,你会得到这样一个代码:
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;
谢谢,马丁。完美的作品。 – Matt
快速问题。我注意到任何运行命令都发生在替换函数(ssPostInstall)之前。在替换命令发生后,是否有办法启动或重新启动服务? – Matt
更简单的方法是在运行部分之前执行'FileReplaceString',请参阅[Inno Setup:如何在运行部分或运行部分之前运行代码过程?](https://stackoverflow.com/q/26257808/850848 ) - 要回答您的问题,请参阅[如何在Inno Setup中执行cmd命令](https://stackoverflow.com/q/14984009/850848) - 如果您需要更多帮助,请提出新问题。 –
[将保存打字文本到Txt文件\ [INNO SETUP \]](https://stackoverflow.com/questions/29000190/save-typed-text-to-txt-file-inno-setup)可能重复 - 保存文件,当用户点击“下一步”时 - 如果你想和其他时间一样,你必须告诉我们。 –
*“想要将此值输出到现有文本文件的中间,这是可能的吗?”* - 一切皆有可能,但您必须定义什么是“中间”。 –
谢谢马丁,我会检查这个帖子。尽管我的狩猎,我没有遇到这个,所以谢谢指出。 我已经在第2点添加了一些额外的信息。感谢您的帮助! – Matt