ConsoleExec.nsi 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. !include MUI2.nsh
  2. Name `nsJSON plug-in`
  3. OutFile nsJSON_ConsoleExec.exe
  4. RequestExecutionLevel user
  5. ShowInstDetails show
  6. !define MUI_COMPONENTSPAGE_SMALLDESC
  7. !define MUI_PAGE_CUSTOMFUNCTION_LEAVE ComponentsPage_Leave
  8. !insertmacro MUI_PAGE_COMPONENTS
  9. !insertmacro MUI_PAGE_INSTFILES
  10. !insertmacro MUI_LANGUAGE English
  11. Section
  12. CreateDirectory $EXEDIR\Output
  13. SectionEnd
  14. Section /o `Console App` NATIVE
  15. InitPluginsDir
  16. StrCpy $R0 $PLUGINSDIR\ConsoleApp.exe
  17. File /oname=$R0 Bin\ConsoleApp.exe
  18. nsJSON::Set /tree ConsoleExec /value `{ "Path": "$R0", "WorkingDir": "$PLUGINSDIR", "RawOutput": true }`
  19. ; Provide arguments as a single string or an array.
  20. nsJSON::Set /tree ConsoleExec Arguments /value `[]`
  21. nsJSON::Set /tree ConsoleExec Arguments /value `"arg1"`
  22. nsJSON::Set /tree ConsoleExec Arguments /value `"arg2"`
  23. ; Provide input as a single string or an array.
  24. nsJSON::Set /tree ConsoleExec Input /value `"hello"`
  25. ; Export the tree to file for debugging.
  26. DetailPrint `Generate: $EXEDIR\Output\ConsoleExecInput.json from ConsoleExec`
  27. nsJSON::Serialize /tree ConsoleExec /format /file $EXEDIR\Output\ConsoleExecInput.json
  28. ; Execute the console application.
  29. DetailPrint `Exec: $R0`
  30. nsJSON::Set /tree ConsoleExecOutput /exec ConsoleExec
  31. ; Save the output to file.
  32. DetailPrint `Generate: $EXEDIR\Output\ConsoleExecOutput.json from ConsoleExecOutput`
  33. nsJSON::Serialize /tree ConsoleExecOutput /format /file $EXEDIR\Output\ConsoleExecOutput.json
  34. SectionEnd
  35. Section /o `Async Console App` NATIVEASYNC
  36. InitPluginsDir
  37. StrCpy $R0 $PLUGINSDIR\ConsoleApp.exe
  38. File /oname=$R0 Bin\ConsoleApp.exe
  39. nsJSON::Set /tree ConsoleExec /value `{ "Async": true, "Path": "$R0", "WorkingDir": "$PLUGINSDIR", "RawOutput": true }`
  40. ; Provide arguments as a single string or an array.
  41. nsJSON::Set /tree ConsoleExec Arguments /value `[]`
  42. nsJSON::Set /tree ConsoleExec Arguments /value `"arg1"`
  43. nsJSON::Set /tree ConsoleExec Arguments /value `"arg2"`
  44. ; Provide input as a single string or an array.
  45. nsJSON::Set /tree ConsoleExec Input /value `"hello"`
  46. ; Export the tree to file for debugging.
  47. DetailPrint `Generate: $EXEDIR\Output\AsyncConsoleExecInput.json from ConsoleExec`
  48. nsJSON::Serialize /tree ConsoleExec /format /file $EXEDIR\Output\AsyncConsoleExecInput.json
  49. ; Execute the console application.
  50. DetailPrint `Exec: $R0`
  51. nsJSON::Set /tree AsyncConsoleExecOutput /exec ConsoleExec
  52. ; Wait until done.
  53. ${Do}
  54. Sleep 1000
  55. nsJSON::Wait ConsoleExec /timeout 0
  56. Pop $R0
  57. ${If} $R0 != wait
  58. ${Break}
  59. ${EndIf}
  60. DetailPrint `Waiting...`
  61. ${Loop}
  62. DetailPrint `Finished...`
  63. ; Save the output to file.
  64. DetailPrint `Generate: $EXEDIR\Output\AsyncConsoleExecOutput.json from AsyncConsoleExecOutput`
  65. nsJSON::Serialize /tree AsyncConsoleExecOutput /format /file $EXEDIR\Output\AsyncConsoleExecOutput.json
  66. SectionEnd
  67. Section /o `.NET Console App` DOTNET
  68. InitPluginsDir
  69. StrCpy $R0 $PLUGINSDIR\ConsoleAppDotNet.exe
  70. File /oname=$R0 Bin\ConsoleAppDotNet.exe
  71. nsJSON::Set /tree ConsoleExec /value `{ "Path": "$R0", "WorkingDir": "$PLUGINSDIR" }`
  72. ; Provide arguments as a single string or an array.
  73. nsJSON::Set /tree ConsoleExec Arguments /value `[]`
  74. nsJSON::Set /tree ConsoleExec Arguments /value `"arg1"`
  75. nsJSON::Set /tree ConsoleExec Arguments /value `"arg2"`
  76. ; Provide input as a single string or an array.
  77. nsJSON::Set /tree ConsoleExec Input /value `"hello"`
  78. ; Export the tree to file for debugging.
  79. DetailPrint `Generate: $EXEDIR\Output\ConsoleExecDotNetInput.json from ConsoleExec`
  80. nsJSON::Serialize /tree ConsoleExec /format /file $EXEDIR\Output\ConsoleExecDotNetInput.json
  81. ; Execute the console application.
  82. DetailPrint `Exec: $R0`
  83. nsJSON::Set /tree ConsoleExecOutput /exec ConsoleExec
  84. ; Save the output to file.
  85. DetailPrint `Generate: $EXEDIR\Output\ConsoleExecDotNetOutput.json from ConsoleExecOutput`
  86. nsJSON::Serialize /tree ConsoleExecOutput /format /file $EXEDIR\Output\ConsoleExecDotNetOutput.json
  87. SectionEnd
  88. Section /o `UI Thread Console App` UINATIVE
  89. SectionEnd
  90. Function ComponentsPage_Leave
  91. ${IfNot} ${SectionIsSelected} ${UINATIVE}
  92. Return
  93. ${EndIf}
  94. GetDlgItem $R0 $HWNDPARENT 1
  95. EnableWindow $R0 0
  96. GetDlgItem $R0 $HWNDPARENT 2
  97. EnableWindow $R0 0
  98. GetDlgItem $R0 $HWNDPARENT 3
  99. EnableWindow $R0 0
  100. FindWindow $R0 `#32770` `` $HWNDPARENT
  101. GetDlgItem $R0 $R0 1032
  102. EnableWindow $R0 0
  103. Banner::Show /set 76 `Executing ConsoleApp.exe` `Please wait...`
  104. InitPluginsDir
  105. StrCpy $R0 $PLUGINSDIR\ConsoleApp.exe
  106. File /oname=$R0 Bin\ConsoleApp.exe
  107. nsJSON::Set /tree ConsoleExec /value `{ "UIAsync": true, "Path": "$R0", "WorkingDir": "$PLUGINSDIR", "RawOutput": true }`
  108. ; Provide arguments as a single string or an array.
  109. nsJSON::Set /tree ConsoleExec Arguments /value `[]`
  110. nsJSON::Set /tree ConsoleExec Arguments /value `"arg1"`
  111. nsJSON::Set /tree ConsoleExec Arguments /value `"arg2"`
  112. ; Provide input as a single string or an array.
  113. nsJSON::Set /tree ConsoleExec Input /value `"hello"`
  114. ; Export the tree to file for debugging.
  115. nsJSON::Serialize /tree ConsoleExec /format /file $EXEDIR\Output\UIConsoleExecInput.json
  116. ; Execute the console application.
  117. nsJSON::Set /tree UIConsoleExecOutput /exec ConsoleExec
  118. ; Save the output to file.
  119. nsJSON::Serialize /tree UIConsoleExecOutput /format /file $EXEDIR\Output\UIConsoleExecOutput.json
  120. Banner::Destroy
  121. GetDlgItem $R0 $HWNDPARENT 1
  122. EnableWindow $R0 1
  123. GetDlgItem $R0 $HWNDPARENT 2
  124. EnableWindow $R0 1
  125. GetDlgItem $R0 $HWNDPARENT 3
  126. EnableWindow $R0 1
  127. FindWindow $R0 `#32770` `` $HWNDPARENT
  128. GetDlgItem $R0 $R0 1032
  129. EnableWindow $R0 1
  130. FunctionEnd
  131. LangString NATIVEDesc ${LANG_ENGLISH} `Executes native console app with STDIN data and reads JSON from STDOUT`
  132. LangString NATIVEASYNCDesc ${LANG_ENGLISH} `Executes native console app asynchronously with STDIN data and reads JSON from STDOUT`
  133. LangString DOTNETDesc ${LANG_ENGLISH} `Executes .NET console app with STDIN data and reads JSON from STDOUT`
  134. LangString UINATIVEDesc ${LANG_ENGLISH} `Executes native console app asynchronously while processing window messages`
  135. !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  136. !insertmacro MUI_DESCRIPTION_TEXT ${NATIVE} $(NATIVEDesc)
  137. !insertmacro MUI_DESCRIPTION_TEXT ${NATIVEASYNC} $(NATIVEASYNCDesc)
  138. !insertmacro MUI_DESCRIPTION_TEXT ${DOTNET} $(DOTNETDesc)
  139. !insertmacro MUI_DESCRIPTION_TEXT ${UINATIVE} $(UINATIVEDesc)
  140. !insertmacro MUI_FUNCTION_DESCRIPTION_END