-1

I am having problems calling the StringChangeEx function which is replacing parts of a file path such as...

THIS: 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

As a way of backing up files before replacing them while maintaining it's original file structure.

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;

Compiler Error!
Line 89: Column 5: Identifier expected.

TLama
  • 75,147
  • 17
  • 214
  • 392
  • Small question: How do you know, that everyone has Steam installed in {pf}? You should look for real Steam location. `RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Valve\Steam','InstallPath', Path)`. What more... Steam allows to install games in different folder (not only in Steam main folder). You should check in Steam Config file where the game is installed. E.g. [like that](http://stackoverflow.com/questions/15789494/find-and-read-specific-string-from-config-file-with-pascal-script-in-inno-setup) to check where the game is installed. – RobeN Aug 01 '13 at 17:21
  • If it can't find Steam using the folder check function then you can define where you want it to be installed as normal. It would be too time consuming to search an entire PC to find the game. –  Aug 01 '13 at 17:23
  • Which is why you need to use the registry lookup. I never install games into {pf}. – Miral Aug 02 '13 at 21:34

1 Answers1

1

Looking for Steam location and game location:

[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;
RobeN
  • 5,346
  • 1
  • 33
  • 50
  • Thanks for this but it's not the problem I am having. Besides the game can be bought as a retail disk which could be installed anywhere. –  Aug 01 '13 at 17:31
  • 1
    @user2643036 this is also a problem with your code. Use that, then post your FULL code so that other users could really help you with your first problem. – RobeN Aug 01 '13 at 17:37
  • This has nothing to do with that problem what so ever and this is the FULL code. Why add more code and potentially more errors that wasn't needed just for people to ignore it and look at the real problem at hand. Considering this is my first day using pascal I don't think I have done too bad. –  Aug 01 '13 at 17:42
  • Are you reading my comments, or are you so ignorative to what I'm trying to tell you ? Today, you've *accidentally* deleted two accounts (???). Now you posted a full script (after the question updates), which is still useless because it fails to compile sooner to us (because we don't have required files you have), so that error message with line and column is useless for us. I asked you for few things and you didn't even replied... So what do you want from us ? [+1 for the answer] – TLama Aug 01 '13 at 17:54
  • You seriously want me to upload 2GB of files just so you can compile it? –  Aug 01 '13 at 18:01
  • I didn't answer your questions because they also have nothing to do with the question. One person mentions steam can now allow you to move games elsewhere and someone provides me a solution for something completely irrelevant to what i am asking, and you wonder why i don't like asking for help on here and delete my account after getting an answer and showing how i fixed it. –  Aug 01 '13 at 18:03
  • You were arguing with me about it not compiling when it was doing. The first time i deleted my account accidentally but the second time was because i got frustrated with the answers i was getting as they were not helpful to me like i had hoped. It is my first time with this so i am bound to be fairly bad at it and didnt think you needed all the code when the problem was in one area which i did mention where. –  Aug 01 '13 at 18:14
  • @user2643036 you may create dummy (empty) files with batch command. – RobeN Aug 01 '13 at 18:16
  • But now this question is essentially a battlefield I may as well forget about releasing this installer which was just to help people as they were struggling to get the mod working because all that has happened is people have complained and answered questions I didn't even ask. –  Aug 01 '13 at 18:19
  • Ok, it might look irrelevant, but you were trying to replace `{app}` constant with a value manually by using `StringReplaceEx` which is not the way how to expand constant values. I've posted you a script showing how to expand constants and let the whole `StringReplaceEx` stuff be because it was not needed there. At all... Now looking at your script; you've successfully adopted that piece of code and you're telling me I didn't helped ? So you rather deleted your account because you got so frustrated from that ? Well, I wish you good luck! – TLama Aug 01 '13 at 18:19
  • @RobeN you may also create dummy files with a batch command and remove the images that will also produce an error because it can't find them. –  Aug 01 '13 at 18:22
  • @TLama I adopted your code but it resulted in the exact same error so to me it didn't look like much has changed. –  Aug 01 '13 at 18:24
  • You're trying to define a constant (`const`) on that line, which is not possible. Even though you're having `Base` declared as a variable. You rather wanted to write `Base := ExpandConstant('{pf}')+'\';` on that failing line. That's all. – TLama Aug 01 '13 at 18:30
  • That just gives me an internal error on that line. Sorry if I have been coming across unpleasant, it just upsets me that I have been helping people all my life and the one time I need help (believe me I would rather try and figure it out on my own), I get this... –  Aug 01 '13 at 18:39
  • So, slow down... Programming is not a trial & error procedure. I know what I'm talking about (sometimes :-), about InnoSetup... If you take the code from your question as it is right now and replace the line I marked with the comment there with the line `Base := ExpandConstant('{pf}')+'\';` you should get at least compilable code... Internal error sounds like something bad happened to IDE, but I've never met this before. If that would happen to me, I'd save my work and restart IDE. – TLama Aug 01 '13 at 18:52