我正在为我的朋友编程一些东西,但我的批处理代码不断崩溃。
有人可以帮忙吗?
这是代码:
@echo off
title xinsOS - Boot
echo.
goto load
:load
cls
if exist colour.txt (
goto loadColour
) else (
color 7
goto desktop
)
:loadColour
cls
< colour.txt (
set /p colour=
)
color %colour%
goto desktop
::Oh, you checked the code...
::while your here i could say this is just an hobby
::it will never be an bootable OS
:desktop
cd "%userprofile%\Documents\xinsOS"
cls
title Desktop
echo Desktop
echo.
echo ([1]) Apps
echo ([2]) Info about the CREATOR
echo ([3]) SystemInfo
echo ([4]) Shutdown and Reboot
choice /N /C:1234
if errorlevel 255 goto desktop
if errorlevel 4 goto shutdown
if errorlevel 3 goto sysInfo
if errorlevel 2 goto CREATORinfo
if errorlevel 1 goto apps
if errorlevel 0 goto desktop
:sysInfo
cls
title System info
echo System Info
echo.
echo.
echo Operating system: xinsOS v0.2
echo RAM: 16MB
echo CPU: XINS-I
echo Computer name: XINS-PC-001
echo PC-SERIAL-NUMBER: 0101-1011-1101-1010
pause>nul
goto desktop
:apps
cd DownloadedApps
if exist "xinsPad\xinsPad.bat" (
cls
title Apps - xinsOS
echo.
echo Apps
echo.
echo ([1]) xinsSettings
echo ([2]) xinsPad
echo ([3]) App Store
echo ([4]) Back
choice /N /C:1234
if errorlevel 255 goto apps
if errorlevel 4 goto desktop
if errorlevel 3 goto StartXinsPad
if errorlevel 2 goto appstore
if errorlevel 1 goto xinssettings
if errorlevel 0 goto apps
) else (
echo hi
)
:xinssettings
cls
title Settings - xinsOS
echo.
echo.
echo ([1]) Colors
echo ([2]) Language
echo ([3]) Back
choice /N /C:123
if errorlevel 255 goto xinssettings
if errorlevel 3 goto apps
if errorlevel 2 goto language
if errorlevel 1 goto colors
if errorlevel 0 goto xinssettings
:colors
cls
title Choose colour - xinsOS
echo.
echo.
echo.
echo.
echo Choose Colour:
echo.
echo.
echo ([1]) Red
echo ([2]) Blue
echo ([3]) Matrix style
echo ([4]) Purple
echo ([5]) Aqua
echo ([6]) Back
choice /N /C:123456
if errorlevel 255 goto colors
if errorlevel 6 goto xinssettings
if errorlevel 5 goto SaveAqua
if errorlevel 4 goto SavePurple
if errorlevel 3 goto SaveGreen
if errorlevel 2 goto SaveBlue
if errorlevel 1 goto SaveRed
if errorlevel 0 goto colors
:SaveRed
color 4
echo Saving color settings...
set colour=4
(
echo %colour%
)>colour.txt
goto colors
:SaveBlue
color 1
echo Saving color settings...
set colour=1
(
echo %colour%
)>colour.txt
goto colors
:SaveGreen
color 2
echo Saving color settings...
set colour=2
(
echo %colour%
)>colour.txt
goto colors
:SavePurple
color 5
echo Saving color settings...
set colour=5
(
echo %colour%
)>colour.txt
goto colors
:SaveAqua
color 3
echo Saving color settings...
set colour=3
(
echo %colour%
)>colour.txt
goto colors
:language
cls
title Language Settings - xinsOS
echo.
echo.
echo ([1]) English (currently chosen)
echo ([2]) Deutsch/German
:appstore
cls
title App Store - xinsOS
echo.
echo App Store
echo.
echo ([1]) xinsPad
echo ([2]) Back
choice /N /C:12
if errorlevel 255 goto appstore
if errorlevel 2 goto apps
if errorlevel 1 goto downloadxinspad
if errorlevel 0 goto appstore
:downloadxinspad
cls
title Downloading xinsPad - xinsOS
echo.
echo xinsPad Download
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Starting Download
timeout /t 2 /nobreak > nul
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Starting Download.
timeout /t 2 /nobreak > nul
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Starting Download..
timeout /t 2 /nobreak > nul
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Starting Download...
timeout /t 4 /nobreak > nul
cls
echo Starting Download - 0KB/s
timeout /t 1 /nobreak > nul
cls
echo Downloading. - 400KB/s
timeout /t 1 /nobreak > nul
cls
echo Downloading.. - 600KB/s
timeout /t 1 /nobreak > nul
cls
echo Downloading... - 800KB/s
timeout /t 1 /nobreak > nul
cls
echo Downloading - 1.2MB/s
timeout /t 1 /nobreak > nul
cls
echo Downloading. - 1.6MB/s
timeout /t 1 /nobreak > nul
cls
echo Downloading.. - 2.0MB/s
timeout /t 1 /nobreak > nul
cls
echo Downloading... - 2.4MB/s
timeout /t 1 /nobreak > nul
cls
echo Downloading - 2.8MB/s
timeout /t 1 /nobreak > nul
cd "%userprofile%\Documents\xinsOS\DownloadedApps"
mkdir xinsPad
xcopy "%userprofile%\Documents\xinsOS\Dependencies\xinsPad" "%userprofile%\Documents\xinsOS\DownloadedApps\xinsPad" > nul
cls
echo Downloading. - 3.2MB/s
timeout /t 1 /nobreak > nul
cls
echo Downloading.. - 3.6MB/s
timeout /t 1 /nobreak > nul
cls
echo Downloading... - 4.0MB/s
timeout /t 5 /nobreak > nul
cls
echo Finished!
timeout /t 3 /nobreak > nul
goto appstore
:CREATORinfo
cls
title INFO ABOUT THE CREATOR - XINSOS
echo.
echo INFO ABOUT THE CREATOR
echo.
echo xinsOS was made by a 10 year old, now 11 year old. (No really, it was). His name is Max Atkinson. He is from Germany.
echo He was born in February 16th 2012, in Germany.
echo He first started programming at 6 years old, just right after getting his first laptop, which 4 years later, he is still programming on.
echo He saw a video from IProgramInCPP, who made his own "OS" in Batch.
echo That was his inspiration to create his own. He first made maxOS, which was discontinued 2 days after initial release.
echo No download is available.
echo Then he made BeeOS, which was discontinued 1 week after initial release.
echo No download available.
echo His video which he made which was called: "Check if Updates are available. | BeeOS", was very cringe.
echo His video didn't make any sense. Here is his youtube channel:
echo https://www.youtube.com/@beeos2639
echo Then he made choOS, which was discontinued 2 weeks after initial release.
echo He just didn't have any motivation anymore.
echo But 1 year later, HE IS BACK!
echo.
echo With xinsOS!
echo He himself said: "I do not have any dates where xinsOS will be discontinued. But I hope you guys enjoy this "OS" made by me!"
echo That was the end of info about the CREATOR. We all at the xinsOS Team, wish you a rest of the day/night.
echo And enjoy the "OS"!
echo PS: this is just a hobby, Max doesn't ever plan to make this a bootable and famous OS. But you never know, maybe he will!
echo Press 1 to see the credits.
echo ([1]) Credits
echo ([2]) Back
choice /N /C:12
if errorlevel 255 goto CREATORinfo
if errorlevel 2 goto desktop
if errorlevel 1 goto credits
if errorlevel 0 goto CREATORinfo
:credits
cls
title CREDITS - xinsOS
echo.
echo.
timeout /t 3 /nobreak > nul
cls
echo CREDITS
echo.
echo.
echo.
timeout /t 3 /nobreak > nul
cls
echo.
echo.
echo.
echo MAX ATKINSON - Creator of the OS.
timeout /t 3 /nobreak > nul
cls
echo.
echo.
echo.
echo KAEJ KAM - Creator of the credits.
timeout /t 3 /nobreak > nul
cls
echo.
echo.
echo.
echo Compo and Stephan (from StackOverflow) - helping me with the code
echo.
echo.
echo.
echo THE END OF CREDITS
timeout /t 3 /nobreak > nul
echo.
echo.
echo.
echo.
echo.
echo.
cls
goto CREATORinfo
:shutdown
cls
title WDYWTD - xinsOS
echo What do you want to do?
echo.
echo ([1]) shutdown
echo ([2]) reboot
echo ([3]) back
choice /N /C:123
if errorlevel 255 goto shutdown
if errorlevel 3 goto desktop
if errorlevel 2 goto reboot
if errorlevel 1 exit
if errorlevel 0 goto shutdown
:reboot
cls
title reboot
echo.
echo.
echo rebooting.
timeout /t 1 /nobreak > nul
cls
echo rebooting..
timeout /t 1 /nobreak > nul
cls
echo rebooting...
timeout /t 1 /nobreak > nul
cls
goto "%userprofile%\Documents\xinsOS"
start desktop.cmd
exit
pause>nul
我尝试转到标签:apps
,但我的代码不断崩溃,我不知道为什么。
in被认为
)
是语句([1])
的结尾if
,因此它尝试xinsSettings
作为命令运行,从而导致错误xinsSettings was unexpected at this time.
解决这个问题的简单方法是,当您在括号内时,永远不要尝试显示括号,但您也可以在文本编辑器中打开查找和替换,并将所有实例替换为以转义并告诉
])
解释]^)
器)
不要将其视为常规括号。ETC。