taskkill /f /im EABackgroundService.exe /t
taskkill /f /im EADesktop.exe /t

rmdir "%~dp0ICafeCloud\LocalAppData\EADesktop\cache" /S /Q
rmdir "%~dp0ICafeCloud\ProgramData\EA Desktop\Logs" /S /Q

mkdir "%~dp0ICafeCloud\LocalAppData\EADesktop\cache" 2>nul
mkdir "%~dp0ICafeCloud\ProgramData\EA Desktop\Logs" 2>nul
mkdir "%~dp0ICafeCloud\LocalAppData\Electronic Arts" 2>nul
mkdir "%~dp0ICafeCloud\LocalAppData\EADesktop" 2>nul

rmdir "%LocalAppData%\Electronic Arts" /S /Q
rmdir "%LocalAppData%\EADesktop" /S /Q
rmdir "%ProgramData%\EA Desktop" /S /Q
rmdir "%ProgramFiles%\Electronic Arts" /S /Q
mklink /J "%LocalAppData%\Electronic Arts" "%~dp0ICafeCloud\LocalAppData\Electronic Arts"
mklink /J "%LocalAppData%\EADesktop" "%~dp0ICafeCloud\LocalAppData\EADesktop"
mklink /J "%ProgramData%\EA Desktop" "%~dp0ICafeCloud\ProgramData\EA Desktop"
mklink /J "%ProgramFiles%\Electronic Arts" "%~dp0ICafeCloud\ProgramFiles\Electronic Arts"

set "eaDefaultPath=C:\Program Files\Electronic Arts\EA Desktop\EA Desktop"
REM import Origin.reg

Reg.exe add "HKLM\software\classes\eadm\shell\open\command" /f /ve /t REG_SZ /d "\"%eaDefaultPath%\EALauncher.exe\" \"%%1\""
Reg.exe add "HKLM\software\classes\ealink\shell\open\command" /f /ve /t REG_SZ /d "\"%eaDefaultPath%\legacyPM\OriginLegacyCLI.exe\" \"%%1\" -wait"
Reg.exe add "HKLM\software\classes\ealink\DefaultIcon" /f /ve /t REG_SZ /d "\"%eaDefaultPath%\legacyPM\OriginLegacyCLI.exe\",-107"
Reg.exe add "HKLM\software\classes\origin\shell\open\command" /f /ve /t REG_SZ /d "\"%eaDefaultPath%\EALauncher.exe\" \"%%1\""
Reg.exe add "HKLM\software\classes\origin2\shell\open\command" /f /ve /t REG_SZ /d "\"%eaDefaultPath%\EALauncher.exe\" \"%%1\""

Reg.exe add "HKLM\SOFTWARE\Electronic Arts\EA Core" /f /v "ClientVersion" /t REG_SZ /d "7.0.0.1"
Reg.exe add "HKLM\SOFTWARE\Electronic Arts\EA Core" /f /v "ClientPath" /t REG_SZ /d "%eaDefaultPath%\legacyPM\OriginLegacyCLI.exe"
Reg.exe add "HKLM\SOFTWARE\Electronic Arts\EA Core" /f /v "ClientAccessDLLPath" /t REG_SZ /d "%eaDefaultPath%\legacyPM\CmdPortalClient.dll"
Reg.exe add "HKLM\SOFTWARE\Electronic Arts\EA Core" /f /v "EADM6Version" /t REG_SZ /d "7.0.0.1"
Reg.exe add "HKLM\SOFTWARE\Electronic Arts\EA Core" /f /v "EADM6InstallDir" /t REG_SZ /d "%eaDefaultPath%\legacyPM"

Reg.exe add "HKLM\SOFTWARE\Electronic Arts\EADM" /f /v "ClientVersion" /t REG_SZ /d "10.4.5.30491"
Reg.exe add "HKLM\SOFTWARE\Electronic Arts\EADM" /f /v "ClientPath" /t REG_SZ /d "%eaDefaultPath%\EADesktop.exe"

Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EA Core" /f /v "ClientVersion" /t REG_SZ /d "7.0.0.1"
Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EA Core" /f /v "ClientPath" /t REG_SZ /d "%eaDefaultPath%\legacyPM\OriginLegacyCLI.exe"
Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EA Core" /f /v "ClientAccessDLLPath" /t REG_SZ /d "%eaDefaultPath%\legacyPM\CmdPortalClient.dll"
Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EA Core" /f /v "EADM6Version" /t REG_SZ /d "7.0.0.1"
Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EA Core" /f /v "EADM6InstallDir" /t REG_SZ /d "%eaDefaultPath%\legacyPM"

Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EADM" /f /v "ClientVersion" /t REG_SZ /d "10.4.5.30491"
Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EADM" /f /v "ClientPath" /t REG_SZ /d "%eaDefaultPath%\EADesktop.exe"

Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EA Desktop" /f /v "DesktopAppPath" /t REG_SZ /d "%eaDefaultPath%\EADesktop.exe"
Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EA Desktop" /f /v "LauncherAppPath" /t REG_SZ /d "%eaDefaultPath%\EALauncher.exe"
Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EA Desktop" /f /v "EaConnectMsAppPath" /t REG_SZ /d "%eaDefaultPath%\EAConnect_microsoft.exe"
Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EA Desktop" /f /v "ErrorReporterPath" /t REG_SZ /d "%eaDefaultPath%\ErrorReporter.exe"
Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EA Desktop" /f /v "ClientPath" /t REG_SZ /d "%eaDefaultPath%\EADesktop.exe"
Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EA Desktop" /f /v "InstallLocation" /t REG_SZ /d "%eaDefaultPath%\"
Reg.exe add "HKLM\SOFTWARE\Wow6432Node\Electronic Arts\EA Desktop" /f /v "InstallSuccesfull" /t REG_SZ /d "true"

2>nul sc delete "EABackgroundService"
sc create "EABackgroundService" binPath="\"%eaDefaultPath%\EABackgroundService.exe\" -start"
sc description "EABackgroundService" "EA app Background Service"
REM https://www.advancedinstaller.com/forums/viewtopic.php?t=49990
sc sdset "EABackgroundService" "D:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)"

REM Origin's protocol
Reg.exe add "HKCR\origin" /f /ve /t REG_SZ /d "URL:ORIGIN Protocol"
Reg.exe add "HKCR\origin" /f /v "URL Protocol" /t REG_SZ /d ""
Reg.exe add "HKCR\origin\shell\open\command" /f /ve /t REG_SZ /d "\"%eaDefaultPath%\EALauncher.exe\" \"%%1\""
Reg.exe add "HKCR\ealink" /f /ve /t REG_SZ /d "URL:ealink Protocol"
Reg.exe add "HKCR\ealink" /f /v "URL Protocol" /t REG_SZ /d ""
Reg.exe add "HKCR\ealink\DefaultIcon" /f /ve /t REG_SZ /d "\"%eaDefaultPath%\legacyPM\OriginLegacyCLI.exe\",-107"
Reg.exe add "HKCR\ealink\shell\open\command" /f /ve /t REG_SZ /d "\"%eaDefaultPath%\legacyPM\OriginLegacyCLI.exe\" \"%%1\" -wait"