-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtools_appInstallPath.bat
More file actions
198 lines (172 loc) · 8.36 KB
/
tools_appInstallPath.bat
File metadata and controls
198 lines (172 loc) · 8.36 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
::Author : Shen Xiaolong((xlshen@126.com))
::Copyright : free use,modify,spread, but MUST include this original two line information(Author and Copyright).
::@set _Echo=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 %*
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 [%~nx0] Run test case [%0 %*]
echo.
echo test call :Help
call :Help
echo.
echo.
echo test call :FindPath7Z _app7Z
call :FindPath7Z _app7Z
echo _app7Z=%_app7Z%
echo.
echo skip Cisco-specified :FindPathStig
:: echo test call :FindPathStig _appStig
:: call :FindPathStig _appStig
:: echo _appStig=%_appStig%
echo.
echo skip nivdia dev-env :FindPathWindbg
:: echo test call :FindPathWindbg _appWindbg
:: call :FindPathWindbg _appWindbg
:: echo _appWindbg=%_appWindbg%
echo.
echo test call :FindVisualStudio _appNewestVs
call :FindVisualStudio _appNewestVs
echo _appNewestVs=%_appNewestVs%
echo.
echo test call :FindPathNotepad _appNotepad
call :FindPathNotepad _appNotepad
echo _appNotepad=%_appNotepad%
echo.
echo test call :FindPathPython _appPython
call :FindPathPython _appPython
echo _appPython=%_appPython%
echo.
echo test call pythonModuleInstalled "Scrapy" bScrapyInstalled
call tools_appInstallPath.bat pythonModuleInstalled "Scrapy" bScrapyInstalled
if defined bScrapyInstalled echo Scrapy is installed.
if not defined bScrapyInstalled echo Scrapy is NOT installed.
echo.
echo test call pythonModuleInstalled "Scrapy11" bScrapyInstalled
call tools_appInstallPath.bat pythonModuleInstalled "Scrapy11" bScrapyInstalled
if defined bScrapyInstalled echo Scrapy11 is installed.
if not defined bScrapyInstalled echo Scrapy11 is NOT installed.
echo.
goto :eof
set "%~1=%~s2"
goto :eof
::[DOS_API:FindPath7Z]find 7-zip application install path
::usage : call :FindPath7Z appPath
::result e.g : set appPath=C:\somepath
:FindPath7Z
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :pathVar.check "7z.exe" %~1
if not defined %~1 call :evnVar.check g_ZipDir "%~1"
if not defined %~1 call tools_path.bat FindAppPathInReg "HKEY_CLASSES_ROOT\Applications\7z.exe\shell\open\command" "%~1"
if not defined %~1 call tools_path.bat FindAppPathinDisk "7z.exe" "%~1"
call :evnVar.set g_ZipDir "%~1"
goto :eof
::[DOS_API:FindPathStig]find stig.exe application path
::usage : call :FindPathStig appPath
::result e.g : set appPath=C:\somepath
:FindPathStig
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :pathVar.check "stig.exe" %~1
if not defined %~1 call :evnVar.check g_StigDir "%~1"
if not defined %~1 call tools_path.bat FindAppPathinDisk "stig.exe" "%~1"
call :evnVar.set g_StigDir "%~1"
goto :eof
::[DOS_API:FindPathWindbg]find windbg application install path
::usage : call :FindPathWindbg appPath
::result e.g : set appPath=C:\somepath
:FindPathWindbg
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
:: set "defWindbgPath=C:\Program Files (x86)\Windows Kits\10\Debuggers"
call :pathVar.check "windbg.exe" %~1 ".."
if not defined %~1 call :evnVar.check g_windbgDir "%~1"
if not defined %~1 call tools_path.bat FindAppPathInReg "HKEY_CURRENT_USER\Software\Classes\Applications\windbg.exe\shell\open\command" %~1 ".."
if not defined %~1 call tools_path.bat FindAppPathinDisk "windbg.exe" %~1 ".."
call :evnVar.set g_windbgDir "%~1"
goto :eof
::[DOS_API:FindVisualStudio]find VisualStudio application install path
::usage : call :FindVisualStudio appPath [optVsVer]
::result e.g : set appPath=C:\somepath
:FindVisualStudio
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
where tools_vs.bat 1>nul 2>nul || @set "path=%~dps0..\windbg;%path%"
if {"%~2"}=={""} call tools_vs.bat vsInstallPath newest "%~1"
if not {"%~2"}=={""} call tools_vs.bat vsInstallPath "%~2" "%~1"
goto :eof
::[DOS_API:FindPathNotepad++]find notepad++ application install path
::usage : call :FindPathNotepad++ appPath
::result e.g : set appPath=C:\somepath
:FindPathNotepad++
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
:: improve performance by checking the default install path first
:: if you have installed notepad++ in other path, you can define disablePathMsg_notepad++ to disable this warning.
:: e.g: set disablePathMsg_notepad++=1
if exist "C:\Program Files\Notepad++\notepad++.exe" (
set "%~1=C:\Program Files\Notepad++"
goto :eof
)
call :pathVar.check "notepad++.exe" %~1
if not defined %~1 call :evnVar.check g_NppDir "%~1"
if not defined %~1 call tools_path.bat FindAppPathInReg "HKEY_CURRENT_USER\Software\Classes\Applications\notepad++.exe\shell\open\command" %~1
if not defined %~1 call tools_path.bat FindAppPathinDisk "notepad++.exe" "%~1"
call :evnVar.set g_NppDir "%~1"
goto :eof
::[DOS_API:FindPathPython]find python application install path
::usage : call :FindPathPython appPath
::result e.g : set appPath=C:\somepath
:FindPathPython
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :pathVar.check "python.exe" %~1
call :evnVar.set g_pythonDir "%~1"
goto :eof
::[DOS_API:pythonModuleInstalled]check whether python extension is installed.
::usage : call tools_path.bat pythonModuleInstalled pythonAppName bOutputValue
::outVar : bOutputValue
::example : set bOutputValue=1
:: : call tools_path.bat pythonModuleInstalled "Scrapy" bScrapyInstalled
:: : bScrapyInstalled=1
:pythonModuleInstalled
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set %~2=
for /f "usebackq tokens=1" %%i in ( ` pip list 2^>^&1 ^| find /i "%~1" ` ) do set %~2=1
goto :eof
::************************************ inner implement begin **********************************************************************************************
:pathVar.check
:: call :pathVar.check "myApp.exe" appPath
:: call :pathVar.check "myApp.exe" appPath "..\..\otherFolder"
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
where "%~nx1" 1>nul 2>nul || goto :eof
if not defined disablePathMsg_%~n1 call tools_message.bat warningMsg "'%~nx1' is already in your path. needn't to find its path. define disablePathMsg_%~n1 to disable this warning. "
for /f "tokens=*" %%i in ( "%~nx1" ) do set "%~2=%%~dp$path:i%~3"
call tools_path.bat ToNormalPath "%~2"
goto :eof
:evnVar.check
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not defined %~1 goto :eof
call set "_tmpEnvPath=%%%~1%%"
if {"%~1"}=={"%~2"} if exist "%_tmpEnvPath%" goto :eof
if exist "%_tmpEnvPath%" set "%~2=%_tmpEnvPath%"
if not exist "%_tmpEnvPath%" set "%~1=" >nul & start setx %~1 "" >nul
goto :eof
:evnVar.set
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if {"%~1"}=={"%~2"} goto :eof
if not defined %~2 goto :eof
if defined %~1 goto :eof
call tools_message.bat enableDebugMsg "%~0" "setx %~1 %%%~2%%"
call echo call setx %~1 "%%%~2%%"
call setx %~1 "%%%~2%%"
goto :eof
::************************************ inner implement end **********************************************************************************************
:End
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [----- %~nx0] commandLine: %0 %* & @echo.