inno-setup – 如何在InnoSetup PreProcessor部分复制文件?
发布时间:2020-12-15 09:17:31 所属栏目:大数据 来源:网络整理
导读:我只想在编译开始之前将一个文件复制到指定的目录. 背景:我需要创建一些zip文件.需要包含的其中一个文件需要复制到最终的zip位置. (我不能直接从原始位置压缩它,因为它会保留zip文件中的原始路径. 我发现,preProcessor动作对此非常完美.我试图使用Windows复
我只想在编译开始之前将一个文件复制到指定的目录.
背景:我需要创建一些zip文件.需要包含的其中一个文件需要复制到最终的zip位置. (我不能直接从原始位置压缩它,因为它会保留zip文件中的原始路径. 我发现,preProcessor动作对此非常完美.我试图使用Windows复制命令,但它不起作用. 提前致谢. 解决方法
虽然我已经建议使用批处理文件进行此类任务,但我已经制作了一个示例脚本,它处理某个目录中的所有* .tzs脚本文件,并且每个脚本尝试检查文件是否有已创建(或更具特色,如果存在).这当然只是假设帮助文件中显示的* .tzs脚本的基本用法.这里是:
#define FindHandle #define FindResult #define ScriptFile #define ScriptLine #define ScriptHandle #define ArchiveFile ; unique identifier for the target archive file name property member #define ArchiveToken ".Archive=" ; path to directory,where all the *.tzs script files will be processed #define ScriptPath "d:Development__StackOverflow14579484" ; tool,which will be used for the *.tzs file processing mentioned above #define ScriptTool "c:Program Files (x86)TUGZipTzScript.exe" ; This procedure tries to extract the name of the archive,to be created from ; the line currently read from the just processed *.tzs script file. It first ; tries to search the ArchiveToken constant value in trimmed,space-less line ; of script. If it's found,and the script line contains also two quotes,the ; file name is stored to the ArchiveFile variable,by which is later checked ; the file existence after the script execution is done #sub ParseScriptLine #define SrcPos = Pos("""",ScriptLine) #define EndPos = RPos("""",ScriptLine) #define ParsedStr = Trim(StringChange(ScriptLine," ","")) #if (Pos(ArchiveToken,ParsedStr) != 0) && (SrcPos != 0) && (EndPos != 0) && (SrcPos != EndPos) #expr ArchiveFile = Copy(ScriptLine,SrcPos + 1,EndPos - SrcPos - 1) #expr ArchiveFile = StringChange(ArchiveFile,"","") #if ArchiveFile != "" #pragma message "ExecuteScriptFile: ArchiveFile=" + ArchiveFile #expr ExecuteScriptFile #endif #endif #endsub ; This procedure opens the currently processed *.tzs script file and starts to ; read it line by line to get the file name of the archive to be created #sub ReadScriptFile #pragma message "ReadScriptFile: ScriptFile=" + ScriptPath + ScriptFile #for {ScriptHandle = FileOpen(ScriptPath + ScriptFile); ScriptHandle && !FileEof(ScriptHandle); ScriptLine = FileRead(ScriptHandle)} ParseScriptLine #if ScriptHandle #expr FileClose(ScriptHandle) #endif #endsub ; This procedure is used for the script execution itself,here the TzScript.exe ; tool is called passing the name of the currently processed script file. After ; this tool is done,it's checked if the expected archive file has been created #sub ExecuteScriptFile #if Exec(ScriptTool,ScriptPath + ScriptFile) == 0 #if FileExists(ArchiveFile) == 0 #error The expected archive was not found. Compilation will abort now! #endif #else #error An error occured at script tool starting. Compilation will abort now! #endif #endsub ; This is the file iteration "callback" #sub ProcessFoundFile #expr ScriptFile = FindGetFileName(FindHandle) #expr ReadScriptFile #endsub ; This procedure is used to find all the *.tzs script files in folder,specified ; by the ScriptPath constant path. All the *.tzs files found there are executed ; by the command line tool specified by the ScriptTool constant #for {FindHandle = FindResult = FindFirst(ScriptPath + "*.tzs",0); FindResult; FindResult = FindNext(FindHandle)} ProcessFoundFile #if FindHandle #expr FindClose(FindHandle) #endif [Setup] AppName=My Program AppVersion=1.5 DefaultDirName={pf}My Program OutputDir=userdocs:Inno Setup Examples Output (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |