REM @echo off
setlocal ENABLEDELAYEDEXPANSION

reg delete HKCU\SOFTWARE\easyNet /f

  pushd ..\..
  set EASYNET_HOME=!CD!
  popd

  set EASYNET_DATA_HOME=!EASYNET_HOME!

reg add HKCU\SOFTWARE\easyNet\GUI\EasyNetHome !EASYNET_HOME!
reg add HKCU\SOFTWARE\easyNet\GUI\EasyNetDataHome !EASYNET_DATA_HOME!

rem set PP=
rem FOR /f "tokens=2*" %%a IN ('REG query HKLM\SOFTWARE\R-core\R /v InstallPath ^| findstr InstallPath') do (
rem set PP=%%b
rem )
rem set R_HOME=!PP!
rem set PATH=!PP!\bin\i386;!PATH!

rem SET PRE_STUB=!R_HOME!
:CLIP
rem SET R_HOME_STUB=!PRE_STUB:*\=!
rem IF NOT !PRE_STUB!==!R_HOME_STUB! (
rem  SET PRE_STUB=!R_HOME_STUB!
rem  GOTO CLIP
rem )
rem SET MAJOR=!R_HOME_STUB:~2,1!

rem pushd ..\..
rem set EASYNET_HOME=!CD!
rem set EASYNET_RLIB=!CD!\bin\R-library
rem set EASYNET_LIB=!CD!\bin\nm_files
rem popd

rem IF !MAJOR! GEQ 3 (

rem  set NEED_LINSTALL=false

rem   IF NOT EXIST !R_HOME!\library\Rcpp (
rem    IF NOT EXIST !EASYNET_RLIB!\Rcpp (
rem      set NEED_LINSTALL=true
rem    )
rem  )

rem  IF !NEED_LINSTALL!==true (
rem    R CMD BATCH !EASYNET_RLIB!\install_packages.R
rem  )
  
rem  set R_LIBS=!EASYNET_RLIB!;!R_LIBS!
  
start easyNet.exe %1 %2
rem ) ELSE (
rem  echo "Needs R version 3 or above.  Will point you to the download page."
rem  pause
rem  "R Download shortcut.url"
rem )
