Created
August 5, 2024 08:40
-
-
Save alezhu/887385998d17759a8891558f488f3963 to your computer and use it in GitHub Desktop.
jetbra.in\scripts\install-current-user PowerShell replace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
powershell -ExecutionPolicy Bypass -File "%~dp0install-current-user.ps1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ExitWithCode($exitcode) { | |
$Host.SetShouldExit($exitcode) | |
exit $exitcode | |
} | |
$sCurrentDirectory = Get-Location | |
$sBasePath = Split-Path -Path $sCurrentDirectory -Parent | |
$sJarFile = Join-Path -Path $sBasePath -ChildPath "ja-netfilter.jar" | |
$bJarFileExists = Test-Path -Path $sJarFile -PathType leaf | |
if (!$bJarFileExists) { | |
Write-Host "ja-netfilter.jar not found" | |
ExitWithCode 2 | |
} | |
Write-Host 'Set VM_OPTIONS for JetBrains products. It may take a few seconds to execute this script.'; | |
# $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); | |
$aJBProducts = @("idea", "clion", "phpstorm", "goland", "pycharm", "webstorm", "webide", "rider", "datagrip", "rubymine", "dataspell", "aqua", "rustrover", "gateway", "jetbrains_client", "jetbrainsclient", "studio", "devecostudio") | |
$sPattern = "^\-javaagent:.*[\/\\]ja\-netfilter\.jar.*" | |
function ProcessVmOptions($sFile) { | |
$aContent = (Get-Content $sFile) | |
$sContent = "" | |
foreach ($sLine in $aContent) { | |
if ($sLine -match $sPattern) { | |
continue; | |
} | |
$sContent += $sLine + "`n" | |
} | |
$sContent = $sContent + "-javaagent:" + $sJarFile + "=jetbrains" | |
Set-Content -Path $sFile -Value $sContent | |
} | |
function setEnvironment($sKey, $value, $sTarget) { | |
$regKey = switch ($sTarget.ToUpper()) { | |
"MACHINE" { 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' } | |
"USER" { 'HKCU:\Environment' } | |
} | |
Set-ItemProperty -Path $regKey -Name $sKey -Value $value | |
} | |
$sLastEnvKey = "" | |
$sLastEnvValue = "" | |
foreach ( $sPrd in $aJBProducts ) { | |
Write-Host "Product: $sPrd" | |
$sVmOptionsFile = Join-Path -Path (Join-Path -Path $sBasePath -ChildPath "vmoptions") -ChildPath "$sPrd.vmoptions" | |
$bVmOptionsFileExists = Test-Path -Path $sVmOptionsFile -PathType leaf | |
if ($bVmOptionsFileExists) { | |
ProcessVmOptions $sVmOptionsFile | |
#$sEnvKey = "Env:$($sPrd.ToUpper())_VM_OPTIONS" | |
$sEnvKey = "$($sPrd.ToUpper())_VM_OPTIONS" | |
#Set-Item -Path $sEnvKey -Value $sVmOptionsFile | |
#[Environment]::SetEnvironmentVariable($sEnvKey, $sVmOptionsFile, 'User') | |
setEnvironment $sEnvKey $sVmOptionsFile 'USER' | |
$sLastEnvKey = $sEnvKey | |
$sLastEnvValue = $sVmOptionsFile | |
} | |
} | |
if ($sLastEnvKey -ne "") { | |
Write-Host 'Send a WM_SETTINGCHANGE message to all windows'; | |
[Environment]::SetEnvironmentVariable($sLastEnvKey, $sLastEnvValue, 'User') | |
} | |
Write-Host 'Done. Press any key to continue...'; | |
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment