-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.bat
85 lines (78 loc) · 2.35 KB
/
init.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
@echo off
setlocal enabledelayedexpansion
set NAMEARG=%1
:loop
if "%NAMEARG%"=="" (
echo Enter Mod Name:
set /p MODNAME=""
echo !MODNAME!>%~dp0/init.modname
) else (
set MODNAME=%NAMEARG%
set "NAMEARG="
)
:: skip verification
::goto exitloop
:: findstr character classes are horribly cursed
:: https://stackoverflow.com/a/8767815
findstr /r /c:"[^0123-9aAb-Cd-EfFg-Ij-NoOp-St-Uv-YzZ _-]" %~dp0/init.modname >nul 2>&1
if errorlevel 1 ( echo. ) else (
echo !!! Name contains invalid characters.
echo Valid characters include \`a-zA-Z0-9 _-\`
set "MODNAME="
goto loop
)
echo Checking for duplicates...
if not exist init.modlist (
:: first command for Win7 compat
powershell -Command "& {[Net.ServicePointManager]::SecurityProtocol = ""Tls, Tls11, Tls12, Ssl3\"";Invoke-WebRequest (Invoke-WebRequest https://everestapi.github.io/modupdater.txt).Content -OutFile init.modlist}"
)
:: in case powershell fails
if exist init.modlist (
findstr /b /l /c:"%MODNAME%:" %~dp0/init.modlist >nul 2>&1
if errorlevel 1 ( echo. ) else (
echo Name already in use^^!
goto loop
)
)
:exitloop
:: this is an absolute mess
setlocal enableextensions disabledelayedexpansion
:recurse
for %%f in (*) do (
:: ignore .* files (.gitignore)
echo %%f|findstr /b \.>nul 2>&1
if errorlevel 1 (
:: ignore init.* files (like this one!)
echo %%f|findstr /b init>nul 2>&1
)
if errorlevel 1 (
echo %%f
>"%%f.tmp" (
for /f "delims=" %%i in ('findstr /n "^" "%%f"') do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:*:=!"
if defined line set "line=!line:$MODNAME$=%MODNAME%!"
echo(!line!
endlocal
)
)
move /y "%%f.tmp" "%%f" >nul
set "file=%%f"
setlocal enabledelayedexpansion
move /y "%%f" "!file:$MODNAME$=%MODNAME%!
endlocal
)
)
for /D %%d in (*) do (
echo %%d|findstr /b \.>nul 2>&1
if errorlevel 1 (
pushd %%d
call :recurse
popd
)
)
echo Initialization Complete.
del "%~dp0/README.md"
del "%~dp0/LICENSE"
(goto) 2>nul & del "%~dp0/init.*" rem delete init files