从Ansi升级到Inno Setup的Unicode版本(任何缺点) [英] Upgrading from Ansi to Unicode version of Inno Setup (any disadvantages)
问题描述
与Ansi版本相比,Inno Setup Unicode版本是否有任何缺点?
Are there any disadvantages of the Inno Setup Unicode version compared to the Ansi version?
或者仍然并行提供两个版本,而不仅剩下Unicode的原因是什么?
Or what is the reason that still both versions are offered in parallel and not only the Unicode one is left?
将Unicode版本用于使用Ansi版本开发的现有Inno Setup项目时,是否存在任何潜在问题?
Are there any potentials problems, when using the Unicode version for my existing Inno Setup project developed with the Ansi version?
推荐答案
没有真正的缺点.主要有优点.显然,Unicode版本不限于旧版Ansi字符集. 有关详情,请参见下文.
There are no real disadvantages. There are mostly advantages. Obviously the fact that the Unicode version is not limited to legacy Ansi character set. See below for details.
如果要启动新的Inno Setup项目,请始终使用Unicode版本.没有理由将Ansi版本用于新项目.实际上,不再有用于最新Inno Setup 6的Ansi版本.
If you are starting new Inno Setup project, always use the Unicode version. There is no reason to use the Ansi version for new projects. Actually there's no Ansi version for the latest Inno Setup 6 anymore.
之所以可以长期使用Inno Setup的Ansi版本,是因为Ansi的Pascal脚本代码和Unicode版本不是100%兼容的.通常是这样,但是有区别.
The reason, why Ansi version of Inno Setup was still available for long time, was that the Pascal Script code of Ansi and Unicode versions are not 100% compatible. Mostly they are, but there are differences.
因此,如果您现有的安装程序脚本没有任何 Pascal脚本代码 (在.iss
中没有 [Code]
部分),您可以(并且应该)立即切换到Unicode版本.
So if your existing installer script does not have any Pascal Script code (there's no [Code]
section in your .iss
), you can (and should) switch to the Unicode version straight away.
如果您有一些Pascal脚本代码,则应格外小心. 有关详情,请参见下文.
If you have some Pascal Script code, you should be more careful. See below for details.
例如Ansi版本的问题,如果您在英语系统上运行使用Ansi版本的Inno Setup构建的仅日语安装程序,则会得到:
For example of problems with the Ansi version, if you run Japanese-only installer built with Ansi version of Inno Setup on English system, you will get:
另请参见 Inno Setup安装程序的文本编码错误.
出于相同的原因,Ansi版本将无法使用名称包含字符的文件来创建文件,这些文件在目标计算机的旧版Ansi字符集中不存在.
For the same reason, the Ansi version will not be able to create files with names containing characters, that are not present in the legacy Ansi character set of the target machine.
如 Unicode Inno设置文章中所述,Unicode版本没有这些问题. :
Unicode Inno Setup的主要功能是它可以在任何系统上显示任何语言,而与系统代码页无关,并且可以使用Unicode文件名.对于那些想要最小尺寸的人,可以将Unicode Inno设置视为新的标准Inno设置,将Non Unicode Inno设置视为旧的特殊Inno设置.
Key features of Unicode Inno Setup are its ability to display any language on any system regardless of the system code page, and its ability to work with Unicode filenames. One could consider Unicode Inno Setup as the new standard Inno Setup and Non Unicode Inno Setup as an old special Inno Setup for those who want the very smallest size possible.
对于Inno Setup 6,也根本没有Ansi版本,因此,如果要在所有
Also for Inno Setup 6, there is no Ansi version at all, so if you want to use the latest version of Inno Setup with all its new features, you need to switch to the Unicode version along.
此外,Unicode版本的Pascal脚本有一些小的改进.它们记录在 Unicode Inno Setup文章中.除此之外,还有一些未记录的改进:
Additionally there are some small improvements in the Unicode version Pascal Script. They are documented in the Unicode Inno Setup article. On top of that, there are few undocumented improvements:
-
Inc
/Dec
功能/语句.参见 Inc函数Inno设置. - 更好的
Variant
支持.例如,请参见 Inno设置:遍历Variant类型的数组(来自OleObject)或 Inno Setup任务栏图标模糊或预期冒号(':')" Inno Setup Pascal脚本中case语句中字符范围上的编译器错误.
带有常量集的 -
in
运算符:似乎在Ansi版本中,总是会出现类型不匹配" 错误,除非先将set
存储到set of
变量中.
请注意,虽然Unicode版本确实支持带有常量集的in
运算符,但它不支持set表达式中的范围,因此X in [1, 2, 3]
是可能的,但X in [1..3]
是不可能的,您将得到 期望关闭方括号(']'). -
TLabel
在Unicode版本中具有透明背景.请参见 Inno设置-页面名称和描述标签中文本下方的透明度 - 在Ansi版本中无法调用某些自定义向导页面的标准事件处理程序,而在Unicode版本中则可以正常工作.对于在TInputDirWizardPage上浏览文件夹时生成的Inno Setup事件,有什么用?
- 更好地支持RTF.请参见如何使用RichEditViewer在Inno Setup中向自定义页面添加可点击链接?
Inc
/Dec
functions/statements. See Inc function Inno Setup.- Better
Variant
support. For example, see Inno Setup: Iterate through array of type Variant (from OleObject) or Is there a way to read the system's information in Inno Setup. - Better high-DPI (and non-standard screen in general) support. For example, see Inno Setup taskbar icon blurred or Inno Setup Installer has squished window on XP?
- Ranges in
case
statement: "colon (':') expected" compiler error on character range in case statement in Inno Setup Pascal script. in
operator with a constant set: It seems that in Ansi version, you always get "Type mismatch" error, unless you store theset
into aset of
variable first.
Note, that while the Unicode version does support thein
operator with a constant set, it does not support ranges in the set expression, soX in [1, 2, 3]
is possible, butX in [1..3]
is not possible, you will get "Closing square bracket (']') expected."TLabel
has transparent background in the Unicode version. See Inno Setup - Transparency under text in page name and description labels- Calling standard event handlers of some custom wizard pages is not possible in Ansi version, while is work fine in Unicode version. What can be useful for things like Inno Setup event that is generated when folder is browsed on TInputDirWizardPage?
- Better support for RTF. See How to add clickable links to custom page in Inno Setup using RichEditViewer?
在很少的地方,Pascal脚本代码中可能会出现问题:
There are few areas, where problems can emerge in the Pascal Script code:
-
对采用字符串参数-
string
和PChar
类型的DLL函数的任何调用.AnsiString
应该可以,因为在Unicode版本中是相同的.
Any calls to DLL functions that take string parameters -
string
andPChar
types.AnsiString
should be ok, as it's the same in the Unicode version.
在Unicode版本中,PChar
重命名为PAnsiChar
.
In Unicode version, PChar
was renamed to PAnsiChar
.
如果调用任何使用字符串的Windows API函数,则应切换到其Wide版本.例如.使用GetFileAttributesW
而不是GetFileAttributesA
.没有PWideChar
类型.因此,如果您的声明在Ansi版本中使用PChar
类型,并且切换到该函数的Wide版本,则必须改为使用string
类型. Inno Setup会自动将其封送至LPCTSTR
(或类似名称),也称为PWideChar
.
If you invoke any Windows API function that uses strings, you should switch to its Wide version. E.g. use GetFileAttributesW
, instead of GetFileAttributesA
. There's no PWideChar
type. So if your declaration used PChar
type in Ansi version, and you switch to Wide version of the function, you have to use string
type instead. Inno Setup will automatically marshal it to the LPCTSTR
(or similar), aka the PWideChar
.
下面的声明在Ansi版本中是正确的,但是在Unicode版本中是错误的,因为GetFileAttributesA
使用PAnsiChar
,但是string
编组为PWideChar
在Unicode版本中.
The declaration below is correct in Ansi version, but wrong in Unicode version, as the GetFileAttributesA
takes PAnsiChar
, but the string
marshals to PWideChar
in the Unicode version.
function GetFileAttributes(lpFileName: string): DWORD;
external 'GetFileAttributesA@kernel32.dll stdcall';
有关完整的示例和解决方案,请参见 Inno Setup FileExists无法找到现有文件.
For a full example and solution, see Inno Setup FileExists unable to find existing file.
在极少数情况下,您要调用一个具有out PWideChar
参数(var S: PWideChar
)的函数,在没有实际PWideChar
类型的情况下使用它非常棘手,因为在这种情况下,您不能使用string
封送处理.但这是可行的,请参见在Inno Setup中对AppData \ LocalLow常数吗?
In rare cases, that you are calling a function that has an out PWideChar
parameter (var S: PWideChar
), it's very tricky to use it, without the actual PWideChar
type, as in this case you cannot use the string
marshaling. But it's doable, see Constant for AppData\LocalLow in Inno Setup?
类似于Windows API,某些第三方库还提供了一个单独的Unicode版本,其API中带有Unicode字符串.例如, ISSkin 具有ISSkinU.dll
.请参阅使ISSkin与最新的Inno Setup 5.5.9 Unicode一起使用.
Similarly to Windows API, some 3rd party libraries also provide a separate Unicode version with Unicode strings in its API. For example ISSkin has ISSkinU.dll
. See Getting ISSkin to work with latest Inno Setup 5.5.9 Unicode.
任何使用string
类型作为字节数组的代码(与Unicode版本一样,string
是宽字符(2字节)数组).仅当您的代码使用TStream
类方法,例如:
Any code that uses string
type as byte array (as in Unicode version, the string
is wide char (2-byte) array). That's mostly concern, only if your code uses TStream
class methods like:
function Read(Buffer: String; Count: Longint): Longint;
function Write(Buffer: String; Count: Longint): Longint;
procedure ReadBuffer(Buffer: String; Count: Longint);
procedure WriteBuffer(Buffer: String; Count: Longint);
这些方法实际上应该已经用AnsiString
重新声明了.对我来说似乎是个虫子.
These methods should have really been re-declared with AnsiString
. Looks like a bug to me.
要使这些方法在Unicode版本中可用,请使用@TLama的BufferToAnsi
函数,该函数已在许多现有答案中使用,例如:
To make these methods usable in Unicode version, use BufferToAnsi
function by @TLama that is used in many existing answers, like:
- Inno Setup LoadStringFromFile fails when file is open in another process
- Read bytes from file at desired position with Inno Setup
- For another approach, see see Writing binary file in Inno Setup
Unicode版本不允许使用set of char
变量(因为对于多字节类型,不允许使用set
).尽管有趣的是,它在表达式中支持set of char
常量.请参见 字符集"错误在Inno Setup Unicode版本的Pascal脚本中.
Unicode version does not allow set of char
variable (as set
is not allowed for multi-byte types). Though interestingly it supports set of char
constants in expressions. See "Type mismatch" error on "set of char" in Pascal Script of the Inno Setup Unicode version.
FloatToStr
在Ansi版本,而在Unicode版本中始终是点.
FloatToStr
uses a locale specific decimal separator in Ansi version, while always a dot in Unicode version.
Unicode版本对分号的使用更加严格. Ansi版本可以忍受一些缺少的分号,因此即使在语法上不是100%正确的代码,它也可以编译.
Unicode version is more strict about use of semicolons. The Ansi version tolerates some missing semicolons, so it can compile even code that is not 100% syntactically correct in this respect.
如果您的代码未使用上述任何内容,并且您使用了分号,那么Unicode版本应该不会有任何问题.
If your code does not use any of the above, and you have your semicolons right, you should not have any problems with the Unicode version.
最后一点是,Unicode版本会创建稍大的安装程序. Inno Setup 6更大了.请参阅为什么在Inno Setup 6中编译安装程序比在Inno Setup 5中大1 MB
Last minor thing is that the Unicode version creates slightly larger installers. And Inno Setup 6 yet bit larger. See Why is installer compiled in Inno Setup 6 one MB larger than in Inno Setup 5
这篇关于从Ansi升级到Inno Setup的Unicode版本(任何缺点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!