我只想在编译开始之前将一个文件复制到指定目录。

背景:我需要创建一些zip文件。其中一个要包含的文件需要复制到最终的zip位置。 (我无法直接从原始位置对其进行压缩,因为它会将原始路径保留在zip文件中。

我发现,preProcessor操作非常适合此操作。我试图使用Windows复制命令,但是它不起作用。
是否可以使用preCompiler部分中CODE部分中的函数?如何?
还是有完全不同的方式实现我的目标?

提前致谢。

最佳答案

尽管我已经建议使用批处理文件来执行此类任务,但是我制作了一个示例脚本,该脚本处理某个目录中的所有* .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\__StackOverflow\14579484\"
; tool, which will be used for the *.tzs file processing mentioned above
#define ScriptTool "c:\Program Files (x86)\TUGZip\TzScript.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

10-07 19:09
查看更多