Что нового

Проверка на наличие и установка шрифта

AlexVong

Новичок
Сообщения
112
Репутация
1
Версия AutoIt: 3.3.6

Описание: Скрипт при запуске должен проверять установлен ли в системе шрифт (например CourierWork.ttf.)
Если да вывести об этом сообщение, если нет установить шрифт из папки со скриптом.

Примечания: Желательно чтобы работало на Win7 и WinXp

Заранее спасибо! :beer:
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
Код:
If _FileFontInstalled("CourierWork") Then
	MsgBox(64, 'Title', 'Font CourierWork already installed.')
Else
	_FileFontInstall(@ScriptDir & "\CourierWork.ttf", "CourierWork")
EndIf

Func _FileFontInstalled($sFontName, $sFontsPath = "")
	If $sFontsPath = "" Then $sFontsPath = @WindowsDir & "\fonts"
	Return FileExists($sFontsPath & "\" & $sFontName & ".ttf")
EndFunc

Func _FileFontInstall($sSourceFile, $sFontDescript = "", $sFontsPath = "")
	Local Const $HWND_BROADCAST = 0xFFFF
	Local Const $WM_FONTCHANGE = 0x1D
	
	If $sFontsPath = "" Then $sFontsPath = @WindowsDir & "\fonts"
	
	Local $sFontName = StringRegExpReplace($sSourceFile, "^.*\\", "")
	If Not FileCopy($sSourceFile, $sFontsPath & "\" & $sFontName, 1) Then Return SetError(1, 0, 0)
	
	Local $hSearch = FileFindFirstFile($sSourceFile)
	Local $iFontIsWildcard = StringRegExp($sFontName, "\*|\?")
	Local $aRet, $hGdi32_DllOpen = DllOpen("GDI32.dll")
	
	If $hSearch = -1 Then Return SetError(2, 0, 0)
	If $hGdi32_DllOpen = -1 Then Return SetError(3, 0, 0)
	
	While 1
		$sFontName = FileFindNextFile($hSearch)
		If @error Then ExitLoop
		
		If $iFontIsWildcard Then $sFontDescript = StringRegExpReplace($sFontName, "\.[^\.]*$", "")
		$aRet = DllCall($hGdi32_DllOpen, "Int", "AddFontResourceW", "wstr", $sFontsPath & "\" & $sFontName)
		
		If IsArray($aRet) And $aRet[0] > 0 Then
			RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $sFontDescript, "REG_SZ", $sFontsPath & "\" & $sFontName)
		EndIf
	WEnd
	
	DllClose($hGdi32_DllOpen)
	DllCall("User32.dll", "Int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_FONTCHANGE, "int", 0, "int", 0)
	
	Return 1
EndFunc
 
Верх