Search Unity

Feedback Unity HUB - Default version + hardlink

Discussion in 'Unity Hub' started by OndrejP, Dec 21, 2019.

  1. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    68
    Allow to select default unity version (from installed versions) and create hardlink:
    c:\Program Files\Unity\Hub\Editor\Default

    I use some other tools which depend on Unity installation path and it's annoying to update paths every week when I switch to new version.

    Tools used:
    ILSpy / DnSpy (remembers list of opened DLLs)
    Pinned shortcuts on taskbar to directly open projects
    Scripts with -batchmode
     
  2. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    68
    Anyway I've created bat file which does this for me, but having this in UI would be much better.

    First part is about requesting admin rights (need those for writing into Program Files).
    Then it lists Unity installations and asks user to select default one.
    After that it creates or updates directory junction (aka hardlink).

    Code (CSharp):
    1. @echo off
    2.  
    3. :: BatchGotAdmin
    4. :-------------------------------------
    5. REM  --> Check for permissions
    6.     IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
    7. >nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
    8. ) ELSE (
    9. >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
    10. )
    11.  
    12. REM --> If error flag set, we do not have admin.
    13. if '%errorlevel%' NEQ '0' (
    14.     echo Requesting administrative privileges...
    15.     goto UACPrompt
    16. ) else ( goto gotAdmin )
    17.  
    18. :UACPrompt
    19.     echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    20.     set params= %*
    21.     echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"
    22.  
    23.    "%temp%\getadmin.vbs"
    24.    del "%temp%\getadmin.vbs"
    25.    exit /B
    26.  
    27. :gotAdmin
    28.    pushd "%CD%"
    29.    CD /D "%~dp0"
    30. :--------------------------------------
    31.  
    32.  
    33. set /a INDEX=0
    34.  
    35. setlocal ENABLEDELAYEDEXPANSION
    36.  
    37. SET "SOURCE=c:\Program Files\Unity\Hub\Editor\"
    38. SET "TARGET=c:\Program Files\Unity\Hub\Editor\Default"
    39.  
    40. ECHO.
    41. ECHO Available Unity versions:
    42.  
    43. for /f "delims=" %%D in ('dir /a:d /b "%SOURCE%"') do (
    44.    IF NOT "%%~nxD" == "Default" (
    45.        SET /a INDEX=INDEX+1
    46.        SET LIST[!INDEX!]=%%~nxD
    47.        ECHO   !INDEX! - %%~nxD
    48.    )
    49. )
    50.  
    51. SET /P SELECTION=Choose default version then press ENTER:
    52.  
    53. ECHO.
    54. ECHO Setting !LIST[%SELECTION%]! as default
    55.  
    56. SET LINKSRC=%SOURCE%!LIST[%SELECTION%]!
    57.  
    58. REM ECHO !LINKSRC!
    59. REM ECHO %TARGET%
    60.  
    61. IF EXIST "%TARGET%" (
    62.    RMDIR "%TARGET%"
    63. )
    64. MKLINK /J "%TARGET%" "!LINKSRC!"
    65.  
    66. pause
     
unityunity