-
-
Save cythux/52d2478f2092202c3c9cfc231e8513f0 to your computer and use it in GitHub Desktop.
Batch script for automatic update of Courseplay (https://github.com/Courseplay/courseplay)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rem This script updates the mod "Courseplay" for Farming Simulator 17 | |
rem Copy this file to a folder of your choice and run in from time to time. | |
rem | |
rem Backups will be stored as ZIP files in a subfolder .\cpbackup | |
rem | |
rem Git for Windows and 7-Zip have to be installed and in reside your PATH! | |
rem For help with setting a program to your path, have a look @ http://www.computerhope.com/issues/ch000549.htm | |
rem | |
rem Have fun! | |
rem | |
rem (c) 2016 M. Busche, [email protected] | |
@echo off | |
rem git.exe startable? | |
echo Courseplay Beta Updatescript | |
echo (c) 2016 [email protected] | |
echo . | |
echo Checking for Git... | |
git > NUL | |
if not errorlevel 1 goto fehlergit | |
echo Git is ok. | |
rem 7-Zip startable? | |
echo Checking for 7-Zip... | |
7z > NUL | |
if not errorlevel 0 goto fehler7z | |
echo 7-Zip is ok. | |
echo . | |
rem Setting `Documents` folder | |
for /f "skip=2 tokens=2*" %%A in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Personal"') do set "UserDocs=%%B" | |
rem Setting Courseplay mod folder | |
set destination=%UserDocs%\my games\FarmingSimulator2017\mods\ZZZ_courseplay | |
echo Your Courseplay mod folder: %destination% | |
rem Backup-Ordner | |
set backup=.\cpbackup | |
if exist "%destination%\moddesc.xml" ( | |
echo Your currently installed Version: | |
find "<version>" "%destination%\modDesc.xml" > "./cpversion.txt" | |
for /f "delims=" %%x in (./cpversion.txt) do set version=%%x | |
echo "%version%" | |
del "./cpversion.txt" > NUL | |
set freshinstall=0 | |
) else ( | |
set freshinstall=1 | |
set version="0" | |
) | |
rem Delete old checkout | |
echo Deleting temporary folder... | |
rd /s/q .\courseplay 2> NUL | |
rem Git clone | |
echo Cloning into https://github.com/Courseplay/courseplay.git | |
git clone --depth=1 https://github.com/Courseplay/courseplay.git > NUL | |
echo Version from fresh clone: | |
find "<version>" ".\courseplay\modDesc.xml" > "./cpversion.txt" | |
for /f "delims=" %%x in (./cpversion.txt) do set newversion=%%x | |
echo "%newversion%" | |
del "./cpversion.txt" | |
rem Do we have an update? | |
if "%newversion%"=="%version%" ( | |
echo No update found, exiting. | |
rd /s/q .\courseplay 2> NUL | |
goto ende | |
) else ( | |
echo We have found an update. | |
) | |
rem Backup current version | |
if %freshinstall%==0 ( | |
echo Creating a backup of your current Courseplay... | |
mkdir %backup% 2> NUL | |
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I | |
set datetime=%datetime:~0,8%-%datetime:~8,6% | |
7z a -r "%backup%\courseplay_backup-%datetime%.zip" "%destination%\*" | |
) else ( | |
echo No former version found - this seems to be a fresh install. Creating new mod directory for Courseplay... | |
md "%destination%" > NUL | |
set freshinstall=1 | |
) | |
rem Copy clone to mod folder | |
echo Copying the update to your mod folder... | |
XCOPY /S /E /H /Y /C "courseplay\*.*" "%destination%" | |
rem Couseplay Git checkout wieder löschen | |
echo Deleting temporory folder... | |
rd /s/q .\courseplay 2> NUL | |
echo Update successfully applied. | |
if not %freshinstall% == 1 ( | |
echo If you consider any problems, check your backup file: "%backup%\courseplay_backup-%datetime%.zip" | |
) | |
goto ende | |
:fehlergit | |
echo Git for Windows has to be installed and in PATH! | |
echo Download: https://git-scm.com/download/win | |
goto ende | |
:fehler7z | |
echo 7-Zip has to be installed and in PATH! | |
echo Download: http://www.7-zip.org/download.html | |
goto ende | |
:ende | |
echo . | |
echo Thanks for using me. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment