build.bat 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. @ECHO OFF
  2. REM Use Setlocal in case this program is started from a working command prompt.
  3. REM This safely preserves the parent process's environment and working folder.
  4. setlocal
  5. REM Immediately retrieve the program's entire path
  6. SET "ProgramDirPath=%~dp0"
  7. REM Start the program
  8. GOTO :Main
  9. REM # ================================================================================================
  10. REM # Documentation
  11. REM # Spine of the program; this makes sure that the execution works as intended.
  12. REM # ================================================================================================
  13. :Main
  14. REM Update the terminal window title
  15. TITLE WolfenDoom EZBake Oven: Now with Nazi Cupcakes!
  16. REM Check if Git executable is available on the host
  17. CALL :GitFeature_DependencyCheck
  18. CALL :MainMenu
  19. GOTO :TerminateProcess
  20. REM # ================================================================================================
  21. REM # Documentation
  22. REM # Displays the main menu - which the user selects how the build is compiled into an archive file.
  23. REM # Default Compression = Type: ZIP ; Method: Deflate ; Compression: 5
  24. REM # Best Compression = Type: ZIP ; Method: LZMA ; Compression: 9
  25. REM # No Compression = Type: ZIP ; Method: Deflate ; Compression: 0
  26. REM # ================================================================================================
  27. :MainMenu
  28. REM Thrash the terminal buffer
  29. CLS
  30. REM Display the title on the buffer
  31. CALL :BufferHeader
  32. ECHO Main Menu
  33. ECHO ------------
  34. ECHO.
  35. ECHO Choose how to compile this project:
  36. ECHO ---------------------
  37. ECHO [1] Default Build
  38. ECHO [2] Best Compression
  39. ECHO [3] No Compression
  40. ECHO ---------------------
  41. ECHO.
  42. ECHO Other available options:
  43. ECHO ---------------------
  44. REM ----
  45. REM Special Features
  46. REM Only draw these options if its possible
  47. IF %featuresGit% EQU True (ECHO [U] Update Repository)
  48. REM ----
  49. ECHO [?] Help
  50. ECHO [X] Exit
  51. ECHO ---------------------
  52. ECHO.
  53. REM Capture the user input
  54. CALL :PromptUserInput
  55. REM Inspect the input
  56. GOTO :MainMenu_STDIN
  57. REM # ================================================================================================
  58. REM # Documentation
  59. REM # Inspect the user's input and execute their desired action
  60. REM # ================================================================================================
  61. :MainMenu_STDIN
  62. IF "%STDIN%" EQU "1" (
  63. CALL :CompactProject ZIP DEFLATE 5 NORMAL
  64. GOTO :MainMenu
  65. )
  66. IF "%STDIN%" EQU "2" (
  67. CALL :CompactProject ZIP LZMA 9 NORMAL
  68. GOTO :MainMenu
  69. )
  70. IF "%STDIN%" EQU "3" (
  71. CALL :CompactProject ZIP DEFLATE 0 NORMAL
  72. GOTO :MainMenu
  73. )
  74. IF /I "%STDIN%" EQU "X" (
  75. GOTO :EOF
  76. )
  77. IF /I "%STDIN%" EQU "Help" (
  78. CALL :Help
  79. GOTO :MainMenu
  80. )
  81. IF "%STDIN%" EQU "?" (
  82. CALL :Help
  83. GOTO :MainMenu
  84. )
  85. IF /I "%STDIN%" EQU "U" (
  86. REM Avoid the end-user from selecting a choice that may not be
  87. REM available to them.
  88. REM Try to detect if Git features is NOT available
  89. IF %featuresGit% NEQ True CALL :MainMenu_STDIN_BadInput
  90. REM Try to detect if Git features IS available
  91. IF %featuresGit% EQU True CALL :GitFeature_UpdateBranch
  92. GOTO :MainMenu
  93. ) ELSE (
  94. CALL :MainMenu_STDIN_BadInput
  95. GOTO :MainMenu
  96. )
  97. REM # ================================================================================================
  98. REM # Documentation
  99. REM # This function displays a message to the user that the STDIN was illegal and not supported
  100. REM # ================================================================================================
  101. :MainMenu_STDIN_BadInput
  102. ECHO.
  103. ECHO ERROR: INVALID OPTION
  104. ECHO The provided input from the user is not either valid or supported. Please select from the choices provided.
  105. ECHO.
  106. PAUSE
  107. GOTO :EOF
  108. REM # ================================================================================================
  109. REM # Documentation
  110. REM # This function captures the standard input from the user.
  111. REM # ================================================================================================
  112. :PromptUserInput
  113. SET /P STDIN=^>^>^>^>
  114. GOTO :EOF
  115. REM # ================================================================================================
  116. REM # Documentation
  117. REM # Displays the title of the program.
  118. REM # ================================================================================================
  119. :BufferHeader
  120. ECHO WolfenDoom Compiler
  121. ECHO =====================
  122. ECHO ---------------------
  123. ECHO =====================
  124. ECHO.&ECHO.&ECHO.
  125. GOTO :EOF
  126. REM # ================================================================================================
  127. REM # Documentation
  128. REM # This function simply displays the help screen; why this program exists and how it works.
  129. REM # ================================================================================================
  130. :Help
  131. REM Thrash the terminal buffer
  132. CLS
  133. REM Display the title on the buffer
  134. CALL :BufferHeader
  135. ECHO Help
  136. ECHO ------------
  137. ECHO.
  138. ECHO This program is a PK3 compiler for the WolfenDoom project. When prompted with compile options such as: Default Build, Best Compression, and No Compression, these provides different forms of compression methods that this program allows. However, compression can also depreciate performance.
  139. ECHO ^* Default Build
  140. ECHO Builds the project with the default compression; what to expect for public builds.
  141. ECHO ^* Best Compression
  142. ECHO Provides the best possible compression, thus tighter filesize but can have an effect with performance when playing the game.
  143. ECHO ^* No Compression
  144. ECHO Builds the project with absolutely no compression; maximizes performance with lack of compression.
  145. ECHO.
  146. ECHO If unsure what to choose, select the default build or option [ 1 ] from the Main Menu.
  147. ECHO For further help is needed, please visit the official ZDoom forum thread:
  148. ECHO http://forum.zdoom.org/viewtopic.php?p=813367#p813367
  149. ECHO.
  150. PAUSE
  151. EXIT /B 0
  152. REM # ================================================================================================
  153. REM # Documentation
  154. REM # This function well walk through the protocol before and during the compiling process.
  155. REM # Parameters
  156. REM # ArchiveType [String] = %1
  157. REM # Contains the archive file type. For example: zip [PK3] or 7zip [PK7]
  158. REM # ArchiveMethod [String] = %2
  159. REM # Contains the method type of the archive file. For example: DEFLATE, DEFLATE64, PPMD, or LZMA.
  160. REM # CompressionLevel [int] = %3
  161. REM # Upholds the compression level of the archive file. Range is from 0-9
  162. REM # PriorityLevel [String] = %4
  163. REM # Manages how much processing time the task has within the process-ribbon managed by the OS.
  164. REM # ================================================================================================
  165. :CompactProject
  166. CALL :ProcessingInterface 0 "Compiling project"
  167. CALL :CompactProject_CheckResources || EXIT /B 1
  168. CALL :CompactProject_Execute_ProjectName
  169. CALL :CompactProject_Execute %1 %2 %3 %4 || EXIT /B 1
  170. CALL :CompactProject_WindowsExplorer || EXIT /B 1
  171. CALL :ProcessingInterface 1
  172. EXIT /B 0
  173. REM # ================================================================================================
  174. REM # Documentation
  175. REM # Before we compile the project, first make sure that the resources exist - and that there will not be any issues.
  176. REM # NOTE: This function does a clean scan each time this is executed.
  177. REM # ================================================================================================
  178. :CompactProject_CheckResources
  179. REM Check to make sure that the 'Tools' directory exists or is accessible
  180. CALL :CompactProject_CheckResources_ToolsDirExists || (EXIT /B 1)
  181. REM Check to see if the files exists within the project's filesystem.
  182. CALL :CompactProject_CheckResources_FilesExists || (EXIT /B 1)
  183. REM Check the file permission of necessary files
  184. CALL :CompactProject_CheckResources_FilePermissions || (EXIT /B 1)
  185. EXIT /B 0
  186. REM # ================================================================================================
  187. REM # Documentation
  188. REM # Check to see if the required files exists within the filesystem structure of the project.
  189. REM # If one or more files were not found, then abort the entire process and display an error
  190. REM # on the buffer.
  191. REM # Return
  192. REM # EvaluationStatus [bool]
  193. REM # 0 = Everything is okay; everything was located successfully
  194. REM # 1 = Files do not exist within the project's filesystem or not accessible
  195. REM # ================================================================================================
  196. :CompactProject_CheckResources_FilesExists
  197. SET ErrorBool=False
  198. SET "ErrorString="
  199. REM Try to check if the resources could be found; if not - prepare an error message.
  200. IF NOT EXIST "%ProgramDirPath%tools\7za\7za.exe" (
  201. SET ErrorBool=True
  202. SET "ErrorString=%ErrorString%Could Not Find 7Zip!&ECHO."
  203. )
  204. IF NOT EXIST "%ProgramDirPath%tools\7za\7zExcludeListDir.txt" (
  205. SET ErrorBool=True
  206. SET "ErrorString=%ErrorString%Could Not Find Exclude Directory List!&ECHO."
  207. )
  208. IF NOT EXIST "%ProgramDirPath%tools\7za\7zExcludeList.txt" (
  209. SET ErrorBool=True
  210. SET "ErrorString=%ErrorString%Could Not Find Exclude List!&ECHO."
  211. )
  212. IF %ErrorBool% EQU True (
  213. CALL :CompactProject_CheckResources_ErrMSG 1 "%ErrorString%"
  214. EXIT /B 1
  215. )
  216. EXIT /B 0
  217. REM # ================================================================================================
  218. REM # Documentation
  219. REM # Check to make sure that the directories are accessible; we do this by viewing the inside of
  220. REM # the directories which requires the user to have not only the necessary privileges but must
  221. REM # also have the directory available and ready.
  222. REM # Return
  223. REM # EvaluationStatus [bool]
  224. REM # 0 = Everything is okay
  225. REM # 1 = Directory is not accessible
  226. REM # ================================================================================================
  227. :CompactProject_CheckResources_ToolsDirExists
  228. REM Does the directory exists?
  229. IF NOT EXIST "%ProgramDirPath%tools" (
  230. CALL :CompactProject_CheckResources_ErrMSG 0 "Unable to locate the [ {PROJECT_ROOT}\Tools ] directory."
  231. EXIT /B 1
  232. )
  233. REM Is there permission issues?
  234. CALL :CompactProject_CheckResources_CheckPermissions_ToolsDir
  235. IF %ERRORLEVEL% NEQ 0 (
  236. CALL :CompactProject_CheckResources_ErrMSG 0 "Insufficient permissions or no data found in the [ {PROJECT_ROOT}\Tools ] directory."
  237. EXIT /B 1
  238. )
  239. EXIT /B 0
  240. REM # ================================================================================================
  241. REM # Documentation
  242. REM # Check to see if the required files are accessible by checking if the user can access\read\execute
  243. REM # the files.
  244. REM # Notes
  245. REM # Error Code of '5' = Permission conflictions; user must resolve this on their own or contact
  246. REM # their network or IT administrator for assistance.
  247. REM # Return
  248. REM # EvaluationStatus [bool]
  249. REM # 0 = Everything is okay; everything was located successfully
  250. REM # 1 = Files do not exist within the project's filesystem or not accessible
  251. REM # ================================================================================================
  252. :CompactProject_CheckResources_FilePermissions
  253. CALL :CompactProject_CheckResources_7ZipExecutableInternal
  254. IF %ERRORLEVEL% NEQ 0 (
  255. CALL :CompactProject_CheckResources_ErrMSG 2 "Unable to execute [ {PROJECT_ROOT}\Tools\7za\7za.exe ] due to insufficient privileges! [Error Code: %ERRORLEVEL%]"
  256. EXIT /B 1
  257. )
  258. EXIT /B 0
  259. REM # ================================================================================================
  260. REM # Documentation
  261. REM # Test the internal 7Zip program and check for possible errors. This can be helpful to detect
  262. REM # for permission issues or other ambiguous complications.
  263. REM # Return
  264. REM # ExitCode [Int]
  265. REM # Returns the exit code reported by the system or 7Zip.
  266. REM # ================================================================================================
  267. :CompactProject_CheckResources_7ZipExecutableInternal
  268. "%ProgramDirPath%tools\7za\7za.exe" 2> NUL 1> NUL
  269. EXIT /B %ERRORLEVEL%
  270. REM # ================================================================================================
  271. REM # Documentation
  272. REM # Test to see if the {PROJECT_ROOT}\Tools dir. exists on the system and if the user has sufficient
  273. REM # privileges to access the directory.
  274. REM # Return
  275. REM # ExitCode [Int]
  276. REM # Returns the exit code reported by the system or DIR [intCMD].
  277. REM # ================================================================================================
  278. :CompactProject_CheckResources_CheckPermissions_ToolsDir
  279. DIR /B "%ProgramDirPath%tools" 2> NUL 1> NUL
  280. EXIT /B %ERRORLEVEL%
  281. REM # ================================================================================================
  282. REM # Documentation
  283. REM # Display an error that some of the required dependencies that is used during the compiling process
  284. REM # could not be located.
  285. REM # Parameters
  286. REM # ErrorCode [int] = %1
  287. REM # Specify the error code that should be presented on the screen.
  288. REM # 0 = Tools Dir Unaccessible
  289. REM # 1 = Missing Files
  290. REM # 2 = Permission Issue
  291. REM # ErrorMSG [String] = %2
  292. REM # Contains the error message that is to be displayed on the screen.
  293. REM # ================================================================================================
  294. :CompactProject_CheckResources_ErrMSG
  295. REM Figure out what error message to display on the screen
  296. IF %1 EQU 0 CALL :CompactProject_CheckResources_ErrMSG_ToolsDirUnaccessible "%~2"
  297. IF %1 EQU 1 CALL :CompactProject_CheckResources_ErrMSG_MissingFiles "%~2"
  298. IF %1 EQU 2 CALL :CompactProject_CheckResources_ErrMSG_PermissionIssue "%~2"
  299. REM Allow the user to read the message
  300. PAUSE
  301. GOTO :EOF
  302. REM # ================================================================================================
  303. REM # Documentation
  304. REM # Display an error message that some of the resources were not successfully located.
  305. REM # Parameters
  306. REM # ErrorMSG [String] = %1
  307. REM # Contains the error message that is to be displayed on the screen.
  308. REM # ================================================================================================
  309. :CompactProject_CheckResources_ErrMSG_MissingFiles
  310. ECHO.
  311. ECHO CRITICAL ERROR: RESOURCES NOT FOUND!
  312. ECHO %~1
  313. ECHO Program Path: %ProgramDirPath%
  314. ECHO User Path: %CD%
  315. ECHO.
  316. ECHO Please report this error to the WolfenDoom project team!
  317. EXPLORER https://github.com/Realm667/WolfenDoom/issues
  318. ECHO.
  319. GOTO :EOF
  320. REM # ================================================================================================
  321. REM # Documentation
  322. REM # Display an error message that there is permission complications and the user needs to resolve.
  323. REM # Parameters
  324. REM # ErrorMSG [String] = %1
  325. REM # Contains the error message that is to be displayed on the screen.
  326. REM # ================================================================================================
  327. :CompactProject_CheckResources_ErrMSG_PermissionIssue
  328. ECHO.
  329. ECHO CRITICAL ERROR: INSUFFICIENT PERMISSIONS
  330. ECHO %~1
  331. ECHO.
  332. ECHO Please inspect the file permissions or contact your administrator for assistance.
  333. ECHO.
  334. GOTO :EOF
  335. REM # ================================================================================================
  336. REM # Documentation
  337. REM # Display an error message that the {PROJECT_ROOT}\Tools} is not accessible; either the directory
  338. REM # does not exist or there is a permission issue that the user needs to resolve.
  339. REM # Parameters
  340. REM # ErrorMSG [String] = %1
  341. REM # Contains the error message that is to be displayed on the screen.
  342. REM # ================================================================================================
  343. :CompactProject_CheckResources_ErrMSG_ToolsDirUnaccessible
  344. ECHO.
  345. ECHO CRITICAL ERROR: TOOLS DIR. UNACCESSIBLE
  346. ECHO %~1
  347. ECHO.
  348. ECHO Check to make sure that the path exists and that you have enough permissions.
  349. ECHO.
  350. GOTO :EOF
  351. REM # ================================================================================================
  352. REM # Documentation
  353. REM # Before we compile the project, first make sure that the resources exist - and that there will not be any issues.
  354. REM # Priorities:
  355. REM # LOW - BELOWNORMAL - NORMAL - ABOVENORMAL - HIGH - REALTIME [AKA Ludicrous Speed - Spaceballs reference]
  356. REM # Parameters
  357. REM # ArchiveType [String] = %1
  358. REM # Contains the archive file type. For example: zip [PK3] or 7zip [PK7]
  359. REM # ArchiveMethod [String] = %2
  360. REM # Contains the method type of the archive file. For example: DEFLATE, DEFLATE64, PPMD, or LZMA.
  361. REM # CompressionLevel [int] = %3
  362. REM # Upholds the compression level of the archive file. Range is from 0-9
  363. REM # PriorityLevel [String] = %4
  364. REM # Manages how much processing time the task has within the process-ribbon managed by the OS.
  365. REM # Do note that 'Normal' is the default value, and 'RealTime' can cause the system to slow-down in favor
  366. REM # of the program that has the 'RealTime' flag. Meaning, if executed with 'RealTime', the user might
  367. REM # notice that their normal activities will be greatly delayed until the program with 'RealTime' is completed.
  368. REM # ================================================================================================
  369. :CompactProject_Execute
  370. START "WolfenDoom Compile: 7Zip" /B /%4 /WAIT "%ProgramDirPath%tools\7za\7za.exe" a -t%1 -mm=%2 -mx=%3 -x@"%ProgramDirPath%tools\7za\7zExcludeListDir.txt" -xr@"%ProgramDirPath%tools\7za\7zExcludeList.txt" "%ProgramDirPath%..\%projectName%.pk3" "%ProgramDirPath%*"
  371. REM Because I couldn't use the error-pipes with 'Start', we'll have to check the ExitCode in a conditional statement
  372. IF %ERRORLEVEL% GEQ 1 (
  373. CALL :CompactProject_Execute_ErrMSG %ERRORLEVEL%
  374. EXIT /B 1
  375. ) ELSE (
  376. EXIT /B 0
  377. )
  378. REM # ================================================================================================
  379. REM # Documentation
  380. REM # Determine what project filename to use.
  381. REM # IIF Git features are enabled, then attach the commit hash to
  382. REM # the filename.
  383. REM # Else use the generic file name without a hash.
  384. REM # ================================================================================================
  385. :CompactProject_Execute_ProjectName
  386. REM If git features is not available, then just use the generic name.
  387. REM No hash will be used.
  388. IF %featuresGit% NEQ True (
  389. REM Avoid redundancy
  390. IF "%projectName%" NEQ "boa" SET "projectName=boa"
  391. GOTO :EOF
  392. )
  393. REM Assume Git features are available for us to utilize
  394. REM Attach the hash to the file name.
  395. CALL :GitFeature_FetchCommitHash
  396. REM Avoid redundancy
  397. IF "%projectName%" NEQ "boa-%GitCommitHash%" SET "projectName=boa-%GitCommitHash%"
  398. GOTO :EOF
  399. REM # ================================================================================================
  400. REM # Documentation
  401. REM # If 7Zip returned an error, let the user know that the process was terminated prematurely or failed.
  402. REM # Parameters
  403. REM # ExitCode [Int] = %1
  404. REM # Holds the value of the ExitCode from 7Zip
  405. REM # ================================================================================================
  406. :CompactProject_Execute_ErrMSG
  407. ECHO.
  408. ECHO CRITICAL ERROR: 7ZIP FAILED!
  409. ECHO 7Zip was unable to complete the operation and closed with an Exit Code: %1.
  410. ECHO.
  411. ECHO Tips:
  412. ECHO * Make sure you have enough permission to run applications.
  413. ECHO * Make sure that the system has enough memory to perform the operation.
  414. ECHO * Make sure that the files are not locked by other applications.
  415. ECHO * Examine any warning messages provided and try to address them as much as possible.
  416. ECHO.
  417. ECHO If this issue reoccurs please let us know.
  418. PAUSE
  419. GOTO :EOF
  420. REM # ================================================================================================
  421. REM # Documentation
  422. REM # Create a new window and highlight the newly created build.
  423. REM # ================================================================================================
  424. :CompactProject_WindowsExplorer
  425. EXPLORER /select,"%ProgramDirPath%..\%projectName%.pk3"
  426. EXIT /B 0
  427. REM # ================================================================================================
  428. REM # Documentation
  429. REM # Provide a simple interface for incoming operations.
  430. REM # The borders in between the actual update is only for readability
  431. REM # to the users.
  432. REM # Parameters
  433. REM # InterfaceHeadOrTail [Int] = %1
  434. REM # Displays either the header or footer on the screen
  435. REM # when processing a task.
  436. REM # 0 = Header
  437. REM # 1 = Footer
  438. REM # TaskString [String] = %2
  439. REM # Displays the message on the screen of the main operation.
  440. REM # ================================================================================================
  441. :ProcessingInterface
  442. IF %1 EQU 0 (
  443. CLS
  444. CALL :BufferHeader
  445. ECHO %~2. . .
  446. ECHO -------------------------------------
  447. ) ELSE (
  448. ECHO -------------------------------------
  449. PAUSE
  450. )
  451. EXIT /B 0
  452. REM # ================================================================================================
  453. REM # Documentation
  454. REM # Check to see if we can be able to utilize Git features within this program.
  455. REM # ================================================================================================
  456. :GitFeature_DependencyCheck
  457. CALL :GitFeature_DependencyCheck_GitExecutable
  458. IF %ERRORLEVEL% EQU 1 (
  459. REM Could not detect the git executable
  460. SET featuresGit=False
  461. GOTO :EOF
  462. )
  463. CALL :GitFeature_DependencyCheck_RepoGitDB
  464. IF %ERRORLEVEL% EQU 1 (
  465. REM Could not find the .git directory
  466. SET featuresGit=False
  467. GOTO :EOF
  468. )
  469. REM Safe to use git features; found the .git directory and the git executable.
  470. SET featuresGit=True
  471. GOTO :EOF
  472. REM # ================================================================================================
  473. REM # Documentation
  474. REM # Check to see if the git executable exists within the host system.
  475. REM # To do this, we merely check if 'git' was detected during an
  476. REM # invoktion test - which requires 'git' to be in %PATH% within the
  477. REM # environment - if git was _NOT_ detected then we can't use git
  478. REM # features, but we can use the features if it was detected.
  479. REM #
  480. REM # Cautionaries:
  481. REM # If git.exe is in the console's environment but failed the
  482. REM # detection phase, the permissions may need to be checked
  483. REM # as well as the network if routing via UNC - I doubt CMD allows
  484. REM # UNC anyways.
  485. REM # IIF %ERRORLEVEL% EQU 9009, then git is not available in the
  486. REM # environment.
  487. REM # IIF %ERRORLEVEL% EQU 1, git was invoked and it successfully
  488. REM # executed by outputting the main menu to NULL.
  489. REM # IIF any other exit code, see documentation for the proper
  490. REM # termination fault.
  491. REM #
  492. REM # Return
  493. REM # ReturnCode [Bool]
  494. REM # 0 = Git executable detected.
  495. REM # 1 = Git executable not detected.
  496. REM # ================================================================================================
  497. :GitFeature_DependencyCheck_GitExecutable
  498. GIT 2> NUL 1> NUL
  499. IF %ERRORLEVEL% EQU 1 (
  500. REM Found the git executable
  501. EXIT /B 0
  502. )
  503. REM Could not find the git executable
  504. EXIT /B 1
  505. REM # ================================================================================================
  506. REM # Documentation
  507. REM # When the end-user has the source code, it may or may not contain the .git DB directory.
  508. REM # This function is designed to check wither or not the directory exists within the source code.
  509. REM #
  510. REM # Return
  511. REM # ReturnCode [Bool]
  512. REM # 0 = .git directory found.
  513. REM # 1 = .git directory not found.
  514. REM # ================================================================================================
  515. :GitFeature_DependencyCheck_RepoGitDB
  516. REM Silently perform a check to see if the source contains the .git directory
  517. GIT --git-dir="%ProgramDirPath%.git" status 2> NUL 1> NUL
  518. IF %ERRORLEVEL% EQU 0 (
  519. REM .git directory was successfully found
  520. EXIT /B 0
  521. )
  522. REM Could not find the .git directory within the source.
  523. EXIT /B 1
  524. REM # ================================================================================================
  525. REM # Documentation
  526. REM # Retrieves and returns the HEAD commit hash of the project.
  527. REM # Sets the value of the commit hash to the variable 'GitCommitHash'.
  528. REM # To use this hash in other functions, first call this function and then use the variable
  529. REM # %GitCommitHash% in any function. However, first make sure that the Git dependency is
  530. REM # available on the host.
  531. REM # ================================================================================================
  532. :GitFeature_FetchCommitHash
  533. FOR /F %%a IN ('GIT --git-dir="%ProgramDirPath%.git" rev-parse --short HEAD') DO SET GitCommitHash=%%a
  534. GOTO :EOF
  535. REM # ================================================================================================
  536. REM # Documentation
  537. REM # Provide a simple interface and automatically update repository.
  538. REM # ================================================================================================
  539. :GitFeature_UpdateBranch
  540. CALL :ProcessingInterface 0 "Updating project repository"
  541. CALL :GitFeature_UpdateBranch_Master
  542. CALL :ProcessingInterface 1
  543. EXIT /B 0
  544. REM # ================================================================================================
  545. REM # Documentation
  546. REM # When called, this function will update the master branch of the GIT local repo. However, first make sure that the Git dependency is
  547. REM # available on the host.
  548. REM # ================================================================================================
  549. :GitFeature_UpdateBranch_Master
  550. GIT --git-dir="%ProgramDirPath%.git" pull origin master
  551. GOTO :EOF
  552. REM # ================================================================================================
  553. REM # Documentation
  554. REM # Terminate the program without destroying the console process if invoked via CUI.
  555. REM # ================================================================================================
  556. :TerminateProcess
  557. ECHO Closing program. . .
  558. REM Restore the terminal window's title to something generic
  559. TITLE Command Prompt
  560. EXIT /B 0