cd /d "%~dp0"
::获取引擎切换云控信息
title 正在读取服务器端引擎配置
cls
del /f /q core\UseIDM.txt
core\EasyDown\EasyDown.exe -Down("http://s.edgeless.top/?token=engineSwitch","UseIDM.txt","%~dp0core")
if not exist core\UseIDM.txt call net_checknet.cmd
set /p UseIDM=<core\UseIDM.txt
if not defined UseIDM set UseIDM=0
if %UseIDM% neq 1 set UseIDM=0
if exist core\NomoreIDM.txt set UseIDM=0
if exist core\ForceIDM.txt set UseIDM=1

:head_diso
title 正在下载Edgeless镜像
del /f /q core\Edgeless_backup.iso
if exist core\Edgeless.iso ren core\Edgeless.iso Edgeless_backup.iso
set failTime=0
:autoRetryDownloadISO
cls
set token=iso
::token后门
if exist token.txt set /p token=<token.txt
if %UseIDM%==0 core\EasyDown\EasyDown.exe -Down("http://s.edgeless.top/?token=%token%","Edgeless.iso","%~dp0core")
if not defined initIDM set initIDM=0
if %UseIDM%==1 (
    if %initIDM%==0 goto installIDM
)
:ctnToDown
if %UseIDM%==1 (
    cls
    echo.
    echo 正在等待IDM完成下载任务，请勿关闭本窗口...
    echo.
    echo 如果您手动关闭了IDM窗口，IDM会在后台继续运行
    start /wait IDMan.exe /d http://s.edgeless.top/?token=%token% /p %~dp0core /f Edgeless.iso /q /n
)

cd /d "%~dp0core"

if not exist Edgeless.iso (
    cls
    if %failTime%==1 goto skipAutoRetryDownloadISO
    if %failTime%==0 set failTime=1
    echo.
    echo Edgeless服务器可能正在解析下载地址，5s后程序将会自动重试
    echo.
    ping 127.0.0.1 -n 6 >nul 2>&1
    goto autoRetryDownloadISO
)
:skipAutoRetryDownloadISO

if not exist Edgeless.iso (
     title 正在尝试使用备用地址下载
     EasyDown\EasyDown.exe -Down("http://s.edgeless.top/?token=subiso","Edgeless.iso","%~dp0core")
     call net_checknet.cmd
)
::校验MD5
cd /d "%~dp0"
title 正在获取MD5信息
del /f /q core\md5_ol.txt
cls
core\EasyDown\EasyDown.exe -Down("http://s.edgeless.top/?token=md5","md5_ol.txt","%~dp0core")
if not exist core\md5_ol.txt call net_checknet.cmd
core\EasyDown\EasyDown.exe -GetMD5("%~dp0core\Edgeless.iso") > "%~dp0core\md5_iso.txt"
set /p md5_iso=<core\md5_iso.txt
set /p md5_ol=<core\md5_ol.txt
if not defined md5_iso goto ctnn
if not defined md5_ol got ctnn
if not %md5_iso%==%md5_ol% goto mdnc
goto ctnn
:mdnc
    cls
    echo.
    echo.
    echo.
    echo   ========================================================
    echo            警告！镜像MD5值与官方值不相符！
    echo.
    echo     官方MD5：%md5_ol%
    echo     本地MD5：%md5_iso%
    echo   ========================================================
    echo 【1】重新下载      【2】继续制作
    echo.
    echo.
    set /p cho=请输入序号并回车：
    if %cho%==1 (
        del /f /q core\Edgeless.iso
        del /f /q core\version_iso.txt
        goto head_diso
    )


:ctnn
if not exist core\version_ol.txt call net_getversion.cmd
del /f /q core\version_iso.txt
ren core\version_ol.txt version_iso.txt
goto endOfDown


:installIDM
cd /d "%~dp0core\IDM"
taskkill /f /im IDM* >NUL 2>NUL
taskkill /f /im IEMon* >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Internet Download Manager" /f>NUL 2>NUL
reg delete "HKLM\SOFTWARE\Wow6432Node\Internet Download Manager" /f>NUL 2>NUL
reg delete HKCU\Software\Classes\CLSID\{07999AC3-058B-40BF-984F-69EB1E554CA7} /f>NUL 2>NUL
reg delete HKCU\Software\Classes\CLSID\{6DDF00DB-1234-46EC-8356-27E7B2051192} /f>NUL 2>NUL
reg delete HKCU\Software\Classes\CLSID\{D5B91409-A8CA-4973-9A0B-59F713D25671} /f>NUL 2>NUL
reg delete HKCU\Software\Classes\CLSID\{7B8E9164-324D-4A2E-A46D-0165FB2000EC} /f>NUL 2>NUL
reg delete HKCU\Software\Classes\CLSID\{5ED60779-4DE2-4E07-B862-974CA4FF2E9C} /f>NUL 2>NUL
reg delete HKLM\Software\Classes\CLSID\{07999AC3-058B-40BF-984F-69EB1E554CA7} /f>NUL 2>NUL
reg delete HKLM\Software\Classes\CLSID\{6DDF00DB-1234-46EC-8356-27E7B2051192} /f>NUL 2>NUL
reg delete HKLM\Software\Classes\CLSID\{D5B91409-A8CA-4973-9A0B-59F713D25671} /f>NUL 2>NUL
reg delete HKLM\Software\Classes\CLSID\{7B8E9164-324D-4A2E-A46D-0165FB2000EC} /f>NUL 2>NUL
reg delete HKLM\Software\Classes\CLSID\{5ED60779-4DE2-4E07-B862-974CA4FF2E9C} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{D0FB58BB-2C07-492F-8BD0-A587E4874B4E} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{0055C089-8582-441B-A0BF-17B458C2A3A8} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{0F947660-8606-420A-BAC6-51B84DD22A47} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{436D67E1-2FB3-4A6C-B3CD-FF8A41B0664D} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{4764030F-2733-45B9-AE62-3D1F4F6F2861} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{52F6F7BD-DF73-44B3-AE13-89E1E1FB8F6A} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{5312C54E-A385-46B7-B200-ABAF81B03935} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{6B9EB066-DA1F-4C0A-AC62-01AC892EF175} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{7D11E719-FF90-479C-B0D7-96EB43EE55D7} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{AC746233-E9D3-49CD-862F-068F7B7CCCA4} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{CDD67718-A430-4AB9-A939-83D9074B0038} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{CDC95B92-E27C-4745-A8C5-64A52A78855D} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\CLSID\{CDD67718-A430-4AB9-A939-83D9074B0038} /f>NUL 2>NUL
reg delete HKLM\Software\Classes\Wow6432Node\CLSID\{07999AC3-058B-40BF-984F-69EB1E554CA7} /f>NUL 2>NUL
reg delete HKLM\Software\Classes\Wow6432Node\CLSID\{6DDF00DB-1234-46EC-8356-27E7B2051192} /f>NUL 2>NUL
reg delete HKLM\Software\Classes\Wow6432Node\CLSID\{D5B91409-A8CA-4973-9A0B-59F713D25671} /f>NUL 2>NUL
reg delete HKCU\Software\Classes\Wow6432Node\CLSID\{7B8E9164-324D-4A2E-A46D-0165FB2000EC} /f>NUL 2>NUL
reg delete HKCU\Software\Classes\Wow6432Node\CLSID\{5ED60779-4DE2-4E07-B862-974CA4FF2E9C} /f>NUL 2>NUL
reg delete HKLM\Software\Classes\Wow6432Node\CLSID\{7B8E9164-324D-4A2E-A46D-0165FB2000EC} /f>NUL 2>NUL
reg delete HKLM\Software\Classes\Wow6432Node\CLSID\{5ED60779-4DE2-4E07-B862-974CA4FF2E9C} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{0055C089-8582-441B-A0BF-17B458C2A3A8} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{0F947660-8606-420A-BAC6-51B84DD22A47} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{436D67E1-2FB3-4A6C-B3CD-FF8A41B0664D} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{4764030F-2733-45B9-AE62-3D1F4F6F2861} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{52F6F7BD-DF73-44B3-AE13-89E1E1FB8F6A} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{5312C54E-A385-46B7-B200-ABAF81B03935} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{6B9EB066-DA1F-4C0A-AC62-01AC892EF175} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{7D11E719-FF90-479C-B0D7-96EB43EE55D7} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{AC746233-E9D3-49CD-862F-068F7B7CCCA4} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{CDD67718-A430-4AB9-A939-83D9074B0038} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{D0FB58BB-2C07-492F-8BD0-A587E4874B4E} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Wow6432Node\Classes\CLSID\{CDC95B92-E27C-4745-A8C5-64A52A78855D} /f>NUL 2>NUL
reg delete HKLM\SOFTWARE\Wow6432Node\Classes\CLSID\{CDD67718-A430-4AB9-A939-83D9074B0038} /f>NUL 2>NUL
reg delete HKCU\SOFTWARE\DownloadManager /v tvfrdt /f>NUL 2>NUL
reg add "HKCU\Software\DownloadManager" /f /v "LName" /d "Version" >NUL
reg add "HKCU\Software\DownloadManager" /f /v "FName" /d "All Users" >NUL
reg add "HKCU\Software\DownloadManager" /f /v "Email" /d "info@tonec.com" >NUL
reg add "HKCU\Software\DownloadManager" /f /v "Serial" /d "VM2HP-0L5CH-REJPM-7YSKI" >NUL
if "%PROCESSOR_ARCHITECTURE%"=="x86"  reg add "HKLM\Software\Internet Download Manager" /f /v LName /d "Version" >NUL
if "%PROCESSOR_ARCHITECTURE%"=="x86"  reg add "HKLM\Software\Internet Download Manager" /f /v FName /d "All Users" >NUL
if "%PROCESSOR_ARCHITECTURE%"=="x86"  reg add "HKLM\Software\Internet Download Manager" /f /v Email /d "info@tonec.com" >NUL
if "%PROCESSOR_ARCHITECTURE%"=="x86"  reg add "HKLM\Software\Internet Download Manager" /f /v Serial /d "VM2HP-0L5CH-REJPM-7YSKI" >NUL
if "%PROCESSOR_ARCHITECTURE%"=="AMD64"  reg add "HKLM\Software\WOW6432Node\Internet Download Manager" /f /v LName /d "Version" >NUL
if "%PROCESSOR_ARCHITECTURE%"=="AMD64"  reg add "HKLM\Software\WOW6432Node\Internet Download Manager" /f /v FName /d "All Users" >NUL
if "%PROCESSOR_ARCHITECTURE%"=="AMD64"  reg add "HKLM\Software\WOW6432Node\Internet Download Manager" /f /v Email /d "info@tonec.com" >NUL
if "%PROCESSOR_ARCHITECTURE%"=="AMD64"  reg add "HKLM\Software\WOW6432Node\Internet Download Manager" /f /v Serial /d "VM2HP-0L5CH-REJPM-7YSKI" >NUL
reg add HKCU\Software\DownloadManager /f /v ToolbarStyle /d "Faenza" >NUL
reg add HKCU\Software\DownloadManager /f /v LstCheck  /d "31/12/99" >NUL
reg add HKCU\Software\DownloadManager /f /v TipStartUp /t REG_DWORD /d 1 >NUL
reg add HKCU\Software\DownloadManager /f /v LaunchOnStart /t REG_DWORD /d 0 >NUL
reg add HKCU\Software\DownloadManager /f /v FSSettingsChecked /t REG_DWORD /d 1 >NUL
reg add HKCU\Software\DownloadManager /f /v LanguageID /t REG_DWORD /d "0x00000804" >NUL
reg add HKCU\Software\DownloadManager /f /v bShVistaAsAdmWarn /t REG_DWORD /d 1
reg add HKCU\Software\DownloadManager /f /v bComlDlgVMS /t REG_DWORD /d 1
reg add HKCU\Software\DownloadManager /f /v bShBTtFQCI /t REG_DWORD /d 1
reg add HKCU\Software\DownloadManager /f /v bShInstEdgeExtTip /t REG_DWORD /d 1
reg add HKCU\Software\DownloadManager /f /v bShTipDD /t REG_DWORD /d 1
set initIDM=1
goto ctnToDown



:endOfDown