-
Notifications
You must be signed in to change notification settings - Fork 257
/
win_configure.ps1
252 lines (222 loc) · 8.99 KB
/
win_configure.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#
# Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
#
# You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
# copy, modify, and distribute this software in source code or binary form for use
# in connection with the web services and APIs provided by Facebook.
#
# As with any software that integrates with the Facebook platform, your use of
# this software is subject to the Facebook Developer Principles and Policies
# [http:\\developers.facebook.com\policy\]. This copyright notice shall be
# included in all copies or substantial portions of the software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# This file performs the custom build logic to setup the Plugins
# in the unity project
# shellcheck disable=SC2039
$ErrorActionPreference = "SilentlyContinue"
$TARGET_VERSION = "NONE"
$SELECTED_VERSION = -1
function copyright {
Write-Output "Copyright (c) 2014-present, Facebook, Inc. All rights reserved."
Write-Output ""
}
function help {
copyright
Write-Output "This script adjusts external references to Unity 3D for each of the Facebook SDK for Unity projects."
Write-Output ""
Write-Output "Usage:"
Write-Output " .\configure.sh"
Write-Output ""
}
# Cheking working dir
if ( ![System.IO.File]::Exists("$PWD\Facebook.sln") ) {
Write-Output "Please, execute win_configure.ps1 script from root project directory"
exit 1
}
if ($args[0]) {
Write-Output "Using arguments not allowed."
Write-Output $args[0]
exit 1
}
else {
$unity_versions = ""
# Interactive process try to find versions
help
Write-Output ""
Write-Output "Searching Unity versions ..."
$unity_versions = Get-ChildItem -Path "c:\Program Files" -Filter "unity.exe" -Recurse | Select-Object Fullname | Format-List | Out-String
Write-Output ""
Write-Output "Processing Unity folders ..."
$unity_array = $unity_versions.Split("`n", [StringSplitOptions]::RemoveEmptyEntries)
$patterns = '^FullName\s:\s(.*)Unity.exe'
$pattern_version = '^(.*)\\Editor\\(.*)\\Editor'
$array_unity_path = @()
$array_unity_version = @()
foreach ($unity_path in $unity_array) {
if ($unity_path) {
$path_data = [regex]::Match($unity_path, $patterns).captures.groups
if ($path_data) {
#Write-Output $path_data[1].value
$array_unity_path = $array_unity_path + $path_data[1].value
$version_number = [regex]::Match($path_data, $pattern_version).captures.groups
if ($version_number) {
#Write-Output $version_number[2].value
$array_unity_version = $array_unity_version + $version_number[2].value
}
else {
#Write-Output "Old Unity"
$array_unity_version = $array_unity_version + "2017"
}
}
}
}
#Show selection menu
do {
Write-Output ""
Write-Output "Interactive mode, the following versions of unity have been found on your system."
Write-Output ""
$option = 1
foreach ($unity_path in $array_unity_path) {
$ver = $array_unity_version[$option - 1]
Write-Output $option" - "$ver" [ "$unity_path" ]"
$option++
}
Write-Output ""
$Prompt = Read-host "Select unity version from the list (Ctrl+C to cancel) "
if ( ($Prompt -gt 0 -and $Prompt -lt $option) ) {
$SELECTED_VERSION = $Prompt - 1
$TARGET_VERSION = $array_unity_version[$SELECTED_VERSION]
$TARGET_PATH = $array_unity_path[$SELECTED_VERSION]
Write-Output ""
Write-Output "You has been selected unity version: "$TARGET_VERSION
Write-Output ""
}
else {
Write-Output ""
Write-Output "Wrong Selection!"
Write-Output ""
$SELECTED_VERSION = -1
}
} while ($SELECTED_VERSION -eq -1)
Write-Output ""
Write-Output "Preparing Unity references..."
Write-Output ""
}
if ( $TARGET_VERSION -eq "NONE" ) {
Write-Output ""
Write-Output "!Unity family version not selected."
Write-Output""
help
exit 1
}
#define full paths for unity version
switch ($TARGET_VERSION) {
'2017.4.40f1' {
$UNITY_MANAGED_DIR = "$TARGET_PATH\Data\Managed\"
$UNITY_UI_DIR = "$TARGET_PATH\Data\UnityExtensions\Unity\GUISystem\"
$UNITY_ENGINE_DIR = "$TARGET_PATH\Data\Managed\"
$UNITY_EXTENSIONS_DIR = "$TARGET_PATH\Data\UnityExtensions\Unity\"
$TARGET_VERSION = "2017";
}
default {
Write-Output ""
Write-Output "Please use Unity 2017.4.40f1 to work with UnitySDK project on Windows devices."
Write-Output ""
exit 1
}
}
#Replace Unity path in UnityReferences.xml
$unity_references_file = "$PWD\UnityReferences.xml"
[xml] $xml_data = Get-Content $unity_references_file -Raw
# Set unity version for projects
$xml_data.Project.PropertyGroup[0].UNITY_VERSION = $TARGET_VERSION
# Set full paths for unity version
$error_version = true
foreach ($property_group in $xml_data.Project.PropertyGroup) {
if ($property_group.Attributes["Condition"]) {
$version_group = $property_group.Attributes["Condition"].Value
if ($version_group.Contains($TARGET_VERSION) ) {
$property_group.UNITY_MANAGED_DIR = $UNITY_MANAGED_DIR
$property_group.UNITY_UI_DIR = $UNITY_UI_DIR
$property_group.UNITY_ENGINE_DIR = $UNITY_ENGINE_DIR
$property_group.UNITY_EXTENSIONS_DIR = $UNITY_EXTENSIONS_DIR
$property_group.UNITY_NETWORKING_DIR = $UNITY_NETWORKING_DIR
$error_version = false
}
}
}
if ($error_version) {
Write-Output ""
Write-Output "Unity version is not in UnityReferences.xml. Please add it or use an exiting Unity version."
Write-Output ""
exit 1
}
else {
$xml_data.Save($unity_references_file)
}
# Fix projects files
Write-Output ""
Write-Output "Preparing Visual Studio Projects..."
Write-Output ""
$projects_array = @("Facebook.Unity", "Facebook.Unity.Settings", "Facebook.Unity.Android", "Facebook.Unity.Canvas", "Facebook.Unity.Editor", "Facebook.Unity.Tests", "UnitySDK", "Facebook.Unity.Windows")
foreach ($PROJECT in $projects_array) {
Write-Output ""
Write-Output "Project: $PROJECT"
Write-Output ""
if ($PROJECT -eq "UnitySDK") {
$PROJECT_FILE_NAME = "Assembly-CSharp"
}
else {
$PROJECT_FILE_NAME = $PROJECT
}
$project_path = "$PWD\" + $PROJECT + "\" + $PROJECT_FILE_NAME + ".csproj"
$project_ref = "$PWD\" + $PROJECT + "\UnityReferences\" + $TARGET_VERSION + ".xml"
# Cheking project file
if ( ![System.IO.File]::Exists($project_path) ) {
Write-Output ""
Write-Output "Project doesn't exist. Please review project list."
Write-Output ""
Write-Output "Error path: " $project_path
Write-Output ""
exit 1
}
else {
# Cheking project ref file
if ( ![System.IO.File]::Exists($project_ref) ) {
Write-Output ""
Write-Output "Project references doesn't exist. Please review project references folder."
Write-Output ""
Write-Output "Error path: " $project_ref
Write-Output ""
exit 1
}
else {
$xml_project_ref = Get-Content $project_ref -raw
$result=Select-String -Path $project_path -Pattern "<!-- BEGIN_UNITY_REFERENCES -->" | Select-Object LineNumber -First 1
$line_start=$result[0].LineNumber
$result=Select-String -Path $project_path -Pattern "<!-- END_UNITY_REFERENCES -->" | Select-Object LineNumber -First 1
$line_end=$result[0].LineNumber
$fileContent = Get-Content $project_path
if( $line_end -gt ($line_start+1) ){
$prev=$fileContent[0..($line_start-1)]
$final=$fileContent[($line_end-1)..($fileContent.length-1)]
$total=$prev+$final
Set-Content $project_path $total
}
$fileContent = Get-Content $project_path
$fileContent[$line_start-1] += "`n" + $xml_project_ref.trimend()
Set-Content $project_path $fileContent
Write-Output " -> $PROJECT/$PROJECT_FILE_NAME.csproj Updated!"
}
}
}
#finish script
Write-Output ""
Write-Output "The script finished successfully."
Write-Output ""
exit 0