forked from toksaitov/AndroidStudioPortable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup-AndroidStudioPortable.ps1
184 lines (149 loc) · 4.25 KB
/
Setup-AndroidStudioPortable.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#Requires -Version 2.0
<#
.SYNOPSIS
Downloads, unpacks, and prepares a portable
Android development environment.
#>
#
# First boost SSL to TLS1.2
#
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
#
# Definitions
#
. '.\AndroidStudioPortable-Definitions.ps1'
#
# Helpers
#
. '.\AndroidStudioPortable-Helpers.ps1'
#
# Steps
#
#
# 0. Check to see if we need to download anything
#
$ToolsAreRequired =
!(Test-Path -Path $AndroidSDKDirectory) -Or
!(Test-Path -Path $AndroidStudioDirectory)
if ($ToolsAreRequired -And !(Test-Path -Path $aria2Directory))
{
if (!(Test-Path -Path $aria2Archive))
{
Write-Output "Get Aria2 Downloader"
Invoke-FileDownload -Uri $aria2URL -OutFile $aria2Archive
}
Write-Output "Expand Aria2"
Expand-Archive -Path $aria2Archive
}
#
# Download and unpack the 7-Zip archive and bootstrap extractor.
#
if ($ToolsAreRequired -And !(Test-Path -Path $7zExecutable))
{
if (!(Test-Path -Path $7zInstaller))
{
Write-Output "Get 7-Zip"
& ".\$aria2Directory\$aria2Executable" --file-allocation=none -o $7zBootStrapExec $7zBootStrapURL
& ".\$aria2Directory\$aria2Executable" --file-allocation=none -o $7zInstaller $7zURL
}
Write-Output "Use 7zr to unpack 7zip"
& ".\$7zBootStrapExec" 'e' $7zInstaller '-bso0' '-bsp1' '-y' $7zExtractFile
}
#
# Download and unpack an Android Studio archive.
#
if (!(Test-Path -Path $AndroidStudioDirectory))
{
if (!(Test-Path -Path $AndroidStudioArchive) -or (Test-Path -Path "$AndroidStudioArchive.aria2"))
{
Write-Output "Download Android Studio $AndroidStudio"
& ".\$aria2Directory\$aria2Executable" --file-allocation=none -c -o $AndroidStudioArchive $AndroidStudioURL
}
Write-Output "Unpacking Android Studio"
& ".\$7zExecutable" 'x' $AndroidStudioArchive '-o*' '-bso0' '-bsp1' '-y'
}
#
# Create a new SDK directory.
#
$NewItemParameters = @{
Path = $AndroidSDKDirectory;
ItemType = 'Directory';
}
New-Item @NewItemParameters -Force | Out-Null
#
# Create a new HOME directory for SDK and configuration files.
#
$NewItemParameters = @{
Path = $PortableHomeDirectory;
ItemType = 'Directory';
}
New-Item @NewItemParameters -Force | Out-Null
#
# Tell the Android Studio to search for configuration files
# relative to its current directory.
#
foreach ($Parameter in $AndroidStudioAdditionalParameters)
{
if (!(Select-String -Pattern $Parameter `
-Path $AndroidStudioConfigurationFile `
-SimpleMatch `
-Quiet))
{
Add-Content -Path $AndroidStudioConfigurationFile `
-Value "`n$Parameter"
}
}
foreach ($VMConfigurationFile in $AndroidStudioVMConfigurationFiles)
{
foreach ($VMParameter in $AndroidStudioAdditionalVMParameters)
{
if (!(Select-String -Pattern $VMParameter `
-Path $VMConfigurationFile `
-SimpleMatch `
-Quiet))
{
Add-Content -Path $VMConfigurationFile `
-Value "`n$VMParameter"
}
}
}
#
# Cleanup Tools
#
. '.\Remove-SetupTemporaryFiles.ps1'
#
# Generate a batch file to start Android Studio.
#
$AndroidSDKBinariesPaths = ''
foreach ($Directory in $AndroidSDKBinariesDirectories)
{
$AndroidSDKBinariesPaths =
"%~dp0$Directory;$AndroidSDKBinariesPaths"
}
$AndroidStudioBatchContent = @"
@echo off
REM
REM Starts an instance of Android Studio.
REM
REM This file is automatically generated. Please, do not edit this file.
REM
SET HOMEPATH=%~dp0$PortableHomeDirectory
SET USERPROFILE=%~dp0$PortableHomeDirectory
SET ANDROID_HOME=%~dp0$AndroidSDKDirectory
SET ANDROID_SDK_HOME=%~dp0$PortableHomeDirectory
SET GRADLE_USER_HOME=%~dp0$GradleUserHomeDirectory
SET PATH=%~dp0$AndroidStudioBinariesDirectory;%PATH%
SET PATH=$AndroidSDKBinariesPaths%PATH%
CHDIR %~dp0$AndroidStudioBinariesDirectory
START $AndroidStudioExecutable
"@
$NewItemParameters = @{
Path = $AndroidStudioBatchFile;
Type = 'File';
Value = $AndroidStudioBatchContent;
}
New-Item @NewItemParameters -Force
#
# The end.
#
Write-Output "`nDone."