-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.bat
More file actions
451 lines (447 loc) · 12.1 KB
/
Copy pathmain.bat
File metadata and controls
451 lines (447 loc) · 12.1 KB
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
@echo off
::
:: *-+-+-+-+-+-+-+-+-+-*
:: | WRICE |
:: + aka WZKRice +
:: >=-=-=-=-=-=-=-=-=<
:: + by donnaken15 +
:: | <wesley@gmx.it> |
:: *-+-+-+-+-+-+-+-+-+-*
::
:: spawn in new instance because of stupid call hierarchy
:: effecting `exit /b` which normally ends a script but also
:: applies to subroutines for some reason, literally
:: like batch scripts embedded into others, wtf
if "%~n0"=="cmd" ( set "THIS=%~1" ) else ( set "THIS=%~0" )
:: and because of terminate batch job stuff
:: call helper functions not easily useable in one instance
if "%~1"=="-" (
shift
call:$-%~2 %3 %4 %5 %6 %7 %8 %9
exit /b %ERRORLEVEL%
)
if not "%INSTANCE%"=="1" (
set INSTANCE=1
start "DO NOT TOUCH THIS WINDOW!! This is required for cleanup once the batch script exits." /min cmd /c "%THIS%" %* ^<nul
set INSTANCE=
exit /b
)
if not "%~1"=="+" (
mode CON cols=20 lines=1 >nul
set "WTMP=%tmp%\WZKRICE_%random%\"
set "OLDPATH=%PATH%"
set "__INVOKED=%CMDCMDLINE%"
start "WRICE" /wait cmd /c "%THIS%" + %*
goto quit
exit /b
)
::
:: ------------------------ initialization ------------------------
::
call:wtitle - Initializing - Variables
set "DDIR=%WTMP%deps\"&set "PATH=%PATH%;%DDIR%"&set "WLOG=%~dp0WRICE.LOG"&
echo [%DATE:~4% %TIME%] Loading>%WLOG%&set WIDTH=80&set HEIGHT=28&
set "fixwindow=mode CON COLS=%WIDTH% LINES=%HEIGHT%"&
%fixwindow%&&cls&
set ROOT=https://github.com/donnaken15/wrice/raw/main/&
set LOG=^>^>"%WLOG%"&set Q=^>nul
:: don't know if i should just even deal with colors here because it's recently
:: added to windows 10 even if i use a compatibility layer like ansicon
set ESC=[
:: because can't just use CP437 symbols, stupid thing
:: (doesn't happen on Cygwin though, which I'm not using because bloat)
set LESSCHARSET=utf-8
:: reg ADD HKCU\Software\Sysinternals\PSexec /v EulaAccepted /t REG_DWORD /d 1 /f
set VER=24.08.14
:: get build number
for /f "tokens=6 delims=. " %%i in ('ver') do set BUILD=%%i
:: if %BUILD% GEQ 16257 // virtual terminal
:: if %BUILD% GEQ 17063 // winver >= 1803 // curl and tar introduced
:: if %BUILD% GEQ 17763 // winver >= 1809 // immersive key removed
:: https://www.anoopcnair.com/windows-10-build-numbers-version-numbers/
:: https://www.tenforums.com/tutorials/89738-enable-disable-wide-context-menus-windows-10-a.html
::
:: most Windows 10 installations will have cURL now
:: if not, get it here and put it in the same directory
:: as the batch file: https://github.com/donnaken15/wrice/raw/main/deps/curl.exe
set sub=call:substitute&set dep=call:dependency&
set subdep=call:substitutedependency&
set seterr=call:seterr&set title=call:wtitle&
set where=where&set ret=exit /b
:: there has to be something like plain file execution calls for this
(set \n=^
%=.=%
)
set to="%WINDIR%\System32\timeout" /T
:: differ from GNU timeout
:: which is faster than where, so check if it's available
call:log `where` time
where which>nul 2>nul&&set where=which
call:log `where` time end
set WARNONCE=0
set ELEVATED=0
call:wtitle - Setting up environment
echo ####### WRICE STARTED %DATE% %TIME% ########%LOG%
mkdir "%WTMP%"&mkdir "%DDIR%"&pushd "%WTMP%"&shift
::
:: ----------------------------------------------------------------
:: for /d %%d in ("%tmp%\WZKRICE_*") do rmdir "%%~d"
:: setlocal enabledelayedexpansion
:: %sub% testvar curl https://donnaken15.com/404
:: echo !testvar!
:: endlocal
:: pause
:home
cls
call:splash
%title%
echo. Improve your Windows experience by giving yourself more freedom,&
echo. customization, personalization, utilities, performance boosts,&
echo. and begin to familiarize yourself with a Unix-like environment&
echo. that can assist you in creating the workflow of your dreams, or&
echo. the most leet multimedia or gaming setup.&echo.&
echo. Requires Windows 10 or Atlas OS&echo.&
echo. Options: (press a key)&
echo. I - Setup (WIP!!)&
echo. C - Credits&
echo. Q - Quit&echo.&
echo. version %VER%&
if "%WARNONCE%"=="0" (
set WARNONCE=1
echo.
echo. Warning: Do not press Ctrl-C at any point in this script.
echo. If you want to abort operations, use the close button or Alt-F4.
echo. And do not resize this window.
)
:homenorefresh
%title%
choice/C ICQ%Q%
goto MENU[0][%ERRORLEVEL%]
:MENU[0][1]
goto premain
:MENU[0][2]
call:readpage credits.txt "Credits"
goto homenorefresh
:MENU[0][3]
%ret%
:MENU[0][END]
goto home
:readpage
%title% - %~2
:: echo loading page %~1
call:getexe curl
:: kind of pointless if you already have it
call:getexe less
::curl -Ls "%ROOT%%~1" | less -R
less -R "%~dp0credits.txt"
%ret%
:: 9999999 iq: curl+less groff page
:: and have to pull all EXEs/DLLs
:: for that
:: %sub% [var] [command]+
:: stupid hack to emulate unix command substitution
:: where output of command is assigned to a variable
:substitute
:: requires enabledelayedexpansion
set STR=
for /f "tokens=1,* delims= " %%a in ("%*") do (
for /f "usebackq tokens=*" %%i in (`%%b`) do ( set "STR=!STR!!\n!%%i" ) )
set "%~1=!STR!"
set STR=
%ret%
:: setlocal enabledelayedexpansion
:: %sub% test printf "2"
:: echo !test!
:: endlocal
:: dep [exe name] [arguments]+
:: find an executable in %PATH%,
:: otherwise download it from me
:dependency
call:getexe %1
%*
%ret%
:substitutedependency
call:getexe %2
%sub% %*
%ret%
:getexe
%WHERE% "%~1" %Q% 2>nul
if exist "%~dp0%~1.exe" ( %seterr% 0 )
if exist "%DDIR%%~1.exe" ( %seterr% 0 )
if "%ERRORLEVEL%"=="1" (
echo Dependency %~1 not on disk, downloading...%LOG% ^
&& call:getbase "%~1.exe" && %seterr% 2 )
:: hack
%ret%
:getbase
curl -Lf "%ROOT%deps/%~1" -o "%DDIR%%~1" 2%LOG% ^
|| echo Failed to get dependency %~1. Exiting... ^
&& %to% 5 && exit
%ret%
:splash
echo.&
echo , ` + /// Welcome to \\\ , * `&
echo - . --+-=-*-({ WRICE })-*-=-+-- ' - + .&
echo * ' - / ( [[[===]]] ) \ . - '&
echo.&
echo windows ricing is completely extinct&
echo.&
%ret%
:wtitle
title WRICE %* & %ret%
:seterr
exit /b %1
:kv
:: example usage:
:: setlocal enabledelayedexpansion
:: call :kv ClassicTheme 1 x
:: echo [ !x! ]
:: endlocal
set got=0
if [%1]==[] exit /b 1
if [%4]==[] (set "f=%~dp0config.ini") else (set "f=%~4")
if exist "!f!" (
for /f "usebackq delims=" %%L in ("!f!") do (
for /f "tokens=1,2 delims==" %%A in ("%%~L") do (
set "x=%~1"
set "y=%%~A"
set "z=%%~B"
call:trim x
call:trim y
call:trim z
if /I "!X!"=="!Y!" (
set got=1
if [%3]==[] (echo.!Z!) else (set "%~3=!Z!")
exit /b 0
)
)
)
)
if "%got%"=="0" (
if not [%2]==[] (
set "x=%~2"
call:trim x
if [%3]==[] (echo.!X!) else (set "%~3=!X!")
) else (echo.)
)
exit /b 0
:trim
:: https://ss64.org/viewtopic.php?t=22
if [%1]==[] exit /b 1
set "inVar=%~1"
set "stripChar=%~2"
if not defined stripChar set "stripChar= "
call set "workVar=%%%inVar%%%"
if "%workVar%"=="" goto t$l3
:: TODO: only count up characters here?
:t$l1
if "%workVar:~-1%" EQU "%stripChar%" (
set "workVar=%workVar:~0,-1%"
goto t$l1
)
:: also trim leading
:t$l2
if "%workVar:~0,1%" EQU "%stripChar%" (
set "workVar=%workVar:~1%"
goto t$l2
)
:t$l3
set "%inVar%=%workVar%"
exit /b 0
:strlen
setlocal enabledelayedexpansion
:: https://www.tutorialspoint.com/batch_script/batch_script_string_length.htm
:: stupid idea: add by 4 for less looping and then subtract if overshot
:strlen_l
if not "!%1:~%len%!"=="" set/a len+=1&goto strlen_l
(endlocal&exit /b %len%)
:fillstr
setlocal enabledelayedexpansion
set i=1
if not [%2]==[] (set "c=%2") else (set "c= ")
set "text=%c%"
:fillstr_l
if %i% LSS %1 (set/a i+=1&set "text=%text%%c%"&goto fillstr_l)
(endlocal&set "fillstr=%text%"&exit /b)
:quit
del /s /q /f "%WTMP%" %q% 2>nul & rmdir "%WTMP%deps" %q% 2>nul & rmdir "%WTMP%" %q% 2>nul
set "PATH=%OLDPATH%"
exit /b
:expr
(setlocal&set /a tmp=%1)&
(endlocal&exit /b %tmp%)
:: seta hah
:premain
:: screw batch
%title% - Checking elevation
if "%ELEVATED%"=="1" goto elevated
:: ELSE (
set SYSDIR=system32
IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" ( set SYSDIR=SysWOW64 )
set "LZ1=%SYSTEMROOT%\%SYSDIR%"
%q% 2>nul "%LZ1%\cacls.exe" "%LZ1%\config\system"
:: cackles
if not "%errorlevel%"=="0" (
rem i'm such a superuser that i can't even test going from unelevated to elevated anymore
rem the temp VBS file has this script ending up at this spot over and over now
echo Elevated privileges are not available.
echo This script cannot run without them.
echo Try rerunning as administrator.
%TO% 10
exit
) else set ELEVATED=1
:: )
:: https://stackoverflow.com/questions/1894967/how-to-request-administrator-access-inside-a-batch-file
:elevated
set OPT_PAGE=1
::goto options
%title% - Setup: LOADING...
call:fillstr %WIDTH%
set fillstr2=%fillstr%
:options
set "o_gray=%ESC%H%ESC%47;30m"
set "o_header=%o_gray%%fillstr2%%ESC%%width%D"&set /a fillwidth=%width%-2
call:fillstr %fillwidth%
set "o_footer=%ESC%46;97m*%fillstr%*%ESC%%fillwidth%D"
%title% - Setup: LOADING...
set scroll=0
set test=1
:opt_page
call:$-INS_o_p%test%h
set/a MSG_W=%width%-%errorlevel%^>^>1
::set tmp3=0
cls&color 1f
:opt_scroll
%fixwindow%&set /a offset=%height%-2&
set/a i=0&set/a ceil=%scroll%+%height%-2
setlocal enabledelayedexpansion
::if !tmp3! EQU 1 (echo %ESC%44;97m)
for /f "usebackq tokens=*" %%v in (`call "%THIS%" - INS_o_p%test%`) do (
if !i! NEQ 0 (
if !i! GTR !ceil! goto why
if !i! GTR !scroll! echo.%ESC%%MSG_W%C%%v
) else (
%title% - Setup: %%v
echo.%o_header% [ %OPT_PAGE%/10] WRICE - Setup: %%v%ESC%44;97m
)
set/a i+=1
)
:why
endlocal
:opt_norefresh
set CC=4&
set "HINT=W: Up, S: Down, A: Prev, D: Next"&
set/a tmp=%width%-%CC%*2-5
::if %tmp3% EQU 0 (
set "tmp2=%ESC%%offset%B%o_footer% %HINT%"
:: set tmp3=1
::) else (
rem HINT GETS ERASED
:: set "tmp2=%ESC%H"
::)
choice/C WSAD /M "%tmp2%%o_gray%%ESC%%tmp%C"
goto MENU[0][%ERRORLEVEL%]
:MENU[0][1]
set/a scroll=%scroll%-1
goto opt_scrollcheck
:MENU[0][2]
set/a scroll=%scroll%+1
:opt_scrollcheck
if %scroll% LSS 0 (echo.&set scroll=0&goto opt_norefresh)
set/a tmp=%pageh%-%height%+2
if %tmp% LEQ 0 (set scroll=0) else (
if %scroll% GTR %tmp% (echo.&set scroll=%tmp%&goto opt_norefresh)
)
goto opt_scroll
:MENU[0][3]
set/a OPT_PAGE=%OPT_PAGE%-1
if %OPT_PAGE% LEQ 0 goto MENU[BREAK]
goto MENU[0][END]
:MENU[0][4]
set/a OPT_PAGE=%OPT_PAGE%+1
goto MENU[0][END]
:MENU[0][END]
echo %ESC%0m
goto opt_page
:MENU[BREAK]
echo %ESC%0m
color&goto home
%ret%
:eulas
%ret%
:log
echo [%DATE:~4% %TIME%] %*%LOG%&%ret%
%ret%
:main
::pushd "%CD%"
::CD /D "%~dp0"
call:log TEST
pause
exit
:MENU[0][0]
color 0c
for /L %%A in (1,1,1000) do ECHO YOU DIDN'T LISTEN!!!!!!
exit
:$-INS_o_p1h
set/a pageh=59
exit /b 51
:: do bitwise/division instead?? console buffer style
:$-INS_o_p1
echo.Test&echo.
echo.This is an instruction where I try to add details,&
echo.but I am just dragging out a sentence where I don't&
echo.even add anything informative to it because I'm&
echo.making an example right now to stylize and test&
echo.my glorified script that breaks Windows.&
echo.---&
echo.alternating text 8&
echo.---&
echo.alternating text 10&
echo.---&
echo.alternating text 12&
echo.---&
echo.alternating text 14&
echo.---&
echo.alternating text 16&
echo.---&
echo.alternating text 18&
echo.---&
echo.alternating text 20&
echo.---&
echo.alternating text 22&
echo.---&
echo.alternating text 24&
echo.---&
echo.alternating text 26&
echo.---&
echo.alternating text 28&
echo.---&
echo.alternating text 30&
echo.---&
echo.alternating text 32&
echo.---&
echo.alternating text 34&
echo.---&
echo.alternating text 36&
echo.---&
echo.alternating text 38&
echo.---&
echo.alternating text 40&
echo.---&
echo.alternating text 42&
echo.---&
echo.alternating text 44&
echo.---&
echo.alternating text 46&
echo.---&
echo.alternating text 48&
echo.---&
echo.alternating text 50&
echo.---&
echo.alternating text 52&
echo.---&
echo.alternating text 54&
echo.---&
echo.alternating text 56&
echo.&
exit /b