@echo off
rem 如需离线集成，请运行 App_Online.cmd "挂载路径"

rem 获取管理员权限
pushd "%~dp0" && Dism 1>nul 2>nul || mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 "%*"","","runas",1)(window.close) && Exit /B 1

setlocal EnableDelayedExpansion

if "%~1" equ "" ( set "Image=/Online" ) else ( set Image=/Image:"%~1" )
set "Dism=Dism /LogLevel:1 /LogPath:%~dp0Dism_%date:~0,4%%date:~5,2%%date:~8,2%.log"
set "Apps=%~dp0Apps"

rem call :AddAppx "DesktopAppInstaller","VCLibs.14"
call :AddAppx "Store","VCLibs.14 Runtime.1.6 Framework.1.6"
rem call :AddAppx "WindowsStore"
goto :End

rem 参数 [ %~1 : 应用包名, %~3 : 应用依赖包名 ]
:AddAppx
set Dependency=
set LicPath=/SkipLicense
for /f %%i in ('"dir /b %Apps%\*%~1*.xml" 2^>nul') do if exist "%Apps%\%%i" set LicPath=/LicensePath:"%Apps%\%%i"
for %%j in (%~2) do for /f %%i IN ('"dir /b %Apps%\*%%j*.appx" 2^>nul') do set Dependency=!Dependency!/DependencyPackagePath:"%Apps%\%%i" 
for /f %%i IN ('"dir /b %Apps%\*%~1*.appxbundle" 2^>nul') do if exist "%Apps%\%%i" (
    echo.正在集成 [%%~ni]
    %Dism% %Image% /Add-ProvisionedAppxPackage /PackagePath:"%Apps%\%%i" %LicPath% %Dependency% /Quiet
    echo.
)
goto :eof

rem 处理完成
:End
pause