1

セクション内で何度もマクロを呼び出しています。マクロは、ディレクトリが存在するかどうかをチェックし、存在しない場合はそのディレクトリを作成します。

私の問題:セクション内からこのマクロを複数回呼び出しているため、エラーが発生します。コンパイル エラーを修正するにはどうすればよいですか?

エラー:「エラー: ラベル "CreateDirThenInstall:" セクションで既に宣言されています」

このマクロを 1 つのセクションで複数回使用する方法を教えてください。

Section "Install Plugin Files" MainSetup
  !insertmacro ValidateDir "c:/blah"
  setOutPath "c:/blah"
  file "C:/blah/a.txt"
  file "C:/blah/b.txt"

  !insertmacro ValidateDir "c:/other"
  setOutPath "c:/other"
  file "c:/other/a.txt"
  file "c:/other/b.txt" 
sectionend

!macro ValidateDir dir
   IfFileExists "$dir" ExitMacro CreateDirThenInstall
   CreateDirThenInstall:   # Error here: Error: label "CreateDirThenInstall:" already declared in section
      createDirectory "${dir}"   
   ExitMacro: 
!macroend
4

1 に答える 1

2

The problem is with label, rather than with the macro. You have used exactly same label twice in the section, which is not possible.

You can make the label in the macro unique (even if macro inserted more than once). Compile time command ${__LINE__} can be used for that. You can then write something like this:

!macro ValidateDir dir
  !define UniqueId1 ${__LINE__}
  !define UniqueId2 ${__LINE__}
  IfFileExists "${dir}" Exit_${UniqueId1} CreateDir_${UniqueId2}
  CreateDir_${UniqueId2}:
      createDirectory "${dir}"   
  Exit_${UniqueId1}: 
  !undef UniqueId1
  !undef UniqueId2
!macroend

But in your case I think the above is not necessary. SetOutPath instruction creates directory if necessary for you. From doc:

Sets the output path ($OUTDIR) and creates it (recursively if necessary), if it does not exist.

So if you don't need to know about every directory created (and write it somewhere, e.g. to use it during uninstall), you don't have to do it at all.

于 2012-05-07T06:52:41.660 に答える