我正在尝试逐行读取文本文件的内容;
我正在寻找一些东西,针对特定的线路。
我需要修改该行;
我需要将新内容保存在另一个文件中,然后删除原始文件并用原始文件名重命名新文件;
function NextButtonClick(CurPageID: Integer): Boolean;
var
ExecInfo: TShellExecuteInfo;
ExecInfoBrowser: TShellExecuteInfo;
textFileFrom, textFileTo : text;
line: string;
begin
Result := True;
if CurPageID = wpFinished then
begin
ExecInfo.cbSize := SizeOf(ExecInfo);
ExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
ExecInfo.Wnd := 0;
ExecInfo.lpFile := ExpandConstant('{app}') + '\{#Exewampmanager}';
ExecInfo.nShow := SW_HIDE;
if ShellExecuteEx(ExecInfo) then
begin
if WaitForSingleObject(ExecInfo.hProcess, 5000) = WAIT_TIMEOUT then
begin
Assign(textFileFrom,'wampmanager.conf');
Reset(textFileFrom);
Assign(textFileto,'wampmanager2.conf');
Rewrite(textFileTo);
repeat
readln(textFileFrom,line);
writeln(textFileto,line);
until eof(textFileFrom);
Close(textFileFrom);
Close(textFileTo);
ExecInfoBrowser.cbSize := SizeOf(ExecInfo);
ExecInfoBrowser.fMask := SEE_MASK_NOCLOSEPROCESS;
ExecInfoBrowser.Wnd := 0;
ExecInfoBrowser.lpFile := 'http://localhost/cow';
ExecInfoBrowser.nShow := SW_HIDE;
ShellExecuteEx(ExecInfoBrowser);
end;
end;
end;
end;
在文件中我需要修改这一行:installDir = "c:/wamp"
因为新安装可能不在同一位置
这是conf文件:
[main]
language = english
status = "offline"
wampserverVersion = 2.2
wampserverLastKnown = 2.2
installDir = "c:/wamp"
navigator = "C:\Windows\explorer.exe"
defaultLanguage = english
[php]
phpVersion = "5.4.3"
phpLastKnown = 5.4.3
phpIniDir = .
phpConfFile = php.ini
phpExeDir = .
[phpCli]
phpCliVersion = 5.4.3
phpExeFile = php.exe
phpCliFile = php-win.exe
[apache]
apacheVersion = "2.2.22"
apacheLastKnown = 2.2.22
apacheExeDir = bin
apacheConfDir = conf
apacheExeFile = httpd.exe
apacheConfFile = httpd.conf
apacheServiceInstallParams = -n wampapache -k install
apacheServiceRemoveParams = -n wampapache -k uninstall
[mysql]
mysqlVersion = "5.5.24"
mysqlLastKnown = 5.5.24
mysqlConfDir = .
mysqlConfFile = my.ini
mysqlExeDir = bin
mysqlExeFile = mysqld.exe
mysqlServiceInstallParams = --install-manual wampmysqld
mysqlServiceRemoveParams = --remove wampmysqld
[apps]
phpmyadminVersion = 3.5.1
sqlbuddyVersion = 1.3.3
webgrindVersion = 1.0
如果该配置文件采用 INI 文件格式(看起来是这样),您可以使用[INI]修改单个值的部分,例如这样(请注意,您必须使用双引号来编译脚本并将值括在双引号中)。当然,您可以像往常一样用常量替换我在这里显示的值:
[INI]
Filename: "{app}\wampmanager.conf"; Section: "main"; Key: "installDir"; String: """{app}"""
或者你可以使用来自的代码使事情变得复杂一些[Code]
部分:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
function ChangeInstallDir(const FileName, InstallDir: string): Boolean;
begin
Result := SetIniString('main', 'installDir', '"' + InstallDir + '"', FileName);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
if not ChangeInstallDir(ExpandConstant('{app}\wampmanager.conf'),
ExpandConstant('{app}')) then
MsgBox('Saving to config file failed!', mbError, MB_OK);
end;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)