Skip to content

Instantly share code, notes, and snippets.

@shinchiro
Last active May 29, 2020 22:13
Show Gist options
  • Save shinchiro/b87ec776982bef8d61b5aa6605d8c95d to your computer and use it in GitHub Desktop.
Save shinchiro/b87ec776982bef8d61b5aa6605d8c95d to your computer and use it in GitHub Desktop.
Creating xdelta patch easy way.
@echo OFF
:: How to use:
:: 1. Put xdelta3.exe in C:\
:: 2. Put old_file and new_file in any folder but must in same directory
:: 3. run with cmd: patch.bat old_file.mkv new_file.mkv mypatch
:: 4. patch now in 'xdelta' folder
set xdelta3="C:\xdelta3.exe"
set patch_dir=%~dp1\xdelta
call :Createxdelta %1 %2 %3
call :CreateBAT %1 %3 %2
cd /d "%~dp0"
goto :EOF
@pause
:Createxdelta
:: 1=OLD_FILE, 2=NEW_FILE, 3=DELTA_FILE
::
:: Make sure the OLD_FILE and NEW_FILE exist in same folder
::
cd /d "%~dp1"
mkdir "xdelta"
%xdelta3% -9 -S djw -e -vfs "%~nx1" "%~nx2" "%patch_dir%\%3.xdelta"
goto :EOF
:CreateBAT
:: 1=OLD_FILE, 2=DELTA_FILE, 3=NEW_FILE
set name=%patch_dir%\run_this.bat
:: Start writing to file
echo @echo OFF > "%name%"
:: Check for xdelta3 file
echo if not exist "xdelta3.exe" ( >> "%name%"
echo echo Put xdelta3.exe inside this folder to begin patch >> "%name%"
echo. pause >> "%name%"
echo goto :EOF >> "%name%"
echo ) >> "%name%"
:: Check for original name
echo if not exist "%~nx1" ( >> "%name%"
echo echo Cannot find "%~nx1". Put the file in this folder. If you has renamed it, rename it back to original name. >> "%name%"
echo. pause >> "%name%"
echo goto :EOF >> "%name%"
echo ) >> "%name%"
:: Check for xdelta file
echo if not exist "%2.xdelta" ( >> "%name%"
echo echo Cannot find "%2.xdelta". Put the file in this folder. If you has renamed it, rename it back to original name. >> "%name%"
echo. pause >> "%name%"
echo goto :EOF >> "%name%"
echo ) >> "%name%"
:: Start patching
echo echo Patching in progress..Make sure to put old file in this folder and the filename still unchanged. >> "%name%"
echo xdelta3 -d "%2.xdelta" >> "%name%"
echo if exist "%~nx3" ( >> "%name%"
echo. echo Cleaning up.. >> "%name%"
echo. del "%~nx1" >> "%name%"
echo. del "%2.xdelta" >> "%name%"
echo. del "run_this.bat" >> "%name%"
echo. echo File successfully patched!
echo ) >> "%name%"
echo @pause >> "%name%"
goto :EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment