Inno Setup DeusEx.ini help needed

Dedicated to the discussion of OTP and Deus Ex in general.

Moderators: Master_Kale, TNM Team

Post Reply
hgdagon
Mole Person
Posts: 5
Joined: Wed Jul 29, 2015 3:06 pm

Inno Setup DeusEx.ini help needed

Post by hgdagon »

I'm trying to create a repack with many DeusEx mods. While Editing DeusEx.ini isn't much of a problem in general, adding new Path keys was quite a headcracker. I'm not particularly keen on Pascal, so I asked around in forums, and people wrote a piece of code for which can do that, but is a little less than satisfactory
Image
As you can see, it adds the keys at the end of the sections, and I would, obviously, prefer them to be after the other Path keys. So can anyone help me with a code that can do that? Thanks in advance.

P.S. I guess the "spoiler" tag doesn't work on this forum...
hgdagon
Mole Person
Posts: 5
Joined: Wed Jul 29, 2015 3:06 pm

Re: Inno Setup DeusEx.ini help needed

Post by hgdagon »

Nevermind, I figured it out. Funny thing, no one even mentioned that I don't need them UNDER the Path keys...
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Inno Setup DeusEx.ini help needed

Post by Hanfling »

hgdagon wrote:Nevermind, I figured it out. Funny thing, no one even mentioned that I don't need them UNDER the Path keys...
Acutally I considered your reasons to be out of a cosmetic concern.
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
ggrotz
X-51
Posts: 780
Joined: Tue Nov 10, 2009 12:55 am

Re: Inno Setup DeusEx.ini help needed

Post by ggrotz »

hgdagon wrote:Nevermind, I figured it out. Funny thing, no one even mentioned that I don't need them UNDER the Path keys...
FWIW, in case someone else has a problem (or you're interested), here's what I've been using for the GMDX and HDTP installers (which will probably be open-sourced on final, mainly as a help towards this kind of purpose). Note that while DeusEx.ini is generally compatible with the INI file facilities available through the OS, since Paths is a duplicate key, it doesn't work. But one can use the TStringList equivalent to do it.

Code: Select all

procedure CopyGMDXIniFiles;
{ procedure that enters the necessary items in the "Paths" portion of DeusEx.ini for GMDX.  The typical INI calls
  do not work for the "Paths" portion since duplicate names are not typical INI standard. }
  var
    sstrings: TStringList;
    ndx1, ndx2: integer;
  begin
    sstrings := TStringList.Create;
    try
      sstrings.LoadFromFile(ExpandConstant('{app}\gmdx\System\gmdx.ini'));
      // system line
      ndx1 := sstrings.IndexOf('Paths=..\GMDX\System\*.u'); // locate target line.
      if ndx1 > -1 then
        sstrings.Delete(ndx1);  // if already exists, delete it.
      ndx1 := sstrings.IndexOf('Paths=..\System\*.u');  // find systems line - will always exist if DeusEx.ini isn't borked.
      if ndx1 > -1 then  // if it exists.
        begin
          ndx2 := sstrings.IndexOf('Paths=..\HDTP\System\*.u');  // look for HDTP system line.
          if ndx2 > -1 then
            sstrings.Insert(ndx2, 'Paths=..\GMDX\System\*.u')  // if found, put the line before HDTP line
          else
            sstrings.Insert(ndx1, 'Paths=..\GMDX\System\*.u');  // if not, put it after the system line.
        end;
{...}
      sstrings.SaveToFile(ExpandConstant('{app}\gmdx\System\gmdx.ini'));
    finally
      sstrings.Free;
    end;
  end;
Basically, the final result we're looking for is either:

Code: Select all

Paths=..\GMDX\System\*.u
Paths=..\HDTP\System\*.u
Paths=..\System\*.u
or

Code: Select all

Paths=..\GMDX\System\*.u
Paths=..\System\*.u
Depending on whether HDTP is present. The main thing is to make sure the target line is placed before the line in which the resources exists.
that guy
The Nameless Mod
The Nameless Mod
Posts: 1312
Joined: Mon Apr 26, 2004 1:54 am
Location: Perth, Western Australia

Re: Inno Setup DeusEx.ini help needed

Post by that guy »

I believe inno setup allows you to package and execute built executables so you could simply write your script in whatever programming language you prefer and then bundle it into the installer to be executed on installation.
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Inno Setup DeusEx.ini help needed

Post by Hanfling »

Afaik non existing Paths are ignored anyway, so it would be probably save to just always have the HDTP entry. And why do you actually modify the game's ini file instead of supplying a Default.ini to be used when starting GMDX?
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
ggrotz
X-51
Posts: 780
Joined: Tue Nov 10, 2009 12:55 am

Re: Inno Setup DeusEx.ini help needed

Post by ggrotz »

Hanfling wrote:And why do you actually modify the game's ini file instead of supplying a Default.ini to be used when starting GMDX?
It's a safer behavior in terms of not breaking any other things or settings as many of the other mod installers do. For instance, the New Vision installer does this and as a result is one of the banes of my existence re the HDTP installer script.
hgdagon
Mole Person
Posts: 5
Joined: Wed Jul 29, 2015 3:06 pm

Re: Inno Setup DeusEx.ini help needed

Post by hgdagon »

@ggrotz

Well, as you mentioned, to help others, who work on projects like this, here's what I got from other communities.

Code: Select all

function FormatPathString(str : String) : String;
var
    firstThreeChars       : String;
    charsAfterFirstThree  : String;
    tempString  : String;
    finalString  : String;
    dividerPosition   : Integer;
begin

  firstThreeChars := Copy(str, 0, 3);                //First copy the first thee character which we want to keep
  charsAfterFirstThree := Copy(str,4,Length(str));   //copy the rest of the string into a new variable
  dividerPosition := Pos('\', charsAfterFirstThree); //find the position of the following '\'
  tempString := Copy(charsAfterFirstThree,dividerPosition+1,Length(charsAfterFirstThree)-dividerPosition);            //Take everything after the position of '\' (dividerPosition+1) and copy it into a temporary string
  finalString := firstThreeChars+tempString;         //put your first three characters and your temporary string together
  Result := finalString;                             //return your final string
end; 

procedure AppendKey(const FileName, Section, KeyName, KeyValue: string);
var
  S: string;
  I: Integer;
  CurLine: string;
  LineIdx: Integer;
  SnFound: Boolean;
  Strings: TStringList;
begin
  Strings := TStringList.Create;
  try
    S := Format('[%s]', [Section]);

    Strings.LoadFromFile(FileName);
    SnFound := False;
    LineIdx := Strings.Count;

    for I := Strings.Count - 1 downto 0 do
    begin
      CurLine := Trim(Strings[I]);
      // if the iterated line is a section, then...
      if (Length(CurLine) > 2) and (CurLine[1] = '[') and (CurLine[Length(CurLine)] = ']') then
      begin
        // if the iterated line is the section we are looking for, then...
        if CompareText(S, CurLine) = 0 then
        begin
          SnFound := True;
          Break;
        end;
      end
      else
        if CurLine = 'Paths=' + FormatPathString(KeyValue) then
          LineIdx := I;
    end;

    if not SnFound then
    begin
      Strings.Add(S);
      Strings.Add(Format('%s=%s', [KeyName, KeyValue]));
    end
    else
      Strings.Insert(LineIdx, Format('%s=%s', [KeyName, KeyValue]));

    Strings.SaveToFile(FileName);
  finally
    Strings.Free;
  end;
end;
And then I call it like this

Code: Select all

procedure CurStepChanged(CurStep: TSetupStep);
Begin
if (CurStep=ssDone) and IsComponentSelected('NV') then
  begin
      AppendKey(ExpandConstant('{app}\System\DeusEx.ini'), 'Core.System', 'Paths', '..\New Vision\Maps\*.dx');
      AppendKey(ExpandConstant('{app}\System\DeusEx.ini'), 'Core.System', 'Paths', '..\New Vision\Textures\*.utx');
  end;
if (CurStep=ssDone) and IsComponentSelected('HDTP') then
  begin
      AppendKey(ExpandConstant('{app}\System\DeusEx.ini'), 'Core.System', 'Paths', '..\HDTP\System\*.u');
      AppendKey(ExpandConstant('{app}\System\DeusEx.ini'), 'Core.System', 'Paths', '..\HDTP\Textures\*.utx');
  end;
if (CurStep=ssDone) and IsComponentSelected('NV') and IsComponentSelected('HDTP') then
  begin
      AppendKey(ExpandConstant('{app}\System\hdtp.ini'), 'Core.System', 'Paths', '..\New Vision\Maps\*.dx');
      AppendKey(ExpandConstant('{app}\System\hdtp.ini'), 'Core.System', 'Paths', '..\New Vision\Textures\*.utx');
  end;
End;
Obviously, your code is much shorter, but I like to keep thing separate (I have a bit of concentration problem).
that guy
The Nameless Mod
The Nameless Mod
Posts: 1312
Joined: Mon Apr 26, 2004 1:54 am
Location: Perth, Western Australia

Re: Inno Setup DeusEx.ini help needed

Post by that guy »

I'd forgotten how ugly pascal is
Post Reply