@echo off
:: ===============================================================================
:: AppFileName:	OneKeyAuto.bat
:: Date:		2025-09-28 20:58:41
:: Version:		2025-09-28
:: Author:		lsl
:: ===============================================================================
::
rem ====----	EndCmd
if "%~1"=="" (
	set "%~n0EndCmd=k"
) else (
	set "%~n0EndCmd=c"
)

if "%~2"=="" (
	set "App_Folder=%ConfFile%"
) else (
	set "App_Folder=%~2"
)

if "%~3"=="" (
	set "InstallType=all"
) else (
	set "InstallType=%~3"
)

rem ====----	IsAdmin
rem ====	基本系統設定 set 一定要加""避免空白
set "Driver=%~d0"
set "FilePath=%~p0"
set "ConfFile=%~n0"
set "FullPath=%~dp0"
set "FullPathFile=%~f0"
rem ====----	IsAdmin
call :IsAdmin
set "OneKeyAutoPath=%FullPath%"

TITLE %ConfFile%

set App_Folder=%ConfFile%

rem set "App_Folder=lsl_Portable"
rem call InstallApp.bat c %App_Folder% curl

set /a isShortcut=1
rem call :RunCall Framework35
call :RunCall AppInstaller
set /a isShortcut=0
call :RunCall App
rem call :RunCall App1
rem call :RunCall App2
rem call :RunCall App3
set /a isShortcut=1
call :RunCall Portable
rem call :RunCall Shell
set /a isShortcut=0
rem call :RunCall lsl_Apps
set /a isShortcut=1
rem call :RunCall lsl_Portable
rem call :RunCall Office365ProPlus
rem call :RunCall OfficeProPlus2024
rem call :RunCall OfficeProPlus2021
rem call :RunCall OfficeProPlus2019
call :Make7zFM

cd /D "%OneKeyAutoPath%"
rem call NCHSoftware\delNCHReg.bat c

goto End

:RunCall
	set "App_Folder=%*"
	rem call %*.bat c %* curl

	rem call %*.bat c %* all

	if %isShortcut% EQU 0 (
		call %*.bat c %* Desktop
	) else (
		call %*.bat c %* Shortcut
	)

	exit /b

:Make7zFM
	::	Make7zFM.bat
	::
	set "ShortCutRoot=%HOMEDRIVE%\PortableApps\ShortCut"
	set "ShortCutName=ShortCut.exe"
	::
	set "AppNameRoot=%ProgramFiles%\7-Zip"
	set "AppName=7zFM.exe"
	::
	set "AppLinkRoot=%PUBLIC%\Desktop\Desktop"
	set "AppLinkFile=7-Zip File Manager.lnk"
	::
	set "AppICON=%AppNameRoot%\%AppName%,0"
	::

	::	2024-08-31
	call :Checkdir "%AppLinkRoot%"
	::
	if not exist "%AppLinkRoot%\%AppLinkFile%" (
		"%ShortCutRoot%\%ShortCutName%" /T:"%AppNameRoot%\%AppName%" /F:"%AppLinkRoot%\%AppLinkFile%" /I:"%AppICON%" /A:c
		echo "%ShortCutRoot%\%ShortCutName%" /T:"%AppNameRoot%\%AppName%" /F:"%AppLinkRoot%\%AppLinkFile%" /I:"%AppICON%" /A:c
	)
	exit /b

:Checkdir
	rem ====----	https://stackoverflow.com/questions/18639663/how-to-pass-command-line-parameters-with-space-in-batch-file

	if exist "%*" (
		exit /b
	)
	if not exist "%*" (
		mkdir "%*"
	)
	if exist "%*" (
		echo "%*" Created
	)

	exit /b

:IsAdmin
	reg.exe query "HKU\S-1-5-19\Environment" >nul
	if not %ERRORLEVEL% EQU 0 (
		echo 必須「以系統管理員身分執行」
		echo You must have administrator rights to continue ...
		pause & exit
	)
	exit /b

:End
	cd /D "%OneKeyAutoPath%"

	FOR /f "tokens=1-2 delims==" %%A in ('set %~n0EndCmd') do (
		set EndCmd=%%B
	)
	%ComSpec% /%EndCmd%
