Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.56 KB | None | 0 0
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. cd /d "%~dp0"
  4. cls
  5. echo.
  6. echo.
  7. echo.
  8. echo ################################################
  9. echo # 'Create sorted list of Banished mods' #
  10. echo # release 6b #
  11. echo # by Gordon Dry #
  12. echo ################################################
  13. echo ########## ugly simple soft #########
  14. echo.
  15. echo.
  16. GOTO check_Permissions
  17. :CHECK
  18. echo.
  19. echo Checking for registry key in HKEY_CURRENT_USER\Software\Shining Rock Software LLC\Banished
  20. REG QUERY "HKEY_CURRENT_USER\Software\Shining Rock Software LLC\Banished" /v GameLastStart
  21. IF %errorlevel%==0 GOTO EXPORTCU
  22. echo.
  23. echo Checking for registry key in HKEY_LOCAL_MACHINE\Software\Shining Rock Software LLC\Banished
  24. REG QUERY "HKEY_LOCAL_MACHINE\Software\Shining Rock Software LLC\Banished" /v GameLastStart
  25. echo.
  26. IF %errorlevel%==0 GOTO EXPORTLM
  27. IF %errorlevel%==1 GOTO FAILED
  28.  
  29. :EXPORTCU
  30. set "key=cu"
  31. echo - Exporting Banished registry key
  32. start /wait regedit.exe /a "Banished registry export.reg" "HKEY_CURRENT_USER\Software\Shining Rock Software LLC\Banished"
  33. GOTO SORT
  34.  
  35. :EXPORTLM
  36. set "key=lm"
  37. echo - Exporting Banished registry key
  38. start /wait regedit.exe /a "Banished registry export.reg" "HKEY_LOCAL_MACHINE\Software\Shining Rock Software LLC\Banished"
  39. GOTO SORT
  40.  
  41. :SORT
  42. echo - Clearing the export to new file
  43. findstr "ModIndex_" "Banished registry export.reg" > "List of Banished mods.txt"
  44. echo - Sorting the list simply
  45. sort "List of Banished mods.txt" /O "List of Banished mods.txt"
  46. echo - Deleting temporary files so far
  47. if exist "Sorted list of Banished mods.txt" del "Sorted list of Banished mods.txt"
  48. if exist "Temp list of Banished mods.txt" del "Temp list of Banished mods.txt"
  49. if exist "Temp2 list of Banished mods.txt" del "Temp2 list of Banished mods.txt"
  50. if exist "Temp3 list of Banished mods.txt" del "Temp3 list of Banished mods.txt"
  51. if exist "Delete obsolete registry entries.reg" del "Delete obsolete registry entries.reg"
  52. echo - Applying a real sorting by index number
  53. cmsort\cmsort.exe /V=$3D,$22 /NV=2,1,0 "List of Banished mods.txt" "List of Banished mods.txt"
  54. echo.
  55. echo - Cleaning up all unnecessary entries by multiple steps
  56. echo - step 1
  57. FOR /F "usebackq delims=" %%G IN ("List of Banished mods.txt") DO (
  58. Set "line=%%G" & echo !line:"=!
  59. )>>"Temp List of Banished mods.txt"
  60. echo - step 2
  61. FOR /F "usebackq tokens=*" %%G IN (`findstr /L "ModIndex_" "Temp List of Banished mods.txt"`) DO (
  62. set "line=%%G"
  63. set str=!line:ModIndex_=!
  64. echo !str!
  65. )>>"Temp2 List of Banished mods.txt"
  66. echo - step 3
  67. echo REGEDIT4>"Delete obsolete registry entries.reg"
  68. echo.>>"Delete obsolete registry entries.reg"
  69. echo [HKEY_CURRENT_USER\Software\Shining Rock Software LLC\Banished]>>"Delete obsolete registry entries.reg"
  70. set /a x=0
  71. FOR /F "usebackq tokens=1 delims==" %%G IN ("Temp2 List of Banished mods.txt") DO (
  72. Set "line=%%G"
  73. echo !line!.pkm
  74. if not exist WinData\!line!.pkm (
  75. echo "ModIndex_!line!"=->>"Delete obsolete registry entries.reg"
  76. echo "ModEnabled_!line!"=->>"Delete obsolete registry entries.reg"
  77. set /a x+=1
  78. set deletekey[!x!]=!line!
  79. )
  80. )>>"Temp3 List of Banished mods.txt"
  81. echo.
  82. echo - Checking if a mod is listed in the registry but no more inside WinData folder
  83. echo #######################################################>"Sorted List of Banished mods.txt"
  84. echo # List of Banished mods sorted by load order #>>"Sorted List of Banished mods.txt"
  85. echo # created with #>>"Sorted List of Banished mods.txt"
  86. echo # 'Create sorted list of Banished mods' #>>"Sorted List of Banished mods.txt"
  87. echo # release 6b #>>"Sorted List of Banished mods.txt"
  88. echo # by Gordon Dry #>>"Sorted List of Banished mods.txt"
  89. echo #######################################################>>"Sorted List of Banished mods.txt"
  90. echo ################### ugly simple soft ##################>>"Sorted List of Banished mods.txt"
  91. echo # http://worldofbanished.com/index.php?topic=790.0 #>>"Sorted List of Banished mods.txt"
  92. echo #######################################################>>"Sorted List of Banished mods.txt"
  93. echo.>>"Sorted List of Banished mods.txt"
  94. FOR /F "usebackq tokens=*" %%G IN ("Temp3 List of Banished mods.txt") DO (
  95. Set "line=%%~nG"
  96. if exist WinData\!line!.pkm (
  97. set "ValueName=ModEnabled_!line!"
  98. if key=="lm" (
  99. for /f "tokens=2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\Software\Shining Rock Software LLC\Banished" /v !ValueName!') do set MODSTATUS=%%b
  100. ) else (
  101. for /f "tokens=2*" %%a in ('reg query "HKEY_CURRENT_USER\Software\Shining Rock Software LLC\Banished" /v !ValueName!') do set MODSTATUS=%%b
  102. )
  103. if !MODSTATUS!==false (
  104. echo !line! - - - - - - MOD DISABLED
  105. ) else (
  106. echo !line!
  107. )
  108. ) else (
  109. echo !line! - - - - - - NO MORE in WinData folder
  110. )
  111. )>>"Sorted List of Banished mods.txt"
  112.  
  113. if !x! GTR 0 (
  114. echo - The following mods are no more in the WinData folder but in the registry:
  115. echo.
  116. for /L %%y IN (1 1 !x!) DO (
  117. echo - !deletekey[%%y]!.pkm
  118. )
  119. echo.
  120. choice /C YN /M "Do you want these obsolete registry entries to be deleted"
  121. IF !errorlevel!==1 goto DELETEEMPTY
  122. IF !errorlevel!==2 goto NEARLY
  123. ) else (
  124. echo - no obsolete mod entries found
  125. goto NEARLY
  126. )
  127.  
  128. :DELETEEMPTY
  129. if exist "Banished registry export.reg" del "Banished registry backup.reg" | ren "Banished registry export.reg" "Banished registry backup.reg"
  130. echo.
  131. echo - Deleting obsolete registry entries
  132. reg IMPORT "Delete obsolete registry entries.reg"
  133. echo.
  134. echo Checking again ...
  135. timeout /T 3
  136. goto CHECK
  137.  
  138. :NEARLY
  139. if exist "Banished registry export.reg" del "Banished registry backup.reg" | ren "Banished registry export.reg" "Banished registry backup.reg"
  140. echo - Deleting temporary files finally
  141. echo.
  142. del "List of Banished mods.txt"
  143. del "Temp list of Banished mods.txt"
  144. del "Temp2 list of Banished mods.txt"
  145. del "Temp3 list of Banished mods.txt"
  146. del "Delete obsolete registry entries.reg"
  147. if exist "Banished registry export.reg" del "Banished registry export.reg"
  148. echo The file "Banished registry backup.reg" includes the registry key as it was before the whole process ...
  149. echo.
  150. choice /C YN /M "Do you want the file 'Banished registry backup.reg' to be deleted"
  151. IF !errorlevel!==1 del "Banished registry backup.reg"
  152. echo.
  153. echo Done!
  154. echo.
  155. GOTO END
  156.  
  157. :FAILED
  158. echo.
  159. echo.
  160. echo I was neither able to find the registry key
  161. echo HKEY_CURRENT_USER\Software\Shining Rock Software LLC\Banished
  162. echo.
  163. echo nor the registry key
  164. echo HKEY_LOCAL_MACHINE\Software\Shining Rock Software LLC\Banished
  165. echo.
  166. echo.
  167. echo Aborting...
  168. echo.
  169. GOTO END
  170.  
  171. :check_Permissions
  172. echo Administrative permissions required. Detecting permissions...
  173. net session >nul 2>&1
  174. if %errorLevel% == 0 (
  175. echo Success: Administrative permissions confirmed.
  176. GOTO CHECK
  177. ) else (
  178. echo Failure: Current permissions inadequate.
  179. echo.
  180. echo Please restart this batch with administrative privileges after it quits.
  181. echo.
  182. echo You can do this by right-clicking the file "Create sorted list of Banished mods.cmd" and choose "Run as administrator"
  183. echo.
  184. echo.
  185. )
  186.  
  187. :END
  188. echo Press a key to exit ... you have 20 seconds to comply
  189. echo.
  190. echo (c) 1989 Silver Bullet
  191. echo https://www.musixmatch.com/de/songtext/Silver-Bullet/20-Seconds-to-Comply
  192. timeout /T 20
  193. endlocal enabledelayedexpansion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement