Compile Unicode NSIs that supports log

Source: Internet
Author: User

Unicode NSIs is a natural choice for developing multi-language installation packages. However, Unicode NSIs is a derivative version of the official NSIs, And the development progress is bound to lag behind the official NSIs, which is mainly maintained by Jim. The latest official version is 2.45, while the Unicode version is still 2.42.

All those who have used NSIs know that NSIs uses the default method to manually uninstall the script. If you use a special version of NSIs (also official) that supports log ). The installation package generated by NSIs of this version can generate a log file during the installation process, coupled with a ready-made script provided by netizens, you can easily uninstall the log file. For the implementation method, see the basic structure of NSIs.

However, the authors of Unicode NSIs did not provide NSIs downloads that support log functions. But only providesSource codeDownload. In this way, we have to re-compile NSIs on our own. The compilation process is very simple. You can add an nsis_config_log compilation parameter. However, if the problem is so simple, there is no need to writeArticleHere is a special introduction.

The problem is that the log file generated by the NSIs installation package is incorrect! What are the errors? I have not found any clues on the Internet. I can only analyze the log file myself and find my own errors. (Jim sent an email yesterday, but he has no time to wait for his reply)

View the Unicode NSIs SourceCodeAnd windows core programming, found that the most likely problem is the writefile function. The source code is as follows.

If(G_log_file [0] & fp = invalid_handle_value)

 
{

Fp = myopenfile (g_log_file, generic_write, open_always );

 
If(FP! = Invalid_handle_value)

Setfilepointer (FP, 0, null, file_end );

 
}

 
If(FP! = Invalid_handle_value)

 
{

 
Dword d;

 
Mystrcat (log_text, _ T ("\ R \ n"));

 
Writefile (FP, log_text, mystrlen (log_text), & D, null );

 
}

 

All the strings generated by Unicode NSIs are unicode encoded, And the strings written to this file are also. The above code has two problems.

1. When creating this file, the author did not declare this file as a Unicode file, so that notepad opened the file in ANSI encoding, resulting in errors. This statement is byte order mark, which is only applicable to Windows platforms.PartUnicode files have this constraint. (For example, VS can choose whether to add BOM to the source code file .)

2. The third parameter is incorrect during writefile. The unit of the third parameter is byte, but the mystrlen function returns the number of log_text characters. A character in Unicode contains sizeof (tchar) bytes. Therefore, the string actually written into the file is only one of the first sizeof (tchar) points of log_text.

Okay, I found the problem. Let's start modifying the source code. Add BOM and multiply the third parameter by sizeof (tchar ). Compilation is completed smoothly. The generated log file is complete and can be opened in notepad.

However, the uninstall function is invalid. Save the generated Unicode-encoded log file as an ANSI-encoded log file. Can be uninstalled ~~~~ It seems that this Unicode NSIs uninstallation package is not perfect. To enable uninstaller to support Unicode, you need to change a lot of code. Another possibility is that uninstaller does not know Bom. After all, NSIs is cross-platform, but it is unacceptable if notepad is unreadable. I tried it later, and there was no Bom. Remove BOM and uninstaller will work normally.

The final code is modified as follows:

 
If(FP! = Invalid_handle_value)

{

 
Dword d;

 
Mystrcat (log_text, _ T ("\ R \ n"));

# IfdefUnicode

 
Writefile (FP, log_text, mystrlen (log_text )*Sizeof(Tchar), & D, null );

# Else

 
Writefile (FP, log_text, mystrlen (log_text), & D, null );

# Endif

 
}

Then run the following command to build it,

Scons Unicode = Yes nsis_config_log = Yes skiputils = "NSIs menu" prefix = "your Install Folder" install

NSIs, which supports the Unicode version of log, is generated.

Add your own compiled patch.To overwrite the existing installation.

Update:

The generated log file is unicode encoded, And the fileread command cannot correctly read the Unicode file. In this way, the uninstall by log function cannot run normally.

The solution is also very simple. Replace the fileread command for reading Unicode files with the unique feature of Unicode NSIs.Filereadutf16leYou can.

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.