@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

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

@ECHO OFF
set count=1
:YPC
@echo YamahaAEDriver Package Component
devcon update "./YamahaAEDriver Package Component/YamahaAEDriver_component.inf" SWC\YamahaAEDriver_ComponentID
timeout /t 5 > nul
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.
) else (
		echo yamahaaedriver is not running.
	set /a count+=1
	if %count% gtr 4 (
		goto :YAR
	)
	goto :YPC
)

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

@echo Done
