- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Pascal Script 函数来读取和检测文件的数组中有多少个名称。当它确定名称数量时,我想要一个 #for
循环来迭代该数量。
我可以使用 Pascal Script 读取和检测名称的数量。问题是,我不知道如何在名称计数过程之后设置 numberOfElements
变量的值。必须将其设置为刚刚使用 Pascal Script 函数读取的名称数量。
这里是一些示例代码:
#define numberOfElements
#sub CreateSubInstallation
[Languages]
//code ommitted
[Files]
//code ommitted
[Run]
//code ommitted
#endsub
#for {i = 0; i < numberOfElements; i++} CreateSubInstallation
采用不同的方法也可以。我只想从文件中读取多个名称,然后根据名称数量制作安装副本。因此,每个名称都有其自己的安装。更详细地说,每个名称都有自己的:目录、子目录和文件中的变量,这些文件会将名称“注入(inject)”到其中。
以下是 INI 文件的格式:
[Customer]
customers={"customerName1","customerName2"}
以下是使用 Pascal Script 读取和检测名称的代码:
{ Get the customer names from file }
function GetCustomersFromFile(fileName : string): string;
var
lines: TArrayOfString;
amountOfLines,i: integer;
tempResult: string;
begin
tempResult := '';
if LoadStringsFromFile(fileName, lines) then
begin
amountOfLines := GetArrayLength(amountOfLines);
{ Keep reading lines until the end of the file is reached }
for i := 0 to amountOfLines - 1 do
begin
if (Pos('customers', lines[i]) = 1) then
tempResult := lines[i];
end;
{ if not found return -1 }
if (tempResult = '') then
{ this result is for debugging and }
{ will have no impact on the array population process }
tempResult := '-1';
Result := tempResult;
end;
end;
{ Count the number of elements present in the array in the file }
{ Done for tempArray initilization }
function CountNumberOfStringElements(line : string): integer;
const
chars = ['0'..'9', 'a'..'z', 'A'..'Z'];
var
ignoreCommas: Boolean;
numElements, numValidText: integer;
i: integer;
begin
ignoreCommas := false;
numValidText := 0;
numElements := 0;
{ Loop through text }
for i := 0 to Length(line) - 1 do
begin
if (line[i] = '"') then
ignoreCommas := (NOT ignoreCommas);
if ((line[i]) IN chars AND (ignoreCommas)) then
Inc(numValidText);
if((line[i] = ',') AND (NOT ignoreCommas) )then
Inc(numElements);
end;
if (numElements >= 1) then
result := numElements + 1
else if ((numElements = 0) AND (numValidText > 0)) then
result := 1
else if ((numElements = 0) AND (numValidText = 0)) then
result := 0;
end;
这本质上就是我希望安装程序执行的操作,只是一个非常精简的版本。
[Setup]
AppName=My Program
AppVersion=1.5
WizardStyle=modern
DefaultDirName={autopf}\My Program
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
Compression=lzma2
SolidCompression=yes
OutputDir=userdocs:Inno Setup Examples Output
ArchitecturesAllowed=x64
ArchitecturesInstallIn64BitMode=x64
[Files]
Source: "MyProg-x64.exe"; DestDir: "{app}/customer1/"; DestName: "MyProg.exe"
Source: "MyProg.chm"; DestDir: "{app}/customer1/"
Source: "Readme.txt"; DestDir: "{app}/customer1/"; Flags: isreadme
Source: "MyProg-x64.exe"; DestDir: "{app}/customer2/"; DestName: "MyProg.exe"
Source: "MyProg.chm"; DestDir: "{app}/customer2/"
Source: "Readme.txt"; DestDir: "{app}/customer2/"; Flags: isreadme
[Icons]
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
请注意之所以这样构造是因为它们是服务。每项服务最终都会包含更多与客户相关的内容。整个安装过程必须使用 .exe 完成,而删除过程则必须使用不同但单一的 .exe 完成。
最佳答案
你的问题很不清楚。但我会尽力给你一些答案。
如果我理解正确的话,您希望在 INI 文件中为每个客户部署相同的文件集。如果您需要在运行/安装时读取 INI 文件(这是可能的,如果您在编译时读取 INI 文件),则无法在 Inno Setup 中使用 [Files]
部分执行此操作。
如果您需要在运行/安装时克隆文件,您所能做的就是将它们安装到临时文件夹,然后使用 Pascal 脚本复制它们。
[Files]
Source: "MyProg.exe"; DestDir: "{tmp}"
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
I: Integer;
SourcePath: string;
TargetPath: string;
begin
if CurStep = ssPostInstall then
begin
for I := 0 to NumberOfCustomers - 1 then
begin
SourcePath := ExpandConstant('{tmp}\MyProg.exe');
TargetPath := GetPathForCustomer(I) + '\MyProg.exe';
if FileCopy(SourcePath, TargetPath, False) then
begin
Log(Format('Installed for customer %d', [I]));
end
else
begin
Log(Format('Failed to install for customer %d', [I]));
end;
end;
end;
end;
(您必须将 NumberOfCustomers
和 GetPathForCustomer
替换为您的实现)
尽管如此,您将不会获得任何进度条,并且会丢失 Inno Setup 的所有内置错误处理功能。您还必须在 Pascal Script 中实现卸载。
<小时/>如果您在编译时读取 INI 文件,那肯定会更好。这意味着您必须在每次更改 INI 文件时重新生成安装程序。但这可以通过单击一下命令行编译器来完成。
尽管使用预处理器解析 INI 文件并不容易。
<小时/>另一个黑客解决方案是在[Files]
部分中生成大量相同的条目,然后可以在运行/安装时动态地将其与客户关联。它不是通用的,因为总会有一个上限。但如果你知道你永远不会拥有比例如更多的东西。 100个客户,这是一个可行的选择。进度条、错误处理和卸载都将起作用。
我不明白,[Languages]
部分与 INI 文件有什么关系,所以我跳过它。
旁注:您的 GetCustomersFromFile
和 GetCustomersFromFile
可以使用 GetIniString
替换为几行代码和TStringList.CommaText。但这是一个单独的问题。
关于arrays - 创新设置: Single installer that reads names from an INI file and creates an installation for each name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57944160/
我有一堆字符串,其中包含以姓氏,名字格式命名的名称列表,并用逗号分隔,如下所示: names 序列化字符串中的“first name last name”,我们在Stack Overflow上找到一个
在尝试合并多个数据框时,我得到了一些非常奇怪的东西。帮助! 我需要通过“RID”和“VISCODE”列合并一堆数据框。这是它的外观示例: d1 = data.frame(ID = sample(9,
让我们尽可能简单地做第一个例子。 我想知道如何应用这个宏;像这里适用于例如printf("%s",macro(arg)); #include #include #include #define
以下2个bean声明之间有什么区别吗? @Bean(name = "bean1") public A getA() { return new A(); } @Bean @Quali
if(c.get_name(&name) && name && !strcmp(name, contName)) 谁能告诉我这行代码在 C++ 中的含义 最佳答案 如果 c 有一个名字并且它等于 co
我是 Rails 的初学者,在改进我的搜索查询时遇到了一些问题: 在我调用的 Controller 中: def index if params[:search] @persons = Pers
谁能帮我解决这段代码的最后一部分的编译错误它的说法创建构造函数请帮助 public class Officer { public static void main(String args[]
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 8 年前。 Improve t
我创建了一个 Web 应用程序,它具有使用 JSF 技术的 createBook.xhtml 并且它使用托管 Bean。在此页面中,用户必须在输入字段中填写所需信息,然后点击提交按钮。然后应使用 do
嘿,我正在尝试弄清楚如何将在 mySQL 中工作的语句转换为 PostgreSQL 并且很好奇是否有人知道解决方案。 这是在 mySQL 中有效的语句: def self.by_name(keywor
如果我要创建所有类型的类型,而不是使用字符串和原始类型,那么最大的缺点是什么? 通常它看起来像: String name = person.getName(); int age = person.ge
我正在尝试从以下内容中提取郊区名称: 12 street name, suburb name, CTG 1234 在 PHP 中使用正则表达式。 街道和郊区名称都可以是任意数量的单词长度。 CTG 是
我有一个呈现个人详细信息组件的父组件,并且正在注入(inject)父组件的验证器范围。如果我使用 v-validate 指令和 this.$validator.validateAll() 或 this
现在,据我了解,name[] 声明中的 extern 告诉编译器它的定义在其他地方(在我的程序中,我定义了它低于我使用它的部分)。但是为什么 strlen() 和 sizeof 会有不同的结果?str
我一直在解决一个问题: "Design a program that asks the user for a series of names (in no particular order). Aft
我的 XML 如下所示: 我想使用 JAXB 来阅读该内容。 我知道我能做到 @XmlRootElement(name="thing") public class Thing{
对于字符串 name[],我们可以使用 strlen(name)+1 和 sizeof(name) 互换 在我们的代码中没有经过深思熟虑?他们不一样吗?我检查了一下,发现两者的返回类型都是相同的,si
我正在尝试从以下内容中提取郊区名称: 12 street name, suburb name, CTG 1234 在 PHP 中使用正则表达式。 街道和郊区名称的长度可以是任意数量。 CTG 是 st
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 8 年前。 Improve t
bash 手册列出了 for 的语法。复合语句为for name [ [ in [ word ... ] ] ; ] do list ; done这意味着 do 之前的分号如果 in 是可选的子句省略
我是一名优秀的程序员,十分优秀!