-
Notifications
You must be signed in to change notification settings - Fork 3
/
restore-msyh.bat
88 lines (66 loc) · 2.93 KB
/
restore-msyh.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
86
87
88
@REM @echo off
SETLOCAL ENABLEEXTENSIONS
net session 2>nul 1>nul
if not %errorlevel% equ 0 (
powershell -Command "Start-Process -Verb RunAs -FilePath '%0'"
exit /b
)
set "rootdir=%~dp0"
pushd "%rootdir%"
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Microsoft Yahei & Microsoft Yahei UI (TrueType)" 2>nul 1>nul
if %ERRORLEVEL% equ 0 (
call:DeleteReg
call:Warning "Press any key to logout"
pause
shutdown -L
) else (
call:ReplaceFiles
call:Warning "Press any key to logout"
pause
shutdown -L
)
popd
pause
exit /b 0
rem ---------------------------------------------------------------------------
:DeleteReg
pushd "%rootdir%\sarasa"
set converted=0
if exist msyh.ttc if exist msyhl.ttc if exist msyhbd.ttc set converted=1
if not %converted% equ 1 call:Error "Custom font not generated!" & exit /b -1
call:Warning "Deleting reg items..."
reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Microsoft Yahei & Microsoft Yahei UI (TrueType)" /f
reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Microsoft Yahei Bold & Microsoft Yahei UI Bold (TrueType)" /f
reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Microsoft Yahei Light & Microsoft Yahei UI Light (TrueType)" /f
popd
exit /b 0
rem ---------------------------------------------------------------------------
:ReplaceFiles
if not exist "%rootdir%\msyh-backup" call:Error "Backup directory not existed!" & exit /b -1
pushd "%rootdir%\msyh-backup"
set converted=0
if exist msyh.ttc if exist msyhl.ttc if exist msyhbd.ttc set converted=1
if not %converted% equ 1 call:Error "Vanilla font not existed!" & exit /b -1
call:Warning "Replacing Files..."
takeown /F C:\Windows\Fonts\msyh* /A
icacls C:\Windows\Fonts\msyh* /grant Administrators:F
del /f /s /q C:\Windows\Fonts\msyh*
if exist C:\Windows\Fonts\msyh* echo Delete fonts failed!&goto:End
copy "msyh*" C:\Windows\Fonts
takeown /F C:\Windows\Fonts\msyh* /A
icacls C:\Windows\Fonts\msyh* /grant Administrators:F
icacls C:\windows\Fonts\msyh* /C /setowner "NT SERVICE\TrustedInstaller"
icacls C:\windows\Fonts\ /C /restore "..\msyh-backup\acl"
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Microsoft Yahei & Microsoft Yahei UI (TrueType)" /t REG_SZ /d "msyh.ttc" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Microsoft Yahei Bold & Microsoft Yahei UI Bold (TrueType)" /t REG_SZ /d "msyhbd.ttc" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Microsoft Yahei Light & Microsoft Yahei UI Light (TrueType)" /t REG_SZ /d "msyhl.ttc" /f
popd
exit /b 0
rem ---------------------------------------------------------------------------
:Warning
echo.[93m%~1[0m>&2
exit /b 0
rem ---------------------------------------------------------------------------
:Error
echo.[91m%~1[0m>&2
exit /b 0