FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
UnityLauncherPro/UnityLauncherPro/GetUnityInstallations.cs at dev · unitycoder/UnityLauncherPro · GitHub
unitycoder
UnityLauncherPro
Repository navigation
Code
Issues
23
(23)
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
UnityLauncherPro
/
UnityLauncherPro
/
GetUnityInstallations.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
178 lines (150 loc) · 7.65 KB
Breadcrumbs
UnityLauncherPro
/
UnityLauncherPro
/
GetUnityInstallations.cs
Copy path
File metadata and controls
178 lines (150 loc) · 7.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
IO
;
namespace
UnityLauncherPro
{
/// <summary>
/// returns unity installations under given root folders
/// </summary>
public
static
class
GetUnityInstallations
{
static
Dictionary
<
string
,
string
>
platformNames
=
new
Dictionary
<
string
,
string
>
{
{
"androidplayer"
,
"Android"
}
,
{
"windowsstandalonesupport"
,
"Win"
}
,
{
"linuxstandalonesupport"
,
"Linux"
}
,
{
"LinuxStandalone"
,
"Linux"
}
,
{
"OSXStandalone"
,
"OSX"
}
,
{
"webglsupport"
,
"WebGL"
}
,
{
"metrosupport"
,
"UWP"
}
,
{
"iossupport"
,
"iOS"
}
}
;
// returns unity installations
public
static
List
<
UnityInstallation
>
Scan
(
)
{
// get list from settings
var
rootFolders
=
Properties
.
Settings
.
Default
.
rootFolders
;
// unityversion, exe_path
List
<
UnityInstallation
>
results
=
new
List
<
UnityInstallation
>
(
)
;
// iterate all folders under root folders
foreach
(
string
rootFolder
in
rootFolders
)
{
// if folder exists
if
(
String
.
IsNullOrWhiteSpace
(
rootFolder
)
==
true
||
Directory
.
Exists
(
rootFolder
)
==
false
)
continue
;
// get all folders
var
directories
=
Directory
.
GetDirectories
(
rootFolder
)
;
// parse all folders under root, and search for unity editor files
for
(
int
i
=
0
,
length
=
directories
.
Length
;
i
<
length
;
i
++
)
{
var
editorFolder
=
Path
.
Combine
(
directories
[
i
]
,
"Editor"
)
;
if
(
Directory
.
Exists
(
editorFolder
)
==
false
)
{
// OPTIONAL scan for source code build output
editorFolder
=
Path
.
Combine
(
directories
[
i
]
,
"build/WindowsEditor/x64/Release"
)
;
if
(
Directory
.
Exists
(
editorFolder
)
==
false
)
{
// no unity editor root folder found, skip this folder
continue
;
}
}
// check if uninstaller is there, sure sign of unity
var
uninstallExe
=
Path
.
Combine
(
editorFolder
,
"Uninstall.exe"
)
;
var
haveUninstaller
=
File
.
Exists
(
uninstallExe
)
;
var
exePath
=
Path
.
Combine
(
editorFolder
,
"Unity.exe"
)
;
if
(
File
.
Exists
(
exePath
)
==
false
)
continue
;
// get full version number from uninstaller (or try exe, if no uninstaller)
var
version
=
Tools
.
GetFileVersionData
(
haveUninstaller
?
uninstallExe
:
exePath
)
;
// we got new version to add
var
dataFolder
=
Path
.
Combine
(
editorFolder
,
"Data"
)
;
DateTime
?
installDate
=
Tools
.
GetLastModifiedTime
(
dataFolder
)
;
UnityInstallation
unity
=
new
UnityInstallation
(
)
;
unity
.
Version
=
version
;
unity
.
VersionCode
=
Tools
.
VersionAsLong
(
version
)
;
// cached version code
unity
.
Path
=
exePath
;
unity
.
Installed
=
installDate
;
unity
.
IsPreferred
=
(
version
==
MainWindow
.
preferredVersion
)
;
unity
.
ProjectCount
=
GetProjectCountForUnityVersion
(
version
)
;
if
(
Tools
.
IsAlpha
(
version
)
)
{
unity
.
ReleaseType
=
"Alpha"
;
}
else
if
(
Tools
.
IsBeta
(
version
)
)
{
unity
.
ReleaseType
=
"Beta"
;
}
else
if
(
Tools
.
IsLTS
(
version
)
)
{
unity
.
ReleaseType
=
"LTS"
;
}
else
{
unity
.
ReleaseType
=
""
;
// cannot be null for UnitysFilter to work properly
}
// get platforms, NOTE if this is slow, do it later, or skip for commandline
var
platforms
=
GetPlatforms
(
dataFolder
)
;
// this is for editor tab, show list of all platforms in cell
if
(
platforms
!=
null
)
unity
.
PlatformsCombined
=
string
.
Join
(
", "
,
platforms
)
;
// this is for keeping array of platforms for platform combobox
if
(
platforms
!=
null
)
unity
.
Platforms
=
platforms
;
// add to list, if not there yet NOTE should notify that there are 2 same versions..? this might happen with preview builds..
if
(
results
.
Contains
(
unity
)
==
true
)
{
Console
.
WriteLine
(
"Warning: 2 same versions found for "
+
version
)
;
continue
;
}
results
.
Add
(
unity
)
;
}
// got folders
}
// all root folders
// sort by version
results
.
Sort
(
(
s1
,
s2
)
=>
s2
.
VersionCode
.
CompareTo
(
s1
.
VersionCode
)
)
;
return
results
;
}
// scan()
public
static
bool
HasUnityInstallations
(
string
path
)
{
var
directories
=
Directory
.
GetDirectories
(
path
)
;
// loop folders inside root
for
(
int
i
=
0
,
length
=
directories
.
Length
;
i
<
length
;
i
++
)
{
var
editorFolder
=
Path
.
Combine
(
directories
[
i
]
,
"Editor"
)
;
if
(
Directory
.
Exists
(
editorFolder
)
==
false
)
continue
;
var
editorExe
=
Path
.
Combine
(
editorFolder
,
"Unity.exe"
)
;
if
(
File
.
Exists
(
editorExe
)
==
false
)
continue
;
// have atleast 1 installation
return
true
;
}
return
false
;
}
// scans unity installation folder for installed platforms
static
string
[
]
GetPlatforms
(
string
dataFolder
)
{
// get all folders inside
var
platformFolder
=
Path
.
Combine
(
dataFolder
,
"PlaybackEngines"
)
;
if
(
Directory
.
Exists
(
platformFolder
)
==
false
)
return
null
;
//var directories = Directory.GetDirectories(platformFolder);
var
directories
=
new
List
<
string
>
(
Directory
.
GetDirectories
(
platformFolder
)
)
;
//for (int i = 0; i < directories.Length; i++)
var
count
=
directories
.
Count
;
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
var
foldername
=
Path
.
GetFileName
(
directories
[
i
]
)
.
ToLower
(
)
;
//Console.WriteLine("PlaybackEngines: " + foldername);
// check if have better name in dictionary
if
(
platformNames
.
ContainsKey
(
foldername
)
)
{
directories
[
i
]
=
platformNames
[
foldername
]
;
// add also 64bit desktop versions for that platform, NOTE dont add android, ios or webgl
if
(
foldername
.
IndexOf
(
"alone"
)
>
-
1
)
directories
.
Add
(
platformNames
[
foldername
]
+
"64"
)
;
}
else
// use raw
{
directories
[
i
]
=
foldername
;
}
//Console.WriteLine(i + " : " + foldername + " > " + directories[i]);
}
return
directories
.
ToArray
(
)
;
}
static
int
GetProjectCountForUnityVersion
(
string
version
)
{
if
(
MainWindow
.
projectsSource
==
null
)
return
0
;
//Console.WriteLine("xxx "+(MainWindow.projectsSource==null));
int
count
=
0
;
// count projects using this exact version
for
(
int
i
=
0
,
len
=
MainWindow
.
projectsSource
.
Count
;
i
<
len
;
i
++
)
{
if
(
MainWindow
.
projectsSource
[
i
]
.
Version
==
version
)
count
++
;
}
return
count
;
}
}
// class
}
// namespace
Back
|
FazBrowse Home
|
New Git URL