Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Programming and Hacking > Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 29th February 2024, 20:56   #1  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,277
Inno Setup,... need help

I use the following inno setup script: https://pastebin.com/YyibJFk6
Now I want to expand this so that after all the file copying the content of the two files:
Code:
{app}\32bit\fonts\local.conf
and
Code:
{app}\64bit\fonts\local.conf
which both contain:
Code:
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>APPDATA/HybridFonts</dir>
<cachedir>APPDATA/fontconfig/cache</cachedir>
</fontconfig>
get adjusted to:
Code:
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>APPDATA/fonts</dir>
<cachedir>APPDATA/fontconfig/cache</cachedir>
</fontconfig>
where APPDATA should be the AddDataFolder of the user (i.e. C:\Users\Selur\AppData\Roaming\.hybrid).

From what I read online extending the Code-section by:
Code:
function ReplaceString(const Source, Find, Replace: string): string;
var
  PosFind: Integer;
begin
  Result := Source;
  PosFind := Pos(Find, Result);
  while PosFind > 0 do
  begin
    Delete(Result, PosFind, Length(Find));
    Insert(Replace, Result, PosFind);
    PosFind := Pos(Find, Result);
  end;
end;

function FileReplaceString(const FileName, SearchString, ReplaceString: string):boolean;
var
  MyFile : TStrings;
  MyText : string;
begin
  MyFile := TStringList.Create;

  try
    result := true;

    try
      MyFile.LoadFromFile(FileName);
      MyText := MyFile.Text;

      { Only save if text has been changed. }
      if StringChangeEx(MyText, SearchString, ReplaceString, True) > 0 then
      begin;
        MyFile.Text := MyText;
        MyFile.SaveToFile(FileName);
      end;
    except
      result := false;
    end;
  finally
    MyFile.Free;
  end;
end;

function ReplaceLocalConfStrings: Boolean;
var
  AppDataPath: string;
  LocalConfPath32: string;
  LocalConfPath64: string;
begin
  Result := True;

  // Ersetze %appdata% durch %appdata%/.hybrid
  AppDataPath := ExpandConstant('{userappdata}');
  AppDataPath := ReplaceString(AppDataPath, '\', '\\');
  AppDataPath := ReplaceString(AppDataPath, 'AppData\Roaming', 'AppData\Roaming\\.hybrid');

  // Pfade zu den local.conf-Dateien in den entsprechenden Ordnern
  LocalConfPath32 := ExpandConstant('{app}\32bit\fonts\local.conf');
  LocalConfPath64 := ExpandConstant('{app}\64bit\fonts\local.conf');

  // Ersetze die Zeichenfolgen in den Dateien
  if not FileReplaceString(LocalConfPath32, '<dir>APPDATA/HybridFonts</dir>', '<dir>' + AppDataPath + '\\.hybrid\\HybridFonts</dir>') then
    Result := False;
  if not FileReplaceString(LocalConfPath32, '<cachedir>APPDATA/fontconfig/cache</cachedir>', '<cachedir>' + AppDataPath + '\\.hybrid\\fontconfig\\cache</cachedir>') then
    Result := False;

  if not FileReplaceString(LocalConfPath64, '<dir>APPDATA/fonts</dir>', '<dir>' + AppDataPath + '\\.hybrid\\fonts</dir>') then
    Result := False;
  if not FileReplaceString(LocalConfPath64, '<cachedir>APPDATA/fontconfig/cache</cachedir>', '<cachedir>' + AppDataPath + '\\.hybrid\\fontconfig\\cache</cachedir>') then
    Result := False;
end;
to do what I want, but it doesn't work, after running the installer, the two files are still as they were.



I got no clue how this all works, so any help is appreciated.

Cu Selur
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 1st March 2024, 01:14   #2  |  Link
clsid
*****
 
Join Date: Feb 2005
Posts: 5,647
Don't copy and then modify the files.

Just write simple function to output the desired content to a file. See for example SaveStringToFile or SaveStringsToUTF8File functions in Inno help file.
__________________
MPC-HC 2.2.1
clsid is offline   Reply With Quote
Old 1st March 2024, 14:45   #3  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,277
Thanks.
Couldn't get it working the way I wanted, but I adjusted Hybrid and the files to work as I need.


Cu Selur
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:05.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.