NSIS之腳本

  • 邏輯代碼結構

1.條件判斷

NSIS腳本中可以使用StrCmp、IntCmp、IfErrors、Goto和其他方法有條件地執行代碼或在循環中執行代碼。

StrCmp $0 'some value' 0 +3
  MessageBox MB_OK '$$0 is some value'
  Goto done
StrCmp $0 'some other value' 0 +3
  MessageBox MB_OK '$$0 is some other value'
  Goto done
# else
  MessageBox MB_OK '$$0 is "$0"'
done:

不過,有一種更簡單的方法[LogicLib],LogicLib提供了一些非常簡單的宏,可以輕鬆地構造複雜的邏輯結構。它的語法,解釋於邏輯庫.nsh,與其他編程語言類似,對初學者和高級用戶來說都更簡單。

!include LogicLib.nsh

${If} $0 == 'some value'
  MessageBox MB_OK '$$0 is some value'
${ElseIf} $0 == 'some other value'
  MessageBox MB_OK '$$0 is some other value'
${Else}
  MessageBox MB_OK '$$0 is "$0"'
${EndIf}

LogicLib消除了對標籤和相對跳轉的需要,從而防止了標籤名稱衝突,並且消除了每次腳本更改時手動調整相對跳轉偏移的需要。

也可以使用switch達到同樣的目的

${Switch} $0
  ${Case} 'some value'
    MessageBox MB_OK '$$0 is some value'
    ${Break}
  ${Case} 'some other value'
    MessageBox MB_OK '$$0 is some other value'
    $
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章