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