Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: [help needed] Error in batch to check md5 and patch with xdelta or bsdiff  (Read 4742 times)

0 Members and 1 Guest are viewing this topic.

rongyao

    Topic Starter


    Newbie

    • Experience: Experienced
    • OS: Other
    I've made a batch file and using few tricks I've made it work quite well but didn't realized that script will generate quite long command and many variables to work with, which generates error.

    The error which sometime appears!
    not enough storage is available to process this command.

    Code: [Select]
    @echo off
    set oldfiledir=E:\patch\12
    set newfiledir=E:\patch\15
    set patcheddir=%~dp0
    IF %patcheddir:~-1%==\ SET patcheddir=%patcheddir:~0,-1%
    @pause >nul
    for /F %%B in ('dir "%newfiledir%\*" /A:-D /S /B') do for /F %%A in ('dir "%oldfiledir%\*" /A:-D /S /B') do (
     IF NOT EXIST "%patcheddir%\patched%%~pA" md "%patcheddir%\patched%%~pA"
     IF "%%~nxB" == "%%~nxA" For /F %%D in ('md5sums -u "%%B"') do for /F %%C in ('md5sums -u "%%A"') do (
     IF NOT "%%D" == "%%C" bsdiff "%%A" "%%B" "%patcheddir%\patched%%~pnxA.bsdfp" )
    )
    ECHO Complete! Press any key to exit!
    @pause >nul

    What the batch is doing.

    It takes files from 2 folders, e:\patch\12 with old files and then e:\patch\15 new files.
    Then compare the files from first dir by name and extension to the file from second dir to check if file name and extension matches. After that md5sums does same check, but only checks the files that matches by name and extension, so we to be sure we are checking data1.dll with newer data1.dll and not with data2.dll, if the md5 of data1.dll does not match with the md5 of the newer data1.dll then use bsdiff to create the patch and put that patch into a new directory.

    Now how i can do that script working? ;D

    The echo bellow is from the same script without showing the error, but probably on bigger files it does showing error. I receive the said error only on files that are quite yuge on file size.
    Code: [Select]
    E:\patch>(
    IF NOT EXIST "E:\patch\patched\patch\12\Dll\" md "E:\patch\patched\patch\12\Dll\"
    IF "data1.dll" == "data1.dll" For /F %D in ('md5sums -u "E:\patch\15\Dll\data1.dll"')
    do for /F %C in ('md5sums -u "E:\patch\12\Dll\data1.dll"')
    do (IF NOT "%D" == "%C"
    bsdiff "E:\patch\12\Dll\data1.dll" "E:\patch\15\Dll\data1.dll" "E:\patch\patched\patch\12\Dll\data1.dll.bsdfp"  )
    )

    E:\patch>for /F %C in ('md5sums -u "E:\patch\12\Dll\data1.dll"')
    do (IF NOT "6fc61964424ed6353b0b2c07c6863c20" == "%C"
    bsdiff "E:\patch\12\Dll\data1.dll" "E:\patch\15\Dll\data1.dlll" "E:\patch\patched\patch\12\Dll\data1.dll.bsdfp"  )

    E:\patch>(IF NOT "6fc61964424ed6353b0b2c07c6863c20" == "6fc61964424ed6353b0b2c07c6863c20"
    bsdiff "E:\patch\12\Dll\data1.dll" "E:\patch\15\Dll\data1.dll" "E:\patch\patched\patch\12\Dll\data1.dll.bsdfp"  )

    If you want to test with xdelta
    replace  IF NOT "%%D" == "%%C" bsdiff
    with  IF NOT "%%D" == "%%C" xdelta3-3.0.8.x86-32 -9 -S djw -e -vfs
    and it will work with xdelta the same way as bsdiff too.

    bsdiff for win32 http://sites.inka.de/tesla/others.html
    xdelta https://code.google.com/p/xdelta/
    md5 for win32 http://www.pc-tools.net/win32/md5sums/

    I prefer bsdiff because it does not shows additional output and compression is much better on patches.
    If anyone can provide a gui which to do that for bsdiff it would be nice, i found a gui for xdelta but is written in net and it doesn't work on x64 bit so tried to write a batch for it instead, any help is appreciated. Thank you in advance!

    rongyao

      Topic Starter


      Newbie

      • Experience: Experienced
      • OS: Other
      BUMP it is working, the error probably were coming out of bsdiff running out of memory, with xdelta i got all the files executed and checked.

      Still i have a new problem, names with spaces are skipped, someone can help me out to find out why names with spaces not works well?
      Also somehow script managed to patch 3 times one readme.txt, because it loops all files and compares the ones from first path to ones with second path, %%~nxA == %%~nxB thats why if see a file with duplicate name in several directories and find out that md5 it does not matches, then will make a patch. Which is a bug, still source directory can't be the same as output directory, otherwise if i set %%A == %%B will never make the patch, because input never matches the output. Solution?

      Both scripts bellow working! ^^

      Code: [Select]
      @echo off
      set oldfiledir=E:\patch\old
      set newfiledir=E:\patch\new
      set patcheddir=%~dp0
      IF %patcheddir:~-1%==\ SET patcheddir=%patcheddir:~0,-1%
      IF EXIST newfiles.md5 del /F /Q newfiles.md5
      IF EXIST oldfiles.md5 del /F /Q oldfiles.md5
      for /F %%B in ('dir "%newfiledir%\*" /A:-D /S /B') DO for /F %%A in ('dir "%oldfiledir%\*" /A:-D /S /B') DO IF "%%~nxB"=="%%~nxA" (
       IF NOT EXIST "%patcheddir%\patched%%~pA" md "%patcheddir%\patched%%~pA"
       For /F "eol=* tokens=1 delims=*" %%D in ('md5sums -u "%%B"') DO For /F "eol=* tokens=1 delims=*" %%C in ('md5sums -u "%%A"') DO IF NOT "%%D"=="%%C" (
        xdelta3 -0 -e -vfs "%%A" "%%B" "%patcheddir%\patched%%~pnxA.pxdelta"
        ECHO.
        ECHO %%~nxA *%%~nxB
        ECHO %%D*%%B>>newfiles.md5
        ECHO %%C*%%A>>oldfiles.md5
       )
      )
      set oldfiledir=
      set newfiledir=
      set patcheddir=
      ECHO Complete... press any key to quit!
      @pause >nul
      exit

      Code: [Select]
      @echo off
      set oldfiledir=E:\patch\old
      set newfiledir=E:\patch\new
      set patcheddir=%~dp0
      IF %patcheddir:~-1%==\ SET patcheddir=%patcheddir:~0,-1%
      IF EXIST newfiles.md5 del /F /Q newfiles.md5
      IF EXIST oldfiles.md5 del /F /Q oldfiles.md5
      for /F %%B in ('dir "%newfiledir%\*" /A:-D /S /B') do for /F %%A in ('dir "%oldfiledir%\*" /A:-D /S /B') do (
       IF NOT EXIST "%patcheddir%\patched%%~pA" md "%patcheddir%\patched%%~pA"
       IF "%%~nxB" == "%%~nxA" For /F %%D in ('md5sums -u "%%B"') do for /F %%C in ('md5sums -u "%%A"') do (
       IF NOT "%%D" == "%%C" xdelta3 -0 -e -vfs "%%A" "%%B" "%patcheddir%\patched%%~pnxA.pxdelta"
        ECHO.
        ECHO %%~nxA *%%~nxB
        ECHO %%D *%%B>>newfiles.md5
        ECHO %%C *%%A>>oldfiles.md5
       )
      )
      set oldfiledir=
      set newfiledir=
      set patcheddir=
      ECHO Complete... press any key to quit!
      @pause >nul
      exit