mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-18 03:19:30 -04:00
Changed Windows build environment
- Fixed deploy path with tor - Disabled webui in installer - Optimized file get-gcc-version.bat - Optimized file get-qt-version.bat - Renamed file msys-path.bat to msys2-path.bat - Removed file download-file-wildcard.bat - Removed file winhttpjs.bat - Removed download and usage of wget.exe
This commit is contained in:
parent
035010af76
commit
8c7920b545
13 changed files with 43 additions and 739 deletions
|
@ -29,15 +29,15 @@ if not exist "%EnvMSYS2SH%" %cecho% error "Please install MSYS2 first." & exit /
|
||||||
call "%~dp0env.bat"
|
call "%~dp0env.bat"
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
call "%ToolsPath%\msys-path.bat" "%~dp0" MSYS2CurPath
|
call "%ToolsPath%\msys2-path.bat" "%~dp0" MSYS2CurPath
|
||||||
call "%ToolsPath%\msys-path.bat" "%BuildLibsPath%" MSYS2BuildLibsPath
|
call "%ToolsPath%\msys2-path.bat" "%BuildLibsPath%" MSYS2BuildLibsPath
|
||||||
|
|
||||||
if not exist "%BuildLibsPath%" mkdir "%BuildLibsPath%"
|
if not exist "%BuildLibsPath%" mkdir "%BuildLibsPath%"
|
||||||
|
|
||||||
set MSYSTEM=MINGW%MSYS2Base%
|
set MSYSTEM=MINGW%MSYS2Base%
|
||||||
set MSYS2_PATH_TYPE=inherit
|
set MSYS2_PATH_TYPE=inherit
|
||||||
|
|
||||||
%EnvMSYS2Cmd% "pacman --needed --noconfirm -S diffutils perl tar make mingw-w64-%MSYS2Architecture%-make"
|
%EnvMSYS2Cmd% "pacman --needed --noconfirm -S diffutils perl tar make wget mingw-w64-%MSYS2Architecture%-make"
|
||||||
::mingw-w64-%MSYS2Architecture%-cmake
|
::mingw-w64-%MSYS2Architecture%-cmake
|
||||||
::%EnvMSYS2Cmd% "pacman --noconfirm -Rd --nodeps mingw-w64-%MSYS2Architecture%-zlib"
|
::%EnvMSYS2Cmd% "pacman --noconfirm -Rd --nodeps mingw-w64-%MSYS2Architecture%-zlib"
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ if "%GCCArchitecture%"=="" %cecho% error "Cannot get gcc architecture." & exit /
|
||||||
set BuildLibsPath=%EnvRootPath%\build-libs\gcc-%GCCVersion%\%GCCArchitecture%
|
set BuildLibsPath=%EnvRootPath%\build-libs\gcc-%GCCVersion%\%GCCArchitecture%
|
||||||
|
|
||||||
set RsBuildPath=%BuildPath%\Qt-%QtVersion%-%GCCArchitecture%-%RsBuildConfig%
|
set RsBuildPath=%BuildPath%\Qt-%QtVersion%-%GCCArchitecture%-%RsBuildConfig%
|
||||||
set RsDeployPath=%DeployPath%\Qt-%QtVersion%%RsType%-%GCCArchitecture%-%RsBuildConfig%
|
set RsDeployPath=%DeployPath%\Qt-%QtVersion%-%GCCArchitecture%%RsType%-%RsBuildConfig%
|
||||||
set RsPackPath=%DeployPath%
|
set RsPackPath=%DeployPath%
|
||||||
set RsArchiveAdd=
|
set RsArchiveAdd=
|
||||||
|
|
||||||
|
|
2
build_scripts/Windows/env/env.bat
vendored
2
build_scripts/Windows/env/env.bat
vendored
|
@ -7,8 +7,6 @@ set EnvToolsPath=%EnvRootPath%\tools
|
||||||
set EnvTempPath=%EnvRootPath%\tmp
|
set EnvTempPath=%EnvRootPath%\tmp
|
||||||
set EnvDownloadPath=%EnvRootPath%\download
|
set EnvDownloadPath=%EnvRootPath%\download
|
||||||
|
|
||||||
::set EnvCurlExe=%EnvToolsPath%\curl.exe
|
|
||||||
set EnvWgetExe=%EnvToolsPath%\wget.exe
|
|
||||||
set EnvSevenZipExe=%EnvToolsPath%\7z.exe
|
set EnvSevenZipExe=%EnvToolsPath%\7z.exe
|
||||||
set EnvJomExe=%EnvToolsPath%\jom.exe
|
set EnvJomExe=%EnvToolsPath%\jom.exe
|
||||||
set EnvSedExe=%EnvToolsPath%\sed.exe
|
set EnvSedExe=%EnvToolsPath%\sed.exe
|
||||||
|
|
|
@ -31,8 +31,10 @@ set CMakeInstall=cmake-3.1.0-win32-x86.zip
|
||||||
set CMakeUrl=http://www.cmake.org/files/v3.1/%CMakeInstall%
|
set CMakeUrl=http://www.cmake.org/files/v3.1/%CMakeInstall%
|
||||||
set CMakeUnpackPath=%EnvMSYS2Path%\msys%MSYS2Base%
|
set CMakeUnpackPath=%EnvMSYS2Path%\msys%MSYS2Base%
|
||||||
|
|
||||||
%cecho% info "Remove previous MSYS2 version"
|
if exist "%EnvMSYS2Path%\msys%MSYS2Base%" (
|
||||||
call "%ToolsPath%\remove-dir.bat" "%EnvMSYS2Path%\msys%MSYS2Base%"
|
%cecho% info "Remove previous MSYS2 version"
|
||||||
|
call "%ToolsPath%\remove-dir.bat" "%EnvMSYS2Path%\msys%MSYS2Base%"
|
||||||
|
)
|
||||||
|
|
||||||
%cecho% info "Download installation files"
|
%cecho% info "Download installation files"
|
||||||
if not exist "%EnvDownloadPath%\%MSYS2Install%" call "%ToolsPath%\download-file.bat" "%MSYS2Url%" "%EnvDownloadPath%\%MSYS2Install%"
|
if not exist "%EnvDownloadPath%\%MSYS2Install%" call "%ToolsPath%\download-file.bat" "%MSYS2Url%" "%EnvDownloadPath%\%MSYS2Install%"
|
||||||
|
|
|
@ -6,10 +6,6 @@ set CEchoUrl=https://github.com/lordmulder/cecho/releases/download/2015-10-10/ce
|
||||||
set CEchoInstall=cecho.2015-10-10.zip
|
set CEchoInstall=cecho.2015-10-10.zip
|
||||||
set SevenZipUrl=https://sourceforge.net/projects/sevenzip/files/7-Zip/19.00/7z1900.msi/download
|
set SevenZipUrl=https://sourceforge.net/projects/sevenzip/files/7-Zip/19.00/7z1900.msi/download
|
||||||
set SevenZipInstall=7z1900.msi
|
set SevenZipInstall=7z1900.msi
|
||||||
::set CurlUrl=https://bintray.com/artifact/download/vszakats/generic/curl-7.50.1-win32-mingw.7z
|
|
||||||
::set CurlInstall=curl-7.50.1-win32-mingw.7z
|
|
||||||
set WgetUrl=https://eternallybored.org/misc/wget/1.19.4/32/wget.exe
|
|
||||||
set WgetInstall=wget.exe
|
|
||||||
set JomUrl=http://download.qt.io/official_releases/jom/jom.zip
|
set JomUrl=http://download.qt.io/official_releases/jom/jom.zip
|
||||||
set JomInstall=jom.zip
|
set JomInstall=jom.zip
|
||||||
set DependsUrl=http://www.dependencywalker.com/depends22_x86.zip
|
set DependsUrl=http://www.dependencywalker.com/depends22_x86.zip
|
||||||
|
@ -27,16 +23,6 @@ set CMakeInstall=%CMakeVersion%.zip
|
||||||
set CMakeUrl=http://www.cmake.org/files/v3.1/%CMakeInstall%
|
set CMakeUrl=http://www.cmake.org/files/v3.1/%CMakeInstall%
|
||||||
set CMakeInstallPath=%EnvToolsPath%\cmake
|
set CMakeInstallPath=%EnvToolsPath%\cmake
|
||||||
|
|
||||||
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" (
|
if not exist "%EnvToolsPath%\7z.exe" (
|
||||||
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
|
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
|
||||||
mkdir "%EnvTempPath%"
|
mkdir "%EnvTempPath%"
|
||||||
|
@ -70,29 +56,13 @@ if not exist "%EnvToolsPath%\cecho.exe" (
|
||||||
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
|
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
|
||||||
)
|
)
|
||||||
|
|
||||||
::if not exist "%EnvToolsPath%\curl.exe" (
|
|
||||||
:: call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
|
|
||||||
:: mkdir "%EnvTempPath%"
|
|
||||||
::
|
|
||||||
:: echo Download Curl installation
|
|
||||||
::
|
|
||||||
:: if not exist "%EnvDownloadPath%\%CurlInstall%" call "%ToolsPath%\winhttpjs.bat" %CurlUrl% -saveTo "%EnvDownloadPath%\%CurlInstall%"
|
|
||||||
:: if not exist "%EnvDownloadPath%\%CurlInstall%" echo Cannot download Curl installation& goto error
|
|
||||||
::
|
|
||||||
:: echo Unpack Curl
|
|
||||||
:: "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%CurlInstall%"
|
|
||||||
:: copy "%EnvTempPath%\curl-7.50.1-win32-mingw\bin\curl.exe" "%EnvToolsPath%"
|
|
||||||
::
|
|
||||||
:: call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
|
|
||||||
::)
|
|
||||||
|
|
||||||
if not exist "%EnvToolsPath%\jom.exe" (
|
if not exist "%EnvToolsPath%\jom.exe" (
|
||||||
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
|
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
|
||||||
mkdir "%EnvTempPath%"
|
mkdir "%EnvTempPath%"
|
||||||
|
|
||||||
%cecho% info "Download jom installation"
|
%cecho% info "Download jom installation"
|
||||||
|
|
||||||
if not exist "%EnvDownloadPath%\%JomInstall%" call "%ToolsPath%\winhttpjs.bat" %JomUrl% -saveTo "%EnvDownloadPath%\%JomInstall%"
|
if not exist "%EnvDownloadPath%\%JomInstall%" call "%ToolsPath%\download-file.bat" %JomUrl% "%EnvDownloadPath%\%JomInstall%"
|
||||||
if not exist "%EnvDownloadPath%\%JomInstall%" %cecho% error "Cannot download jom installation" & goto error
|
if not exist "%EnvDownloadPath%\%JomInstall%" %cecho% error "Cannot download jom installation" & goto error
|
||||||
|
|
||||||
%cecho% info "Unpack jom"
|
%cecho% info "Unpack jom"
|
||||||
|
@ -108,7 +78,7 @@ if not exist "%EnvToolsPath%\depends.exe" (
|
||||||
|
|
||||||
%cecho% info "Download Dependency Walker installation"
|
%cecho% info "Download Dependency Walker installation"
|
||||||
|
|
||||||
if not exist "%EnvDownloadPath%\%DependsInstall%" call "%ToolsPath%\winhttpjs.bat" %DependsUrl% -saveTo "%EnvDownloadPath%\%DependsInstall%"
|
if not exist "%EnvDownloadPath%\%DependsInstall%" call "%ToolsPath%\download-file.bat" %DependsUrl% "%EnvDownloadPath%\%DependsInstall%"
|
||||||
if not exist "%EnvDownloadPath%\%DependsInstall%" %cecho% error "Cannot download Dependendy Walker installation" & goto error
|
if not exist "%EnvDownloadPath%\%DependsInstall%" %cecho% error "Cannot download Dependendy Walker installation" & goto error
|
||||||
|
|
||||||
%cecho% info "Unpack Dependency Walker"
|
%cecho% info "Unpack Dependency Walker"
|
||||||
|
@ -124,7 +94,7 @@ if not exist "%EnvToolsPath%\cut.exe" (
|
||||||
|
|
||||||
%cecho% info "Download Unix Tools installation"
|
%cecho% info "Download Unix Tools installation"
|
||||||
|
|
||||||
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" call "%ToolsPath%\winhttpjs.bat" %UnixToolsUrl% -saveTo "%EnvDownloadPath%\%UnixToolsInstall%"
|
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" call "%ToolsPath%\download-file.bat" %UnixToolsUrl% "%EnvDownloadPath%\%UnixToolsInstall%"
|
||||||
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" %cecho% error "Cannot download Unix Tools installation" & goto error
|
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" %cecho% error "Cannot download Unix Tools installation" & goto error
|
||||||
|
|
||||||
%cecho% info "Unpack Unix Tools"
|
%cecho% info "Unpack Unix Tools"
|
||||||
|
@ -140,7 +110,7 @@ if not exist "%EnvToolsPath%\sed.exe" (
|
||||||
|
|
||||||
%cecho% info "Download Unix Tools installation"
|
%cecho% info "Download Unix Tools installation"
|
||||||
|
|
||||||
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" call "%ToolsPath%\winhttpjs.bat" %UnixToolsUrl% -saveTo "%EnvDownloadPath%\%UnixToolsInstall%"
|
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" call "%ToolsPath%\download-file.bat" %UnixToolsUrl% "%EnvDownloadPath%\%UnixToolsInstall%"
|
||||||
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" %cecho% error "Cannot download Unix Tools installation" & goto error
|
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" %cecho% error "Cannot download Unix Tools installation" & goto error
|
||||||
|
|
||||||
%cecho% info "Unpack Unix Tools"
|
%cecho% info "Unpack Unix Tools"
|
||||||
|
|
|
@ -263,8 +263,8 @@ Section $(Section_Main) Section_Main
|
||||||
File /r "${QTDIR}\translations\qtxmlpatterns_*.qm"
|
File /r "${QTDIR}\translations\qtxmlpatterns_*.qm"
|
||||||
|
|
||||||
; WebUI
|
; WebUI
|
||||||
SetOutPath "$INSTDIR\webui"
|
; SetOutPath "$INSTDIR\webui"
|
||||||
File /r "${SOURCEDIR}\libresapi\src\webui\*.*"
|
; File /r "${SOURCEDIR}\libresapi\src\webui\*.*"
|
||||||
|
|
||||||
; License
|
; License
|
||||||
SetOutPath "$INSTDIR\license"
|
SetOutPath "$INSTDIR\license"
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
:: Usage:
|
|
||||||
:: call download-file-wildcard.bat url file-wildcard download-path variable
|
|
||||||
|
|
||||||
if "%~4"=="" (
|
|
||||||
echo.
|
|
||||||
echo Parameter error.
|
|
||||||
exit /B 1
|
|
||||||
)
|
|
||||||
|
|
||||||
if "%EnvTempPath%"=="" (
|
|
||||||
echo.
|
|
||||||
echo Environment error.
|
|
||||||
exit /B 1
|
|
||||||
)
|
|
||||||
|
|
||||||
setlocal
|
|
||||||
|
|
||||||
set Url=%~1
|
|
||||||
set FileWildcard=%~2
|
|
||||||
set DownloadPath=%~3
|
|
||||||
set Var=%~4
|
|
||||||
set File=
|
|
||||||
|
|
||||||
call "%~dp0remove-dir.bat" "%EnvTempPath%"
|
|
||||||
mkdir "%EnvTempPath%"
|
|
||||||
|
|
||||||
"%EnvWgetExe%" --recursive --continue --no-directories --no-parent -A "%FileWildcard%" --directory-prefix="%EnvTempPath%" "%Url%"
|
|
||||||
|
|
||||||
if errorlevel 1 (
|
|
||||||
call "%~dp0remove-dir.bat" "%EnvTempPath%"
|
|
||||||
endlocal & set %Var%=
|
|
||||||
exit /B %ERRORLEVEL%
|
|
||||||
)
|
|
||||||
|
|
||||||
for %%A in (%EnvTempPath%\%FileWildcard%) do set File=%%~nxA
|
|
||||||
if "%File%"=="" (
|
|
||||||
call "%~dp0remove-dir.bat" "%EnvTempPath%"
|
|
||||||
endlocal & set %Var%=
|
|
||||||
exit /B %ERRORLEVEL%
|
|
||||||
)
|
|
||||||
|
|
||||||
move "%EnvTempPath%\%File%" "%DownloadPath%"
|
|
||||||
call "%~dp0remove-dir.bat" "%EnvTempPath%"
|
|
||||||
|
|
||||||
endlocal & set %Var%=%File%
|
|
||||||
exit /B 0
|
|
|
@ -7,7 +7,6 @@ if "%~2"=="" (
|
||||||
exit /B 1
|
exit /B 1
|
||||||
)
|
)
|
||||||
|
|
||||||
::"%EnvCurlExe%" -L -k "%~1" -o "%~2"
|
powershell -NoLogo -NoProfile -Command (New-Object System.Net.WebClient).DownloadFile(\""%~1\"", \""%~2\"")
|
||||||
"%EnvWgetExe%" --no-check-certificate --continue "%~1" --output-document="%~2"
|
|
||||||
|
|
||||||
exit /B %ERRORLEVEL%
|
exit /B %ERRORLEVEL%
|
||||||
|
|
|
@ -19,45 +19,19 @@ if "%VarArchitecture%"=="" (
|
||||||
|
|
||||||
set GCCVersion=
|
set GCCVersion=
|
||||||
set GCCArchitecture=
|
set GCCArchitecture=
|
||||||
|
set _Architecture=
|
||||||
|
|
||||||
call "%~dp0find-in-path.bat" GCCPath gcc.exe
|
call "%~dp0find-in-path.bat" GCCPath gcc.exe
|
||||||
if "%GCCPath%"=="" (
|
if "%GCCPath%"=="" (
|
||||||
echo.
|
echo.
|
||||||
echo Cannot find gcc.exe in PATH.
|
echo Cannot find gcc.exe in PATH.
|
||||||
goto exit
|
exit /B 1
|
||||||
)
|
)
|
||||||
|
|
||||||
gcc --version >"%~dp0gccversion.tmp"
|
for /F "tokens=1-8* delims= " %%A in ('gcc --version') do if "%%A"=="gcc" set _Architecture=%%B& set GCCVersion=%%G
|
||||||
for /F "tokens=1*" %%A in (%~sdp0gccversion.tmp) do (
|
|
||||||
if "%%A"=="gcc" (
|
|
||||||
call :find_version %%B
|
|
||||||
call :find_architecture %%B
|
|
||||||
goto exit
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
:exit
|
|
||||||
if exist "%~dp0gccversion.tmp" del /Q "%~dp0gccversion.tmp"
|
|
||||||
|
|
||||||
endlocal & set %VarVersion%=%GCCVersion%& set %VarArchitecture%=%GCCArchitecture%
|
|
||||||
goto :EOF
|
|
||||||
|
|
||||||
:find_version
|
|
||||||
:loop_version
|
|
||||||
if "%2" NEQ "" (
|
|
||||||
shift
|
|
||||||
goto loop_version
|
|
||||||
)
|
|
||||||
set GCCVersion=%1
|
|
||||||
goto :EOF
|
|
||||||
|
|
||||||
:find_architecture
|
|
||||||
:loop_architecture
|
|
||||||
if "%7" NEQ "" (
|
|
||||||
shift
|
|
||||||
goto loop_architecture
|
|
||||||
)
|
|
||||||
set _Architecture=%1
|
|
||||||
if "%_Architecture:~1,4%"=="i686" set GCCArchitecture=x86
|
if "%_Architecture:~1,4%"=="i686" set GCCArchitecture=x86
|
||||||
if "%_Architecture:~1,6%"=="x86_64" set GCCArchitecture=x64
|
if "%_Architecture:~1,6%"=="x86_64" set GCCArchitecture=x64
|
||||||
goto :EOF
|
|
||||||
|
endlocal & set %VarVersion%=%GCCVersion%& set %VarArchitecture%=%GCCArchitecture%
|
||||||
|
exit /B 0
|
||||||
|
|
|
@ -16,19 +16,10 @@ call "%~dp0find-in-path.bat" QMakePath qmake.exe
|
||||||
if "%QMakePath%"=="" (
|
if "%QMakePath%"=="" (
|
||||||
echo.
|
echo.
|
||||||
echo Cannot find qmake.exe in PATH.
|
echo Cannot find qmake.exe in PATH.
|
||||||
goto exit
|
exit /B 1
|
||||||
)
|
)
|
||||||
|
|
||||||
qmake.exe -version >"%~dp0qtversion.tmp"
|
for /F "tokens=1,2,3,4 delims= " %%A in ('qmake.exe -version') do if "%%A"=="Using" set QtVersion=%%D
|
||||||
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%
|
endlocal & set %Var%=%QtVersion%
|
||||||
exit /B 0
|
exit /B 0
|
|
@ -1,20 +0,0 @@
|
||||||
:: Usage:
|
|
||||||
:: call msys-path.bat path variable
|
|
||||||
|
|
||||||
setlocal
|
|
||||||
|
|
||||||
set WinPath=%~1
|
|
||||||
set MSYSVar=%~2
|
|
||||||
|
|
||||||
if "%MSYSVar%"=="" (
|
|
||||||
echo.
|
|
||||||
echo Parameter error.
|
|
||||||
exit /B 1
|
|
||||||
)
|
|
||||||
|
|
||||||
set MSYSPath=/%WinPath:~0,1%/%WinPath:~3%
|
|
||||||
set MSYSPath=%MSYSPath:\=/%
|
|
||||||
|
|
||||||
endlocal & set %MSYSVar%=%MSYSPath%
|
|
||||||
|
|
||||||
exit /B 0
|
|
20
build_scripts/Windows/tools/msys2-path.bat
Normal file
20
build_scripts/Windows/tools/msys2-path.bat
Normal 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
|
|
@ -1,584 +0,0 @@
|
||||||
@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();
|
|
Loading…
Add table
Add a link
Reference in a new issue