-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtools_zipUnzip.bat
More file actions
180 lines (153 loc) · 5.51 KB
/
tools_zipUnzip.bat
File metadata and controls
180 lines (153 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
::Author : Shen Xiaolong((xlshen@126.com))
::Copyright : free use,modify,spread, but MUST include this original two line information(Author and Copyright).
:: using built-in command to zip/unzip .zip file
::@set _Echo=1
::set _Debug=1
::set _Stack=%~nx0
@if {"%_Echo%"}=={"1"} ( @echo on ) else ( @echo off )
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo. & @echo [+++++ %~nx0] commandLine: %0 %*
rem title length limited to 256 chars , else dos will report "Not enough memory resources are available to process this command"
rem @title %0 %*
where "%~nx0" 1>nul 2>nul || set "path=%~dp0;%path%"
if {"%~1"}=={""} call :Test NoOutput & goto End
call :%~1 %2 %3 %4 %5 %6 %7 %8 %9
goto :End
::[DOS_API:Help]Display help information
:Help
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call tools_miscellaneous.bat DisplayHelp "%~f0"
goto :eof
::[DOS_API:Test]Test DOS API in this script file
:Test
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
echo.
@echo [%~nx0] Run test case [%0 %*]
echo.
echo test call :Help
call :Help
echo.
goto :eof
::[DOS_API:unzip] extract all files from one compressed file
::usage : call :unzip msiFileFullPath optionalTargetDirectory
::call e.g. : call :unzip "D:\tasks\CiscoJabberSetup.msi"
:: call :unzip "D:\tasks\CiscoJabberSetup.msi" "D:\tasks\instalerFiles"
:unzip
call tools_error.bat checkFileExist "%~fs1"
set "_tmpOutputDir=%~2"
if not defined _tmpOutputDir set "_tmpOutputDir=%~dpn1"
if {"%_tmpOutputDir:~-1%"}=={"\"} set "_tmpOutputDir=%_tmpOutputDir:~0,-1%"
if not exist "%_tmpOutputDir%\" md "%_tmpOutputDir%\"
if {"%~x1"}=={".zip"} call :unzip.zip %*
if {"%~x1"}=={".bz2"} call :unzip.bz2 %*
if {"%~x1"}=={".gz"} call :unzip.gz %*
if {"%~x1"}=={".tar"} call :unzip.tar %*
if {"%~x1"}=={".cab"} call :unzip.cab %*
if {"%~x1"}=={".msi"} call :unzip.msi %*
goto :eof
:unzip.zip
@where "%~nx0" || set "path=%~dp0;%path%"
tar.exe -C "%_tmpOutputDir%" -xvf "%~fs1"
goto :eof
:unzip.tar
@where "%~nx0" || set "path=%~dp0;%path%"
tar.exe -C "%_tmpOutputDir%" -xf "%~fs1"
goto :eof
:unzip.bz2
@where "%~nx0" || set "path=%~dp0;%path%"
tar.exe -C "%_tmpOutputDir%" -xjf "%~fs1"
goto :eof
:unzip.gz
@where "%~nx0" || set "path=%~dp0;%path%"
:: tar.exe -C "%_tmpOutputDir%" -xzf "%~fs1"
call %myWinScriptPath%\common\bin\7z.exe e "%~fs1" -o"%_tmpOutputDir%"
goto :eof
:unzip.cab
::expand.exe <source>.cab <dest>
call expand.exe "%~fs1" "%_tmpOutputDir%"
goto :eof
:unzip.msi
if not {"%~x1"}=={".msi"} call tools_message.bat errorMsg "file MUST be .msi file"
set "_msiLogFile=%~dpn1_unzip.log"
call :msiInstaller.impl /a "%~f1" TARGETDIR="%_tmpOutputDir%"
goto :eof
::[DOS_API:zip]compress one zip or folder into one compressed file.
::usage : call :zip <folerOrFile> <outfile>
::e.g. : call :zip "d:\mytestFolder" d:\self_extracted.exe
:zip
if {"%~x2"}=={".zip"} call :zip.zip %*
if {"%~x2"}=={".cab"} call :zip.cab %*
if {"%~x2"}=={".exe"} call :zip.exe %*
goto :eof
:zip.cab
::makecab <source> <dest>.cab
call makecab.exe "%~f1" "%~f2"
goto :eof
:zip.zip
echo TODO
goto :eof
:zip.exe
if {"%~x1"}=={".cab"} call zip.exe.fromCab %*
if not {"%~x1"}=={".cab"} call zip.exe.fromFolder %*
goto :eof
:zip.exe.fromCab
copy /b extrac32.exe+"%~f1" "%~dpn2.exe"
goto :eof
:zip.exe.fromFolder
set "_tempCab=%temp%\%~n2.cab"
call makecab.exe "%~f1" "%_tempCab%"
call :zip.exe.fromCab "%_tempCab%" "%~f2"
del /q/f "%_tempCab%"
goto :eof
:installWithLog
call :msiInstaller.check %*
set "_msiLogFile=%_tmpOutputDir%\%~n1_install.log"
call :msiInstaller.impl /i "%~f1"
goto :eof
:uninstallWithLog
call :msiInstaller.check %*
set "_msiLogFile=%_tmpOutputDir%\%~n1_uninstall.log"
call :msiInstaller.impl /x "%~f1"
goto :eof
:msiInstaller.check
call tools_error.bat checkFileExist "%~fs1"
call tools_error.bat checkFileExtName "%~fs1" ".msi"
call tools_error.bat checkZeroSizeFile "%~fs1"
set "_tmpOutputDir=%~2"
if not defined _tmpOutputDir set "_tmpOutputDir=%~dp1"
if {"%_tmpOutputDir:~-1%"}=={"\"} set "_tmpOutputDir=%_tmpOutputDir:~0,-1%"
goto :eof
:msiInstaller.impl
if exist "%_msiLogFile%" del /f/q "%_msiLogFile%"
set _tmpMsiCmd=msiexec /qb %* /l*v "%_msiLogFile%"
echo.
echo %_tmpMsiCmd%
echo log file : %_msiLogFile%
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo.
%_tmpMsiCmd%
echo.
echo -------------------------------------------------------------
echo %_tmpMsiCmd%
echo.
call :msiInstaller.checkError "%_msiLogFile%"
:: if exist "%_msiLogFile%" call tools_txtFile.bat openTxtFile "%_msiLogFile%"
goto :eof
:msiInstaller.checkError
if not exist "%~fs1" goto :eof
for /f "usebackq tokens=1" %%i in ( ` type "%~fs1" ^| find /c /i "Error 2203" ` ) do set errorCode2203=%%~i
if {"%errorCode2203%"}=={"0"} goto :eof
echo.
echo below error found:
type "%~fs1" | find /i "Error 2203"
echo.
echo it is caused by permission is rejected for folder "C:\Windows\Temp"
echo please confirm the folder "C:\Windows\Temp" to grante the permission
echo or check the output folder "%_tmpOutputDir%" -- it MUST be existed empty folder.
echo And run below command again:
echo %_tmpMsiCmd%
echo.
echo press any key to exit.
pause > nul
goto :eof
:End
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [----- %~nx0] commandLine: %0 %* & @echo.