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
15REM
16REM THIS SCRIPT SETS DEFAULT OPTIONS FOR OPENING A CAFE WINDOW.  IT'S THE
17REM SAME AS RUNNING "cafe.bat [-option ...] -default".
18REM
19
20:: ************************************************************
21:: * CAFE - Environment
22:: ************************************************************
23
24: From here, variable changes to do not affect environment
25SETLOCAL
26
27set _ME=%~nx0
28
29REM ***
30REM Set options
31
32REM Don't take any current settings from the environment
33    set _SETDEFAULTS=
34    set USE_CAFEX=
35    set SESSION_MANAGER=
36    set DO_SYNC_SESSION=
37    set USE_PCFS_OVER_SATA=
38    set USE_CYGWIN=
39
40REM Commandline (per-invocation) options.  Takes precedence.
41    :getopt
42    if "%~1" == "" goto :getopt_done
43
44    for %%i in (-h -help --help) do if "%~1" == "%%i" goto :usage
45    if "%~1" == "-?" goto :usage && REM "-?" doesn't work in "for" loop 8-(
46
47    set _SETDEFAULTS=1
48
49    if /i "%~1" == "-cafex" set USE_CAFEX=1&& goto :getopt_next
50    if /i "%~1" == "-nocafex" set USE_CAFEX=0&& goto :getopt_next
51    if /i "%~1" == "-multi" set SESSION_MANAGER=1&& goto :getopt_next
52    if /i "%~1" == "-nomulti" set SESSION_MANAGER=0&& goto :getopt_next
53    if /i "%~1" == "-session" set SESSION_MANAGER=1&& goto :getopt_next
54    if /i "%~1" == "-nosession" set SESSION_MANAGER=0&& goto :getopt_next
55    if /i "%~1" == "-syncsession" set DO_SYNC_SESSION=1&& goto :getopt_next
56    if /i "%~1" == "-nosyncsession" set DO_SYNC_SESSION=0&& goto :getopt_next
57    if /i "%~1" == "-pcfsoversata" set USE_PCFS_OVER_SATA=1&& goto :getopt_next
58    if /i "%~1" == "-nopcfsoversata" set USE_PCFS_OVER_SATA=0&& goto :getopt_next
59    if /i "%~1" == "-cygwin" set USE_CYGWIN=1&& goto :getopt_next
60    if /i "%~1" == "-nocygwin" set USE_CYGWIN=0&& goto :getopt_next
61
62    if /i "%~1" == "-reset" set _RESET_CONFIG=1&& goto :getopt_next
63
64    echo. && echo ERROR! Unrecognized option '%~1'! && goto :usage
65
66    :getopt_next
67    shift
68    goto :getopt
69
70    :getopt_done
71
72REM Read defaults from config file, for anything that's not set yet.
73    set _CONFIG=%APPDATA%\Nintendo\cafe.defaults
74    if NOT EXIST "%_CONFIG%" goto :update_config
75
76    if NOT "%_RESET_CONFIG%" == "" goto :update_config
77
78    for /f "tokens=1,2 delims==" %%i in (%_CONFIG%) do call :set_config_value %%i %%j
79    if not exist "%APPDATA%\disable_pcfs_over_sata" goto :update_config
80        REM old "pcfs_over_sata" sentinel exists; update to new config file
81        set USE_PCFS_OVER_SATA=0
82        del /f "%APPDATA%\disable_pcfs_over_sata" 2>nul
83    goto :update_config
84
85    :set_config_value
86    if "%USE_CAFEX%" == "" if /i "%1" == "USE_CAFEX" set USE_CAFEX=%2
87    if "%SESSION_MANAGER%" == "" if /i "%1" == "SESSION_MANAGER" set SESSION_MANAGER=%2
88    if "%SESSION_MANAGER%" == "" if /i "%1" == "USE_MULTI" set SESSION_MANAGER=%2
89    if "%DO_SYNC_SESSION%" == "" if /i "%1" == "DO_SYNC_SESSION" set DO_SYNC_SESSION=%2
90    if "%USE_PCFS_OVER_SATA%" == "" if /i "%1" == "USE_PCFS_OVER_SATA" set USE_PCFS_OVER_SATA=%2
91    if "%USE_CYGWIN%" == "" if /i "%1" == "USE_CYGWIN" set USE_CYGWIN=%2
92    goto :eof
93
94    :update_config
95    REM rewrite config file if requested; NOT "thread-safe"!
96    set _CONFIG="%_CONFIG%"
97    for %%i in (%_CONFIG%) do md %%~dpi 2>nul
98    del /f %_CONFIG% 2>nul
99    copy /y NUL %_CONFIG% 1>nul 2>nul
100    if NOT EXIST %_CONFIG% echo WARNING! Could not save options as default! && goto :config_done
101    for %%i in (%_CONFIG%) do if NOT "%%~zi" == "0" echo WARNING! Could not save options as default! && goto :config_done
102
103    if NOT "%USE_CAFEX%" == "" >>%_CONFIG% echo USE_CAFEX=%USE_CAFEX%
104    if NOT "%SESSION_MANAGER%" == "" >>%_CONFIG% echo SESSION_MANAGER=%SESSION_MANAGER%
105    if NOT "%DO_SYNC_SESSION%"  == "" >>%_CONFIG% echo DO_SYNC_SESSION=%DO_SYNC_SESSION%
106    if NOT "%USE_PCFS_OVER_SATA%"  == "" >>%_CONFIG% echo USE_PCFS_OVER_SATA=%USE_PCFS_OVER_SATA%
107    if NOT "%USE_CYGWIN%" == "" >>%_CONFIG% echo USE_CYGWIN=%USE_CYGWIN%
108    :config_done
109    set _CONFIG=
110
111REM Display current settings
112    echo Currently saved options:
113    if "%USE_CAFEX%" == "0" echo    -nocafex
114    if "%USE_CAFEX%" == "1" echo    -cafex
115    if "%SESSION_MANAGER%" == "0" echo    -nomulti
116    if "%SESSION_MANAGER%" == "1" echo    -multi
117    if "%DO_SYNC_SESSION%"  == "0" echo    -nosyncsession
118    if "%DO_SYNC_SESSION%"  == "1" echo    -syncsession
119    if "%USE_PCFS_OVER_SATA%"  == "0" echo    -nopcfsoversata
120    if "%USE_PCFS_OVER_SATA%"  == "1" echo    -pcfsoversata
121    if "%USE_CYGWIN%" == "0" echo    -nocygwin
122    if "%USE_CYGWIN%" == "1" echo    -cygwin
123
124REM Are we running in a Bash shell?
125if not "%SHLVL%" == "" if not "%_SETDEFAULTS%" == "" echo *** Options will take effect the next time you open a Cafe window!
126
127goto :end
128
129:usage
130echo.
131echo ==================================================
132echo NINTENDO CAFE ENVIRONMENT!
133echo ==================================================
134echo.
135echo Usage: %_ME% [options]
136echo.
137echo Options:
138echo    -cafex           Use CafeX to run applications (default)
139echo    -nocafex         Do not use CafeX; uses Cygwin shell scripts
140echo    -multi           Enable multisession CAFE support
141echo    -nomulti         Do not enable multisession support (default)
142echo    -syncsession     Copy per-session files (default)
143echo    -nosyncsession   Do not copy files; data files shared across sessions
144echo    -pcfsoversata    Enable PCFS over SATA (default)
145echo    -nopcfsoversata  Disable PCFS over SATA; use PCFS over SDIO
146echo    -cygwin          Use Cygwin (default)
147echo    -nocygwin        Do not use Cygwin; for running apps only
148echo.
149echo    -reset           Remove all currently set options
150echo                       (other than ones specified on this commandline)
151echo.
152goto :end
153
154:end
155set _SETDEFAULT=
156ENDLOCAL
157