Rockbox General > Rockbox General Discussion

Windows Batch Script for Updating to Latest Rockbox Build

(1/6) > >>

Shiftlock:
This Windows batch script will download the current build for your player, and install it.  Note that this isn't the "stable" release version that Rockbox Installer defaults to, it's the current build which is updated daily with the latest changes.  It's pretty good at telling you what it's doing while it's doing it, like giving you the percent complete while it's downloading, and displaying the old version of Rockbox on your player, and the new version it's installing.  I set this script to run automatically each night so my player is always running the latest build. 

All you have to do is run it, and it will do the rest.  It will detect the drive letter and model of your player, and download the correct version for your model, then install it.  If you prefer, or if there's a problem with the player determining the location and player model, you can define these settings manually in the beginning of the script.

This script requires two utilities in order to run properly.  They may be on your system already (one of them should be included with Vista and Windows 7) but if they're not, the script will help you download them.

Sometimes Windows throws an error when the script tries to look for the DAP on a removable media drive that doesn't have media in it (like the memory expansion slot on the side of some players).  I can't figure out a way to trap that error, but it can be ignored by pressing the "Continue" button, which is what the script instructs you to do. 

The script makes a directory under c:\Program Files (or wherever your "Program Files" directory is located) called RockboxUpdate where it downloads Rockbox and unzips it before installing.

If anybody tries this script, I would be interested in hearing about any problems, comments, suggestions, or even if it just worked successfully for you.  I think I pushed myself and Windows Batch to the very limit of our respective abilities with this script.

You can copy the code below into a .bat file yourself, or download it from here: http://www.mediafire.com/file/ozoyzowdmrz/RockboxUpdate.bat


--- Code: ---::
::     This Windows batch script will update your player to the most current build of Rockbox.
::
::     If desired, change the following "set" definitions to reflect your configuration.  If
::     left blank, the script will automatically determine the correct settings.

:: *** This script will automatically determine the correct URL for your model player unless it's specified here
set RockboxURL=

:: *** This script will automatically locate your player unless the drive letter is specified here
Set DAPLetter=

:: -------------------------------------------------------------------------------------------

@echo off
setlocal enableextensions

if exist %Systemroot%\System32\bitsadmin.exe GoTo FindDAPLetter
if exist %systemroot%\MPSReports\MSUS\bin\bitsadmin.exe GoTo FindDAPLetter
if exist %Systemroot%\bitsadmin.exe GoTo FindDAPLetter
GoTo BitsAdminNotFound

:FindDAPLetter
cls
if defined DAPLetter GoTo FindRockboxURL
echo Locating Your Player...
echo.
echo *****************************************************************************
echo ***                                                                       ***
echo ***  If a Windows error box pops up, simply choose "Continue". This will  ***
echo ***  not have a negative effect on locating or updating your player.      ***
echo ***                                                                       ***
echo *****************************************************************************
FOR %%g IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%g:\.rockbox\rockbox-info.txt SET DAPLetter=%%g
if (%DAPLetter%)==() GoTo DAPNotFound

:FindRockboxURL
cls
if defined RockboxURL GoTo CheckDir
for /f "delims=" %%h in ('qgrep -e "Target:" %DAPLetter%:\.rockbox\rockbox-info.txt') do @set TargetDefine=%%h
set PlayerType=%TargetDefine:~8%
Set RockboxURL=http://build.rockbox.org/data/rockbox-%PlayerType%.zip

:CheckDir
cls
echo Checking for RockboxUpdate Directory...
if exist "%programfiles%\RockboxUpdate" GoTo CheckForUnzip
mkdir "%programfiles%\RockboxUpdate"

:CheckForUnzip
set path=%path%;%systemroot%\MPSReports\MSUS\bin;%programfiles%\RockboxUpdate
cls
echo Checking For unzip.exe to Extract Rockbox Files...
if exist "%programfiles%\RockboxUpdate\unzip.exe" GoTo Begin

cls
bitsadmin /RawReturn /Reset
bitsadmin /RawReturn /Create DownloadUnzip
bitsadmin /RawReturn /AddFile DownloadUnzip http://stahlworks.com/dev/unzip.exe "%programfiles%\RockboxUpdate\unzip.exe"
bitsadmin /RawReturn /Resume DownloadUnzip

:StatusLoop1
for /f "delims=" %%d in ('bitsadmin /RawReturn /GetState DownloadUnzip') do @set DownloadUnzipStatus=%%d
for /f "delims=" %%e in ('bitsadmin /RawReturn /GetBytesTotal DownloadUnzip') do @set DownloadUnzipBytesTotal=%%e
for /f "delims=" %%f in ('bitsadmin /RawReturn /GetBytesTransferred DownloadUnzip') do @set DownloadUnzipBytesTransferred=%%f
Set /A DownloadUnzipPercentDone = (%DownloadUnzipBytesTransferred% * 100) / %DownloadUnzipBytesTotal%

cls
echo Downloading unzip.exe to Extract Rockbox Files
echo Status: %DownloadUnzipStatus%
echo File Transfer is %DownloadUnzipPercentDone%%% Complete

ping 224.0.0.0 -n 1 -w 500 > NUL
if %DownloadUnzipStatus% EQU TRANSIENT_ERROR GoTo ErrorDownloadingUnzip
if %DownloadUnzipStatus% NEQ TRANSFERRED GoTo StatusLoop1
bitsadmin /Complete DownloadUnzip

:Begin

cls
echo Deleting Old Rockbox Files...
del /F /Q "%programfiles%\RockboxUpdate\Rockbox_Current.zip"
rd /S /Q "%programfiles%\RockboxUpdate\.rockbox"

cls
echo Starting Transfer of Latest Rockbox Build For: %PlayerType%
bitsadmin /RawReturn /Reset
bitsadmin /RawReturn /Create rockbox
bitsadmin /RawReturn /AddFile rockbox %RockboxURL% "%programfiles%\RockboxUpdate\Rockbox_Current.zip"
bitsadmin /RawReturn /Resume rockbox

:StatusLoop2
for /f "delims=" %%a in ('bitsadmin /RawReturn /GetState rockbox') do @set status=%%a
for /f "delims=" %%b in ('bitsadmin /RawReturn /GetBytesTotal rockbox') do @set BytesTotal=%%b
for /f "delims=" %%c in ('bitsadmin /RawReturn /GetBytesTransferred rockbox') do @set BytesTransferred=%%c
Set /A PercentDone = (%BytesTransferred% * 100) / %BytesTotal%

cls
echo Downloading Latest Rockbox Build For: %PlayerType%
echo Status: %status%
echo File Transfer is %PercentDone%%% Complete

ping 224.0.0.0 -n 1 -w 500 > NUL
if %Status% EQU TRANSIENT_ERROR GoTo ErrorDownloadingRockbox
if %status% NEQ TRANSFERRED GoTo StatusLoop2
bitsadmin /Complete rockbox

:unzip
cls
echo Unzipping Latest Rockbox Build...
unzip -o -qq "%programfiles%\RockboxUpdate\Rockbox_Current.zip" -d "%programfiles%\RockboxUpdate"

::Determine Old Version
for /f "delims=" %%i in ('qgrep -e "Version:" %DAPLetter%:\.rockbox\rockbox-info.txt') do @set OldVersion=%%i
set OldVersion=%OldVersion:~9,-7%

::Determine New Version
for /f "delims=" %%j in ('qgrep -e "Version:" "%programfiles%\RockboxUpdate\.rockbox\rockbox-info.txt"') do @set NewVersion=%%j
set NewVersion=%NewVersion:~9,-7%

cls
echo Updating Your Player with the Latest Rockbox Build For: %PlayerType%
echo.
echo Old Rockbox Version: %OldVersion%
echo New Rockbox Version: %NewVersion%
echo.
echo Please Wait...
xcopy "%programfiles%\RockboxUpdate\.rockbox" %DAPLetter%:\.rockbox /C /E /H /I /R /Y /Q

bitsadmin /Reset
cls

echo Your %PlayerType% Has Been Updated With Rockbox Version %NewVersion%
echo.
echo This Window Will Close Momentarily...
ping 224.0.0.0 -n 1 -w 5000 > NUL

endlocal
exit


::------------------
::Error Handling
::------------------

:ErrorDownloadingUnzip
cls
echo.
echo The following error occurred while downloading unzip.exe:
echo.
bitsadmin /GetError DownloadUnzip
echo.
echo Please restart this script, or try again later.
echo.
pause
bitsadmin /Reset
endlocal
exit

:ErrorDownloadingRockbox
cls
echo.
echo The following error occurred while downloading Rockbox:
echo.
bitsadmin /GetError Rockbox
echo.
echo Please restart this script, or try again later.
echo.
pause
bitsadmin /Reset
endlocal
exit

:DAPNotFound
cls
echo.
echo The script could not locate your player. Make sure it's plugged in and run
echo this script again. If it is plugged in, then manually edit script and modify
echo "Set DAPLetter= " to reflect your player's drive letter.
echo.
pause
bitsadmin /Reset
endlocal
exit

:BitsAdminNotFound
cls
echo.
echo This script requires the Microsoft BITS Administration utility in order to
echo download files. This utility could not be found on your system. You will now
echo be forwarded to a Microsoft URL to download the MS Support Services Reporting
echo Tool, which includes the needed BitsAdmin utility. Run this script again after
echo you have downloaded and installed it.
echo.
pause
cmd /c start http://download.microsoft.com/download/b/b/1/bb139fcb-4aac-4fe5-a579-30b0bd915706/MPSRPT_SUS.EXE
endlocal
exit

--- End code ---

evilnick:
I guess that this would be more useful in the Wiki rather than on the forums.

Shiftlock:
Oh, okay.  It didn't occur to me to put it in the wiki.  I've never contributed to it.  I'll look into that tonight.  For now, if anyone wants the companion executables (bitsadmin.exe, sleep,exe, and unzip.exe) I zipped them together with this batch file and it can be downloaded here:

Edit: I removed the link because someone suggested it may be a licensing violation.  Sorry.

Llorean:
What are the licenses on those?

Shiftlock:

--- Quote from: Llorean on April 20, 2010, 02:30:39 PM ---What are the licenses on those?

--- End quote ---

unzip.exe - "Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely."

bitsadmin.exe - This is already part of Vista and Windows 7, and is included with XP Service Pack 2 Support Tools, which can be downloaded from MS.  I can't find any specific licensing information, but I think anyone running Windows will already have a copy of this somewhere on their system.

sleep.exe - I don't know where this came from.  It's such a simple program, there are quite a few different programs called "sleep.exe" floating around the net that all do the same thing.  I suppose I could just re-write this myself.

If it's an issue, I'll remove the link, or just delete the info in this thread entirely.  I certainly didn't intend to steal anyone's software.

Navigation

[0] Message Index

[#] Next page

Go to full version