
@chcp 65001
@cd /d "%~dp1"
@cls
@echo off

set exe=%~dp0_exe
If Not Exist "%exe%" echo.&&echo  [exe:%exe%] Not Found.&&echo.&&pause&&goto End
If Not Exist "%exe%\arc_conv.exe" echo.&&echo  [exe:arc_conv.exe] Not Found.&&echo.&&pause&&goto End
If Not Exist "%exe%\SwapStrings.exe" echo.&&echo  [exe:SwapStrings.exe] Not Found.&&echo.&&pause&&goto End

set Ext0=py
set Ext1=py

set Src0=%~nx1
If Not Exist "%Src0%" echo.&&echo  [Src0:%Src0%] Not Found.&&echo.&&pause&&goto End
If Not Exist "%Src0%\*.%Ext0%" echo.&&echo  [Src0:%Src0%\*.%Ext0%] Not Found.&&echo.&&pause&&goto End

set Dest0=%Src0%-TBL
If Exist "%Dest0%" echo.&&echo  [Dest0:%Dest0%] Aleady Existed.&&echo.&&pause&&goto End

set Opt0=--mod textenc auto utf8

set TBL0=%exe%\UTF8-ED6_TXT-1.txt
set TBL1=%exe%\UTF8-ED6_TXT-2.txt



REM ------------------------------------------------------

setlocal enabledelayedexpansion
set /a Total=0
set /a Count=0

for %%f IN ("%Src0%\*.%Ext0%") DO (set /a Total+=1)

for %%f IN ("%Src0%\*.%Ext0%") DO (
set /a Count+=1

If Not Exist "%Dest0%" mkdir "%Dest0%">nul

copy /y /b "%%f" "%Dest0%\!Count!.TMP">nul

If Exist "%Dest0%\!Count!.TMP" "%exe%\arc_conv.exe" %Opt0% "%Dest0%\!Count!.TMP" "%Dest0%\!Count!.%Ext1%"
If Exist "%Dest0%\!Count!.TMP" move /y "%Dest0%\!Count!.TMP" "%Dest0%\!Count!.%Ext1%">nul
If Exist "%Dest0%\!Count!.%Ext1%" echo.&&echo [!Count!/%Total%] : %%~nxf
If Exist "%Dest0%\!Count!.%Ext1%" "%exe%\SwapStrings.exe" "%TBL1%" "%Dest0%\!Count!.%Ext1%"
If Exist "%Dest0%\!Count!.%Ext1%" move /y "%Dest0%\!Count!.%Ext1%" "%Dest0%\%%~nf.%Ext1%">nul

If Exist "%Dest0%\!Count!.TMP" del /q "%Dest0%\!Count!.TMP">nul
If Exist "%Dest0%\!Count!.%Ext1%" del /q "%Dest0%\!Count!.%Ext1%">nul
If Exist "%Dest0%\!Count!.%Ext1%.old" del /q "%Dest0%\!Count!.%Ext1%.old">nul

If Not Exist "%Dest0%\%%~nf.%Ext1%" echo.&&echo  [%%~nxf] Error !!!&&set ERROR=1
)

endlocal
call "%exe%\cleanup.bat">nul
If "%ERROR%" == "1" pause

REM ------------------------------------------------------



:End
rem pause
