<commit_before>﻿################################
# powershell env functions
################################

[string]$APP_PATH = 'd:\.app\';
[string]$CACHE_PATH = 'd:\.cache\';
[string]$CONFIG_DIR = 'd:\.config\';
[string]$DATA_DIR   = 'd:\.data\';

function script:Env-TrySetVariable (
    [string]$Variable = $(throw "Variable is null!"),
    [string]$Value = $(throw "Value is null!")
) {
    $Target = [System.EnvironmentVariableTarget]::Machine

    # 输出旧值
    [string]$OldValue = [System.Environment]::GetEnvironmentVariable($Variable, $Target);
    Log-Info "[$Target][$Variable] 旧值:" $OldValue

    if ($OldValue -eq $Value) {
        Log-Warn "[$Target][$Variable] 新值:" $Value
        return
    }

    # 设置环境变量
    [System.Environment]::SetEnvironmentVariable($Variable, $Value, $Target)
    
    # 输出新值
    [string]$NewValue = [System.Environment]::GetEnvironmentVariable($Variable, $Target);
    Log-Debug "[$Target][$Variable] 新值:" $NewValue
    Write-Host
}

function script:Env-TryAppendPathVariable (
    [string]$Value = $(throw "Value is null!")
) {
    $Target = [System.EnvironmentVariableTarget]::Machine
    $Variable = 'Path'
    # 获取旧值
    [string]$OldValue = [System.Environment]::GetEnvironmentVariable($Variable, $Target);

    # 检测是否已经存在
    if ($OldValue.Split(';').Contains($Value)) {
        Log-Warn "[$Target][$Variable] 已存在：$Value"
        return
    }

    Log-Debug "[$Target][$Variable] 追加：$Value"

    # 追加新值
    [string]$NewValue = $OldValue;
    if ($OldValue.EndsWith(';')) {
        $NewValue = $OldValue + $Value + ';'
    }
    else {
        $NewValue = $OldValue + ';' + $Value + ';'
    }

    Env-TrySetVariable -Variable $Variable -Value $NewValue
}


function Env-TrySetAll() {
    Get-Command -Name 'Env-Set*EnvironmentVariable' -CommandType Function | ForEach-Object {
        Log-Info "执行: $($_.Name)"
        Invoke-Expression -Command $_.Name
        Write-Host
        Write-Host
    }
}

function Env-GetAllVariable() {
    Get-ChildItem ENV:
}

function Env-GetPathVariavle() {
    $ENV:PATH.Split(';')
}

# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
function Env-SetXDGEnvironmentVariable() {
    Env-TrySetVariable -Variable 'XDG_CONFIG_HOME' -Value $CONFIG_DIR
    Env-TrySetVariable -Variable 'XDG_CACHE_HOME' -Value $CACHE_PATH
    Env-TrySetVariable -Variable 'XDG_DATA_HOME' -Value $DATA_DIR
}

# https://github.com/MicrosoftArchive/redis/releases
function Env-SetRedisEnvironmentVariable() {
    $APP_REDIS_PATH = $APP_PATH + '.redis\';

    Env-TryAppendPathVariable -Value $APP_REDIS_PATH
}

# https://www.mongodb.org/dl/win32/x86_64-2008plus-ssl
function Env-SetMongoDBEnvironmentVariable() {
    $APP_MONGO_PATH = $APP_PATH + '.mongo\';

    Env-TryAppendPathVariable -Value $APP_MONGO_PATH
}

# https://www.putty.org/
function Env-SetPuttyEnvironmentVariable() {
    $APP_PUTTY_PATH = $APP_PATH + '.putty\';

    Env-TryAppendPathVariable -Value $APP_PUTTY_PATH
}

# https://github.com/shadowsocks/shadowsocks-windows
function Env-SetShadowsocksEnvironmentVariable() {
    $APP_SHADOWSOCKS_PATH = $APP_PATH + '.shadowsocks\';

    Env-TryAppendPathVariable -Value $APP_SHADOWSOCKS_PATH
}

# https://developers.redhat.com/products/openjdk/download
function Env-SetJavaEnvironmentVariable() {
    $APP_JAVA_JDK_PATH = $APP_PATH + '.java\';
    $APP_JAVA_JDK_BIN_PATH = $APP_JAVA_JDK_PATH + 'bin\';
    $APP_JAVA_JDK_LIB_PATH = $APP_JAVA_JDK_PATH + 'lib\';
    $APP_JAVA_JDK_LIB_TOOLS_JAR = $APP_JAVA_JDK_LIB_PATH + 'tools.jar';

    Env-TrySetVariable -Variable 'JAVA_HOME' -Value $APP_JAVA_JDK_PATH
    Env-TrySetVariable -Variable 'CLASSPATH' -Value ".;$APP_JAVA_JDK_LIB_PATH;$APP_JAVA_JDK_LIB_TOOLS_JAR"
    Env-TryAppendPathVariable -Value $APP_JAVA_JDK_BIN_PATH
}

# https://golang.org/doc/install
function Env-SetGoEnvironmentVariable() {
    $APP_GO_PATH = $APP_PATH + '.go\';
    $APP_GO_BIN_PATH = $APP_GO_PATH + 'bin\';

    $CACHE_GO_PATH = $CACHE_PATH + '.go\';

    Env-TrySetVariable -Variable 'GOROOT' -Value $APP_GO_PATH
    Env-TrySetVariable -Variable 'GOCACHE' -Value $CACHE_GO_PATH
    Env-TryAppendPathVariable -Value $APP_GO_BIN_PATH
}

# https://rubyinstaller.org/downloads/
function Env-SetRubyEnvironmentVariable() {
    $APP_RUBY_PATH = $APP_PATH + '.ruby\';
    $APP_RUBY_BIN_PATH = $APP_RUBY_PATH + 'bin\';

    Env-TrySetVariable -Variable 'RUBY_HOME' -Value $APP_RUBY_PATH
    Env-TryAppendPathVariable -Value $APP_RUBY_BIN_PATH
}

# https://nodejs.org/en/download/
function Env-SetNodeEnvironmentVariable() {
    $APP_NODE_PATH = $APP_PATH + '.node\';
    $APP_NODE_MODULES_PATH = $APP_NODE_PATH + 'node_modules\';

    $CACHE_NODE_PATH = $CACHE_PATH + '.node\';

    Env-TrySetVariable -Variable 'NODE_PATH' -Value $APP_NODE_MODULES_PATH
    Env-TryAppendPathVariable -Value $APP_NODE_PATH

    npm config set cache $CACHE_NODE_PATH --global
    npm config set registry "https://registry.npm.taobao.org" --global
    npm install -g cnpm --registry=https://registry.npm.taobao.org
}


# https://kotlinlang.org/docs/tutorials/command-line.html
function Env-SetKotlinEnvironmentVariable() {
    $APP_KOTLIN_PATH = $APP_PATH + '.kotlin\'
    $APP_KOTLIN_BIN_PATH = $APP_KOTLIN_PATH + 'bin\'

    Env-TryAppendPathVariable -Value $APP_KOTLIN_BIN_PATH
}


# https://dotnet.github.io/
# https://docs.microsoft.com/en-us/dotnet/core/tools/telemetry
function Env-SetNetEnvironmentVariable() {
    Env-TrySetVariable -Variable 'DOTNET_CLI_TELEMETRY_OPTOUT' -Value "true" 
    Env-TryAppendPathVariable -Value 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\'
}

# https://www.python.org/downloads/windows/
# Windows x86-64 embeddable zip file
function Env-SetPythonEnvironmentVariable() {
    $APP_PYTHON_PATH = $APP_PATH + '.python\';
    $APP_PYTHON_SCRIPTS_PATH = $APP_PYTHON_PATH + 'scripts\';

    Env-TryAppendPathVariable -Value $APP_PYTHON_PATH
    Env-TryAppendPathVariable -Value $APP_PYTHON_SCRIPTS_PATH
}

# https://github.com/icsharpcode/ILSpy/releases
function Env-SetILSpyEnvironmentVariable() {
    $APP_ILSPY_PATH = $APP_PATH + '.ilspy\';

    Env-TryAppendPathVariable -Value $APP_ILSPY_PATH
}

# https://www.nuget.org/downloads 
# https://docs.microsoft.com/en-us/nuget/tools/cli-ref-environment-variables
function Env-SetNugetEnvironmentVariable() {
    $APP_NUGET_PATH = $APP_PATH + '.nuget\';

    $CACHE_NUGET_PATH = $CACHE_PATH + '.nuget\';

    Env-TrySetVariable -Variable 'NUGET_PACKAGES' -Value $CACHE_NUGET_PATH
    Env-TryAppendPathVariable -Value $APP_NUGET_PATH
}

# https://developer.android.com/studio/releases/platform-tools.html
function Env-SetADBEnvironmentVariable() {
    $APP_ADB_PATH = $APP_PATH + '.adb\';

    Env-TryAppendPathVariable -Value $APP_ADB_PATH
}

# https://www.cpuid.com/softwares/cpu-z.html
function Env-SetCPUZEnvironmentVariable() {
    $APP_CPU_Z_PATH = $APP_PATH + '.cpu-z\';

    Env-TryAppendPathVariable -Value $APP_CPU_Z_PATH
}

# https://www.techpowerup.com/gpuz/
function Env-SetGPUZEnvironmentVariable() {
    $APP_GPU_Z_PATH = $APP_PATH + '.gpu-z\';

    Env-TryAppendPathVariable -Value $APP_GPU_Z_PATH
}

# http://www.superpi.net/Download/
function Env-SetPIEnvironmentVariable() {
    $APP_PI_PATH = $APP_PATH + '.pi\';

    Env-TryAppendPathVariable -Value $APP_PI_PATH
}

# https://maven.apache.org/
function Env-SetMavenEnvironmentVariable() {
    $APP_MAVEN_PATH = $APP_PATH + '.maven\'
    $APP_MAVEN_BIN_PATH = $APP_MAVEN_PATH + 'bin\'
    $CACHE_MAVEN_PATH = $CACHE_PATH + '.maven\'

    # for maven 1
    Env-TrySetVariable -Variable 'MAVEN_HOME' -Value $APP_MAVEN_PATH

    # for maven 2 or 3
    Env-TrySetVariable -Variable 'M2_HOME' -Value $APP_MAVEN_PATH

    # for maven-wrapper https://github.com/takari/maven-wrapper
    Env-TrySetVariable -Variable 'MAVEN_USER_HOME' -Value $APP_MAVEN_PATH
    
    # http://maven.apache.org/configure.html
    Env-TrySetVariable -Variable 'MAVEN_OPTS' -Value '-Dfile.encoding=UTF-8'

    # custom
    Env-TrySetVariable -Variable 'MAVEN_REPOSITORY_HOME' -Value $CACHE_MAVEN_PATH

    Env-TryAppendPathVariable -Value $APP_MAVEN_BIN_PATH
}

# https://gradle.org/releases/
# https://docs.gradle.org/current/userguide/installation.html
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_environment_variables
function Env-SetGradleEnvironmentVariable() {
    $APP_GRADLE_PATH = $APP_PATH + '.gradle\';
    $APP_GRADLE_BIN_PATH = $APP_GRADLE_PATH + 'bin\';

    $CACHE_GRADLE_PATH = $CACHE_PATH + '.gradle\';

    Env-TrySetVariable -Variable 'GRADLE_HOME' -Value $APP_GRADLE_PATH
    Env-TrySetVariable -Variable 'GRADLE_USER_HOME' -Value $CACHE_GRADLE_PATH
    Env-TryAppendPathVariable -Value $APP_GRADLE_BIN_PATH
}

# https://projects.spring.io/spring-boot/
function Env-SetSpringBootCliEnvironmentVariable() {
    $APP_SPRING_BOOT_CLI_PATH = $APP_PATH + '.spring-boot-cli\';
    $APP_SPRING_BOOT_CLI_BIN_PATH = $APP_SPRING_BOOT_CLI_PATH + 'bin\';

    Env-TryAppendPathVariable -Value $APP_SPRING_BOOT_CLI_BIN_PATH
}

# http://httpd.apache.org/download.cgi
function Env-SetHttpdEnvironmentVariable() {
    $APP_HTTPD_PATH = $APP_PATH + '.httpd\';

    Env-TryAppendPathVariable -Value $APP_HTTPD_PATH
}

# http://nginx.org/en/download.html
function Env-SetNginxEnvironmentVariable() {
    $APP_NGINX_PATH = $APP_PATH + '.nginx\';

    Env-TryAppendPathVariable -Value $APP_NGINX_PATH
}

# https://kubernetes.io/docs/tasks/tools/install-kubectl
function Env-SetKubectlEnvironmentVariable() {
    $APP_KUBECTL_PATH = $APP_PATH + '.kubectl\';
    $APP_KUBECTL_CONFIG_FILE = $APP_KUBECTL_PATH + 'kubectl-config.yml';

    Env-TrySetVariable -Variable 'KUBECONFIG' -Value $APP_KUBECTL_CONFIG_FILE
    Env-TryAppendPathVariable -Value $APP_KUBECTL_PATH
}

# https://github.com/kubernetes/minikube/releases
function Env-SetMinikubeEnvironmentVariable() {
    $APP_MINIKUBE_PATH = $APP_PATH + '.minikube\';
    $CACHE_MINIKUBE_PATH = 'e:\.minikube\';

    Env-TrySetVariable -Variable 'MINIKUBE_HOME' -Value $CACHE_MINIKUBE_PATH
    Env-TrySetVariable -Variable 'MINIKUBE_WANTUPDATENOTIFICATION' -Value 'false'
    Env-TrySetVariable -Variable 'MINIKUBE_WANTREPORTERRORPROMPT' -Value 'false'
    Env-TrySetVariable -Variable 'CHANGE_MINIKUBE_NONE_USER' -Value 'true'
    Env-TryAppendPathVariable -Value $APP_MINIKUBE_PATH
}

# https://docs.docker.com/engine/reference/commandline/cli/#environment-variables
# https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-socket-option
function Env-SetDockerEnvironmentVariable() {
    $APP_DOCKER_PATH = $APP_PATH + '.docker\';

    Env-TrySetVariable -Variable 'DOCKER_HOST' -Value 'tcp://127.0.0.1:2375'
    Env-TryAppendPathVariable -Value $APP_DOCKER_PATH
}

# https://docs.docker.com/machine
# https://docs.docker.com/machine/drivers/hyper-v/
function Env-SetDockerMachineEnvironmentVariable() {
    $APP_DOCKER_PATH = $APP_PATH + '.docker\';
    $BOOT2DOCKER_ISO_PATH = 'file://' + $APP_DOCKER_PATH + 'boot2docker.iso';
    $CACHE_DOCKER_PATH = 'e:\.docker\';

    Env-TrySetVariable -Variable 'MACHINE_STORAGE_PATH' -Value $CACHE_DOCKER_PATH
    Env-TrySetVariable -Variable 'MACHINE_NATIVE_SSH' -Value 1
    Env-TrySetVariable -Variable 'HYPERV_BOOT2DOCKER_URL' -Value $BOOT2DOCKER_ISO_PATH
    Env-TrySetVariable -Variable 'HYPERV_VIRTUAL_SWITCH' -Value 'HVS'
    Env-TrySetVariable -Variable 'HYPERV_CPU_COUNT' -Value 1
    Env-TrySetVariable -Variable 'HYPERV_MEMORY' -Value 1024
    Env-TrySetVariable -Variable 'HYPERV_DISK_SIZE' -Value 10240

    Env-TryAppendPathVariable -Value $APP_DOCKER_PATH
}

# https://helm.sh/docs
# https://github.com/helm/helm-www
# https://github.com/helm/helm/releases
function Env-SetHelmEnvironmentVariable() {
    $APP_HLEM_PATH = $APP_PATH + '.helm\';

    Env-TryAppendPathVariable -Value $APP_HLEM_PATH
}

# https://github.com/mholt/caddy
# https://caddyserver.com/docs/cli
function Env-SetCaddyEnvironmentVariable() {
    $APP_CADDY_PATH = $APP_PATH + '.caddy\';
    $CACHE_CADDY_PATH = $CACHE_PATH + '.caddy\';

    Env-TrySetVariable -Variable 'CADDYPATH' -Value $CACHE_CADDY_PATH
    Env-TryAppendPathVariable -Value $APP_CADDY_PATH
}

# https://coreos.com/os/docs/1911.5.0/overview-of-ct.html
# https://github.com/coreos/container-linux-config-transpiler
function Env-SetCoreOSEnvironmentVariable() {
    $APP_COREOS_PATH = $APP_PATH + '.coreos\';

    Env-TryAppendPathVariable -Value $APP_COREOS_PATH
}

# https://docs.microsoft.com/en-us/powershell/scripting/overview?view=powershell-6
function Env-SetPowerShellEnvironmentVariable() {
    Env-TrySetVariable -Variable 'POWERSHELL_TELEMETRY_OPTOUT' -Value 'true'
}

# https://github.com/v2ray/v2ray-core
function Env-SetV2RayEnvironmentVariable() {
    $APP_V2RAY_PATH = $APP_PATH + '.v2ray\';

    Env-TryAppendPathVariable -Value $APP_V2RAY_PATH
}

function Env-SetLocaleEnvironmentVariable() {
    Env-TrySetVariable -Variable 'LC_ALL' -Value 'zh_CN.UTF-8'
    Env-TrySetVariable -Variable 'LANG' -Value 'C.UTF-8'
}

# https://www.alex-is.de/PHP/fusion/downloads.php?cat_id=4&download_id=9
function Env-SetASSSDBenchmarkEnvironmentVariable() {
    $APP_AS_SSD_BENCHMARK_PATH = $APP_PATH + '.as-ssd-benchmark\';

    Env-TryAppendPathVariable -Value $APP_AS_SSD_BENCHMARK_PATH
}

# https://crystalmark.info/en/download/
function Env-SetDiskInfoEnvironmentVariable() {
    $APP_DISK_INFO_PATH = $APP_PATH + '.disk-info\';

    Env-TryAppendPathVariable -Value $APP_DISK_INFO_PATH
}

# https://github.com/pbatard/rufus
function Env-SetRufusEnvironmentVariable() {
    $APP_RUFUS_PATH = $APP_PATH + '.rufus\';

    Env-TryAppendPathVariable -Value $APP_RUFUS_PATH
}

# https://github.com/FFmpeg/FFmpeg
function Env-SetFFmpegEnvironmentVariable() {
    $APP_FFMPEG_PATH = $APP_PATH + '.ffmpeg\bin';

    Env-TryAppendPathVariable -Value $APP_FFMPEG_PATH
}

# https://www.rust-lang.org/
function Env-SetRustEnvironmentVariable() {
    $APP_RUSTUP_PATH = $APP_PATH + '.rustup\';
    $APP_CARGO_PATH = $APP_PATH + '.cargo\';
    $APP_CARGO_BIN_PATH = $APP_CARGO_PATH + 'bin\';

    # https://github.com/rust-lang/rustup.rs#environment-variables
    Env-TrySetVariable -Variable 'RUSTUP_HOME' -Value $APP_RUSTUP_PATH
    Env-TrySetVariable -Variable 'RUSTUP_DIST_SERVER' -Value 'http://mirrors.ustc.edu.cn/rust-static'
    Env-TrySetVariable -Variable 'RUSTUP_UPDATE_ROOT' -Value 'http://mirrors.ustc.edu.cn/rust-static/rustup'
    
    # https://github.com/rust-lang/cargo/blob/master/src/doc/src/reference/environment-variables.md
    Env-TrySetVariable -Variable 'CARGO_HOME' -Value $APP_CARGO_PATH

    Env-TrySetVariable -Variable 'RUST_BACKTRACE' -Value 'full'
    Env-TrySetVariable -Variable 'RUST_TEST_NOCAPTURE' -Value '0'

    Env-TryAppendPathVariable -Value $APP_CARGO_BIN_PATH
}

# https://github.com/gohugoio/hugo
function Env-SetHugoEnvironmentVariable() {
    $APP_HUGO_PATH = $APP_PATH + '.hugo\';

    Env-TryAppendPathVariable -Value $APP_HUGO_PATH
}<commit_msg>Rename APP_PATH to APP_DIR<commit_after>﻿################################
# powershell env functions
################################

[string]$APP_DIR    = 'd:\.app\';
[string]$CACHE_PATH = 'd:\.cache\';
[string]$CONFIG_DIR = 'd:\.config\';
[string]$DATA_DIR   = 'd:\.data\';

function script:Env-TrySetVariable (
    [string]$Variable = $(throw "Variable is null!"),
    [string]$Value = $(throw "Value is null!")
) {
    $Target = [System.EnvironmentVariableTarget]::Machine

    # 输出旧值
    [string]$OldValue = [System.Environment]::GetEnvironmentVariable($Variable, $Target);
    Log-Info "[$Target][$Variable] 旧值:" $OldValue

    if ($OldValue -eq $Value) {
        Log-Warn "[$Target][$Variable] 新值:" $Value
        return
    }

    # 设置环境变量
    [System.Environment]::SetEnvironmentVariable($Variable, $Value, $Target)
    
    # 输出新值
    [string]$NewValue = [System.Environment]::GetEnvironmentVariable($Variable, $Target);
    Log-Debug "[$Target][$Variable] 新值:" $NewValue
    Write-Host
}

function script:Env-TryAppendPathVariable (
    [string]$Value = $(throw "Value is null!")
) {
    $Target = [System.EnvironmentVariableTarget]::Machine
    $Variable = 'Path'
    # 获取旧值
    [string]$OldValue = [System.Environment]::GetEnvironmentVariable($Variable, $Target);

    # 检测是否已经存在
    if ($OldValue.Split(';').Contains($Value)) {
        Log-Warn "[$Target][$Variable] 已存在：$Value"
        return
    }

    Log-Debug "[$Target][$Variable] 追加：$Value"

    # 追加新值
    [string]$NewValue = $OldValue;
    if ($OldValue.EndsWith(';')) {
        $NewValue = $OldValue + $Value + ';'
    }
    else {
        $NewValue = $OldValue + ';' + $Value + ';'
    }

    Env-TrySetVariable -Variable $Variable -Value $NewValue
}


function Env-TrySetAll() {
    Get-Command -Name 'Env-Set*EnvironmentVariable' -CommandType Function | ForEach-Object {
        Log-Info "执行: $($_.Name)"
        Invoke-Expression -Command $_.Name
        Write-Host
        Write-Host
    }
}

function Env-GetAllVariable() {
    Get-ChildItem ENV:
}

function Env-GetPathVariavle() {
    $ENV:PATH.Split(';')
}

# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
function Env-SetXDGEnvironmentVariable() {
    Env-TrySetVariable -Variable 'XDG_CONFIG_HOME' -Value $CONFIG_DIR
    Env-TrySetVariable -Variable 'XDG_CACHE_HOME' -Value $CACHE_PATH
    Env-TrySetVariable -Variable 'XDG_DATA_HOME' -Value $DATA_DIR
}

# https://github.com/MicrosoftArchive/redis/releases
function Env-SetRedisEnvironmentVariable() {
    $APP_REDIS_PATH = $APP_DIR + '.redis\';

    Env-TryAppendPathVariable -Value $APP_REDIS_PATH
}

# https://www.mongodb.org/dl/win32/x86_64-2008plus-ssl
function Env-SetMongoDBEnvironmentVariable() {
    $APP_MONGO_PATH = $APP_DIR + '.mongo\';

    Env-TryAppendPathVariable -Value $APP_MONGO_PATH
}

# https://www.putty.org/
function Env-SetPuttyEnvironmentVariable() {
    $APP_PUTTY_PATH = $APP_DIR + '.putty\';

    Env-TryAppendPathVariable -Value $APP_PUTTY_PATH
}

# https://github.com/shadowsocks/shadowsocks-windows
function Env-SetShadowsocksEnvironmentVariable() {
    $APP_SHADOWSOCKS_PATH = $APP_DIR + '.shadowsocks\';

    Env-TryAppendPathVariable -Value $APP_SHADOWSOCKS_PATH
}

# https://developers.redhat.com/products/openjdk/download
function Env-SetJavaEnvironmentVariable() {
    $APP_JAVA_JDK_PATH = $APP_DIR + '.java\';
    $APP_JAVA_JDK_BIN_PATH = $APP_JAVA_JDK_PATH + 'bin\';
    $APP_JAVA_JDK_LIB_PATH = $APP_JAVA_JDK_PATH + 'lib\';
    $APP_JAVA_JDK_LIB_TOOLS_JAR = $APP_JAVA_JDK_LIB_PATH + 'tools.jar';

    Env-TrySetVariable -Variable 'JAVA_HOME' -Value $APP_JAVA_JDK_PATH
    Env-TrySetVariable -Variable 'CLASSPATH' -Value ".;$APP_JAVA_JDK_LIB_PATH;$APP_JAVA_JDK_LIB_TOOLS_JAR"
    Env-TryAppendPathVariable -Value $APP_JAVA_JDK_BIN_PATH
}

# https://golang.org/doc/install
function Env-SetGoEnvironmentVariable() {
    $APP_GO_PATH = $APP_DIR + '.go\';
    $APP_GO_BIN_PATH = $APP_GO_PATH + 'bin\';

    $CACHE_GO_PATH = $CACHE_PATH + '.go\';

    Env-TrySetVariable -Variable 'GOROOT' -Value $APP_GO_PATH
    Env-TrySetVariable -Variable 'GOCACHE' -Value $CACHE_GO_PATH
    Env-TryAppendPathVariable -Value $APP_GO_BIN_PATH
}

# https://rubyinstaller.org/downloads/
function Env-SetRubyEnvironmentVariable() {
    $APP_RUBY_PATH = $APP_DIR + '.ruby\';
    $APP_RUBY_BIN_PATH = $APP_RUBY_PATH + 'bin\';

    Env-TrySetVariable -Variable 'RUBY_HOME' -Value $APP_RUBY_PATH
    Env-TryAppendPathVariable -Value $APP_RUBY_BIN_PATH
}

# https://nodejs.org/en/download/
function Env-SetNodeEnvironmentVariable() {
    $APP_NODE_PATH = $APP_DIR + '.node\';
    $APP_NODE_MODULES_PATH = $APP_NODE_PATH + 'node_modules\';

    $CACHE_NODE_PATH = $CACHE_PATH + '.node\';

    Env-TrySetVariable -Variable 'NODE_PATH' -Value $APP_NODE_MODULES_PATH
    Env-TryAppendPathVariable -Value $APP_NODE_PATH

    npm config set cache $CACHE_NODE_PATH --global
    npm config set registry "https://registry.npm.taobao.org" --global
    npm install -g cnpm --registry=https://registry.npm.taobao.org
}


# https://kotlinlang.org/docs/tutorials/command-line.html
function Env-SetKotlinEnvironmentVariable() {
    $APP_KOTLIN_PATH = $APP_DIR + '.kotlin\'
    $APP_KOTLIN_BIN_PATH = $APP_KOTLIN_PATH + 'bin\'

    Env-TryAppendPathVariable -Value $APP_KOTLIN_BIN_PATH
}


# https://dotnet.github.io/
# https://docs.microsoft.com/en-us/dotnet/core/tools/telemetry
function Env-SetNetEnvironmentVariable() {
    Env-TrySetVariable -Variable 'DOTNET_CLI_TELEMETRY_OPTOUT' -Value "true" 
    Env-TryAppendPathVariable -Value 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\'
}

# https://www.python.org/downloads/windows/
# Windows x86-64 embeddable zip file
function Env-SetPythonEnvironmentVariable() {
    $APP_PYTHON_PATH = $APP_DIR + '.python\';
    $APP_PYTHON_SCRIPTS_PATH = $APP_PYTHON_PATH + 'scripts\';

    Env-TryAppendPathVariable -Value $APP_PYTHON_PATH
    Env-TryAppendPathVariable -Value $APP_PYTHON_SCRIPTS_PATH
}

# https://github.com/icsharpcode/ILSpy/releases
function Env-SetILSpyEnvironmentVariable() {
    $APP_ILSPY_PATH = $APP_DIR + '.ilspy\';

    Env-TryAppendPathVariable -Value $APP_ILSPY_PATH
}

# https://www.nuget.org/downloads 
# https://docs.microsoft.com/en-us/nuget/tools/cli-ref-environment-variables
function Env-SetNugetEnvironmentVariable() {
    $APP_NUGET_PATH = $APP_DIR + '.nuget\';

    $CACHE_NUGET_PATH = $CACHE_PATH + '.nuget\';

    Env-TrySetVariable -Variable 'NUGET_PACKAGES' -Value $CACHE_NUGET_PATH
    Env-TryAppendPathVariable -Value $APP_NUGET_PATH
}

# https://developer.android.com/studio/releases/platform-tools.html
function Env-SetADBEnvironmentVariable() {
    $APP_ADB_PATH = $APP_DIR + '.adb\';

    Env-TryAppendPathVariable -Value $APP_ADB_PATH
}

# https://www.cpuid.com/softwares/cpu-z.html
function Env-SetCPUZEnvironmentVariable() {
    $APP_CPU_Z_PATH = $APP_DIR + '.cpu-z\';

    Env-TryAppendPathVariable -Value $APP_CPU_Z_PATH
}

# https://www.techpowerup.com/gpuz/
function Env-SetGPUZEnvironmentVariable() {
    $APP_GPU_Z_PATH = $APP_DIR + '.gpu-z\';

    Env-TryAppendPathVariable -Value $APP_GPU_Z_PATH
}

# http://www.superpi.net/Download/
function Env-SetPIEnvironmentVariable() {
    $APP_PI_PATH = $APP_DIR + '.pi\';

    Env-TryAppendPathVariable -Value $APP_PI_PATH
}

# https://maven.apache.org/
function Env-SetMavenEnvironmentVariable() {
    $APP_MAVEN_PATH = $APP_DIR + '.maven\'
    $APP_MAVEN_BIN_PATH = $APP_MAVEN_PATH + 'bin\'
    $CACHE_MAVEN_PATH = $CACHE_PATH + '.maven\'

    # for maven 1
    Env-TrySetVariable -Variable 'MAVEN_HOME' -Value $APP_MAVEN_PATH

    # for maven 2 or 3
    Env-TrySetVariable -Variable 'M2_HOME' -Value $APP_MAVEN_PATH

    # for maven-wrapper https://github.com/takari/maven-wrapper
    Env-TrySetVariable -Variable 'MAVEN_USER_HOME' -Value $APP_MAVEN_PATH
    
    # http://maven.apache.org/configure.html
    Env-TrySetVariable -Variable 'MAVEN_OPTS' -Value '-Dfile.encoding=UTF-8'

    # custom
    Env-TrySetVariable -Variable 'MAVEN_REPOSITORY_HOME' -Value $CACHE_MAVEN_PATH

    Env-TryAppendPathVariable -Value $APP_MAVEN_BIN_PATH
}

# https://gradle.org/releases/
# https://docs.gradle.org/current/userguide/installation.html
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_environment_variables
function Env-SetGradleEnvironmentVariable() {
    $APP_GRADLE_PATH = $APP_DIR + '.gradle\';
    $APP_GRADLE_BIN_PATH = $APP_GRADLE_PATH + 'bin\';

    $CACHE_GRADLE_PATH = $CACHE_PATH + '.gradle\';

    Env-TrySetVariable -Variable 'GRADLE_HOME' -Value $APP_GRADLE_PATH
    Env-TrySetVariable -Variable 'GRADLE_USER_HOME' -Value $CACHE_GRADLE_PATH
    Env-TryAppendPathVariable -Value $APP_GRADLE_BIN_PATH
}

# https://projects.spring.io/spring-boot/
function Env-SetSpringBootCliEnvironmentVariable() {
    $APP_SPRING_BOOT_CLI_PATH = $APP_DIR + '.spring-boot-cli\';
    $APP_SPRING_BOOT_CLI_BIN_PATH = $APP_SPRING_BOOT_CLI_PATH + 'bin\';

    Env-TryAppendPathVariable -Value $APP_SPRING_BOOT_CLI_BIN_PATH
}

# http://httpd.apache.org/download.cgi
function Env-SetHttpdEnvironmentVariable() {
    $APP_HTTPD_PATH = $APP_DIR + '.httpd\';

    Env-TryAppendPathVariable -Value $APP_HTTPD_PATH
}

# http://nginx.org/en/download.html
function Env-SetNginxEnvironmentVariable() {
    $APP_NGINX_PATH = $APP_DIR + '.nginx\';

    Env-TryAppendPathVariable -Value $APP_NGINX_PATH
}

# https://kubernetes.io/docs/tasks/tools/install-kubectl
function Env-SetKubectlEnvironmentVariable() {
    $APP_KUBECTL_PATH = $APP_DIR + '.kubectl\';
    $APP_KUBECTL_CONFIG_FILE = $APP_KUBECTL_PATH + 'kubectl-config.yml';

    Env-TrySetVariable -Variable 'KUBECONFIG' -Value $APP_KUBECTL_CONFIG_FILE
    Env-TryAppendPathVariable -Value $APP_KUBECTL_PATH
}

# https://github.com/kubernetes/minikube/releases
function Env-SetMinikubeEnvironmentVariable() {
    $APP_MINIKUBE_PATH = $APP_DIR + '.minikube\';
    $CACHE_MINIKUBE_PATH = 'e:\.minikube\';

    Env-TrySetVariable -Variable 'MINIKUBE_HOME' -Value $CACHE_MINIKUBE_PATH
    Env-TrySetVariable -Variable 'MINIKUBE_WANTUPDATENOTIFICATION' -Value 'false'
    Env-TrySetVariable -Variable 'MINIKUBE_WANTREPORTERRORPROMPT' -Value 'false'
    Env-TrySetVariable -Variable 'CHANGE_MINIKUBE_NONE_USER' -Value 'true'
    Env-TryAppendPathVariable -Value $APP_MINIKUBE_PATH
}

# https://docs.docker.com/engine/reference/commandline/cli/#environment-variables
# https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-socket-option
function Env-SetDockerEnvironmentVariable() {
    $APP_DOCKER_PATH = $APP_DIR + '.docker\';

    Env-TrySetVariable -Variable 'DOCKER_HOST' -Value 'tcp://127.0.0.1:2375'
    Env-TryAppendPathVariable -Value $APP_DOCKER_PATH
}

# https://docs.docker.com/machine
# https://docs.docker.com/machine/drivers/hyper-v/
function Env-SetDockerMachineEnvironmentVariable() {
    $APP_DOCKER_PATH = $APP_DIR + '.docker\';
    $BOOT2DOCKER_ISO_PATH = 'file://' + $APP_DOCKER_PATH + 'boot2docker.iso';
    $CACHE_DOCKER_PATH = 'e:\.docker\';

    Env-TrySetVariable -Variable 'MACHINE_STORAGE_PATH' -Value $CACHE_DOCKER_PATH
    Env-TrySetVariable -Variable 'MACHINE_NATIVE_SSH' -Value 1
    Env-TrySetVariable -Variable 'HYPERV_BOOT2DOCKER_URL' -Value $BOOT2DOCKER_ISO_PATH
    Env-TrySetVariable -Variable 'HYPERV_VIRTUAL_SWITCH' -Value 'HVS'
    Env-TrySetVariable -Variable 'HYPERV_CPU_COUNT' -Value 1
    Env-TrySetVariable -Variable 'HYPERV_MEMORY' -Value 1024
    Env-TrySetVariable -Variable 'HYPERV_DISK_SIZE' -Value 10240

    Env-TryAppendPathVariable -Value $APP_DOCKER_PATH
}

# https://helm.sh/docs
# https://github.com/helm/helm-www
# https://github.com/helm/helm/releases
function Env-SetHelmEnvironmentVariable() {
    $APP_HLEM_PATH = $APP_DIR + '.helm\';

    Env-TryAppendPathVariable -Value $APP_HLEM_PATH
}

# https://github.com/mholt/caddy
# https://caddyserver.com/docs/cli
function Env-SetCaddyEnvironmentVariable() {
    $APP_CADDY_PATH = $APP_DIR + '.caddy\';
    $CACHE_CADDY_PATH = $CACHE_PATH + '.caddy\';

    Env-TrySetVariable -Variable 'CADDYPATH' -Value $CACHE_CADDY_PATH
    Env-TryAppendPathVariable -Value $APP_CADDY_PATH
}

# https://coreos.com/os/docs/1911.5.0/overview-of-ct.html
# https://github.com/coreos/container-linux-config-transpiler
function Env-SetCoreOSEnvironmentVariable() {
    $APP_COREOS_PATH = $APP_DIR + '.coreos\';

    Env-TryAppendPathVariable -Value $APP_COREOS_PATH
}

# https://docs.microsoft.com/en-us/powershell/scripting/overview?view=powershell-6
function Env-SetPowerShellEnvironmentVariable() {
    Env-TrySetVariable -Variable 'POWERSHELL_TELEMETRY_OPTOUT' -Value 'true'
}

# https://github.com/v2ray/v2ray-core
function Env-SetV2RayEnvironmentVariable() {
    $APP_V2RAY_PATH = $APP_DIR + '.v2ray\';

    Env-TryAppendPathVariable -Value $APP_V2RAY_PATH
}

function Env-SetLocaleEnvironmentVariable() {
    Env-TrySetVariable -Variable 'LC_ALL' -Value 'zh_CN.UTF-8'
    Env-TrySetVariable -Variable 'LANG' -Value 'C.UTF-8'
}

# https://www.alex-is.de/PHP/fusion/downloads.php?cat_id=4&download_id=9
function Env-SetASSSDBenchmarkEnvironmentVariable() {
    $APP_AS_SSD_BENCHMARK_PATH = $APP_DIR + '.as-ssd-benchmark\';

    Env-TryAppendPathVariable -Value $APP_AS_SSD_BENCHMARK_PATH
}

# https://crystalmark.info/en/download/
function Env-SetDiskInfoEnvironmentVariable() {
    $APP_DISK_INFO_PATH = $APP_DIR + '.disk-info\';

    Env-TryAppendPathVariable -Value $APP_DISK_INFO_PATH
}

# https://github.com/pbatard/rufus
function Env-SetRufusEnvironmentVariable() {
    $APP_RUFUS_PATH = $APP_DIR + '.rufus\';

    Env-TryAppendPathVariable -Value $APP_RUFUS_PATH
}

# https://github.com/FFmpeg/FFmpeg
function Env-SetFFmpegEnvironmentVariable() {
    $APP_FFMPEG_PATH = $APP_DIR + '.ffmpeg\bin';

    Env-TryAppendPathVariable -Value $APP_FFMPEG_PATH
}

# https://www.rust-lang.org/
function Env-SetRustEnvironmentVariable() {
    $APP_RUSTUP_PATH = $APP_DIR + '.rustup\';
    $APP_CARGO_PATH = $APP_DIR + '.cargo\';
    $APP_CARGO_BIN_PATH = $APP_CARGO_PATH + 'bin\';

    # https://github.com/rust-lang/rustup.rs#environment-variables
    Env-TrySetVariable -Variable 'RUSTUP_HOME' -Value $APP_RUSTUP_PATH
    Env-TrySetVariable -Variable 'RUSTUP_DIST_SERVER' -Value 'http://mirrors.ustc.edu.cn/rust-static'
    Env-TrySetVariable -Variable 'RUSTUP_UPDATE_ROOT' -Value 'http://mirrors.ustc.edu.cn/rust-static/rustup'
    
    # https://github.com/rust-lang/cargo/blob/master/src/doc/src/reference/environment-variables.md
    Env-TrySetVariable -Variable 'CARGO_HOME' -Value $APP_CARGO_PATH

    Env-TrySetVariable -Variable 'RUST_BACKTRACE' -Value 'full'
    Env-TrySetVariable -Variable 'RUST_TEST_NOCAPTURE' -Value '0'

    Env-TryAppendPathVariable -Value $APP_CARGO_BIN_PATH
}

# https://github.com/gohugoio/hugo
function Env-SetHugoEnvironmentVariable() {
    $APP_HUGO_PATH = $APP_DIR + '.hugo\';

    Env-TryAppendPathVariable -Value $APP_HUGO_PATH
}
{'fraction_non_alphanumeric': 0.13755231876778837, 'fraction_numerical': 0.004754729616608069, 'mean_word_length': 4.275746334569864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 100, 'lorem ipsum': 0, 'www.': 18, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1259285', 'n_tokens_mistral': 11258, 'n_tokens_neox': 10834, 'n_words': 1557}