加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

inno-setup – 从Ansi升级到Inno Setup的Unicode版本(任何缺点)

发布时间:2020-12-15 09:31:46 所属栏目:大数据 来源:网络整理
导读:与Ansi版本相比,Inno Setup Unicode版本有任何缺点吗? 或者是什么原因仍然是两个版本并行提供,而不仅仅是Unicode版本? 在使用Ansi版本开发的现有Inno Setup项目中使用Unicode版本时是否存在任何潜在问题? 解决方法 没有真正的缺点.主要有优点.显然,Unicod
与Ansi版本相比,Inno Setup Unicode版本有任何缺点吗?

或者是什么原因仍然是两个版本并行提供,而不仅仅是Unicode版本?

在使用Ansi版本开发的现有Inno Setup项目中使用Unicode版本时是否存在任何潜在问题?

解决方法

没有真正的缺点.主要有优点.显然,Unicode版本不仅限于传统的Ansi字符集.请参阅下文了解详情.

如果要启动新的Inno Setup项目,请始终使用Unicode版本.没有理由将Ansi版本用于新项目.

原因,为什么Ansi版本的Inno Setup仍然可用,是Ansi和Unicode版本的Pascal脚本代码不是100%兼容的.他们大多是,但有差异.

因此,如果您现有的安装程序脚本没有任何Pascal Script code(您的.iss中没有[Code] section),您可以(并且应该)立即升级到Unicode版本.

如果你有一些Pascal脚本代码,你应该更加小心.请参阅下文了解详情.

为什么要使用Unicode版本

例如Ansi版本的问题,如果您在英文系统上运行使用Ansi版本的Inno Setup构建的仅限日语的安装程序,您将获得:

Japanese Ansi installer on English system

另见Inno Setup installator has wrong text encoding.

出于同样的原因,Ansi版本将无法创建名称包含字符的文件,这些文件在目标计算机的旧版Ansi字符集中不存在.

Unicode版本没有这些问题,如Unicode Inno Setup article中所述:

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.

此外,Unicode版Pascal脚本还有一些小的改进.它们记录在Unicode Inno Setup article中.最重要的是,几乎没有未记录的改进:

> Inc / Dec函数/语句.见Inc function Inno Setup.
>更好的Variant支持.例如,请参阅Inno Setup: Iterate through array of type Variant (from OleObject)或Is?there a way to read the system’s information in Inno Setup.
>更好的高DPI(以及一般的非标准屏幕)支持.例如,请参阅Inno Setup taskbar icon blurred或Inno Setup Installer has squished window on XP?
>案件陈述范围:“colon (‘:’) expected” compiler error on character range in case statement in Inno Setup Pascal script.
>在具有常量集的运算符中:似乎在Ansi版本中,除非先将集合存储到一组变量中,否则总会出现“类型不匹配”错误.
注意,虽然Unicode版本确实支持带有常量集的in运算符,但它不支持set表达式中的范围,因此[1,2,3]中的X是可能的,但[1..3]中的X是不可能,你会得到“关闭方括号(‘]’).”
> TLabel在Unicode版本中具有透明背景.见Inno Setup – Transparency under text in page name and description labels
>在Ansi版本中无法调用某些自定义向导页面的标准事件处理程序,而在Unicode版本中可以正常工作.什么对像Inno Setup event that is generated when folder is browsed on TInputDirWizardPage?这样的东西有用

Pascal脚本代码中可能存在的问题

Pascal脚本代码中可能出现问题的区域很少:

>对DLL函数的任何调用都采用字符串参数 – 字符串和PChar类型. AnsiString应该没问题,因为它在Unicode版本中是相同的.

在Unicode版本中,PChar被重命名为PAnsiChar.

如果您调用任何使用字符串的Windows API函数,则应切换到其Wide版本.例如.使用GetFileAttributesW而不是GetFileAttributesA.没有PWideChar类型.因此,如果您的声明在Ansi版本中使用了PChar类型,并且您切换到该函数的Wide版本,则必须使用字符串类型. Inno Setup会自动将其封送到LPCTSTR(或类似的),也就是PWideChar.

以下声明在Ansi版本中是正确的,但在Unicode版本中是错误的,因为GetFileAttributesA采用PAnsiChar,但字符串编组为Unicode版本中的PWideChar.

function GetFileAttributes(lpFileName: string): DWORD;
  external 'GetFileAttributesA@kernel32.dll stdcall';

有关完整示例和解决方案,请参阅Inno Setup FileExists unable to find existing file.

在极少数情况下,您正在调用具有out PWideChar参数的函数(var S:PWideChar),使用它时非常棘手,没有实际的PWideChar类型,因为在这种情况下您不能使用字符串编组.但这是可行的,见Constant for AppDataLocalLow?

与Windows API类似,某些第三方库也在其API中提供带有Unicode字符串的单独Unicode版本.例如ISSkin有ISSkinU.dll.见Getting ISSkin to work with latest Inno Setup 5.5.9 Unicode.
>任何使用字符串类型作为字节数组的代码(如在Unicode版本中,字符串是宽字符(2字节)数组).这主要是关注,只有当您的代码使用TStream类方法时:

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重新声明这些方法.对我来说看起来像个错误.

要使这些方法在Unicode版本中可用,请使用@TLama中的BufferToAnsi函数,该函数在许多现有答案中使用,例如:

> Inno Setup LoadStringFromFile fails when file is open in another process
> Read bytes from file at desired position with Inno Setup
>有关其他方法,请参阅Writing binary file in Inno Setup

> Unicode版本不允许使用char变量集(因为多字节类型不允许使用set).虽然有趣的是它支持表达式中的char常量集.见“Type mismatch” error on “set of char” in Pascal Script of the Inno Setup Unicode version.
> FloatToStr在Ansi版本中使用特定于语言环境的小数点分隔符,而在Unicode版本中始终使用点.
> Unicode版本对分号的使用更为严格. Ansi版本容忍一些丢失的分号,因此它甚至可以编译在这方面不是100%语法正确的代码.

如果您的代码不使用上述任何一项,并且您的分号正确,则不应该对Unicode版本有任何问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读