rasc_launcher.bat 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. @echo off
  2. REM RASC launcher 2024-05-23
  3. setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
  4. REM Initialisations
  5. set "RascVersionFileHeader=# RASC version and installation file"
  6. set "RascDescRootKey=SOFTWARE\Renesas\RASC\Installations"
  7. set "VersionUnknown=Unknown"
  8. set "RascVersionValueName=Version"
  9. set "RascExeValueName=ExePath"
  10. set "RascSearchPath=C:\Renesas"
  11. set /a NumRascs=0
  12. set "TargetRascVersion="
  13. set "TargetRascExe="
  14. set "TargetRascVersionDiffers="
  15. REM First parameter is (possibly non-existent) file containing RASC version to invoke
  16. set "RascVersionFile=%~1"
  17. REM Shift to leave remaining parameters as input parameters to RASC
  18. shift
  19. REM Extract specific RASC version from file
  20. REM echo "%RascVersionFile%"
  21. if exist "%RascVersionFile%" (
  22. REM echo DEBUG: Have version file: "%RascVersionFile%"
  23. set /a idx=0
  24. for /f "usebackq tokens=*" %%a in ("%RascVersionFile%") do (
  25. if !idx! EQU 0 (
  26. if not "%%a" == "%RascVersionFileHeader%" (
  27. REM echo DEBUG: Header doesn't match
  28. goto _EndVersionFileParse
  29. )
  30. )
  31. if !idx! EQU 1 (
  32. set "TargetRascVersion=%%a"
  33. )
  34. if !idx! EQU 2 (
  35. set "TargetRascExe=%%a"
  36. )
  37. set /a idx+=1
  38. )
  39. )
  40. :_EndVersionFileParse
  41. REM echo DEBUG: Target version: "%TargetRascVersion%"
  42. REM echo DEBUG: Target exe: "%TargetRascExe%"
  43. REM Search through registry RASC descriptions for match on exe path and version
  44. for %%h in (HKCU HKLM) do (
  45. for %%v in (32 64) do (
  46. for /f "usebackq skip=1 tokens=*" %%a in (`reg query "%%h\%RascDescRootKey%" /reg:%%v 2^>nul`) do (
  47. set "RascDescKey=%%a"
  48. set "RascVersion="
  49. set "RascExe="
  50. REM echo DEBUG: Desc Key: !RascDescKey!
  51. for /f "usebackq skip=2 tokens=3" %%b in (`reg query "!RascDescKey!" /v "%RascVersionValueName%" /reg:%%v 2^>nul`) do (
  52. set "RascVersion=%%b"
  53. )
  54. REM echo DEBUG: Version: !RascVersion!
  55. for /f "usebackq skip=2 tokens=2*" %%b in (`reg query "!RascDescKey!" /v "%RascExeValueName%" /reg:%%v 2^>nul`) do (
  56. REM %%b is value name, so %%c is the value - supports values with spaces
  57. set "RascExe=%%c"
  58. )
  59. REM echo DEBUG: Exe: !RascExe!
  60. if not defined RascExe (
  61. REM Error - unable to extract executable
  62. set ErrorMessage=Unable to extract RASC executable path from the registry
  63. goto _Error
  64. )
  65. REM Check if exe exists, otherwise assume it's been removed
  66. if exist "!RascExe!" (
  67. REM Check for specified target version and exe path match
  68. if defined RascVersion (
  69. if defined TargetRascVersion (
  70. if /i "!RascExe!" == "%TargetRascExe%" (
  71. echo "!RascVersion!"
  72. echo "%TargetRascVersion%"
  73. if "!RascVersion!" == "%TargetRascVersion%" (
  74. REM echo DEBUG: Found match
  75. goto _LaunchRasc
  76. ) else (
  77. REM Indicate target RASC has a different version than
  78. REM the registry entry. In this case, target RASC has
  79. REM changed, so possibly prompt the user to select a
  80. REM RASC again
  81. set "TargetRascVersionDiffers=true"
  82. )
  83. )
  84. )
  85. ) else (
  86. REM Error - unable to extract version
  87. set ErrorMessage=Unable to extract RASC version from the registry
  88. goto _Error
  89. )
  90. call :SubAddFoundRasc "!RascExe!" "!RascVersion!"
  91. )
  92. )
  93. )
  94. )
  95. REM If target RASC exists and doesn't differ from the registry version (i.e.
  96. REM was not found in the registry), just run it
  97. if defined TargetRascExe (
  98. if exist "%TargetRascExe%" (
  99. if not defined TargetRascVersionDiffers (
  100. set "RascExe=%TargetRascExe%"
  101. set "RascVersion=%VersionUnknown%"
  102. goto _LaunchRasc
  103. )
  104. )
  105. )
  106. if %NumRascs% EQU 0 (
  107. REM No entries found in the registry, search C:\Renesas\ as fallback
  108. echo/
  109. echo Searching in "%RascSearchPath%" for RA Smart Configurator installations ...
  110. for /f "usebackq tokens=*" %%a in (`dir "%RascSearchPath%\rasc.exe" /s /b 2^>nul`) do (
  111. if not "%%a" == "" (
  112. call :SubAddFoundRasc "%%a" "%VersionUnknown%"
  113. )
  114. )
  115. )
  116. if %NumRascs% EQU 0 (
  117. REM Still no RASCs found - give up
  118. set ErrorMessage=No "RA Smart Configurator" installations found, download one from renesas.com
  119. goto _Error
  120. )
  121. if %NumRascs% EQU 1 (
  122. set "RascExe=%RascExeList[0]%"
  123. set "RascVersion=%RascVersionList[0]%"
  124. goto _LaunchRasc
  125. )
  126. REM Prompt for user to choose from multiple RASCs
  127. echo/
  128. echo Multiple RA Smart Configurators installed:
  129. set /a RascIdxMax=%NumRascs% - 1
  130. set Choices=""
  131. for /l %%a in (0,1,%RascIdxMax%) do (
  132. echo %%a: Version !RascVersionList[%%a]! ^("!RascExeList[%%a]!"^)
  133. set "Choices=!Choices!%%a"
  134. )
  135. echo/
  136. set /a ChosenIdx=%NumRascs%
  137. if %RascIdxMax% GTR 9 (
  138. set /p InputIdx=Select which one to run [0-%RascIdxMax%]?
  139. REM Check if the input string is a number
  140. set "NonNumber=" & for /f "delims=0123456789" %%i in ("!InputIdx!") do set "NonNumber=%%i"
  141. if not defined NonNumber (
  142. set /a ChosenIdx=!InputIdx!
  143. )
  144. ) else (
  145. choice /c %Choices% /m "Select which one to run"
  146. set /a ChosenIdx=!ERRORLEVEL! - 1
  147. )
  148. if %ChosenIdx% GEQ %NumRascs% (
  149. REM Out of range
  150. set ErrorMessage=Invalid selection
  151. goto _Error
  152. )
  153. set "RascExe=!RascExeList[%ChosenIdx%]!"
  154. set "RascVersion=!RascVersionList[%ChosenIdx%]!"
  155. :_LaunchRasc
  156. REM Carefully re-write specific version file, if required
  157. if exist "%RascVersionFile%" (
  158. if not defined TargetRascVersion (
  159. if not defined TargetRascExe (
  160. REM Unexpected version file contents, skip rewriting
  161. goto _EndRascVersionRewrite
  162. )
  163. )
  164. )
  165. if "!RascVersion!" == "%TargetRascVersion%" (
  166. if /i "!RascExe!" == "%TargetRascExe%" (
  167. REM Version file already up-to-date, skip rewriting
  168. goto _EndRascVersionRewrite
  169. )
  170. )
  171. echo %RascVersionFileHeader%>"%RascVersionFile%"
  172. echo %RascVersion%>>"%RascVersionFile%"
  173. echo %RascExe%>>"%RascVersionFile%"
  174. :_EndRascVersionRewrite
  175. REM Synchronous behaviour for build pre/post steps
  176. set "WaitRasc="
  177. IF "%~3"=="--generate" SET CLI=true
  178. IF "%~3"=="--gensmartbundle" SET CLI=true
  179. IF "%CLI%"=="true" (
  180. SET "WaitRasc=/b /wait"
  181. SET RascExe=%RascExe:rasc.exe=rascc.exe%
  182. )
  183. set Parameters=
  184. for %%a in (%*) do (
  185. if defined FirstParamSkipped set Parameters=!Parameters! %%a
  186. set FirstParamSkipped=true
  187. )
  188. REM echo DEBUG: Launching "%RascExe%" %Parameters%
  189. start "" %WaitRasc% "%RascExe%" %Parameters% & goto :EOF
  190. REM Add specified RASC to pseudo-list
  191. REM Parameters:
  192. REM 1: RascExe
  193. REM 2: RascVersion
  194. :SubAddFoundRasc
  195. set "RascExeList[%NumRascs%]=%~1"
  196. set "RascVersionList[%NumRascs%]=%~2"
  197. set /a NumRascs+=1
  198. goto :EOF
  199. :_Error
  200. REM start cmd /c "echo %ErrorMessage% && pause"
  201. echo/
  202. echo %ErrorMessage% && pause
  203. goto :EOF