1@echo off
2
3:: ###############################################################################
4:: #
5:: # Copyright (C) 2009-2013 Nintendo.  All rights reserved.
6:: #
7:: # These coded instructions, statements, and computer programs contain
8:: # proprietary information of Nintendo of America Inc. and/or Nintendo
9:: # Company Ltd., and are protected by Federal copyright law.  They may
10:: # not be disclosed to third parties or copied or duplicated in any form,
11:: # in whole or in part, without the prior written consent of Nintendo.
12:: #
13:: ###############################################################################
14
15:: Run setbridgeconfig to update INI file
16setbridgeconfig.exe %*
17if not "%errorlevel%"=="0" (
18    :: Something went wrong; setbridgeconfig should have
19    :: issued an error message, so let's just die here.
20    exit /b 1
21)
22
23set is_default=0
24if "%1"=="-default" (
25    set is_default=1
26    shift
27)
28set bridge_name=%1
29set bridge_ipaddr=
30
31:: Look up the bridges IP from the INI file by name.
32::   This allows us to set the bridge by it's name only.
33for /f "eol=; tokens=1,2 delims==" %%i in (%APPDATA%\bridge_env.ini) do (
34    if "BRIDGE_NAME_%bridge_name%"=="%%i" (
35        set bridge_ipaddr=%%j
36    )
37)
38
39if "%bridge_ipaddr%"=="" (
40    :: Must've deleted a bridge with "-d" option...
41    :: TODO: Should I clear the BRIDGE_CURRENT_* variables, or set them to
42    ::       the default bridge, if we cleared the current session's bridge?
43    echo Cleared stored IP address for %bridge_name%. ^(current environment unchanged^).
44) else (
45    if "%is_default%"=="1" (
46        echo Setting hostbridge for current session ^(and default^) to %bridge_name% %bridge_ipaddr%.
47    ) else (
48        echo Setting hostbridge for current session to %bridge_name% %bridge_ipaddr%.
49    )
50
51    set BRIDGE_CURRENT_NAME=%bridge_name%
52    set BRIDGE_CURRENT_IP_ADDRESS=%bridge_ipaddr%
53
54    if "%SESSION_MANAGER%"=="1" goto multisession
55)
56
57goto END
58
59:multisession
60
61:: Call the SessionManager to get the session information
62for /f "usebackq tokens=1,2,3,4,5,6,7" %%a in (`"%MION_BRIDGE_TOOLS%\SessionManagerUtil" -p NAME DEBUG_OUT DEBUG_CONTROL HIO_OUT LAUNCH_CTRL NET_MANAGE PCFS_SATA`) do (
63    set SESSION_NAME=%%a
64    set SESSION_DEBUG_OUT_PORT=%%b
65    set SESSION_DEBUG_CONTROL_PORT=%%c
66    set SESSION_HIO_OUT_PORT=%%d
67    set SESSION_LAUNCH_CTRL_PORT=%%e
68    set SESSION_NET_MANAGE_PORT=%%f
69    set SESSION_PCFS_SATA_PORT=%%g
70)
71
72set SESSION_PATH_PREFIX=%SESSION_NAME%_
73set CAFE_DATA_DIR=%CAFE_ROOT%\%SESSION_PATH_PREFIX%data
74if "%CAFE_CONTENT_DEFAULT%"=="1" set CAFE_CONTENT_DIR=%CAFE_DATA_DIR%\disc\content
75if "%CAFE_META_DEFAULT%"=="1" set CAFE_META_DIR=%CAFE_DATA_DIR%\disc\meta
76if "%CAFE_SAVE_DEFAULT%"=="1" set CAFE_SAVE_DIR=%CAFE_DATA_DIR%\save
77if "%CAFE_SLC_DEFAULT%"=="1" set CAFE_SLC_DIR=%CAFE_DATA_DIR%\slc
78if "%CAFE_MLC_DEFAULT%"=="1" set CAFE_MLC_DIR=%CAFE_DATA_DIR%\mlc
79set CAFE_DATA_TMP=%CAFE_DATA_DIR%/tmp
80
81if not "%bridge_ipaddr%"=="" (
82title Multi-Cafe Session for %bridge_name%^(%bridge_ipaddr%^)
83) else (
84title Multi-Cafe Session
85)
86
87
88:END
89
90set bridge_name=
91set bridge_ipaddr=
92set is_default=
93