FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
flashdevelop/PluginCore/PluginCore/PlatformData.cs at open_folder · SandersAlex/flashdevelop · GitHub
SandersAlex
flashdevelop
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
flashdevelop
/
PluginCore
/
PluginCore
/
PlatformData.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
268 lines (238 loc) · 9.73 KB
Breadcrumbs
flashdevelop
/
PluginCore
/
PluginCore
/
PlatformData.cs
Copy path
File metadata and controls
268 lines (238 loc) · 9.73 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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
IO
;
using
System
.
Xml
;
namespace
PluginCore
{
// When updating, update also AirProperties plugin!
// This class must not have any dependencies
public
class
PlatformData
{
public
static
string
CUSTOM_PLATFORM
=
"Custom"
;
public
static
string
FLASHPLAYER_PLATFORM
=
"Flash Player"
;
public
static
string
JAVASCRIPT_PLATFORM
=
"JavaScript"
;
public
static
Dictionary
<
String
,
SupportedLanguage
>
SupportedLanguages
;
public
static
string
ResolveFlashPlayerVersion
(
string
lang
,
string
platformName
,
string
version
)
{
if
(
!
SupportedLanguages
.
ContainsKey
(
lang
)
)
return
"19.0"
;
var
platforms
=
SupportedLanguages
[
lang
.
ToLower
(
)
]
.
Platforms
;
if
(
!
platforms
.
ContainsKey
(
FLASHPLAYER_PLATFORM
)
)
return
"19.0"
;
var
flashPlatform
=
platforms
[
FLASHPLAYER_PLATFORM
]
;
if
(
platforms
.
ContainsKey
(
platformName
)
)
{
var
otherTarget
=
platforms
[
platformName
]
;
foreach
(
var
otherVersion
in
otherTarget
.
Versions
)
if
(
otherVersion
.
Value
==
version
)
{
foreach
(
var
flashVersion
in
flashPlatform
.
Versions
)
if
(
flashVersion
.
SwfVersion
==
otherVersion
.
SwfVersion
)
return
flashVersion
.
Value
;
}
}
// default to last FP
return
flashPlatform
.
LastVersion
.
Value
;
}
public
static
string
ResolveSwfVersion
(
string
lang
,
string
platformName
,
string
version
)
{
if
(
!
SupportedLanguages
.
ContainsKey
(
lang
)
)
return
"30"
;
var
platforms
=
SupportedLanguages
[
lang
.
ToLower
(
)
]
.
Platforms
;
if
(
!
platforms
.
ContainsKey
(
FLASHPLAYER_PLATFORM
)
||
!
platforms
.
ContainsKey
(
platformName
)
)
return
"29"
;
var
platform
=
platforms
[
platformName
]
;
foreach
(
var
platformVersion
in
platform
.
Versions
)
if
(
platformVersion
.
Value
==
version
)
return
platformVersion
.
SwfVersion
;
// default to last FP
return
platform
.
LastVersion
.
SwfVersion
;
}
#region platform config loading
public
static
void
Load
(
string
path
)
{
SupportedLanguages
=
new
Dictionary
<
String
,
SupportedLanguage
>
(
)
;
if
(
!
Directory
.
Exists
(
path
)
)
return
;
// walk AS2, AS3, Haxe...
foreach
(
string
langDir
in
Directory
.
GetDirectories
(
path
)
)
{
try
{
SupportedLanguage
lang
=
new
SupportedLanguage
{
Name
=
Path
.
GetFileNameWithoutExtension
(
langDir
)
,
Platforms
=
LoadPlatforms
(
langDir
)
}
;
lang
.
PlatformNames
=
new
string
[
lang
.
Platforms
.
Count
]
;
lang
.
Platforms
.
Keys
.
CopyTo
(
lang
.
PlatformNames
,
0
)
;
SupportedLanguages
.
Add
(
lang
.
Name
.
ToLower
(
)
,
lang
)
;
}
catch
{
}
}
}
private
static
Dictionary
<
string
,
LanguagePlatform
>
LoadPlatforms
(
string
langDir
)
{
// walk flashplayer.xml, openfl.xml,... for one language (ie. Haxe)
var
platforms
=
new
Dictionary
<
string
,
LanguagePlatform
>
(
)
;
foreach
(
string
platformFile
in
Directory
.
GetFiles
(
langDir
,
"*.xml"
)
)
{
try
{
var
doc
=
new
XmlDocument
(
)
;
doc
.
Load
(
platformFile
)
;
if
(
doc
.
FirstChild
.
Name
==
"platform"
)
{
var
platform
=
ParsePlatform
(
doc
.
FirstChild
)
;
platforms
.
Add
(
platform
.
Name
,
platform
)
;
}
}
catch
{
}
}
return
platforms
;
}
private
static
LanguagePlatform
ParsePlatform
(
XmlNode
node
)
{
// parse platform file, ie. flashplayer.xml
List
<
PlatformVersion
>
versions
=
null
;
Dictionary
<
string
,
PlatformCommand
>
defaultCommands
=
null
;
foreach
(
XmlNode
sub
in
node
.
ChildNodes
)
{
switch
(
sub
.
Name
)
{
case
"defaults"
:
defaultCommands
=
ParseCommands
(
sub
,
null
)
;
break
;
case
"versions"
:
versions
=
ParseVersions
(
sub
,
defaultCommands
)
;
break
;
}
}
var
platform
=
new
LanguagePlatform
{
Name
=
node
.
Attributes
[
"name"
]
.
Value
,
Targets
=
GetList
(
node
,
"targets"
)
,
Versions
=
versions
,
LastVersion
=
versions
[
versions
.
Count
-
1
]
,
IsFlashPlatform
=
GetBool
(
node
,
"flash"
)
,
IsGraphical
=
GetBool
(
node
,
"graphical"
)
,
ExternalToolchain
=
GetAttribute
(
node
,
"external"
)
,
ExternalToolchainCapture
=
GetList
(
node
,
"external-capture"
)
,
DefaultProjectFile
=
GetList
(
node
,
"default-project"
)
,
HaxeTarget
=
GetAttribute
(
node
,
"haxe-target"
)
,
DebuggerSupported
=
GetList
(
node
,
"debugger"
)
,
RawData
=
node
}
;
platform
.
VersionNames
=
new
string
[
platform
.
Versions
.
Count
]
;
for
(
int
i
=
0
;
i
<
platform
.
Versions
.
Count
;
i
++
)
platform
.
VersionNames
[
i
]
=
platform
.
Versions
[
i
]
.
Value
;
return
platform
;
}
private
static
bool
GetBool
(
XmlNode
node
,
string
attribute
)
{
return
(
GetAttribute
(
node
,
attribute
)
??
"false"
)
.
ToLower
(
)
==
"true"
;
}
private
static
string
GetAttribute
(
XmlNode
node
,
string
name
)
{
var
attr
=
node
.
Attributes
[
name
]
;
if
(
attr
!=
null
)
return
attr
.
Value
;
return
null
;
}
private
static
string
[
]
GetList
(
XmlNode
node
,
string
attribute
)
{
// build targets, ie. html5, flash, android for openfl
var
attr
=
node
.
Attributes
[
attribute
]
;
if
(
attr
==
null
)
return
null
;
else
return
attr
.
Value
.
Split
(
','
)
;
}
private
static
List
<
PlatformVersion
>
ParseVersions
(
XmlNode
language
,
Dictionary
<
string
,
PlatformCommand
>
defaultCommands
)
{
if
(
!
language
.
HasChildNodes
)
return
new
List
<
PlatformVersion
>
{
new
PlatformVersion
{
Value
=
"1.0"
,
Commands
=
defaultCommands
}
}
;
var
versions
=
new
List
<
PlatformVersion
>
(
)
;
foreach
(
XmlNode
node
in
language
.
ChildNodes
)
{
if
(
node
.
Name
==
"version"
)
{
versions
.
Add
(
new
PlatformVersion
{
Value
=
node
.
Attributes
[
"value"
]
.
Value
,
SwfVersion
=
ParseSwfVersion
(
node
)
,
Commands
=
ParseCommands
(
node
,
defaultCommands
)
,
RawData
=
node
}
)
;
}
}
return
versions
;
}
private
static
Dictionary
<
string
,
PlatformCommand
>
ParseCommands
(
XmlNode
version
,
Dictionary
<
string
,
PlatformCommand
>
defaultCommands
)
{
// custom display/build/run/clean commands, ie. for openfl
var
commands
=
defaultCommands
==
null
?
new
Dictionary
<
string
,
PlatformCommand
>
(
)
:
new
Dictionary
<
string
,
PlatformCommand
>
(
defaultCommands
)
;
foreach
(
XmlNode
node
in
version
.
ChildNodes
)
{
if
(
node
.
Name
==
"command"
)
{
var
command
=
new
PlatformCommand
{
Name
=
node
.
Attributes
[
"name"
]
.
Value
,
Value
=
node
.
Attributes
[
"value"
]
.
Value
,
RawData
=
node
}
;
commands
.
Add
(
command
.
Name
.
ToLower
(
)
,
command
)
;
}
}
if
(
commands
.
Count
>
0
)
return
commands
;
return
null
;
}
private
static
string
ParseSwfVersion
(
XmlNode
node
)
{
var
attr
=
node
.
Attributes
[
"swf-version"
]
;
return
attr
!=
null
?
attr
.
Value
:
null
;
}
#endregion
}
public
class
SupportedLanguage
{
public
string
Name
;
public
string
[
]
PlatformNames
;
public
Dictionary
<
string
,
LanguagePlatform
>
Platforms
;
}
public
class
LanguagePlatform
{
public
string
Name
;
public
string
[
]
Targets
;
public
string
[
]
VersionNames
;
public
List
<
PlatformVersion
>
Versions
;
public
PlatformVersion
LastVersion
;
public
bool
IsFlashPlatform
;
public
bool
IsGraphical
;
public
string
ExternalToolchain
;
public
string
[
]
ExternalToolchainCapture
;
public
string
[
]
DefaultProjectFile
;
public
string
HaxeTarget
;
public
string
[
]
DebuggerSupported
;
public
XmlNode
RawData
;
public
PlatformVersion
GetVersion
(
string
value
)
{
foreach
(
var
version
in
Versions
)
{
if
(
version
.
Value
==
value
)
return
version
;
}
return
LastVersion
;
}
public
string
GetProjectTemplate
(
string
target
)
{
var
templateNode
=
RawData
.
SelectSingleNode
(
"templates/template[@target='"
+
target
+
"']/@value"
)
;
if
(
templateNode
!=
null
)
return
templateNode
.
Value
;
return
null
;
}
}
public
class
PlatformVersion
{
public
string
Value
;
public
string
SwfVersion
;
public
Dictionary
<
string
,
PlatformCommand
>
Commands
;
public
XmlNode
RawData
;
}
public
class
PlatformCommand
{
public
string
Name
;
public
string
Value
;
public
XmlNode
RawData
;
}
}
Back
|
FazBrowse Home
|
New Git URL