我在调用StringChangeEx函数时遇到问题,该函数正在替换部分文件路径,例如......
这个: C:\ Program Files(x86)\ Steam \ SteamApps \ common \ Stalker Call of Pripyat \ bin
TO: C:\ Program Files(x86)\ Steam \ SteamApps \ common \ Stalker Call of Pripyat_mm2 \ bin
作为在替换文件之前备份文件的方法,同时保持文件的原始文件结构。
http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_stringchangeex
#define Name "Misery Mod"
#define Description "Misery Mod Installer"
#define Version "2.0"
#define Author "Misery Mod Development Team"
#define Website "http://miserymod.com"
#define Support "support@miserymod.com"
#define Copyright "Copyright [c] 2013 Misery Mod. All Rights Reserved."
#define Executable "Stalker-COP.exe"
[Setup]
AppId={{6423E48F-04F4-4E99-9420-FDD9165A6A90}
AppName={#Name}
AppVersion={#Version}
AppVerName={#Name} {#Version}
AppPublisher={#Author}
AppPublisherURL={#Website}
AppSupportURL={#Website}
AppUpdatesURL={#Website}
AppContact={#Support}
AppComments={#Description}
AppCopyright={#Copyright}
DefaultDirName={code:DetectIP}
DirExistsWarning=no
OutputDir=debug
OutputBaseFilename=mm2-installer
Compression=lzma2/ultra64
SolidCompression=yes
InternalCompressLevel=ultra
CompressionThreads=2
VersionInfoVersion={#Version}
VersionInfoCompany={#Author}
VersionInfoDescription={#Description}
VersionInfoTextVersion={#Name} {#Version}
VersionInfoCopyright={#Copyright}
VersionInfoProductName={#Name}
VersionInfoProductVersion={#Version}
VersionInfoProductTextVersion={#Name} {#Version}
DiskSpanning=True
DiskSliceSize=1566000000
SlicesPerDisk=1
MinVersion=0,5.01
SetupIconFile=mm2.ico
UninstallDisplayIcon={uninstallexe}
ShowTasksTreeLines=True
AlwaysShowGroupOnReadyPage=True
AlwaysShowDirOnReadyPage=True
LicenseFile=agreement.rtf
WizardImageFile=mm2-sidebar.bmp
WizardSmallImageFile=mm2-header.bmp
AllowCancelDuringInstall=False
DisableProgramGroupPage=yes
UninstallDisplayName={#Name}
InfoBeforeFile=C:\Users\Nathaniel\Desktop\MM2\readme.rtf
[Run]
Filename: {app}\{#Executable}; Description: {cm:LaunchProgram, {#Name}}; Flags: nowait postinstall skipifsilent unchecked
Filename: {#Website}; Description: {cm:VisitWebsite, {#Name}}; Flags: nowait shellexec postinstall skipifsilent unchecked
[CustomMessages]
LaunchProgram=Enter the Wasteland.
VisitWebsite=Visit {#Website}.
[Languages]
Name: "English"; MessagesFile: "compiler:Default.isl"
Name: "Ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl"
[Dirs]
Name: "{app}\_mm2"
[Files]
Source: "files\bin\*"; DestDir: {app}; Flags: ignoreversion createallsubdirs recursesubdirs; BeforeInstall: BackupFile
[Code]
var Base:String;
var Backup:String;
function DetectIP(Path:String): string;
var Steam:String;
var Retail:String;
Begin
const Base=ExpandConstant('{pf}')+'\'; // <- Identifier expected.
Steam:=ExpandConstant('{pf}')+'\Steam\SteamApps\common\Stalker Call of Pripyat';
Retail:=ExpandConstant('{pf}')+'\Steam\SteamApps\common\Stalker Call of Pripyat';
Begin
if DirExists(Steam) then
Base:=Steam;
End;
Begin
if DirExists(Retail) then
Base:=Retail;
End;
Result:=Base;
End;
procedure BackupFile();
var Folder:String;
var File:String;
Begin
Folder:=ExpandConstant(ExtractFilePath(CurrentFileName));
File:=ExpandConstant(CurrentFileName);
Backup:=StringChangeEx(Folder, Base, Base+'_mm2/', false);
MsgBox(Backup, mbInformation, MB_OK);
Begin
if not DirExists(Backup) then
CreateDir(Backup);
End;
End;
编译器错误!
第89行:第5列:预期的标识符。
答案 0 :(得分:1)
寻找Steam位置和游戏位置:
[Code]
var
CPath: String;
function GetInstallDir(const FileName, Section: string): string;
var
S: string;
DirLine: Integer;
LineCount: Integer;
SectionLine: Integer;
Lines: TArrayOfString;
begin
Result := '';
S := '"' + Section + '"';
if LoadStringsFromFile(FileName, Lines) then
begin
LineCount := GetArrayLength(Lines);
for SectionLine := 0 to LineCount - 1 do
if Trim(Lines[SectionLine]) = S then
begin
if (SectionLine < LineCount) and (Trim(Lines[SectionLine + 1]) = '{') then
for DirLine := SectionLine to LineCount - 1 do
begin
if ((Pos('"installdir"', Lines[DirLine]) > 0) and
(StringChangeEx(Lines[DirLine], '"installdir"', '', True) > 0)) or
((Pos('"InstallDir"', Lines[DirLine]) > 0) and
(StringChangeEx(Lines[DirLine], '"InstallDir"', '', True) > 0)) then
begin
S := RemoveQuotes(Trim(Lines[DirLine]));
StringChangeEx(S, '\\', '\', True);
Result := S;
Exit;
end;
if Trim(Lines[DirLine]) = '}' then
Exit;
end;
Exit;
end;
end;
end;
function InitializeSetup: Boolean;
var
Path: string;
begin
if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Valve\Steam',
'InstallPath', Path) then begin
CPath := '';
CPath := GetInstallDir(Path + '\config\config.vdf', '228200');
//here put you Game ID (this one is for Company of Heroes (new version))
if CPath = '' then begin
MsgBox(ExpandConstant('{cm:NoGameDetected}'), mbInformation, MB_OK);
result := false;
end
else begin
result := true;
end;
end
else begin
MsgBox(ExpandConstant('{cm:NoSteamDetected}'), mbInformation, MB_OK);
result := false;
end;
end;
function GetDefaultInstallPath(DefaultPath: String):String;
begin
DefaultPath := CPath;
Result := DefaultPath;
end;