logo
down
shadow

How to use Inno Setup scripting to edit a text file?


How to use Inno Setup scripting to edit a text file?

By : user21436
Date : November 19 2020, 07:01 PM
around this issue You can use the SaveStringToFile() function to append text to a file.
code :


Share : facebook icon twitter icon
Can I edit a file before installing with Inno Setup?

Can I edit a file before installing with Inno Setup?


By : user4240315
Date : March 29 2020, 07:55 AM
Hope that helps You can do a simple string replace on the installed executable using LoadStringFromFile(), StringChange() and SaveStringToFile(). Note that your needle and the replacement have to be the exact same length otherwise the executable will be corrupted.
Inno Setup How to edit a ini file during the installation

Inno Setup How to edit a ini file during the installation


By : Funny Thing
Date : March 29 2020, 07:55 AM
With these it helps If you put the lines from the [Languages] section into a separate file (in this case the c:\Languages.txt), the following preprocessor script will generate the script that will add to the combo box placed on a custom page list of available languages and select the current one. On that custom page will also be the edit box for entering player's name. The name of the language along with the entered name will then be stored in the Setup.ini file into a selected application directory. The preprocessed script is saved as c:\PreprocessedScript.iss file.
Languages.txt content:
code :
Name: "default"; MessagesFile: "compiler:Default.isl"
Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl"
Name: "french"; MessagesFile: "compiler:Languages\French.isl"
Name: "german"; MessagesFile: "compiler:Languages\German.isl"
Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl"
Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl"
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
#define LanguageFile "c:\Languages.txt"
#define LanguageName
#define LanguageIndex
#define LanguageCount
#define FileLine
#define FileHandle
#dim LanguageList[65536]
#sub ProcessFileLine
  #if FileLine != ""
    #expr LanguageList[LanguageCount] = FileLine
    #expr LanguageCount = ++LanguageCount
  #endif  
#endsub
#for {FileHandle = FileOpen(LanguageFile); \
  FileHandle && !FileEof(FileHandle); \
  FileLine = FileRead(FileHandle)} \
  ProcessFileLine
#if FileHandle
  #expr FileClose(FileHandle)
#endif
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Languages]
#sub AddLanguageItemSection
  #emit LanguageList[LanguageIndex]
#endsub
#for {LanguageIndex = 0; LanguageIndex < LanguageCount; LanguageIndex++} AddLanguageItemSection

[INI]
Filename: "{app}\Setup.ini"; Section: "Emulator"; Key: "Language"; String: "{code:GetLanguageName}"; Flags: createkeyifdoesntexist 
Filename: "{app}\Setup.ini"; Section: "SteamClient"; Key: "PlayerName"; String: "{code:GetPlayerName}"; Flags: createkeyifdoesntexist

[Code]
var  
  NameEdit: TNewEdit;
  LanguageCombo: TNewComboBox;
  LanguageNames: TStringList;

function ConvertLanguageName(const Value: string): string;
var
  I: Integer;
  WideCharCode: Word;
begin
  Result := '';
  I := 1;
  while I <= Length(Value) do 
  begin
    if Value[I] = '<' then 
    begin
      WideCharCode := StrToInt('$' + Copy(Value, I + 1, 4));
      I := I + 6;
    end
    else 
    begin
      WideCharCode := Ord(Value[I]);
      I := I + 1;
    end;
    SetLength(Result, Length(Result) + 1);
    Result[Length(Result)] := Chr(WideCharCode);
  end;
end;

function GetLanguageName(const Value: string): string;
begin
  Result := LanguageNames[LanguageCombo.ItemIndex];
end;

function GetPlayerName(const Value: string): string;
begin
  Result := NameEdit.Text;
end;

procedure InitializeWizard;
var
  PlayerSettingsPage: TWizardPage;
  NameLabel: TLabel;
  LanguageLabel: TLabel;
begin
  PlayerSettingsPage := CreateCustomPage(wpWelcome, 'Caption', 'Description');

  NameLabel := TLabel.Create(WizardForm);
  NameLabel.Parent := PlayerSettingsPage.Surface;
  NameLabel.Left := 0;
  NameLabel.Top := 0;
  NameLabel.Caption := 'Name';
  NameEdit := TNewEdit.Create(WizardForm);
  NameEdit.Parent := PlayerSettingsPage.Surface;
  NameEdit.Left := 0;
  NameEdit.Top := NameLabel.Top + NameLabel.Height + 4;
  NameEdit.Width := 250;

  LanguageNames := TStringList.Create;
  #sub AddLanguageInternalNames
    #define GetLanguageInternalName(str S) \
      Local[0] = Copy(S, Pos("Name:", S) + Len("Name:")), \
      Local[1] = Copy(Local[0], Pos("""", Local[0]) + 1), \
      Copy(Local[1], 1, Pos("""", Local[1]) - 1)
    #emit '  LanguageNames.Add(''' + GetLanguageInternalName(LanguageList[LanguageIndex]) + ''');'    
  #endsub
  #for {LanguageIndex = 0; LanguageIndex < LanguageCount; LanguageIndex++} AddLanguageInternalNames

  LanguageLabel := TLabel.Create(WizardForm);
  LanguageLabel.Parent := PlayerSettingsPage.Surface;
  LanguageLabel.Left := 0;
  LanguageLabel.Top := NameEdit.Top + NameEdit.Height + 8;
  LanguageLabel.Caption := 'Language';
  LanguageCombo := TNewComboBox.Create(WizardForm);
  LanguageCombo.Parent := PlayerSettingsPage.Surface;
  LanguageCombo.Left := 0;
  LanguageCombo.Top := LanguageLabel.Top + LanguageLabel.Height + 4;
  LanguageCombo.Width := NameEdit.Width; 
  LanguageCombo.Style := csDropDownList;  
  #sub AddLanguageDisplayNames
    #define GetLanguageDisplayName(str S) \
      ReadIni(S, "LangOptions", "LanguageName")
    #define GetLanguageFile(str S) \
      Local[0] = Copy(S, Pos("MessagesFile:", S) + Len("MessagesFile:")), \
      Local[1] = Copy(Local[0], Pos("""", Local[0]) + 1), \
      StringChange(Copy(Local[1], 1, Pos("""", Local[1]) - 1), "compiler:", CompilerPath)
    #expr LanguageName = GetLanguageDisplayName(GetLanguageFile(LanguageList[LanguageIndex]))
    #emit '  LanguageCombo.Items.Add(ConvertLanguageName(''' + LanguageName + '''));'
  #endsub
  #for {LanguageIndex = 0; LanguageIndex < LanguageCount; LanguageIndex++} AddLanguageDisplayNames
  LanguageCombo.ItemIndex := LanguageNames.IndexOf(ActiveLanguage);
end;

procedure DeinitializeSetup;
begin
  LanguageNames.Free;
end;

#expr SaveToFile("c:\PreprocessedScript.iss")
Inno Setup - How to edit a specific line from a text file during setup?

Inno Setup - How to edit a specific line from a text file during setup?


By : Donovan Ye
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , This code can do it. But note, that this code doesn't check, if the value for the tag is enclosed by quote chars, once it finds a tag specified by TagName parameter, it cuts off the rest of the line and appends the value given by TagValue parameter:
code :
function ReplaceValue(const FileName, TagName, TagValue: string): Boolean;
var
  I: Integer;
  Tag: string;
  Line: string;
  TagPos: Integer;
  FileLines: TStringList;
begin
  Result := False;
  FileLines := TStringList.Create;
  try
    Tag := '"' + TagName + '"';
    FileLines.LoadFromFile(FileName);
    for I := 0 to FileLines.Count - 1 do
    begin
      Line := FileLines[I];
      TagPos := Pos(Tag, Line);
      if TagPos > 0 then
      begin
        Result := True;
        Delete(Line, TagPos + Length(Tag), MaxInt);
        Line := Line + ' "' + TagValue + '"';
        FileLines[I] := Line;
        FileLines.SaveToFile(FileName);
        Break;
      end;
    end;
  finally
    FileLines.Free;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
  NewPath: string;
begin
  if CurStep = ssDone then
  begin
    NewPath := ExpandConstant('{app}') + '\apps\common\App70';
    StringChangeEx(NewPath, '\', '\\', True);

    if ReplaceValue(ExpandConstant('{app}\app70.txt'), 'appinstalldir', 
      NewPath) 
    then
      MsgBox('Tag value has been replaced!', mbInformation, MB_OK)
    else  
      MsgBox('Tag value has not been replaced!.', mbError, MB_OK);
  end;
end;
Need to find if the text box (edit box) contains only alphabet in inno setup

Need to find if the text box (edit box) contains only alphabet in inno setup


By : Hiếu Nghĩa
Date : March 29 2020, 07:55 AM
wish help you to fix your issue First of all, InnoSetup scripting doesn't allow constant set ranges. Even though, your code wouldn't do what seems you want to. By using DBPage.Values[0] you're accessing the whole string value, not a single char as you probably wanted.
If you don't want to write a pretty complex condition for all alphabetical chars, you can advance from the Windows API function IsCharAlpha. The following code shows, how to use it in your code:
code :
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
#ifdef UNICODE
  #define AW "W"
#else
  #define AW "A"
#endif

var
  DBPage: TInputQueryWizardPage;

function IsCharAlpha(ch: Char): BOOL;
  external 'IsCharAlpha{#AW}@user32.dll stdcall';

function NextButtonClick(CurPageID: Integer): Boolean;
var
  S: string;  
  I: Integer;
begin
  Result := True;
  // store the edit value to a string variable
  S := DBPage.Values[0];
  // iterate the whole string char by char and check if the currently
  // iterated char is alphabetical; if not, don't allow the user exit
  // the page, show the error message and exit the function
  for I := 1 to Length(S) do
    if not IsCharAlpha(S[I]) then
    begin
      Result := False;
      MsgBox('You must enter alphabets only.', mbError, MB_OK);
      Exit;
    end;
end;

procedure InitializeWizard;
begin
  DBPage := CreateInputQueryPage(wpWelcome, 'Caption', 'Description', 'SubCaption');
  DBPage.Add('Name:', False);
  DBPage.Values[0] := 'Name';
end;
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
#ifdef UNICODE
  #define AW "W"
#else
  #define AW "A"
#endif

var
  DBPage: TInputQueryWizardPage;

function IsCharAlpha(ch: Char): BOOL;
  external 'IsCharAlpha{#AW}@user32.dll stdcall';

procedure AlphaEditKeyPress(Sender: TObject; var Key: Char);
begin
  if not IsCharAlpha(Key) and (Key <> #8) then
    Key := #0;
end;

procedure InitializeWizard;
var
  ItemIndex: Integer;
begin
  DBPage := CreateInputQueryPage(wpWelcome, 'Caption', 'Description', 'SubCaption');
  ItemIndex := DBPage.Add('Name:', False);
  DBPage.Values[ItemIndex] := 'Name';
  DBPage.Edits[ItemIndex].OnKeyPress := @AlphaEditKeyPress;
end;
Inno Setup: Populating VersionInfoDescription and VersionInfoCopyright from an INI file using Pascal Scripting (scripted

Inno Setup: Populating VersionInfoDescription and VersionInfoCopyright from an INI file using Pascal Scripting (scripted


By : leqiang
Date : March 29 2020, 07:55 AM
hope this fix your issue The VersionInfoDescription and VersionInfoCopyright cannot contain constants (like {code:...})
But if you use the Pascal Scripting to load an INI file only, you can use preprocessor instead:
code :
VersionInfoDescription={#ReadIni("C:\path\test.ini", "Section", "Name")}
Related Posts Related Posts :
  • which is the best iPhone and Android Simulator for Kubuntu Linux?
  • Open Microsoft Word in "compare document" mode from command prompt
  • What is a header? Especially, what are POST@GET headers?
  • Tomcat fails to start because of jdbc driver loading
  • Reimplementing data structures in the real world
  • Condition check inside a function or before its call?
  • Is it possible to embed dynamic text into Keynote'09?
  • VS2010 express beta2 - no add reference dialog, no open file/project dialogs
  • Starting Java applet directly from jar file
  • How is other content besides views handled with PortableAreas from the MVCContrib library?
  • Nabaztag alternatives?
  • I've made something that might be useful to the community. Now what?
  • JasperReports multi-page report with different content
  • Clojure agents consuming from a queue
  • Use single static image as map
  • Why does this B+ tree have repeated elements?
  • OpenLayers eraseFeatures doesn't erase features from map screen
  • Can you help me think of problems for my programming language?
  • How to merge/crosslink Javadoc?
  • How do you automate building notes NTF files from lotus script files (lss) file?
  • How to build a programmer's wiki
  • How not to output default T4 generated file?
  • RichTextBox EnableAutoDragDrop=true requires CTRL key pressed when dropping a ListBox item?
  • How can I get Symbolic-Name of an Osgi bundle which is using one of my exported packages?
  • Get network address of a file in AppleScript
  • What is purpose of T4 Generator in T4toolbox
  • How to correctly formalize the command line usage of GNU/Linux commands?
  • What's the difference between a UseCase and a Workflow?
  • How to write a virtual machine
  • NServiceBus FullDuplex sample compiled and debugging against .NET 4.0 framework throws exception
  • Glade: How do I pass more than one argument to a signal handler?
  • Case statements in VHDL
  • New NSData with range of old NSData maintaining bytes
  • How do I convert a column of text URLs into active hyperlinks in Excel?
  • serial port parity
  • @Override fix-code shortcut in NetBeans
  • Import small number of records from a very large CSV file in Biztalk 2006
  • How to clear browser's cache from server side?
  • Execute remote Lua Script
  • Website.com/cpanel access
  • Which LOGO implementation?
  • How to add files to a document library in a site definition in SharePoint 2007?
  • JavaFX layouts question
  • Is it possible to access variable of subclass using object of superclass in polymorphism
  • How can the reliability of Software be checked through analysis?
  • Prototype Multi-Event Observation for Multi-Elements
  • maximum stored proc name in firebird
  • AutoComplete implementation
  • How is it that i am getting two different open ids for the same site for the same user
  • Revision histories and documenting changes
  • How to use Int13H Ext to read /write all sectors on each partition of harddisk (>8GB)
  • Dijit.Dialog 1.4, setting size is limited to 600x400 no matter what size I set it
  • Windows Phone 7 Notifications/Pop/Toasts
  • StructureMap: "No default instance of plugin defined" - even though it is
  • Getting HTTPS working with Traefik and GCE Ingress
  • flask with bootstrap4, not show modal, use CDN works well
  • How to get the formatted view of YQL as result?
  • wsadmin is taking 10 minutes to connect to Application Server
  • TCL array values updation based on command line argument
  • Wordpress: help with posts_nav_link()
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk