Inno Setup How to read and write files

Source: Internet
Author: User

The essence of software installation is the copy, for a simple package of course there is no need to consider modifying a (configuration) file. The purpose of modifying a file through Inno is to write the information about the installation to the file and provide other applications with the information that can only be determined at installation time, such as installing a user-selected installation directory or a port number entered via a custom interface. So other information that is not related to the installation can try not to use Inno to write to the file, just to increase the workload.

Inno There are many ways to modify the contents of a file. I have summarized the following three ways: through the [INI] segment to write configuration information directly, call external programs to read and write files, using the built-in read-write file functions to modify the file.

1, [INI] paragraph way write

The Inno itself provides a write operation to the INI file. Add the following code to the [INI] section.

Filename: "{App}\myprog.ini"; Section: "1"; Key: "InstallPath"; String: "{app}"; Flags:uninsdeletesection

Filename: "{App}\myprog.ini"; Section: "2"; Key: "InstallPath"; String: "{app}"; Flags:uninsdeletesection

Filename: "{App}\myprog.ini"; Section: "3"; Key: "InstallPath"; String: "{app}"; Flags:uninsdeletesection

Filename: "{App}\myprog.ini"; Section: "4"; Key: "InstallPath"; String: "{app}"; Flags:uninsdeletesection

Filename: "{App}\myprog.ini"; Section: "5"; Key: "InstallPath"; String: "{app}"; Flags:uninsdeletesection

FileName is the one you want the installer to modify. INI file name. If this parameter is blank, it will be written to WIN in the Windows directory of the system. INI, where {app} is the application directory selected by the user in the Select Target Location page of the Installation Wizard.

section is the name of the segment to be created to place the INI entry.

Key is the key name to set. If this parameter is not specified or is blank, the key is not created.

The sring is the value corresponding to the key, which synthesizes a key-value pair.

Flags flags The Uninsdeletesection, which, as the name implies, will delete this section when uninstalling.

The contents of the INI file generated after installation are as follows:

This INI file can be recognized by most programming languages, such as C language GetPrivateProfileString, WritePrivateProfileString is specialized in reading and writing INI format files.

2. Calling external programs to read and write files via Inno

When you encounter modifications to non-INI format files, such as XML files, and do not want to use the Pascal language to complete, choose your most handy language to complete the writing file operation best. But now the problem is that you write the program to write the file how to know the software installation of some information about the user, such as the installation of the directory, the user entered the interface of the Apache port data. The answer is through the command line of the way to pass the argument!

Assuming that the application I used to write the file is called Wf.exe, it needs to be packaged with the software first and then started in the [Run] segment: Filename: "{App}\wf.exe"; Description: "Modify the File"; Parameters:{code:getparams}; STATUSMSG: "Configuring information ..."; Flags:runhidden

The above parameters is to run the specified command-line argument to Wf.exe, {Code:getparams} indicates that the parameter is returned by the call Getparams function inside the code segment. The Getparams function is defined as follows:

function Getparams (param:string): string;

Begin

Result: = ' "' + Apacheedit.text + '" ' + ' {app} ' + ' ";

End

where {app} is one of the parameters the installation directory tells Wf.exe,apacheedit.text to get the text inside the Apacheedit, and Apacheedit is a custom edit box to receive the Apache port that the user entered at the time of installation. Wf.exe get the installation directory, you can also know the user in the interface input some information, then how to implement it depends on how you write Wf.exe. Also note is the string format returned by Getparams, for Wf.exe need more than one argument, the return of each parameter is separated by double quotation marks, do not use the space is because many paths exist spaces, so in Wf.exe will get the wrong parameter information.

3, through the function provided by Inno (Pascal language) to implement the modified file

The most common practice for reading and writing files is to read all the contents of the file, make the appropriate changes based on the string match, and then write the file. The Pascal language is no exception, and the main difficulty is how to skillfully use the string manipulation functions provided in the Inno. For various cases of write file operations see the following delivery: www.baidu.com

Inno Setup How to read and write files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.