-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftpSetWiiuFirmwareUpdateMode.bat
225 lines (176 loc) · 7.4 KB
/
ftpSetWiiuFirmwareUpdateMode.bat
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
@echo off
setlocal EnableExtensions
REM : ------------------------------------------------------------------
REM : main
setlocal EnableDelayedExpansion
color 4F
set "THIS_SCRIPT=%~0"
title Set Wii-U Firmware Update Mode
REM : directory of this script
set "SCRIPT_FOLDER="%~dp0"" && set "HERE=!SCRIPT_FOLDER:\"="!"
pushd !HERE!
set "RESOURCES_PATH="!HERE:"=!\resources""
set "WinScpFolder="!RESOURCES_PATH:"=!\winSCP""
set "WinScp="!WinScpFolder:"=!\WinScp.com""
set "cmdOw="!RESOURCES_PATH:"=!\cmdOw.exe"" if not exist !LOGS! mkdir !LOGS! > NUL 2>&1
REM : set current char codeset
call:setCharSet
REM : checking arguments
set /A "nbArgs=0"
:continue
if "%~1"=="" goto:end
set "args[%nbArgs%]="%~1""
set /A "nbArgs +=1"
shift
goto:continue
:end
if %nbArgs% NEQ 0 goto:treatArgs
echo =========================================================
echo Set the WiiU firmware update feature mode
echo =========================================================
echo.
echo y : enabling firmware update on the Wii-U
echo n : disabling firmware update on the Wii-U
REM : Wii-U firmaware update mode
REM : 0 : disable update
REM : 1 : enable update
set /A "wfum=0"
echo.
choice /C yn /N /M "Do you want to enable the firmware update on your wii-U (y, n)? : "
if !ERRORLEVEL! EQU 1 set /A "wfum=1
if !wfum! EQU 1 (
echo Continue with allowing firmware upate on your Wii-U ^?
echo.
pause
) else (
echo Continue with disabling firmware upate on your Wii-U ^?
echo.
pause
)
goto:inputsAvailable
:treatArgs
if %nbArgs% GTR 1 (
echo ERROR on arguments passed ^(%nbArgs%^)
echo SYNTAX^: "!THIS_SCRIPT!" OFF^(or ON^)
echo given {%*}
pause
exit /b 9
)
REM : get and check str
set "str=!args[0]!"
if [!str!] == ["ON"] set /A "wfum=1"
:inputsAvailable
cls
if !wfum! EQU 1 (
title Enabling Wii-U Firmware Update feature
) else (
title Disabling Wii-U Firmware Update feature
)
echo On your Wii-U^, you need to ^:
echo - launch WiiU FTP Server and press B to mount NAND paths
echo - get the IP adress displayed on Wii-U gamepad
echo.
echo Press any key to continue when you^'re ready
echo ^(CTRL-C^) to abort
pause
cls
set "winScpIniTmpl="!WinScpFolder:"=!\WinSCP.ini-tmpl""
set "winScpIni="!WinScpFolder:"=!\WinScp.ini""
if not exist !winScpIni! goto:getWiiuIp
REM : get the hostname
set "ipRead="
for /F "delims=~= tokens=2" %%i in ('type !winScpIni! ^| find "HostName="') do set "ipRead=%%i"
if ["!ipRead!"] == [""] goto:getWiiuIp
REM : and the port
set "portRead="
for /F "delims=~= tokens=2" %%i in ('type !winScpIni! ^| find "PortNumber="') do set "portRead=%%i"
if ["!portRead!"] == [""] goto:getWiiuIp
echo Found an existing FTP configuration ^:
echo.
echo PortNumber=!ipRead!
echo HostName=!portRead!
echo.
choice /C yn /N /M "Use this setup (y, n)? : "
if !ERRORLEVEL! EQU 1 set "wiiuIp=!ipRead!" && goto:checkConnection
:getWiiuIp
set /P "wiiuIp=Please enter your Wii-U local IP adress : "
set /P "port=Please enter the port used : "
REM : prepare winScp.ini file
copy /Y !winScpIniTmpl! !winScpIni! > NUL 2>&1
set "fnrLog="!HERE:"=!\logs\fnr_WinScp.log""
REM : set WiiU ip adress
!StartHiddenWait! !fnrPath! --cl --dir !WinScpFolder! --fileMask WinScp.ini --find "FTPiiU-IP" --replace "!wiiuIp!" --logFile !fnrLog!
!StartHiddenWait! !fnrPath! --cl --dir !WinScpFolder! --fileMask WinScp.ini --find "FTPiiU-port" --replace "!port!" --logFile !fnrLog!
:checkConnection
cls
REM : check its state
set /A "state=0"
call:getHostState !wiiuIp! state
if !state! EQU 0 (
echo ERROR^: !wiiuIp! was not found on your network ^!
echo exiting 2
if %nbArgs% EQU 0 pause && exit 2
if %nbArgs% NEQ 0 exit /b 2
)
set "ftplogFile="!HERE:"=!\logs\ftpCheck_swfum.log""
!winScp! /command "option batch on" "open ftp://USER:PASSWD@!wiiuIp!/ -timeout=5 -rawsettings FollowDirectorySymlinks=1 FtpForcePasvIp2=0 FtpPingType=0" "ls /storage_mlc/usr/save/system/act" "exit" > !ftplogFile! 2>&1
type !ftplogFile! | find /I "Connection failed" > NUL 2>&1 && (
echo ERROR ^: unable to connect^, check that your Wii-U is powered on and that WiiuFtpServer is launched
echo WiiuFtpServer was launched with mounting NAND paths ^(press B^)
echo Pause this script until you fix it ^(CTRL-C to abort^)
pause
goto:checkConnection
)
type !ftplogFile! | find /I "Could not retrieve directory listing" > NUL 2>&1 && (
echo ERROR ^: unable to list games on NAND^, launch MOCHA CFW before WiiuFtpServer on the Wii-U
echo Pause this script until you fix it ^(CTRL-C to abort^)
pause
goto:checkConnection
)
cls
REM : in function of wfum
if !wfum! EQU 0 (
echo.
echo Disabling firmware update on your Wii-U^.^.^.
echo.
REM : disable firmware update on the Wii-U
!winScp! /command "open ftp://USER:PASSWD@!wiiuIp!/ -timeout=5 -rawsettings FollowDirectorySymlinks=1 FtpForcePasvIp2=0 FtpPingType=0" "option batch on" "rmdir /storage_mlc/sys/update" "option batch off" "exit" > !ftplogFile! 2>&1
) else (
REM : enable firmware update on the Wii-U
echo.
echo Enabling firmware update on your Wii-U^.^.^.
echo.
!winScp! /command "open ftp://USER:PASSWD@!wiiuIp!/ -timeout=5 -rawsettings FollowDirectorySymlinks=1 FtpForcePasvIp2=0 FtpPingType=0" "option batch on" "mkdir /storage_mlc/sys/update" "option batch off" "exit" > !ftplogFile! 2>&1
)
echo done
if %nbArgs% EQU 0 pause & exit 0
if %nbArgs% NEQ 0 timeout /T 4 > NUL 2>&1 & exit /b 0
goto:eof
REM : ------------------------------------------------------------------
REM : ------------------------------------------------------------------
REM : functions
:getHostState
set "ipaddr=%~1"
set /A "state=0"
ping -n 1 !ipaddr! > NUL 2>&1
if !ERRORLEVEL! EQU 0 set /A "state=1"
set "%2=%state%"
goto:eof
REM : ------------------------------------------------------------------
REM : function to get and set char set code for current host
:setCharSet
REM : get charset code for current HOST
set "CHARSET=NOT_FOUND"
for /F "tokens=2 delims=~=" %%f in ('wmic os get codeset /value 2^>NUL ^| find "="') do set "CHARSET=%%f"
if ["%CHARSET%"] == ["NOT_FOUND"] (
echo Host char codeSet not found in %0 ^?
timeout /t 8 > NUL 2>&1
exit /b 9
)
REM : set char code set, output to host log file
chcp %CHARSET% > NUL 2>&1
REM : get locale for current HOST
set "L0CALE_CODE=NOT_FOUND"
for /F "tokens=2 delims=~=" %%f in ('wmic path Win32_OperatingSystem get Locale /value 2^>NUL ^| find "="') do set "L0CALE_CODE=%%f"
goto:eof
REM : ------------------------------------------------------------------