Guest User


a guest
May 18th, 2019
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  3. rem Name of the script
  4. set scriptname=7 Days to Die Mod Localization loader
  5. rem Version of the script
  6. set scriptver=v4.6a
  8. title %scriptname% %scriptver%
  10. call :Header
  11. echo.
  12. echo Press any key if you want to continue.
  13. echo Otherwise you may close this window now and no changes will me made.
  14. pause>nul
  15. call :Process
  16. goto :EOP
  18. :Process
  19. cls
  21. setlocal enabledelayedexpansion
  23. rem Set some internal variables:
  24. rem Path to Vanilla Configuration directory
  25. set "vanillacfgpath=%~dp0Data\Config"
  26. set "vanillacfgpath=!vanillacfgpath:\Mods=!"
  27. rem Localization file names
  28. set "loc=Localization.txt"
  29. set "locq=Localization - Quest.txt"
  30. rem Backup exists variable
  31. set /a backupexists=1
  33. rem Backup original Localizations
  34. rem If a previous backup is present, we notify the user and let them decide what to do next
  35. if /I NOT exist "!vanillacfgpath!\!loc!.bak" if /I NOT exist "!vanillacfgpath!\!locq!.bak" set /a backupexists=0
  36. if !backupexists! EQU 1 goto :BackupExists else goto :BackupNow
  38. :BackupNow
  39. cls
  40. echo Creating backups of the original files:
  41. echo.
  42. echo Creating a backup file: !vanillacfgpath!\!loc!.bak
  43. type "!vanillacfgpath!\!loc!" >"!vanillacfgpath!\!loc!.bak"
  44. echo Creating a backup file: !vanillacfgpath!\!locq!.bak
  45. type "!vanillacfgpath!\!locq!" >"!vanillacfgpath!\!locq!.bak"
  46. echo Backups created successfully.
  47. echo.
  48. echo Press any key to continue...
  49. pause>nul
  50. goto :LoadLocalizations
  52. :BackupExists
  53. echo It seems that we already have some backup files.
  54. echo Please note that if you proceed, your backup files will be overwritten.
  55. echo.
  56. echo Press any key if you want to continue.
  57. echo Otherwise you may close this window now and no changes will me made.
  58. pause>nul
  59. goto :BackupNow
  61. :LoadLocalizations
  62. rem Let's make a quick run through all the files that we need to process to give the user
  63. rem an idea about the progress in percentage...
  64. set /a filecount=0
  65. for /R %%f in (*.txt) do (
  66.     set countthis=yes
  67.     if /I NOT "%%~nxf"=="!loc!" if /I NOT "%%~nxf"=="!locq!" set countthis=no
  68.     if !countthis!==yes (
  69.         set /a filecount+=1
  70.     )
  71. )
  72. rem Let's split the progress into individual files that must be processed
  73. rem and define it by percentage, starting at 0%
  74. set /a progress=0
  75. set /a percentincrement=100/%filecount%
  77. call :Progress
  79. rem Append Localizations from all mods into the Vanilla Localizations
  80. for /R %%f in (*.txt) do (
  81.     rem Let's sort the files and pick the ones we want to work with
  82.     set usethis=yes
  83.     if /I NOT "%%~nxf"=="!loc!" if /I NOT "%%~nxf"=="!locq!" set usethis=no
  84.     if !usethis!==yes (
  85.         rem Save Localization file name into a variable !thisloc!
  86.         set "thisloc=%%~nf"
  87.         rem Save the current working path into a variable !thisdir!
  88.         set "thisdir=%%~dpf"
  89.         set "thisdir=!thisdir:~0,-1!"
  90.         rem Create a temporary localization file from the original, but exclude the header if there is one...
  91.         findstr /I /V "Key,Source,Context,Changes*" "!thisdir!\!thisloc!.txt" >"!thisdir!\!thisloc!_temp.txt"
  92.         rem ...and use valid lines only
  93.         type "!thisdir!\!thisloc!_temp.txt" >"!thisdir!\!thisloc!_temp.txt.old" & del "!thisdir!\!thisloc!_temp.txt"
  94.         findstr /I /R "^.*," "!thisdir!\!thisloc!_temp.txt.old" >"!thisdir!\!thisloc!_temp.txt"
  95.         del "!thisdir!\!thisloc!_temp.txt.old"
  96.         rem Process the temporary localization file line by line
  97.         for /F "usebackq tokens=*" %%l in ("!thisdir!\!thisloc!_temp.txt") do (
  98.             rem Save the line key into a variable !lkey!
  99.             set "lkey="
  100.             for /F "tokens=1 delims=," %%k in ("%%l") do set "lkey=%%k"
  101.             rem If !lkey! exists in vanilla localization, save the line into a variable for replacement
  102.             rem for /F "usebackq tokens=* delims=," %%r in ('findstr /I "!lkey!" "!vanillacfgpath!\!thisloc!.txt"') do set "linetoreplace=%%r"
  103.             set "linetoreplace="
  104.             for /F "tokens=*" %%r in ('findstr /I /B "!lkey!" "!vanillacfgpath!\!thisloc!.txt"') do set "linetoreplace=%%r"
  105.             rem Does the line with the same key exist in vanilla localization? It must be removed, before adding a new one to avoid duplicates
  106.             if NOT "!linetoreplace!"=="" (
  107.                 rem We found the line with this key in vanilla localization, let's remove it
  108.                 type "!vanillacfgpath!\!thisloc!.txt" >"!vanillacfgpath!\!thisloc!_edit.txt" & del "!vanillacfgpath!\!thisloc!.txt"
  109.                 findstr /I /V /B /C:"!lkey!" "!vanillacfgpath!\!thisloc!_edit.txt" > "!vanillacfgpath!\!thisloc!.txt"
  110.                 rem find /v "!lkey!" "!vanillacfgpath!\!thisloc!_edit.txt" > "!vanillacfgpath!\!thisloc!.txt"
  111.                 del "!vanillacfgpath!\!thisloc!_edit.txt"
  112.             )
  113.         )
  114.     rem Append and clean up...
  115.     echo( >> "!vanillacfgpath!\!thisloc!.txt"
  116.     type "!thisdir!\!thisloc!_temp.txt" >> "!vanillacfgpath!\!thisloc!.txt"
  117.     del "!thisdir!\!thisloc!_temp.txt"
  118.     rem Update progress status
  119.     set /a progress+=percentincrement & call :Progress
  120.     )
  121. )
  122. rem Final clean up - fix garbage and empty lines
  123. type "!vanillacfgpath!\!loc!" >"!vanillacfgpath!\!loc!.old" & del "!vanillacfgpath!\!loc!"
  124. findstr /I /R "^.*," "!vanillacfgpath!\!loc!.old" >"!vanillacfgpath!\!loc!"
  125. del "!vanillacfgpath!\!loc!.old"
  126. type "!vanillacfgpath!\!locq!" >"!vanillacfgpath!\!locq!.old" & del "!vanillacfgpath!\!locq!"
  127. findstr /I /R "^.*," "!vanillacfgpath!\!locq!.old" >"!vanillacfgpath!\!locq!"
  128. del "!vanillacfgpath!\!locq!.old"
  129. rem Update progress status with 100% since we are done at this point
  130. set /a progress=100 & call :Progress
  131. endlocal
  132. exit /b
  134. :Header
  135. echo %scriptname% %scriptver%
  136. echo Coded by mr.devolver
  137. echo.
  138. echo Description:
  139. echo This script is supposed to go through all of your 7 Days to Die mods
  140. echo and automatically load their localization.txt and localization - quest.txt
  141. echo files into the original game localization files.
  142. echo.
  143. echo Before making any changes, this script creates a backup of your original
  144. echo game localization files.
  145. echo.
  146. echo Warning:
  147. echo It does NOT keep track of your changes, so if you want to keep your
  148. echo current backup, you should save it to a special directory somewhere
  149. echo outside of its original location.
  150. echo.
  151. echo Please note that this script must run from your Mods directory.
  152. echo If you're running it from a different location, it will not work.
  153. echo.
  154. echo !!!! USE AT YOUR OWN RISK !!!!
  155. echo This script is provided AS IS. At this point it's a highly experimental
  156. echo alpha version and may damage your game files.
  157. echo.
  158. echo Feel free to improve it and share your improved version with other users!
  159. echo.
  160. echo Thanks!
  161. exit /b
  163. :Progress
  164. cls
  165. echo Loading localizations, please wait...
  166. echo Progress: !progress!%%
  167. exit /b
  169. :EOP
  170. echo.
  171. echo Finished! Let's hope this works! Good luck, survivor!
  172. echo.
  173. echo Press any key to exit...
  174. pause>nul
  175. exit
RAW Paste Data