@ECHO ON

:BasicSetting
::Please modify below information(If none,please keep blank) for your UWP Driver UI

PUSHD %~dp0
SET AppxName=
SET LicenseName=
SET /P AUMID=<AUMIDs.txt
ECHO %AUMID%
SET /a NUM=0
SET Displayname=
SET DependencyPackagePath0=
SET DependencyPackagePath1=
SET DependencyPackagePath2=
SET DependencyPackagePath3=
SET DependencyPackagePath4=
SET DependencyPackagePath5=
SET DependencyPackagePath6=
SET DependencyPackagePath7=
SET DependencyPackagePath8=
SET DependencyPackagePath9=

:DisplaynameSearch
FOR /F "tokens=1 delims=_" %%i IN ("%AUMID%") DO SET Displayname=%%i
ECHO %Displayname%

:PackageSearch
SETLOCAL EnableDelayedExpansion
rem ECHO start to search app packages for %PACKAGEID%_[MODULENAME]=%PACKAGENAME% >> %WLOG%
FOR /f %%i IN ('DIR /b *_License1.xml') DO SET LicenseName=%%~nxi
SET AppxName=%LicenseName:~0,-13%
FOR /f %%i IN ('DIR /b %AppxName%.*') DO SET AppxName=%%~nxi
IF "%AppxName%" == "" GOTO :AppxNameSearchFail
SETLOCAL EnableDelayedExpansion
FOR /f %%i IN ('DIR /b *_x64__*') DO (
	SET DependencyPackagePath!NUM!=%%~nxi
	SET /a NUM=!NUM!+1
)

:Install
IF "%DependencyPackagePath0%" NEQ "" SET DependencyPackagePath0=/DependencyPackagePath:%~dp0%DependencyPackagePath0%
IF "%DependencyPackagePath1%" NEQ "" SET DependencyPackagePath1=/DependencyPackagePath:%~dp0%DependencyPackagePath1%
IF "%DependencyPackagePath2%" NEQ "" SET DependencyPackagePath2=/DependencyPackagePath:%~dp0%DependencyPackagePath2%
IF "%DependencyPackagePath3%" NEQ "" SET DependencyPackagePath3=/DependencyPackagePath:%~dp0%DependencyPackagePath3%
IF "%DependencyPackagePath4%" NEQ "" SET DependencyPackagePath4=/DependencyPackagePath:%~dp0%DependencyPackagePath4%
IF "%DependencyPackagePath5%" NEQ "" SET DependencyPackagePath5=/DependencyPackagePath:%~dp0%DependencyPackagePath5%
IF "%DependencyPackagePath6%" NEQ "" SET DependencyPackagePath6=/DependencyPackagePath:%~dp0%DependencyPackagePath6%
IF "%DependencyPackagePath7%" NEQ "" SET DependencyPackagePath7=/DependencyPackagePath:%~dp0%DependencyPackagePath7%
IF "%DependencyPackagePath8%" NEQ "" SET DependencyPackagePath8=/DependencyPackagePath:%~dp0%DependencyPackagePath8%
IF "%DependencyPackagePath9%" NEQ "" SET DependencyPackagePath9=/DependencyPackagePath:%~dp0%DependencyPackagePath9%
DISM /Online /Add-ProvisionedAppxPackage /PackagePath:%~dp0%AppxName% %DependencyPackagePath0% %DependencyPackagePath1% %DependencyPackagePath2% %DependencyPackagePath3% %DependencyPackagePath4% %DependencyPackagePath5% %DependencyPackagePath6% %DependencyPackagePath7% %DependencyPackagePath8% %DependencyPackagePath9% /LicensePath:%~dp0%LicenseName% /region="all"
IF %ERRORLEVEL% == 0 GOTO :APPX_Check
GOTO :INS_Fail

:APPX_Check
IF "%Displayname%" == "" GOTO :END
DISM /online /get-provisionedappxpackages | Find /i "%Displayname%"
IF %ERRORLEVEL% == 0 GOTO :END
GOTO :APPX_Fail

:AppxNameSearchFail
ECHO %DATE% %TIME% [%AUMID%] CAN NOT FIND AppxName AND INSTALL FAIL,ErrorLevel=%ERRORLEVEL% !!!!!! > modules.log
EXIT /B1

:INS_Fail
ECHO %DATE% %TIME% [%AUMID%] INSTALL FAIL,ErrorLevel=%ERRORLEVEL% !!!!!! >> modules.log
EXIT /B1

:APPX_Fail
ECHO %DATE% %TIME% [%AUMID%] APPX CHECK FAIL,ErrorLevel=%ERRORLEVEL% !!!!!! >> modules.log
EXIT /B1

:END
POPD
SET AppxName=
SET LicenseName=
SET FrameworkName=
SET RuntimeName=
SET VCLibsName=
SET Engagement=
SET AUMID=
SET Displayname=
EXIT /B0