Automatic SVN updater (detects SVN folders automatically)

NAPALMSTRIKE2007’S AUTOMATIC SVN UPDATER
You have two choices:
[ol]
[li]If you keep all your svn directories in your addons folder(this causes very long load up times. if you have enough hdd space consider using code in section B ) read section A.
[/li][li]If you keep all your svn directories in an external folder, read section B. If you don’t know how to create batch files, read section A, after learning how to create a batch file from section A, read section B.
[/li][/ol]

A ) CODE TO UPDATE ALL SVN’S

**It automatically detects all svn folders in its running directory so, you don’t need to type in all of your svn folders into a text file to get them updated
**

INSTRUCTIONS

[ol]
[li]Download SilkSVN(others won’t work) Download Subversion Client | Slik SVN
[/li][li]Open up notepad or any similar text editing software
[/li][li]Copy and paste the code below into the notepad and save the file as svnupdate.bat
[/li][li]Put the batch file you created in your garrysmod\garrysmod\addons folder (or the folder you keep your SVN folders in)
[/li][li]IMPORTANT You should remove all white spaces from the names of your SVN folders
[/li](for example: “advanced duplicator”->“advanced_duplicator”)
[li]Double click(just execute the batch file, you can use any way you like to) to the batch file. A DOS window will pop out. It should automatically detect all of your SVN folders and update all of them. When the process is finnished press any key to close the window.
[/li][/ol]

BATCH FILE CODE



@echo off
echo STARTING THE UPDATE...
FOR /F %%A IN ('dir /A:D /B') DO svn update %%A
echo UPDATES COMPLETED
pause 1


B ) CODE TO UPDATE AND EXPORT SVN’S

I combined the two functions (update and export) into one file. And it will NOT export if no updates were done(saves great amount of time). It will even try to repair broken svn’s that don’t get updated for some reason.
It will copy ONLY updated/added files, not the whole folder to the addons folder(unlike the svn export command). This saves great amount of time.

INSTRUCTIONS

[ol]
[li]Download SilkSVN(others won’t work) Download Subversion Client | Slik SVN
[/li][li]Browse to the folder you keep your svn files in. (this folder MUST BE in “C:\Program Files\Steam\SteamApps\USERNAME\garrysmod\garrysmod”)
[/li][li]IMPORTANT You should remove all white spaces from the names of your SVN folders
[/li](for example: “advanced duplicator”->“advanced_duplicator”)
[li]create launch.bat in your SVN folder
[/li][/ol]


@echo off
echo STARTING THE UPDATE...
FOR /F %%A IN ('dir /A:D /B') do CALL upd.bat %%A 
echo UPDATES COMPLETED
pause 1


  1. create upd.bat in your SVN folder


@echo off
set svnfolder=%cd%
set someerror=0
:begin
echo CHECKING %1

IF NOT EXIST ..\addons\%1\NUL GOTO exportit

svn update "%1">revision.txt

findstr /m "A" revision.txt>%TEMP%\NUL
if %errorlevel%==0 GOTO found
findstr /m "D" revision.txt>%TEMP%\NUL
if %errorlevel%==0 GOTO found
findstr /m "U" revision.txt>%TEMP%\NUL
if %errorlevel%==0 GOTO found
findstr /m "G" revision.txt>%TEMP%\NUL
if %errorlevel%==0 GOTO found
findstr /m "revision" revision.txt>%TEMP%\NUL
if %errorlevel%==0 GOTO noupd
set /a someerror=%someerror%+1
IF %someerror%==1 echo ERROR: %1. TRYING TO FIX.
if not %someerror%==1 echo ERROR COULD NOT BE FIXED.
cd %1
svn cleanup
cd..
IF %someerror%==1 GOTO begin
GOTO end
:noupd
echo NO UPDATE NEEDED: %1.
GOTO end

:found
FOR /F "tokens=1,2" %%i IN (revision.txt) DO (
if %%i==A (
IF "%%~xj"=="" (
echo CREATING DIRECTORY %%j
MD ..\addons\%%j>%TEMP%\NUL
) ELSE (
echo ADDING %%j
COPY %%j ..\addons\%%j /y>%TEMP%\NUL
)
)

if %%i==U (
echo UPDATING %%j
COPY %%j ..\addons\%%j /y>%TEMP%\NUL
)

if %%i==D (
IF "%%~xj"=="" (
echo DELETING DIRECTORY %%j
RMDIR /S /Q ..\addons\%%j>%TEMP%\NUL
) ELSE (
echo DELETING %%j
DEL /F /Q ..\addons\%%j>%TEMP%\NUL
)
)
)
goto end

:exportit
echo EXPORTING %1
svn export %1 ..\addons\%1

:end
echo Done.
echo.


  1. Execute *launch.bat *to detect & update & export automatically.

**UPDATES: **

**15.02.2011: **
Old batch file was copying/deleting/updating anything with commands only appliable to files. So, if the update was including removal/creation of directories old batch file gave an error of filename not having a proper extension. With this update, this problem is solved.

Removed revision.txt spam on screen.

Made batch file more user friendly, now it is easier to understand what happened, is happening and will happen.

Now the batch file completely exports svn’s to addons folder if this is not done allready by the player ( for example your addons folder is completely empty, and you have an older wiremod revision in your svn folder. Old batch file would have given an error message complaining about wire folder not being found in addons. But after this update, batch file exports whole wire svn folder to the addons in that case.)

Nice job!

Now it won’t be so annoying when people don’t have a updated SVN of something when they join a server that has otherwise.