@ECHO ON

@echo Uninstall

cd /d %~dp0

@echo YamahaAEDriver Package Component
devcon remove "./YamahaAEDriver Package Component/YamahaAEDriver_component.inf" SWC\YamahaAEDriver_ComponentID

@echo YamahaAEDriver Package Extension
devcon remove "./YamahaAEDriver Package Extension/YamahaAEDriver_extension.inf" ROOT\YamahaAEDriver

@echo YamahaAEDriver Package Base
devcon remove "./YamahaAEDriver Package Base/YamahaAEDriver.inf" ROOT\YamahaAEDriver

@echo YamahaAudioRelay Package
devcon remove "./YamahaAudioRelay Package/YARelay.inf" Root\YARelay

@echo pnputil-d oem*.inf
RemoveOem -r
if %ERRORLEVEL% equ 0 (
	echo 削除に成功しました。
) else (
	echo 削除に失敗しました。
)

@echo Install
@echo YamahaAEDriver Package Base
devcon install "./YamahaAEDriver Package Base/YamahaAEDriver.inf" ROOT\YamahaAEDriver

timeout /t 5 > nul

@echo YamahaAEDriver Package Extension
devcon update "./YamahaAEDriver Package Extension/YamahaAEDriver_extension.inf" ROOT\YamahaAEDriver

timeout /t 5 > nul

@ECHO OFF
set count=1

:WAITBEFOREYPC
@echo Wait before installing Component
for /f "usebackq delims=" %%A in (`devcon /status root\yamahaaedriver ^| findstr "Driver is running."`) do set HOGE=%%A
if "%HOGE%"=="    Driver is running." (
	echo yamahaaedriver is running.
	goto :YPCINST
) else (
	echo yamahaaedriver is not running.
	set /a count+=1
	if %count% gtr 11 (
		goto :YPCINST
	)
	timeout /t 5 > nul
	goto :WAITBEFOREYPC
)

:YPCINST

@echo YamahaAEDriver Package Component

devcon update "./YamahaAEDriver Package Component/YamahaAEDriver_component.inf" SWC\YamahaAEDriver_ComponentID
timeout /t 5 > nul
if exist "C:\Windows\System32\DriverStore\FileRepository\yamahaaedriver_component.inf_amd64_*" (
	echo yamahaaedriver_component.inf_amd64_ Exists.
) else (
	echo yamahaaedriver_component.inf_amd64_ Not Exist.
)

:YAR
@ECHO ON
@echo YamahaAudioRelay Package
devcon install "./YamahaAudioRelay Package/YARelay.inf" Root\YARelay

@echo Done
