-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
markus
committed
Dec 5, 2016
1 parent
c56dd2e
commit 5a1930f
Showing
1 changed file
with
144 additions
and
41 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,71 @@ | ||
@echo off | ||
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 (c) 2016 M. Busche, [email protected] | ||
rem | ||
rem | ||
rem _ _ | ||
rem | | | | | ||
rem ___ _ __ _ _ _ __ __| | __ _| |_ ___ | ||
rem / __| '_ \| | | | '_ \ / _` |/ _` | __/ _ \ | ||
rem | (__| |_) | |_| | |_) | (_| | (_| | || __/ | ||
rem \___| .__/ \__,_| .__/ \__,_|\__,_|\__\___| | ||
rem | | | | | ||
rem |_| |_| | ||
rem | ||
rem Backups will be stored as ZIP files in a subfolder .\cpbackup | ||
rem | ||
rem This script installs or updates the mod "Courseplay" for Farming Simulator 17 | ||
rem Copy this file to a folder of your choice and run it from time to time. | ||
rem | ||
rem ============================================================================= | ||
rem I M P O R T A N T N O T I C E | ||
rem ============================================================================= | ||
rem Git for Windows and 7-Zip have to be installed and reside in your PATH! | ||
rem Otherwise, adjust 'set gitexe=' and 'set zipexe' to your needs. | ||
rem Backups will be stored as ZIP files in the subfolder .\cpbackup | ||
rem | ||
rem For help with setting a program to your path, have a look @ http://www.computerhope.com/issues/ch000549.htm | ||
rem Have a look at the settings described below! | ||
rem | ||
rem Have fun! | ||
rem ============================================================================= | ||
rem Set deployment mode: | ||
rem * "ZIPFILE" creates a ZZZ_Courseplay.zip file in your mod directory | ||
rem * "DIRECTORY" copies the Courseplay as subdirectory to your mod directory | ||
rem Both modes work fine, you have the choice. | ||
rem | ||
set deployment="ZIPFILE" | ||
rem set deployment="DIRECTORY" | ||
rem ============================================================================= | ||
rem If you want the command window to close after run: set autoclose="YES". | ||
rem Otherwise you have to hit a keystroke after the run - which enables you | ||
rem to see what happened. | ||
rem | ||
rem set autoclose="YES" | ||
set autoclose="NO" | ||
rem ============================================================================= | ||
rem You should replace these with the full path to the files if you use this | ||
rem script without the portable editions of Git and 7-Zip. | ||
rem | ||
rem (c) 2016 M. Busche, [email protected] | ||
rem You could replace these with the full path to the files if they don´t reside in your PATH | ||
set gitexe=".\cmd\git.exe" | ||
set zipexe=".\App\7-Zip\7z.exe" | ||
|
||
rem setlocal EnableDelayedExpansion | ||
Setlocal | ||
echo Courseplay Beta Updatescript | ||
rem ============================================================================= | ||
rem End of user settings | ||
setlocal enabledelayedexpansion | ||
echo Courseplay Beta Updatescript v1.1 | ||
echo (c) 2016 elpatron@mailbox.org | ||
echo . | ||
rem git.exe startable? | ||
echo Checking for Git... | ||
%gitexe% --version > NUL | ||
if not errorlevel == 1 set gitok="-1" | ||
if not %errorlevel%==1 set gitok="-1" | ||
rem 7-Zip startable? | ||
echo Checking for 7-Zip... | ||
%zipexe% >NUL | ||
if errorlevel == 9009 goto zipok="-1" | ||
if %errorlevel%==9009 goto zipok="-1" | ||
if "%gitok%"=="-1" goto gitzipfehler | ||
if "%zipok%"=="-1" goto gitzipfehler | ||
|
||
echo Git and 7-Zip are ok, lets move on... | ||
echo. | ||
|
||
rem Write a VBS file for getting Courseplay version | ||
> "%temp%\getversion.vbs" ( | ||
rem Write a VBS file for getting Courseplay version from moddesc.xml | ||
> "%TEMP%\getversion.vbs" ( | ||
echo.Dim oXml: Set oXml = CreateObject^("Microsoft.XMLDOM"^) | ||
echo.oXml.Load WScript.Arguments.Item^(0^) | ||
echo.Dim oDoc: Set oDoc = oXml.documentElement | ||
|
@@ -54,38 +80,87 @@ echo.Set oXml = Nothing | |
|
||
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 is: %destination% | ||
rem Backup-Ordner | ||
rem Setting Courseplay mod folder or file | ||
set _dest=%UserDocs%\my games\FarmingSimulator2017\mods\ZZZ_courseplay | ||
echo Deployment method is %deployment%. | ||
if %deployment%=="DIRECTORY" ( | ||
set destination=%_dest% | ||
) else ( | ||
set destination=%_dest%.zip | ||
) | ||
echo Your destination is: %destination% | ||
|
||
rem Is this a fresh installation or an update? | ||
if exist "%destination%" ( | ||
set freshinstall="no" | ||
echo Previous version found, switching to update mode. | ||
) else ( | ||
set freshinstall="yes" | ||
echo No previous version found, switching to fresh install mode.. | ||
) | ||
|
||
rem Backup directory | ||
set "curpath=%cd%" | ||
set backup=%curpath%\cpbackup | ||
echo Your backup folder ist %backup% | ||
set backupdir=%curpath%\cpbackup | ||
echo Your backup folder is: %backupdir% | ||
|
||
rem Extract moddesc.xml from ZIPFILE | ||
if %deployment%=="ZIPFILE" ( | ||
if %freshinstall%=="no" ( | ||
echo Extracting 'moddesc.xml' for version detection... | ||
del /q "%TEMP%\moddesc.xml" > NUL | ||
%zipexe% e "%destination%" -o"%TEMP%" moddesc.xml -r -aoa > NUL 2>&1 | ||
) | ||
) | ||
|
||
rem Get current Courseplay version with vbs script | ||
if exist "%destination%\moddesc.xml" ( | ||
del /q "%temp%\cpversion.txt" > NUL | ||
cscript "%temp%\getversion.vbs" "%destination%\modDesc.xml" //Nologo >"%temp%\cpversion.txt" | ||
set /p version=<"%temp%\cpversion.txt" | ||
echo Your currently installed Version is: %version% | ||
del "%temp%\cpversion.txt" > NUL | ||
if exist .\cpversion.txt ( | ||
del /q .\cpversion.txt > NUL | ||
) | ||
rem ...from directory | ||
if %deployment%=="DIRECTORY" ( | ||
if %freshinstall%=="no" ( | ||
cscript "%TEMP%\getversion.vbs" "%destination%\modDesc.xml" //Nologo >.\cpversion.txt | ||
) | ||
) | ||
rem from zip file | ||
if %deployment%=="ZIPFILE" ( | ||
if %freshinstall%=="no" ( | ||
cscript "%TEMP%\getversion.vbs" "%TEMP%\moddesc.xml" //Nologo >.\cpversion.txt | ||
) | ||
) | ||
|
||
rem sleep 2 seconds | ||
ping 127.0.0.1 -n 2 > nul | ||
|
||
rem Read version from output file | ||
if exist .\cpversion.txt ( | ||
set /p version=<.\cpversion.txt | ||
del /q .\cpversion.txt" > NUL | ||
set freshinstall="no" | ||
) else ( | ||
set freshinstall="yes" | ||
set version="0" | ||
) | ||
if not %version%=="0" ( | ||
echo Your currently installed Version is: %version% | ||
) | ||
|
||
rem Delete old checkout | ||
echo Deleting temporary folder... | ||
rd /s/q .\courseplay 2> NUL | ||
|
||
rem Git clone | ||
echo Cloning Courseplay repository from Github... | ||
%gitexe% clone --depth=1 -q https://github.com/Courseplay/courseplay.git | ||
|
||
rem Get new Courseplay version | ||
cscript "%temp%\getversion.vbs" ".\courseplay\modDesc.xml" //Nologo >"%temp%\cpversion.txt" | ||
set /p newversion=<"%temp%\cpversion.txt" | ||
cscript "%TEMP%\getversion.vbs" ".\courseplay\modDesc.xml" //Nologo >.\cpversion.txt | ||
set /p newversion=<.\cpversion.txt | ||
echo Version from Github: %newversion% | ||
del "%temp%\cpversion.txt" > NUL | ||
if exist .\cpversion.txt ( | ||
del /q .\cpversion.txt > NUL | ||
) | ||
|
||
rem Do we have an update? | ||
if "%newversion%"=="%version%" ( | ||
|
@@ -97,20 +172,45 @@ if "%newversion%"=="%version%" ( | |
) | ||
|
||
rem Backup current version | ||
if %deployment%=="DIRECTORY" ( | ||
set backupfile=%backupdir%\courseplay_backup-%version%.zip | ||
) else ( | ||
set backupfile=%backupdir%\ZZZ_courseplay_%version%.zip | ||
) | ||
|
||
if %freshinstall%=="no" ( | ||
echo Creating a backup of your current Courseplay... | ||
mkdir %backup% 2> NUL | ||
%zipexe% a -r "%backup%\courseplay_backup-%version%.zip" "%destination%\*" >NUL 2>&1 | ||
echo If you consider any problems, check your backup file: "%backup%\courseplay_backup-%version%.zip" | ||
mkdir %backupdir% 2> NUL | ||
if %deployment%=="DIRECTORY" ( | ||
echo backupfile: %backupfile% | ||
pause | ||
%zipexe% a -r "%backupfile%" "%destination%\*" >NUL 2>&1 | ||
) else ( | ||
|
||
copy "%destination%" "%backupfile%" > NUL | ||
) | ||
) else ( | ||
echo No former version found - this seems to be a fresh install. Creating new mod directory for Courseplay... | ||
md "%destination%" > NUL | ||
if %deployment%=="DIRECTORY" ( | ||
md "%destination%" > NUL | ||
) | ||
) | ||
|
||
if not %backupfile%1==1 ( | ||
echo If you consider any problems, check your backup file: "%backupfile%" | ||
) | ||
|
||
rem Copy clone to mod folder | ||
echo Copying the update to your mod folder... | ||
xcopy /S /E /H /Y /C /Q ".\courseplay\*.*" "%destination%\" >NUL | ||
rem Couseplay Git checkout wieder löschen | ||
rem Copy cloned directory to mod folder | ||
if %deployment%=="DIRECTORY" ( | ||
echo Copying the update to your mod folder... | ||
xcopy /S /E /H /Y /C /Q ".\courseplay\*.*" "%destination%\" >NUL | ||
) | ||
if %deployment%=="ZIPFILE" ( | ||
echo Copying the updated Courseplay directory as ZIP file to your mod folder... | ||
%zipexe% a -r -tzip "%destination%" .\courseplay\* >NUL 2>&1 | ||
) | ||
|
||
rem Delete Git clone directory | ||
echo Deleting temporary folder... | ||
rd /s/q .\courseplay 2> NUL | ||
echo Sucessfully updated from %version% to %newversion%. | ||
|
@@ -129,6 +229,9 @@ if "%zipok%"=="-1" ( | |
goto ende | ||
|
||
:ende | ||
del "%temp%\getversion.vbs" >NUL | ||
del /q "%TEMP%\getversion.vbs" >NUL | ||
echo. | ||
echo Thanks for using me. | ||
echo Thanks for using me. (Any key to exit) | ||
if %autoclose%=="No" ( | ||
pause >NUL | ||
) |