-
Notifications
You must be signed in to change notification settings - Fork 14
/
Driver Downloader.cmd
249 lines (212 loc) · 8.13 KB
/
Driver Downloader.cmd
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
:: This file is licensed under the Microsoft Reciprocal License (MS-RL).
:: A copy of this license is provided in the file LICENSE-SCRIPTS.txt.
@echo off
set "CurrentDir=%~dp0"
if "%CurrentDir:!=%" NEQ "%CurrentDir%" (
echo Please remove exclamation marks ^(^!^) from the current path.
pause
exit /B
)
setlocal EnableDelayedExpansion
cd /D "%~dp0"
for /f "tokens=3" %%a in ('Reg Query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuild ^| findstr /r /i "REG_SZ"') do set "WinBuild=%%a"
if %WinBuild% LSS 10586 (
Files\ansicon_%PROCESSOR_ARCHITECTURE% -p
)
title WFAv7 Driver Downloader 4.2
color 0f
set "ESC="
goto ChooseDev
::---------------------------------------------------------------
:PrintLabel
echo %ESC%[93m//////////////////////////////////////////////////////////////////////////////////////////////
echo // %ESC%[97mWFAv7 Driver Downloader 4.2%ESC%[93m //
echo // %ESC%[97mby RedGreenBlue123%ESC%[93m //
echo //////////////////////////////////////////////////////////////////////////////////////////////%ESC%[92m
echo.
goto :EOF
::------------------------------------------------------------------
:ChooseDev
set "Model="
cls
call :PrintLabel
echo %ESC%[92mChoose your device model below:
echo %ESC%[36m1) %ESC%[97mLumia 1520
echo %ESC%[36m2) %ESC%[97mLumia 930
echo %ESC%[36m3) %ESC%[97mLumia 929 (Icon)
echo %ESC%[36m4) %ESC%[97mLumia 830 Global
echo %ESC%[36m5) %ESC%[97mLumia 735 Global
echo %ESC%[36m6) %ESC%[97mLumia 650
echo %ESC%[36m7) %ESC%[97mLumia 640 / 640 XL
echo %ESC%[36m8) %ESC%[97mLumia 1020
echo %ESC%[36m9) %ESC%[97mLumia 920
echo %ESC%[36mA) %ESC%[97mLumia 520
set /p "Model=%ESC%[92mDevice:%ESC%[0m "
if not defined Model goto ChooseDev
set "Model=%Model:"=%"
if "%Model%" EQU "1" (goto ChooseDev1520)
if "%Model%" EQU "2" (set "ModelDir=Lumia930" & set "DefName=930.xml" & goto DoDownload)
if "%Model%" EQU "3" (set "ModelDir=LumiaIcon" & set "DefName=icon.xml" & goto DoDownload)
if "%Model%" EQU "4" (set "ModelDir=Lumia830" & set "DefName=830.xml" & goto DoDownload)
if "%Model%" EQU "5" (set "ModelDir=Lumia735" & set "DefName=735.xml" & goto DoDownload)
if "%Model%" EQU "6" (set "ModelDir=Lumia650" & set "DefName=650.xml" & goto DoDownload)
if "%Model%" EQU "7" (goto ChooseDev640)
if "%Model%" EQU "8" (goto ChooseDev1020)
if "%Model%" EQU "9" (set "ModelDir=Lumia920" & set "DefName=920.xml" & goto DoDownload)
if /i "%Model%" EQU "A" (set "ModelDir=Lumia520" & set "DefName=520.xml" & goto DoDownload)
goto ChooseDev
:ChooseDev1520
set "Model="
cls
call :PrintLabel
echo %ESC%[92mChoose your device variant below:
echo %ESC%[36m1) %ESC%[97mLumia 1520 Global
echo %ESC%[36m2) %ESC%[97mLumia 1520 AT^&T
set /p "Model=%ESC%[92mDevice:%ESC%[0m "
if not defined Model goto ChooseDev1520
set "Model=%Model:"=%"
if "%Model%" EQU "1" (set "ModelDir=Lumia1520" & set "DefName=1520upsidedown.xml" & goto DoDownload)
if "%Model%" EQU "2" (set "ModelDir=Lumia1520-AT&T" & set "DefName=1520attupsidedown.xml" & goto DoDownload)
goto ChooseDev1520
:ChooseDev640
set "Model="
cls
call :PrintLabel
echo %ESC%[92mChoose your device variant below:
echo %ESC%[36m1) %ESC%[97mLumia 640 3G
echo %ESC%[36m2) %ESC%[97mLumia 640 LTE
echo %ESC%[36m3) %ESC%[97mLumia 640 XL 3G
echo %ESC%[36m4) %ESC%[97mLumia 640 XL LTE Global
echo %ESC%[36m5) %ESC%[97mLumia 640 XL LTE AT^&T
set /p "Model=%ESC%[92mDevice:%ESC%[0m "
if not defined Model goto ChooseDev640
set "Model=%Model:"=%"
if "%Model%" EQU "1" (set "ModelDir=Lumia640-3G" & set "DefName=640ds.xml" & goto DoDownload)
if "%Model%" EQU "2" (set "ModelDir=Lumia640-LTE" & set "DefName=640lte.xml" & goto DoDownload)
if "%Model%" EQU "3" (set "ModelDir=Lumia640XL-3G" & set "DefName=640xlds.xml" & goto DoDownload)
if "%Model%" EQU "4" (set "ModelDir=Lumia640XL-LTE" & set "DefName=640xl.xml" & goto DoDownload)
if "%Model%" EQU "5" (set "ModelDir=Lumia640XL-AT&T" & set "DefName=640xlatt.xml" & goto DoDownload)
goto ChooseDev640
:ChooseDev1020
set "Model="
cls
call :PrintLabel
echo %ESC%[92mChoose your device variant below:
echo %ESC%[36m1) %ESC%[97mLumia 1020 Global
echo %ESC%[36m2) %ESC%[97mLumia 1020 AT^&T
set /p "Model=%ESC%[92mDevice:%ESC%[0m "
if not defined Model goto ChooseDev1020
set "Model=%Model:"=%"
if "%Model%" EQU "1" (set "ModelDir=Lumia1020" & set "DefName=1020.xml" & goto DoDownload)
if "%Model%" EQU "2" (set "ModelDir=Lumia1020-AT&T" & set "DefName=1020att.xml" & goto DoDownload)
goto ChooseDev1020
::------------------------------------------------------------------
:DoDownload
:: set "RepoLink=https://github.com/WOA-Project/Lumia-Drivers.git"
set "RepoLink=https://github.com/bibarub/Lumia-Drivers.git"
set "GitPath=%~dp0\Files\DriverDownloader\Git\cmd\git"
cls
if not exist Drivers\ md Drivers\
if not exist Temp\ md Temp\
echo Fetching latest release tag ...
"%GitPath%" ls-remote --tags "%RepoLink%" >Temp\Tags.txt || (
del Temp\Tags.txt
goto DownloadFailed
)
:: The last line is the latest tag
for /f "tokens=2 delims= " %%A in (Temp\Tags.txt) do (
set "Tag=%%A"
)
del Temp\Tags.txt
:: Remove refs/tags/
set "Tag=%Tag:~10%"
::------------------------------------------------------------------
set "InstallerDir=%~dp0"
set "RepoDir=%InstallerDir%\Drivers\%ModelDir%"
if exist "%RepoDir%\" (
echo Removing old drivers ...
rd /s /q "%RepoDir%"
)
echo.
echo Setting up the repository...
echo.
md "%RepoDir%"
"%GitPath%" clone --filter=tree:0 --no-checkout --depth 1 --branch %Tag% "%RepoLink%" "%RepoDir%" || goto DownloadFailed
"%GitPath%" -C "%RepoDir%" sparse-checkout set --no-cone
"%GitPath%" -C "%RepoDir%" config core.ignorecase true
"%GitPath%" -C "%RepoDir%" config core.autocrlf false
::------------------------------------------------------------------
echo.
echo Downloading definition file ...
echo.
echo>"%RepoDir%\.git\info\sparse-checkout" definitions/%DefName% || goto DownloadFailed
"%GitPath%" -C "%RepoDir%" checkout || goto DownloadFailed
echo.
echo Enumerating INF files ...
echo.
Files\DriverDownloader\DriverDefPaths "%RepoDir%\definitions\%DefName%" >Temp\InfList.txt || (
del Temp\InfList.txt
goto DownloadFailed
)
for /f "usebackq delims=" %%A in ("Temp\InfList.txt") do (
set "InfPath=%%A"
set "InfPath=!InfPath:\=/!"
echo>>"%RepoDir%\.git\info\sparse-checkout" !InfPath!
)
echo.
echo Downloading INF files ...
echo.
"%GitPath%" -C "%RepoDir%" checkout || goto DownloadFailed
::------------------------------------------------------------------
echo.
echo Enumerating driver source files ...
echo.
for /f "usebackq delims=" %%A in ("Temp\InfList.txt") do (
set "MyPath=%%A"
call :FilePathOnly
set "InfPathOnly=!Output!"
Files\DriverDownloader\GetDriverFiles ".\Drivers\%ModelDir%\%%A" >"Temp\DriverSourceList.txt" || (
del Temp\DriverSourceList.txt
del Temp\InfList.txt
goto DownloadFailed
)
for /f "usebackq delims=" %%B in ("Temp\DriverSourceList.txt") do (
set "SourcePath=!InfPathOnly!%%B"
set "SourcePath=!SourcePath:\=/!"
echo>>"%RepoDir%\.git\info\sparse-checkout" !SourcePath!
)
)
if exist "Temp\DriverSourceList.txt" del "Temp\DriverSourceList.txt"
del "Temp\InfList.txt"
echo.
echo Downloading driver source files ...
echo.
"%GitPath%" -C "%RepoDir%" checkout || goto DownloadFailed
::------------------------------------------------------------------
rd /s /q "%RepoDir%\.git\"
echo.
echo Drivers have been downloaded successfully.
pause
goto ChooseDev
:DownloadFailed
echo.
echo Failed to download drivers.
pause
goto ChooseDev
::------------------------------------------------------------------
:FilePathOnly
set "MyPath2=%MyPath:/=\%"
set "MyPath2=%MyPath2: =/%"
set "MyPath2="%MyPath2:\=" "%""
set "Output="
set "Output2="
for %%A in (%MyPath2%) do (
set "Line=%%~A"
if "!Line!" NEQ "" (
set "Output=!Output2!"
set "Output2=!Output2!!Line:/= !\"
)
)
:: Edge case: trailing slash
if "%Line%" EQU "" set "Output=%Output2%"
goto :EOF