Added Windows build environment with MSYS2

This commit is contained in:
thunder2 2018-06-14 14:22:23 +02:00
parent 1eed404170
commit 7bdc61e3e3
24 changed files with 1658 additions and 0 deletions

View File

@ -0,0 +1,23 @@
@echo off
setlocal
:: Initialize environment
call "%~dp0env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env.bat"
if errorlevel 1 goto error_env
%cecho% info "Build %SourceName%"
call "%~dp0build\build.bat" 32 release tor version autologin plugins
if errorlevel 1 %cecho% error "Failed to build %SourceName%." & exit /B %ERRORLEVEL%
%cecho% info "Pack %SourceName%"
call "%~dp0build\pack.bat" 32 release tor
if errorlevel 1 %cecho% error "Failed to pack %SourceName%." & exit /B %ERRORLEVEL%
exit /B 0
:error_env
echo Failed to initialize environment.
exit /B 1

View File

@ -0,0 +1,23 @@
@echo off
setlocal
:: Initialize environment
call "%~dp0env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env.bat"
if errorlevel 1 goto error_env
%cecho% info "Build %SourceName%"
call "%~dp0build\build.bat" 32 release version autologin plugins
if errorlevel 1 %cecho% error "Failed to build %SourceName%." & exit /B %ERRORLEVEL%
%cecho% info "Pack %SourceName%"
call "%~dp0build\pack.bat" 32 release
if errorlevel 1 %cecho% error "Failed to pack %SourceName%." & exit /B %ERRORLEVEL%
exit /B 0
:error_env
echo Failed to initialize environment.
exit /B 1

View File

@ -0,0 +1,81 @@
@echo off
setlocal
:: Initialize environment
call "%~dp0..\env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env-msys2.bat"
if errorlevel 1 goto error_env
:: Initialize base environment
call "%~dp0env-base.bat" %*
if errorlevel 2 exit /B 2
if errorlevel 1 goto error_env
:: Install needed things
%EnvMSYS2Cmd% "pacman --noconfirm --needed -S make git mingw-w64-%RsMSYS2Architecture%-toolchain mingw-w64-%RsMSYS2Architecture%-qt5 mingw-w64-%RsMSYS2Architecture%-miniupnpc mingw-w64-%RsMSYS2Architecture%-sqlcipher mingw-w64-%RsMSYS2Architecture%-libmicrohttpd mingw-w64-%RsMSYS2Architecture%-xapian-core"
:: Plugins
if "%ParamPlugins%"=="1" %EnvMSYS2Cmd% "pacman --noconfirm --needed -S mingw-w64-%RsMSYS2Architecture%-speex mingw-w64-%RsMSYS2Architecture%-speexdsp mingw-w64-%RsMSYS2Architecture%-curl mingw-w64-%RsMSYS2Architecture%-libxslt mingw-w64-%RsMSYS2Architecture%-opencv mingw-w64-%RsMSYS2Architecture%-ffmpeg"
:: Initialize environment
call "%~dp0env.bat" %*
if errorlevel 2 exit /B 2
if errorlevel 1 goto error_env
echo.
echo === Version
echo.
title Build - %SourceName%-%RsBuildConfig% [Version]
pushd "%SourcePath%\retroshare-gui\src\gui\images"
:: Touch resource file
copy /b retroshare_win.rc +,,
popd
if not exist "%RsBuildPath%" mkdir "%RsBuildPath%"
pushd "%RsBuildPath%"
echo.
echo === qmake
echo.
title Build - %SourceName%-%RsBuildConfig% [qmake]
set RS_QMAKE_CONFIG="CONFIG+=%RsBuildConfig%"
if "%ParamVersion%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% "CONFIG+=version_detail_bash_script"
if "%ParamAutologin%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% "CONFIG+=rs_autologin"
if "%ParamPlugins%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% "CONFIG+=retroshare_plugins"
if "%ParamRetroTor%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% "CONFIG+=retrotor"
call "%ToolsPath%\msys2-path.bat" "%SourcePath%" MSYS2SourcePath
call "%ToolsPath%\msys2-path.bat" "%EnvMSYS2Path%" MSYS2EnvMSYS2Path
%EnvMSYS2Cmd% "qmake "%MSYS2SourcePath%/RetroShare.pro" -r -spec win32-g++ %RS_QMAKE_CONFIG%"
if errorlevel 1 goto error
echo.
echo === make
echo.
title Build - %SourceName%-%RsBuildConfig% [make]
%EnvMSYS2Cmd% "make -j 4"
:error
popd
title %COMSPEC%
if errorlevel 1 echo.& echo Build failed& echo.
exit /B %ERRORLEVEL%
:error_env
echo Failed to initialize environment.
endlocal
exit /B 1

View File

@ -0,0 +1,25 @@
@echo off
setlocal
:: Initialize environment
call "%~dp0..\env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env-msys2.bat"
if errorlevel 1 goto error_env
call "%~dp0env.bat" %*
if errorlevel 2 exit /B 2
if errorlevel 1 goto error_env
if not exist "%RsBuildPath%" exit /B 0
call "%ToolsPath%\remove-dir.bat" "%RsBuildPath%"
exit /B %ERRORLEVEL%
:error_env
echo Failed to initialize environment.
endlocal
exit /B 1

View File

@ -0,0 +1,97 @@
:: Process commandline parameter
set Param32=0
set Param64=0
set ParamRelease=0
set ParamDebug=0
set ParamVersion=0
set ParamAutologin=0
set ParamPlugins=0
set ParamTor=0
:parameter_loop
if "%~1" NEQ "" (
for /f "tokens=1,2 delims==" %%a in ("%~1") do (
if "%%~a"=="32" (
set Param32=1
) else if "%%~a"=="64" (
set Param64=1
) else if "%%~a"=="release" (
set ParamRelease=1
) else if "%%~a"=="debug" (
set ParamDebug=1
) else if "%%~a"=="version" (
set ParamVersion=1
) else if "%%~a"=="autologin" (
set ParamAutologin=1
) else if "%%~a"=="plugins" (
set ParamPlugins=1
) else if "%%~a"=="tor" (
set ParamTor=1
) else (
echo.
echo Unknown parameter %1
goto :usage
)
)
shift /1
goto parameter_loop
)
if "%Param32%"=="1" (
if "%Param64%"=="1" (
echo.
echo 32-bit or 64-bit?
goto :usage
)
set RsBit=32
set RsArchitecture=x86
set RsMSYS2Architecture=i686
)
if "%Param64%"=="1" (
set RsBit=64
set RsArchitecture=x64
set RsMSYS2Architecture=x86_64
)
if "%RsBit%"=="" goto :usage
if "%ParamRelease%"=="1" (
if "%ParamDebug%"=="1" (
echo.
echo Release or Debug?
goto :usage
)
set RsBuildConfig=release
) else if "%ParamDebug%"=="1" (
set RsBuildConfig=debug
) else goto :usage
if "%ParamTor%"=="1" (
set RsType=-tor
) else (
set RsType=
)
exit /B 0
:usage
echo.
echo Usage: 32^|64 release^|debug [version autologin plugins]
echo.
echo Mandatory parameter
echo 32^|64 32-bit or 64-bit Version
echo release^|debug Build release or debug version
echo.
echo Optional parameter (need clean when changed)
echo version Create version information from git
echo autologin Build with autologin
echo plugins Build plugins
echo.
echo Parameter for pack
echo tor Pack tor version
echo.
exit /B 2

View File

@ -0,0 +1,29 @@
call "%~dp0env-base.bat" %*
if errorlevel 2 exit /B 2
if errorlevel 1 goto error_env
set MSYSTEM=MINGW%RsBit%
set BuildPath=%EnvRootPath%\builds
set DeployPath=%EnvRootPath%\deploy
if not exist "%BuildPath%" mkdir "%BuildPath%"
if not exist "%DeployPath%" mkdir "%DeployPath%"
:: Get Qt version
call "%ToolsPath%\get-qt-version.bat" QtVersion
if "%QtVersion%"=="" %cecho% error "Cannot get Qt version." & exit /B 1
set RsMinGWPath=%EnvMSYS2BasePath%\mingw%RsBit%
set RsBuildPath=%BuildPath%\Qt-%QtVersion%-%RsArchitecture%-%RsBuildConfig%
set RsDeployPath=%DeployPath%\Qt-%QtVersion%%RsType%-%RsArchitecture%-%RsBuildConfig%
set RsPackPath=%DeployPath%
set RsArchiveAdd=
if not exist "%~dp0env-mod.bat" goto no_mod
call "%~dp0env-mod.bat"
if errorlevel 1 exit /B %ERRORLEVEL%
:no_mod
exit /B 0

View File

@ -0,0 +1,118 @@
@echo off
setlocal
set NoAsk=
if "%~2"=="no-ask" set NoAsk=1
:: Initialize environment
call "%~dp0..\env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env-msys2.bat"
if errorlevel 1 goto error_env
call "%~dp0env.bat" %*
if errorlevel 2 exit /B 2
if errorlevel 1 goto error_env
:: Check git executable
set GitPath=
call "%ToolsPath%\find-in-path.bat" GitPath git.exe
if "%GitPath%"=="" echo Git executable not found in PATH.& exit /B 1
:: Get compiled revision
set GetRsVersion=%SourcePath%\build_scripts\Windows\tools\get-rs-version.bat
if not exist "%GetRsVersion%" (
echo File not found
echo %GetRsVersion%
exit /B 1
)
call "%GetRsVersion%" RS_REVISION_STRING RsRevision
if "%RsRevision%"=="" echo Revision not found.& exit /B 1
:: Get compiled version
call "%GetRsVersion%" RS_REVISION_STRING RsRevision
if "%RsRevision%"=="" echo Revision not found.& exit /B 1
call "%GetRsVersion%" RS_MAJOR_VERSION RsMajorVersion
if "%RsMajorVersion%"=="" echo Major version not found.& exit /B 1
call "%GetRsVersion%" RS_MINOR_VERSION RsMinorVersion
if "%RsMinorVersion%"=="" echo Minor version not found.& exit /B 1
call "%GetRsVersion%" RS_BUILD_NUMBER RsBuildNumber
if "%RsBuildNumber%"=="" echo Build number not found.& exit /B 1
call "%GetRsVersion%" RS_BUILD_NUMBER_ADD RsBuildNumberAdd
set RsVersion=%RsMajorVersion%.%RsMinorVersion%.%RsBuildNumber%%RsBuildNumberAdd%
:: Check WMIC is available
wmic.exe alias /? >nul 2>&1 || echo WMIC is not available.&& exit /B 1
:: Use WMIC to retrieve date in format YYYYMMDD
set RsDate=
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set RsDate=%%I
set RsDate=%RsDate:~0,4%%RsDate:~4,2%%RsDate:~6,2%
:: Get last revision
set RsLastRefFile=%BuildPath%\Qt-%QtVersion%%RsType%-%RsBuildConfig%-LastRef.txt
set RsLastRef=
if exist "%RsLastRefFile%" set /P RsLastRef=<"%RsLastRefFile%"
if "%NoAsk%"=="1" goto no_ask_for_last_revision
if not "%RsLastRef%"=="" echo Last Revision was %RsLastRef%
set /P RsLastRefInput=Last Revision:
if "%RsLastRefInput%" NEQ "" set RsLastRef=%RsLastRefInput%
:no_ask_for_last_revision
:: Get current revision
pushd "%SourcePath%"
call "%ToolsPath%\get-git-ref.bat" RsRef
popd
if errorlevel 1 exit /B 1
if "%RsRef%"=="" echo Cannot get git revision.& exit /B 1
echo.
echo Creating log from %RsLastRef%
echo to %RsRef%
if "%NoAsk%"=="1" goto no_confirm
choice /M "Do you want to proceed?"
if %errorlevel%==2 exit /B 1
:no_confirm
if "%RsBuildConfig%" NEQ "release" (
set RsGitLog=%DeployPath%\RetroShare-%RsVersion%-Windows-Portable-%RsDate%-%RsRevision%-Qt-%QtVersion%%RsType%-msys2%RsArchiveAdd%-%RsBuildConfig%.txt
) else (
set RsGitLog=%DeployPath%\RetroShare-%RsVersion%-Windows-Portable-%RsDate%-%RsRevision%-Qt-%QtVersion%%RsType%-msys2%RsArchiveAdd%.txt
)
title %SourceName%-%RsBuildConfig% [git log]
pushd "%SourcePath%"
if "%RsLastRef%"=="" (
git log %RsRef% >"%RsGitLog%"
) else (
if "%RsLastRef%"=="%RsRef%" (
git log %RsRef% --max-count=1 >"%RsGitLog%"
) else (
git log %RsLastRef%..%RsRef% >"%RsGitLog%"
)
)
popd
title %COMSPEC%
echo %RsRef%>"%RsLastRefFile%"
exit /B %ERRORLEVEL%
:error_env
echo Failed to initialize environment.
endlocal
exit /B 1

View File

@ -0,0 +1,222 @@
@echo off
setlocal
set Quite=^>nul
:: Initialize environment
call "%~dp0..\env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env-msys2.bat"
if errorlevel 1 goto error_env
:: Initialize environment
call "%~dp0env.bat" %*
if errorlevel 2 exit /B 2
if errorlevel 1 goto error_env
:: Remove deploy path
if exist "%RsDeployPath%" rmdir /S /Q "%RsDeployPath%"
:: Check compilation
if not exist "%RsBuildPath%\Makefile" echo Project is not compiled.& goto error
:: Get compiled revision
set GetRsVersion=%SourcePath%\build_scripts\Windows\tools\get-rs-version.bat
if not exist "%GetRsVersion%" (
echo File not found
echo %GetRsVersion%
goto error
)
call "%GetRsVersion%" RS_REVISION_STRING RsRevision
if "%RsRevision%"=="" echo Revision not found.& goto error
:: Get compiled version
call "%GetRsVersion%" RS_MAJOR_VERSION RsMajorVersion
if "%RsMajorVersion%"=="" echo Major version not found.& goto error
call "%GetRsVersion%" RS_MINOR_VERSION RsMinorVersion
if "%RsMinorVersion%"=="" echo Minor version not found.& goto error
call "%GetRsVersion%" RS_BUILD_NUMBER RsBuildNumber
if "%RsBuildNumber%"=="" echo Build number not found.& goto error
call "%GetRsVersion%" RS_BUILD_NUMBER_ADD RsBuildNumberAdd
set RsVersion=%RsMajorVersion%.%RsMinorVersion%.%RsBuildNumber%%RsBuildNumberAdd%
:: Check WMIC is available
wmic.exe alias /? >nul 2>&1 || echo WMIC is not available.&& goto error
:: Use WMIC to retrieve date in format YYYYMMDD
set RsDate=
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set RsDate=%%I
set RsDate=%RsDate:~0,4%%RsDate:~4,2%%RsDate:~6,2%
if "%ParamTor%"=="1" (
:: Check for tor executable
if not exist "%EnvDownloadPath%\tor\Tor\tor.exe" (
echo Tor binary not found. Please download Tor Expert Bundle from
echo https://www.torproject.org/download/download.html.en
echo and unpack to
echo %EnvDownloadPath%\tor
goto error
)
)
set QtMainVersion=%QtVersion:~0,1%
set QtSharePath=%RsMinGWPath%\share\qt%QtMainVersion%\
rem Qt 4 = QtSvg4.dll
rem Qt 5 = Qt5Svg.dll
set QtMainVersion1=
set QtMainVersion2=
if "%QtMainVersion%"=="4" set QtMainVersion2=4
if "%QtMainVersion%"=="5" set QtMainVersion1=5
if "%RsBuildConfig%" NEQ "release" (
set Archive=%RsPackPath%\RetroShare-%RsVersion%-Windows-Portable-%RsDate%-%RsRevision%-Qt-%QtVersion%-msys2%RsType%%RsArchiveAdd%-%RsBuildConfig%.7z
) else (
set Archive=%RsPackPath%\RetroShare-%RsVersion%-Windows-Portable-%RsDate%-%RsRevision%-Qt-%QtVersion%-msys2%RsType%%RsArchiveAdd%.7z
)
if exist "%Archive%" del /Q "%Archive%"
:: Create deploy path
mkdir "%RsDeployPath%"
title Pack - %SourceName%%RsType%-%RsBuildConfig% [copy files]
set ExtensionsFile=%SourcePath%\libretroshare\src\rsserver\rsinit.cc
set Extensions=
for /f %%e in ('type "%ExtensionsFile%" ^| sed.exe -n "s/^.*\/\(extensions[^/]*\)\/.*$/\1/p" ^| sed.exe -n "1,1p"') do set Extensions=%%e
if "%Extensions%"=="" echo Folder for extensions not found in %ExtensionsFile%& goto error
:: Copy files
mkdir "%RsDeployPath%\Data\%Extensions%"
mkdir "%RsDeployPath%\imageformats"
mkdir "%RsDeployPath%\qss"
mkdir "%RsDeployPath%\stylesheets"
mkdir "%RsDeployPath%\sounds"
mkdir "%RsDeployPath%\translations"
copy nul "%RsDeployPath%\portable" %Quite%
echo copy binaries
copy "%RsBuildPath%\retroshare-gui\src\%RsBuildConfig%\RetroShare*.exe" "%RsDeployPath%" %Quite%
copy "%RsBuildPath%\retroshare-nogui\src\%RsBuildConfig%\retroshare*-nogui.exe" "%RsDeployPath%" %Quite%
echo copy extensions
for /D %%D in ("%RsBuildPath%\plugins\*") do (
call :copy_extension "%%D" "%RsDeployPath%\Data\%Extensions%"
call :copy_dependencies "%RsDeployPath%\Data\%Extensions%\%%~nxD.dll" "%RsDeployPath%"
)
echo copy dependencies
call :copy_dependencies "%RsDeployPath%\retroshare.exe" "%RsDeployPath%"
echo copy Qt DLL's
copy "%RsMinGWPath%\bin\Qt%QtMainVersion1%Svg%QtMainVersion2%.dll" "%RsDeployPath%" %Quite%
if "%QtMainVersion%"=="5" (
mkdir "%RsDeployPath%\platforms"
copy "%QtSharePath%\plugins\platforms\qwindows.dll" "%RsDeployPath%\platforms" %Quite%
mkdir "%RsDeployPath%\audio"
copy "%QtSharePath%\plugins\audio\qtaudio_windows.dll" "%RsDeployPath%\audio" %Quite%
)
if exist "%QtSharePath%\plugins\styles\qwindowsvistastyle.dll" (
echo Copy styles
mkdir "%RsDeployPath%\styles" %Quite%
copy "%QtSharePath%\plugins\styles\qwindowsvistastyle.dll" "%RsDeployPath%\styles" %Quite%
)
copy "%QtSharePath%\plugins\imageformats\*.dll" "%RsDeployPath%\imageformats" %Quite%
del /Q "%RsDeployPath%\imageformats\*d?.dll" %Quite%
echo copy qss
xcopy /S "%SourcePath%\retroshare-gui\src\qss" "%RsDeployPath%\qss" %Quite%
echo copy stylesheets
xcopy /S "%SourcePath%\retroshare-gui\src\gui\qss\chat" "%RsDeployPath%\stylesheets" %Quite%
rmdir /S /Q "%RsDeployPath%\stylesheets\compact" %Quite%
rmdir /S /Q "%RsDeployPath%\stylesheets\standard" %Quite%
rmdir /S /Q "%RsDeployPath%\stylesheets\__MACOSX__Bubble" %Quite%
echo copy sounds
xcopy /S "%SourcePath%\retroshare-gui\src\sounds" "%RsDeployPath%\sounds" %Quite%
echo copy translation
copy "%SourcePath%\retroshare-gui\src\translations\qt_tr.qm" "%RsDeployPath%\translations" %Quite%
copy "%QtSharePath%\translations\qt_*.qm" "%RsDeployPath%\translations" %Quite%
if "%QtMainVersion%"=="5" (
copy "%QtSharePath%\translations\qtbase_*.qm" "%RsDeployPath%\translations" %Quite%
copy "%QtSharePath%\translations\qtscript_*.qm" "%RsDeployPath%\translations" %Quite%
copy "%QtSharePath%\translations\qtquick1_*.qm" "%RsDeployPath%\translations" %Quite%
copy "%QtSharePath%\translations\qtmultimedia_*.qm" "%RsDeployPath%\translations" %Quite%
copy "%QtSharePath%\translations\qtxmlpatterns_*.qm" "%RsDeployPath%\translations" %Quite%
)
echo copy bdboot.txt
copy "%SourcePath%\libbitdht\src\bitdht\bdboot.txt" "%RsDeployPath%" %Quite%
echo copy changelog.txt
copy "%SourcePath%\retroshare-gui\src\changelog.txt" "%RsDeployPath%" %Quite%
if exist "%SourcePath%\libresapi\src\webui" (
echo copy webui
mkdir "%RsDeployPath%\webui"
xcopy /S "%SourcePath%\libresapi\src\webui" "%RsDeployPath%\webui" %Quite%
)
if "%ParamTor%"=="1" (
echo copy tor
echo n | copy /-y "%EnvDownloadPath%\tor\Tor\*.*" "%RsDeployPath%" %Quite%
)
rem pack files
title Pack - %SourceName%%RsType%-%RsBuildConfig% [pack files]
"%EnvSevenZipExe%" a -mx=9 -t7z "%Archive%" "%RsDeployPath%\*"
title %COMSPEC%
call :cleanup
endlocal
exit /B 0
:error
call :Cleanup
endlocal
exit /B 1
:cleanup
goto :EOF
:error_env
echo Failed to initialize environment.
endlocal
exit /B 1
:copy_extension
if exist "%~1\%RsBuildConfig%\%~n1.dll" (
copy "%~1\%RsBuildConfig%\%~n1.dll" %2 %Quite%
)
goto :EOF
:copy_dependencies
set CopyDependenciesCopiedSomething=0
for /F "usebackq" %%A in (`%ToolsPath%\depends.bat list %1`) do (
if not exist "%~2\%%A" (
if exist "%RsMinGWPath%\bin\%%A" (
set CopyDependenciesCopiedSomething=1
copy "%RsMinGWPath%\bin\%%A" %2 %Quite%
)
)
)
if "%CopyDependenciesCopiedSomething%"=="1" goto copy_dependencies
goto :EOF

View File

@ -0,0 +1,19 @@
call :make_path SourcePath "%~dp0..\.."
call :make_path RootPath "%SourcePath%\.."
call :source_name SourceName "%SourcePath%"
set ToolsPath=%~dp0tools
set EnvPath=%~dp0env
exit /B 0
:make_path
setlocal
set Var=%~1
pushd %2
set CD=%cd%
popd
endlocal & set %Var%=%CD%
goto :EOF
:source_name
set %~1=%~nx2

View File

@ -0,0 +1,37 @@
:: Usage:
:: call env-msys2.bat [reinstall|clean]
:: Initialize environment
call "%~dp0env.bat"
if errorlevel 1 goto error_env
IF DEFINED ProgramFiles(x86) (
:: x64
set MSYS2Architecture=x86_64
set MSYS2Base=64
) else (
:: x86
set MSYS2Architecture=i686
set MSYS2Base=32
)
set CHERE_INVOKING=1
set EnvMSYS2Path=%EnvRootPath%\msys2
set EnvMSYS2BasePath=%EnvMSYS2Path%\msys%MSYS2Base%
call "%~dp0tools\prepare-msys2.bat" %1
if errorlevel 1 exit /B %ERRORLEVEL%
set EnvMSYS2SH=%EnvMSYS2BasePath%\usr\bin\sh.exe
if not exist "%EnvMSYS2SH%" if errorlevel 1 goto error_env
set EnvMSYS2Cmd="%EnvMSYS2SH%" -lc
set PATH=%EnvMSYS2BasePath%\usr\bin;%PATH%
exit /B 0
:error_env
echo Failed to initialize environment.
exit /B 1

26
build_scripts/Windows-msys2/env/env.bat vendored Normal file
View File

@ -0,0 +1,26 @@
:: Initialize environment
call "%~dp0..\env.bat"
if errorlevel 1 goto error_env
set EnvRootPath=%RootPath%\%SourceName%-msys2
set EnvToolsPath=%EnvRootPath%\tools
set EnvTempPath=%EnvRootPath%\tmp
set EnvDownloadPath=%EnvRootPath%\download
set EnvWgetExe=%EnvToolsPath%\wget.exe
set EnvSevenZipExe=%EnvToolsPath%\7z.exe
set EnvDependsExe=%EnvToolsPath%\depends.exe
set EnvCEchoExe=%EnvToolsPath%\cecho.exe
set cecho=call "%ToolsPath%\cecho.bat"
:: Create folders
if not exist "%EnvRootPath%" mkdir "%EnvRootPath%"
if not exist "%EnvToolsPath%" mkdir "%EnvToolsPath%"
if not exist "%EnvDownloadPath%" mkdir "%EnvDownloadPath%"
call "%~dp0tools\prepare-tools.bat"
exit /B %ERRORLEVEL%
:error_env
echo Failed to initialize environment.
exit /B 1

View File

@ -0,0 +1,57 @@
:: Usage:
:: call prepare-msys2.bat [reinstall|clean]
setlocal enabledelayedexpansion
if "%EnvMSYS2Path%"=="" exit /B 1
if "%MSYS2Architecture%"=="" exit /B 1
if "%MSYS2Base%"=="" exit /B 1
if not exist "%EnvRootPath%"=="" exit /B 1
copy "%~dp0root\update-msys2.bat" "%EnvRootPath%" >nul
if "%~1"=="clean" (
%cecho% info "Clean MSYS2"
call "%ToolsPath%\remove-dir.bat" "%EnvMSYS2Path%"
goto exit
)
if exist "%EnvMSYS2Path%\msys%MSYS2Base%\usr\bin\pacman.exe" (
if "%~1"=="reinstall" (
choice /M "Found existing MSYS2 version. Do you want to proceed?"
if !ERRORLEVEL!==2 goto exit
) else (
goto exit
)
)
set MSYS2Install=msys2-base-%MSYS2Architecture%-20180531.tar.xz
set MSYS2Url=http://sourceforge.net/projects/msys2/files/Base/%MSYS2Architecture%/%MSYS2Install%/download
%cecho% info "Remove previous MSYS2 version"
call "%ToolsPath%\remove-dir.bat" "%EnvMSYS2Path%"
%cecho% info "Download installation files"
if not exist "%EnvDownloadPath%\%MSYS2Install%" call "%ToolsPath%\download-file.bat" "%MSYS2Url%" "%EnvDownloadPath%\%MSYS2Install%"
if not exist "%EnvDownloadPath%\%MSYS2Install%" %cecho% error "Cannot download MSYS" & goto error
%cecho% info "Unpack MSYS2"
"%EnvSevenZipExe%" x -so "%EnvDownloadPath%\%MSYS2Install%" | "%EnvSevenZipExe%" x -y -si -ttar -o"%EnvMSYS2Path%"
set MSYS2SH=%EnvMSYS2Path%\msys%MSYS2Base%\usr\bin\sh
%cecho% info "Initialize MSYS2"
"%MSYS2SH%" -lc "pacman -Sy"
"%MSYS2SH%" -lc "pacman --noconfirm --needed -S bash pacman pacman-mirrors msys2-runtime"
call "%EnvMSYS2Path%\msys%MSYS2Base%\autorebase.bat"
call "%EnvRootPath%\update-msys2.bat"
call "%EnvRootPath%\update-msys2.bat"
:exit
endlocal
exit /B 0
:error
endlocal
exit /B 1

View File

@ -0,0 +1,79 @@
setlocal
if "%EnvRootPath%"=="" exit /B 1
set CEchoUrl=https://github.com/lordmulder/cecho/releases/download/2015-10-10/cecho.2015-10-10.zip
set CEchoInstall=cecho.2015-10-10.zip
set SevenZipUrl=https://sourceforge.net/projects/sevenzip/files/7-Zip/18.05/7z1805.msi/download
set SevenZipInstall=7z1805.msi
set WgetUrl=https://eternallybored.org/misc/wget/1.19.4/32/wget.exe
set WgetInstall=wget.exe
set DependsUrl=http://www.dependencywalker.com/depends22_x86.zip
set DependsInstall=depends22_x86.zip
if not exist "%EnvToolsPath%\wget.exe" (
echo Download Wget installation
if not exist "%EnvDownloadPath%\%WgetInstall%" call "%ToolsPath%\winhttpjs.bat" %WgetUrl% -saveTo "%EnvDownloadPath%\%WgetInstall%"
if not exist "%EnvDownloadPath%\%WgetInstall%" %cecho% error "Cannot download Wget installation" & goto error
echo Copy Wget
copy "%EnvDownloadPath%\wget.exe" "%EnvToolsPath%"
)
if not exist "%EnvToolsPath%\7z.exe" (
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
echo Download 7z installation
if not exist "%EnvDownloadPath%\%SevenZipInstall%" call "%ToolsPath%\download-file.bat" "%SevenZipUrl%" "%EnvDownloadPath%\%SevenZipInstall%"
if not exist "%EnvDownloadPath%\%SevenZipInstall%" echo Cannot download 7z installation& goto error
echo Unpack 7z
msiexec /a "%EnvDownloadPath%\%SevenZipInstall%" /qb TARGETDIR="%EnvTempPath%"
copy "%EnvTempPath%\Files\7-Zip\7z.dll" "%EnvToolsPath%"
copy "%EnvTempPath%\Files\7-Zip\7z.exe" "%EnvToolsPath%"
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
)
if not exist "%EnvToolsPath%\cecho.exe" (
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
echo Download cecho installation
if not exist "%EnvDownloadPath%\%CEchoInstall%" call "%ToolsPath%\download-file.bat" "%CEchoUrl%" "%EnvDownloadPath%\%CEchoInstall%"
if not exist "%EnvDownloadPath%\%cCEhoInstall%" echo Cannot download cecho installation& goto error
echo Unpack cecho
"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%CEchoInstall%"
copy "%EnvTempPath%\cecho.exe" "%EnvToolsPath%"
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
)
if not exist "%EnvToolsPath%\depends.exe" (
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
%cecho% info "Download Dependency Walker installation"
if not exist "%EnvDownloadPath%\%DependsInstall%" call "%ToolsPath%\winhttpjs.bat" %DependsUrl% -saveTo "%EnvDownloadPath%\%DependsInstall%"
if not exist "%EnvDownloadPath%\%DependsInstall%" %cecho% error "Cannot download Dependendy Walker installation" & goto error
%cecho% info "Unpack Dependency Walker"
"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%DependsInstall%"
copy "%EnvTempPath%\*" "%EnvToolsPath%"
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
)
:exit
endlocal
exit /B 0
:error
endlocal
exit /B 1

View File

@ -0,0 +1,19 @@
@echo off
setlocal
if exist "%~dp0msys2\msys32" call :update 32
if exist "%~dp0msys2\msys64" call :update 64
goto :EOF
:update
set MSYSSH=%~dp0msys2\msys%~1\usr\bin\sh
echo Update MSYS2 %~1
"%MSYSSH%" -lc "pacman -Sy"
"%MSYSSH%" -lc "pacman --noconfirm -Su"
:exit
endlocal
goto :EOF

View File

@ -0,0 +1,6 @@
:: Usage:
:: call cecho.bat [info|error|std] "text"
if "%~1"=="std" echo %~2
if "%~1"=="info" "%EnvCEchoExe%" green "%~2"
if "%~1"=="error" "%EnvCEchoExe%" red "%~2"

View File

@ -0,0 +1,40 @@
:: Usage:
:: call depends.bat [list^|missing] file
if "%2"=="" (
echo Usage: %~nx0 [list^|missing] File
exit /B 1
)
setlocal
if not exist "%EnvDependsExe%" echo depends.exe not found in %EnvToolsPath%.& exit /B 1
set CutPath=
call "%ToolsPath%\find-in-path.bat" CutPath cut.exe
if "%CutPath%"=="" echo cut.exe not found in PATH.& exit /B 1
start /wait "" "%EnvDependsExe%" /c /oc:"%~dp0depends.tmp" %2
if "%1"=="missing" (
cut.exe --delimiter=, --fields=1,2 "%~dp0depends.tmp" >"%~dp0depends1.tmp"
for /F "tokens=1,2 delims=," %%A in (%~sdp0depends1.tmp) do (
if "%%A"=="?" (
echo %%~B
)
)
)
if "%1"=="list" (
cut.exe --delimiter=, --fields=2 "%~dp0depends.tmp" >"%~dp0depends1.tmp"
for /F "tokens=1 delims=," %%A in (%~sdp0depends1.tmp) do (
if "%%A" NEQ "Module" (
echo %%~A
)
)
)
if exist "%~dp0depends.tmp" del /Q "%~dp0depends.tmp"
if exist "%~dp0depends1.tmp" del /Q "%~dp0depends1.tmp"
endlocal
exit /B 0

View File

@ -0,0 +1,13 @@
:: Usage:
:: call download-file.bat url file
if "%~2"=="" (
echo.
echo Parameter error.
exit /B 1
)
::"%EnvCurlExe%" -L -k "%~1" -o "%~2"
"%EnvWgetExe%" --no-check-certificate --continue "%~1" --output-document="%~2"
exit /B %ERRORLEVEL%

View File

@ -0,0 +1,26 @@
:: Usage:
:: call find-in-path.bat variable file
setlocal
set Var=%~1
set File=%~2
if "%File%"=="" (
echo.
echo Parameter error.
exit /B 1
)
set FoundPath=
SET PathTemp="%Path:;=";"%"
FOR %%P IN (%PathTemp%) DO (
IF EXIST "%%~P.\%File%" (
set FoundPath=%%~P
goto :found
)
)
:found
endlocal & set %Var%=%FoundPath%

View File

@ -0,0 +1,39 @@
REM Usage:
REM call get-git-ref.bat Variable [Branch]
setlocal
set Variable=%~1
if "%Variable%"=="" (
echo.
echo Parameter error
exit /B 1
)
set Ref=
:: Check git executable
set GitPath=
call "%~dp0find-in-path.bat" GitPath git.exe
if "%GitPath%"=="" (
echo.
echo Git executable not found in PATH.
goto exit
)
set GitParameter=
set Branch=%~2
if "%Branch%"=="" (
set Branch=HEAD
set GitParameter=--head
)
for /F "tokens=1*" %%A in ('git show-ref %GitParameter% %Branch%') do (
if "%%B"=="%Branch%" (
set Ref=%%A
)
)
:exit
endlocal & set %Variable%=%Ref%
exit /B 0

View File

@ -0,0 +1,27 @@
:: Usage:
:: call get-qt-version.bat variable
setlocal
set Var=%~1
if "%Var%"=="" (
echo.
echo Parameter error.
exit /B 1
)
set QtVersion=
%EnvMSYS2Cmd% "qmake -version" >"%~dp0qtversion.tmp"
for /F "tokens=1,2,3,4" %%A in (%~sdp0qtversion.tmp) do (
if "%%A"=="Using" (
set QtVersion=%%D
goto exit
)
)
:exit
if exist "%~dp0qtversion.tmp" del /Q "%~dp0qtversion.tmp"
endlocal & set %Var%=%QtVersion%
exit /B 0

View File

@ -0,0 +1,33 @@
:: Usage:
:: call get-rs-version.bat Define Variable
setlocal
set Define=%~1
set Variable=%~2
if "%Variable%"=="" (
echo.
echo Parameter error.
exit /B 1
)
set Result=
set VersionFile="%~dp0..\..\..\libretroshare\src\retroshare\rsversion.h"
if not exist "%VersionFile%" (
echo.
echo Version file doesn't exist.
echo %VersionFile%
exit /B1
)
for /F "usebackq tokens=1,2,3" %%A in (%VersionFile%) do (
if "%%A"=="#define" (
if "%%B"=="%Define%" (
set Result=%%~C
)
)
)
endlocal & set %Variable%=%Result%
exit /B 0

View File

@ -0,0 +1,20 @@
:: Usage:
:: call msys2-path.bat path variable
setlocal
set WinPath=%~1
set MSYS2Var=%~2
if "%MSYS2Var%"=="" (
echo.
echo Parameter error.
exit /B 1
)
set MSYS2Path=/%WinPath:~0,1%/%WinPath:~3%
set MSYS2Path=%MSYS2Path:\=/%
endlocal & set %MSYS2Var%=%MSYS2Path%
exit /B 0

View File

@ -0,0 +1,15 @@
:: Usage:
:: call remove-dir.bat path
if "%~1"=="" (
echo.
echo Parameter error.
exit /B 1
)
if exist %1 (
del /s /f /q %1 >nul
rmdir /s /q %1
)
exit /B 0

View File

@ -0,0 +1,584 @@
@if (@X) == (@Y) @end /* JScript comment
@echo off
rem :: the first argument is the script name as it will be used for proper help message
cscript //E:JScript //nologo "%~f0" "%~nx0" %*
exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */
// used resources
// update 12.10.15
// osvikvi(https://github.com/osvikvi) has nodited that the -password option is not set , so this is fixed
//https://msdn.microsoft.com/en-us/library/windows/desktop/aa384058(v=vs.85).aspx
//https://msdn.microsoft.com/en-us/library/windows/desktop/aa384055(v=vs.85).aspx
//https://msdn.microsoft.com/en-us/library/windows/desktop/aa384059(v=vs.85).aspx
// global variables and constants
// ----------------------------------
// -- asynch requests not included --
// ----------------------------------
//todo - save responceStream instead of responceBody !!
//todo - set all winthttp options ->//https://msdn.microsoft.com/en-us/library/windows/desktop/aa384108(v=vs.85).aspx
//todo - log all options
//todo - improve help message . eventual verbose option
var ARGS = WScript.Arguments;
var scriptName = ARGS.Item(0);
var url = "";
var saveTo = "";
var user = 0;
var pass = 0;
var proxy = 0;
var bypass = 0;
var proxy_user = 0;
var proxy_pass = 0;
var certificate = 0;
var force = true;
var body = "";
//ActiveX objects
var WinHTTPObj = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
var FileSystemObj = new ActiveXObject("Scripting.FileSystemObject");
var AdoDBObj = new ActiveXObject("ADODB.Stream");
// HttpRequest SetCredentials flags.
var proxy_settings = 0;
//
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0;
HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1;
//timeouts and their default values
var RESOLVE_TIMEOUT = 0;
var CONNECT_TIMEOUT = 90000;
var SEND_TIMEOUT = 90000;
var RECEIVE_TIMEOUT = 90000;
//HttpRequestMethod
var http_method = 'GET';
//header
var header_file = "";
//report
var reportfile = "";
//test-this:
var use_stream = false;
//autologon policy
var autologon_policy = 1; //0,1,2
//headers will be stored as multi-dimensional array
var headers = [];
//user-agent
var ua = "";
//escape URL
var escape = false;
function printHelp() {
WScript.Echo(scriptName + " - sends HTTP request and saves the request body as a file and/or a report of the sent request");
WScript.Echo(scriptName + " url [-force yes|no] [-user username -password password] [-proxy proxyserver:port] [-bypass bypass_list]");
WScript.Echo(" [-proxyuser proxy_username -proxypassword proxy_password] [-certificate certificateString]");
WScript.Echo(" [-method GET|POST|PATCH|DELETE|HEAD|OPTIONS|CONNECT]");
WScript.Echo(" [-saveTo file] - to print response to console use con");
WScript.Echo(" [-sendTimeout int(milliseconds)]");
WScript.Echo(" [-resolveTimeout int(milliseconds)]");
WScript.Echo(" [-connectTimeout int(milliseconds)]");
WScript.Echo(" [-receiveTimeout int(milliseconds)]");
WScript.Echo(" [-autologonPolicy 1|2|3]");
WScript.Echo(" [-proxySettings 1|2|3] (https://msdn.microsoft.com/en-us/library/windows/desktop/aa384059(v=vs.85).aspx)");
//header
WScript.Echo(" [-headers-file header_file]");
//reportfile
WScript.Echo(" [-reportfile reportfile]");
WScript.Echo(" [-ua user-agent]");
WScript.Echo(" [-ua-file user-agent-file]");
WScript.Echo(" [-escape yes|no]");
WScript.Echo(" [-body body-string]");
WScript.Echo(" [-body-file body-file]");
WScript.Echo("-force - decide to not or to overwrite if the local files exists");
WScript.Echo("proxyserver:port - the proxy server");
WScript.Echo("bypass- bypass list");
WScript.Echo("proxy_user , proxy_password - credentials for proxy server");
WScript.Echo("user , password - credentials for the server");
WScript.Echo("certificate - location of SSL certificate");
WScript.Echo("method - what HTTP method will be used.Default is GET");
WScript.Echo("saveTo - save the responce as binary file");
WScript.Echo(" ");
WScript.Echo("Header file should contain key:value pairs.Lines starting with \"#\" will be ignored.");
WScript.Echo("value should NOT be enclosed with quotes");
WScript.Echo(" ");
WScript.Echo("Examples:");
WScript.Echo(scriptName + " http://somelink.com/somefile.zip -saveTo c:\\somefile.zip -certificate \"LOCAL_MACHINE\\Personal\\My Middle-Tier Certificate\"");
WScript.Echo(scriptName + " http://somelink.com/something.html -method POST -certificate \"LOCAL_MACHINE\\Personal\\My Middle-Tier Certificate\" -header c:\\header_file -reportfile c:\\reportfile.txt");
WScript.Echo(scriptName + "\"http://somelink\" -method POST -header hdrs.txt -reportfile reportfile2.txt -saveTo responsefile2 -ua \"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36\" -body-file some.json");
}
function parseArgs() {
//
if (ARGS.Length < 2) {
WScript.Echo("insufficient arguments");
printHelp();
WScript.Quit(43);
}
// !!!
url = ARGS.Item(1);
// !!!
if (ARGS.Length % 2 != 0) {
WScript.Echo("illegal arguments");
printHelp();
WScript.Quit(44);
}
for (var i = 2; i < ARGS.Length - 1; i = i + 2) {
var arg = ARGS.Item(i).toLowerCase();
var next = ARGS.Item(i + 1);
try {
switch (arg) { // the try-catch is set mainly because of the parseInts
case "-force":
if (next == "no") {
force = false;
}
break;
case "-escape":
if (next == "yes") {
escape = true;
}
break;
case "-saveto":
saveTo = next;
break;
case "-user":
case "-u":
user = next;
break;
case "-pass":
case "-password":
case "-p":
pass = next;
break;
case "-proxy":
proxy = next;
break;
case "-bypass":
bypass = next;
break;
case "-proxyuser":
case "-pu":
proxy_user = next;
break;
case "-proxypassword":
case "-pp":
proxy_pass = next;
break;
case "-ua":
ua = next;
break;
case "-ua-file":
ua = readFile(next);
break;
case "-body":
body = next;
break;
case "-usestream":
//WScript.Echo("~~");
if (next.toLowerCase() === "yes") {
use_stream = true
};
break;
case "-body-file":
body = readFile(next);
break;
case "-certificate":
certificate = next;
break;
case "-method":
switch (next.toLowerCase()) {
case "post":
http_method = 'POST';
break;
case "get":
http_method = 'GET';
break;
case "head":
http_method = 'HEAD';
break;
case "put":
http_method = 'PUT';
break;
case "options":
http_method = 'OPTIONS';
break;
case "connect":
http_method = 'CONNECT';
break;
case "patch":
http_method = 'PATCH';
break;
case "delete":
http_method = 'DELETE';
break;
default:
WScript.Echo("Invalid http method passed " + next);
WScript.Echo("possible values are GET,POST,DELETE,PUT,CONNECT,PATCH,HEAD,OPTIONS");
WScript.Quit(1326);
break;
}
break;
case "-headers-file":
case "-header":
headers = readPropFile(next);
break;
case "-reportfile":
reportfile = next;
break;
//timeouts
case "-sendtimeout":
SEND_TIMEOUT = parseInt(next);
break;
case "-connecttimeout":
CONNECT_TIMEOUT = parseint(next);
break;
case "-resolvetimeout":
RESOLVE_TIMEOUT = parseInt(next);
break;
case "-receivetimeout":
RECEIVE_TIMEOUT = parseInt(next);
break;
case "-autologonpolicy":
autologon_policy = parseInt(next);
if (autologon_policy > 2 || autologon_policy < 0) {
WScript.Echo("out of autologon policy range");
WScript.Quit(87);
};
break;
case "-proxysettings":
proxy_settings = parseInt(next);
if (proxy_settings > 2 || proxy_settings < 0) {
WScript.Echo("out of proxy settings range");
WScript.Quit(87);
};
break;
default:
WScript.Echo("Invalid command line switch: " + arg);
WScript.Quit(1405);
break;
}
} catch (err) {
WScript.Echo(err.message);
WScript.Quit(1348);
}
}
}
stripTrailingSlash = function(path) {
while (path.substr(path.length - 1, path.length) == '\\') {
path = path.substr(0, path.length - 1);
}
return path;
}
function existsItem(path) {
return FileSystemObj.FolderExists(path) || FileSystemObj.FileExists(path);
}
function deleteItem(path) {
if (FileSystemObj.FileExists(path)) {
FileSystemObj.DeleteFile(path);
return true;
} else if (FileSystemObj.FolderExists(path)) {
FileSystemObj.DeleteFolder(stripTrailingSlash(path));
return true;
} else {
return false;
}
}
//-------------------------------
//----------------------
//----------
//-----
//--
function request(url) {
try {
WinHTTPObj.Open(http_method, url, false);
if (proxy != 0 && bypass != 0) {
WinHTTPObj.SetProxy(proxy_settings, proxy, bypass);
}
if (proxy != 0) {
WinHTTPObj.SetProxy(proxy_settings, proxy);
}
if (user != 0 && pass != 0) {
WinHTTPObj.SetCredentials(user, pass, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER);
}
if (proxy_user != 0 && proxy_pass != 0) {
WinHTTPObj.SetCredentials(proxy_user, proxy_pass, HTTPREQUEST_SETCREDENTIALS_FOR_PROXY);
}
if (certificate != 0) {
WinHTTPObj.SetClientCertificate(certificate);
}
//set autologin policy
WinHTTPObj.SetAutoLogonPolicy(autologon_policy);
//set timeouts
WinHTTPObj.SetTimeouts(RESOLVE_TIMEOUT, CONNECT_TIMEOUT, SEND_TIMEOUT, RECEIVE_TIMEOUT);
if (headers.length !== 0) {
WScript.Echo("Sending with headers:");
for (var i = 0; i < headers.length; i++) {
WinHTTPObj.SetRequestHeader(headers[i][0], headers[i][1]);
WScript.Echo(headers[i][0] + ":" + headers[i][1]);
}
WScript.Echo("");
}
if (ua !== "") {
//user-agent option from:
//WinHttpRequestOption enumeration
// other options can be added like bellow
//https://msdn.microsoft.com/en-us/library/windows/desktop/aa384108(v=vs.85).aspx
WinHTTPObj.Option(0) = ua;
}
if (escape) {
WinHTTPObj.Option(3) = true;
}
if (trim(body) === "") {
WinHTTPObj.Send();
} else {
WinHTTPObj.Send(body);
}
var status = WinHTTPObj.Status
} catch (err) {
WScript.Echo(err.message);
WScript.Quit(666);
}
////////////////////////
// report //
////////////////////////
if (reportfile != "") {
//var report_string="";
var n = "\r\n";
var report_string = "Status:" + n;
report_string = report_string + " " + WinHTTPObj.Status;
report_string = report_string + " " + WinHTTPObj.StatusText + n;
report_string = report_string + " " + n;
report_string = report_string + "Response:" + n;
report_string = report_string + WinHTTPObj.ResponseText + n;
report_string = report_string + " " + n;
report_string = report_string + "Headers:" + n;
report_string = report_string + WinHTTPObj.GetAllResponseHeaders() + n;
WinHttpRequestOption_UserAgentString = 0; // Name of the user agent
WinHttpRequestOption_URL = 1; // Current URL
WinHttpRequestOption_URLCodePage = 2; // Code page
WinHttpRequestOption_EscapePercentInURL = 3; // Convert percents
// in the URL
// rest of the options can be seen and eventually added using this as reference
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa384108(v=vs.85).aspx
report_string = report_string + "URL:" + n;
report_string = report_string + WinHTTPObj.Option(WinHttpRequestOption_URL) + n;
report_string = report_string + "URL Code Page:" + n;
report_string = report_string + WinHTTPObj.Option(WinHttpRequestOption_URLCodePage) + n;
report_string = report_string + "User Agent:" + n;
report_string = report_string + WinHTTPObj.Option(WinHttpRequestOption_UserAgentString) + n;
report_string = report_string + "Escapped URL:" + n;
report_string = report_string + WinHTTPObj.Option(WinHttpRequestOption_EscapePercentInURL) + n;
prepareateFile(force, reportfile);
WScript.Echo("Writing report to " + reportfile);
writeFile(reportfile, report_string);
}
switch (status) {
case 200:
WScript.Echo("Status: 200 OK");
break;
default:
WScript.Echo("Status: " + status);
WScript.Echo("Status was not OK. More info -> https://en.wikipedia.org/wiki/List_of_HTTP_status_codes");
}
//if as binary
if (saveTo.toLowerCase() === "con") {
WScript.Echo(WinHTTPObj.ResponseText);
}
if (saveTo !== "" && saveTo.toLowerCase() !== "con") {
prepareateFile(force, saveTo);
try {
if (use_stream) {
writeBinFile(saveTo, WinHTTPObj.ResponseStream);
} else {
writeBinFile(saveTo, WinHTTPObj.ResponseBody);
}
} catch (err) {
WScript.Echo("Failed to save the file as binary.Attempt to save it as text");
AdoDBObj.Close();
prepareateFile(true, saveTo);
writeFile(saveTo, WinHTTPObj.ResponseText);
}
}
WScript.Quit(status);
}
//--
//-----
//----------
//----------------------
//-------------------------------
function prepareateFile(force, file) {
if (force && existsItem(file)) {
if (!deleteItem(file)) {
WScript.Echo("Unable to delete " + file);
WScript.Quit(8);
}
} else if (existsItem(file)) {
WScript.Echo("Item " + file + " already exist");
WScript.Quit(9);
}
}
function writeBinFile(fileName, data) {
AdoDBObj.Type = 1;
AdoDBObj.Open();
AdoDBObj.Position = 0;
AdoDBObj.Write(data);
AdoDBObj.SaveToFile(fileName, 2);
AdoDBObj.Close();
}
function writeFile(fileName, data) {
AdoDBObj.Type = 2;
AdoDBObj.CharSet = "iso-8859-1";
AdoDBObj.Open();
AdoDBObj.Position = 0;
AdoDBObj.WriteText(data);
AdoDBObj.SaveToFile(fileName, 2);
AdoDBObj.Close();
}
function readFile(fileName) {
//check existence
try {
if (!FileSystemObj.FileExists(fileName)) {
WScript.Echo("file " + fileName + " does not exist!");
WScript.Quit(13);
}
if (FileSystemObj.GetFile(fileName).Size === 0) {
return "";
}
var fileR = FileSystemObj.OpenTextFile(fileName, 1);
var content = fileR.ReadAll();
fileR.Close();
return content;
} catch (err) {
WScript.Echo("Error while reading file: " + fileName);
WScript.Echo(err.message);
WScript.Echo("Will return empty string");
return "";
}
}
function readPropFile(fileName) {
//check existence
resultArray = [];
if (!FileSystemObj.FileExists(fileName)) {
WScript.Echo("(headers)file " + fileName + " does not exist!");
WScript.Quit(15);
}
if (FileSystemObj.GetFile(fileName).Size === 0) {
return resultArray;
}
var fileR = FileSystemObj.OpenTextFile(fileName, 1);
var line = "";
var k = "";
var v = "";
var lineN = 0;
var index = 0;
try {
WScript.Echo("parsing headers form " + fileName + " property file ");
while (!fileR.AtEndOfStream) {
line = fileR.ReadLine();
lineN++;
index = line.indexOf(":");
if (line.indexOf("#") === 0 || trim(line) === "") {
continue;
}
if (index === -1 || index === line.length - 1 || index === 0) {
WScript.Echo("Invalid line " + lineN);
WScript.Quit(93);
}
k = trim(line.substring(0, index));
v = trim(line.substring(index + 1, line.length));
resultArray.push([k, v]);
}
fileR.Close();
return resultArray;
} catch (err) {
WScript.Echo("Error while reading headers file: " + fileName);
WScript.Echo(err.message);
WScript.Echo("Will return empty array");
return resultArray;
}
}
function trim(str) {
return str.replace(/^\s+/, '').replace(/\s+$/, '');
}
function main() {
parseArgs();
request(url);
}
main();