FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SwfLib/SwfLib.Tests/SamplesTest.cs at master · unusable/SwfLib · GitHub
unusable
/
SwfLib
Public
forked from
SavchukSergey/SwfLib
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
SwfLib
/
SwfLib.Tests
/
SamplesTest.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
154 lines (133 loc) · 5.58 KB
Breadcrumbs
SwfLib
/
SwfLib.Tests
/
SamplesTest.cs
Copy path
File metadata and controls
154 lines (133 loc) · 5.58 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
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
IO
;
using
System
.
Linq
;
using
NUnit
.
Framework
;
using
SwfLib
.
Tags
;
using
SwfLib
.
Tests
.
Asserts
.
Utils
;
using
SwfLib
.
Tests
.
Samples
;
namespace
SwfLib
.
Tests
{
[
TestFixture
]
public
class
SamplesTest
:
BaseSampleTest
{
[
Test
]
public
void
Sample1Test
(
)
{
const
string
path
=
"Sample - 1.swf"
;
var
file
=
ReadSwfFile
(
path
)
;
var
mem
=
new
MemoryStream
(
)
;
file
.
WriteTo
(
mem
)
;
mem
.
Seek
(
0
,
SeekOrigin
.
Begin
)
;
var
firstTags
=
IterateTags
(
OpenEmbeddedResource
(
path
)
)
.
ToList
(
)
;
var
secondTags
=
IterateTags
(
mem
)
.
ToList
(
)
;
var
deserializer
=
new
SwfTagDeserializer
(
file
)
;
for
(
var
i
=
0
;
i
<
firstTags
.
Count
;
i
++
)
{
var
firstTag
=
firstTags
[
i
]
;
var
secondTag
=
secondTags
[
i
]
;
var
firstType
=
firstTag
.
Type
;
var
secondType
=
secondTag
.
Type
;
if
(
firstType
!=
secondType
)
throw
new
InvalidOperationException
(
)
;
//if (firstType == SwfTagType.DefineSprite) continue; //For now
var
dual
=
new
DualSwfStreamReader
(
new
MemoryStream
(
firstTag
.
Data
)
,
new
MemoryStream
(
secondTag
.
Data
)
)
;
//var dual = new SwfStreamReader(new MemoryStream(firstTag.Data));
deserializer
.
ReadTag
(
firstType
,
dual
)
;
}
}
[
Test
]
public
void
Test
(
)
{
const
string
source
=
@"D:\Test\swf\"
;
var
first
=
Path
.
Combine
(
source
,
"first.swf"
)
;
var
second
=
Path
.
Combine
(
source
,
"second.swf"
)
;
var
firstTags
=
GetTagsMap
(
IterateTags
(
first
)
)
;
var
secondTags
=
GetTagsMap
(
IterateTags
(
second
)
)
;
foreach
(
var
tag
in
firstTags
.
ToList
(
)
)
{
if
(
secondTags
.
ContainsKey
(
tag
.
Key
)
)
{
firstTags
.
Remove
(
tag
.
Key
)
;
secondTags
.
Remove
(
tag
.
Key
)
;
}
}
foreach
(
var
tag
in
secondTags
.
ToList
(
)
)
{
if
(
firstTags
.
ContainsKey
(
tag
.
Key
)
)
{
firstTags
.
Remove
(
tag
.
Key
)
;
secondTags
.
Remove
(
tag
.
Key
)
;
}
}
foreach
(
var
tag
in
firstTags
)
{
if
(
tag
.
Value
!=
null
)
{
SaveTag
(
tag
.
Value
,
Path
.
Combine
(
source
,
"first"
)
)
;
ReadTag
(
tag
.
Value
)
;
}
}
foreach
(
var
tag
in
secondTags
)
{
if
(
tag
.
Value
!=
null
)
{
SaveTag
(
tag
.
Value
,
Path
.
Combine
(
source
,
"second"
)
)
;
ReadTag
(
tag
.
Value
)
;
}
}
}
protected
IDictionary
<
string
,
SwfTagData
>
GetTagsMap
(
IEnumerable
<
SwfTagData
>
tags
)
{
return
tags
.
Select
(
item
=>
new
{
Hash
=
item
.
Type
.
ToString
(
)
+
" "
+
GetTagHash
(
item
)
,
Tag
=
item
}
)
.
GroupBy
(
item
=>
item
.
Hash
)
.
ToDictionary
(
item
=>
item
.
Key
,
item
=>
item
.
First
(
)
.
Tag
)
;
}
protected
void
ReadTag
(
SwfTagData
tagData
)
{
try
{
var
tagReader
=
new
SwfTagDeserializer
(
new
SwfFile
(
)
)
.
ReadTag
(
tagData
)
;
}
catch
{
}
}
[
Test
]
public
void
GrabAllSwfsFromMachine
(
)
{
var
source
=
@"D:\Test\Samples\"
;
var
target
=
Path
.
Combine
(
source
,
"tags"
)
;
if
(
!
Directory
.
Exists
(
target
)
)
{
Directory
.
CreateDirectory
(
target
)
;
}
var
dirInfo
=
new
DirectoryInfo
(
source
)
;
Grab
(
dirInfo
,
target
)
;
}
public
void
Grab
(
DirectoryInfo
source
,
string
target
)
{
foreach
(
var
subdir
in
source
.
GetDirectories
(
)
)
{
Grab
(
subdir
,
target
)
;
}
foreach
(
var
f
in
source
.
GetFiles
(
"*.swf"
)
)
{
try
{
var
tags
=
IterateTags
(
f
.
FullName
)
;
foreach
(
var
tagData
in
tags
)
{
SaveTag
(
tagData
,
target
)
;
}
}
catch
{
Console
.
WriteLine
(
"Couldn't grab {0}"
,
f
.
FullName
)
;
}
}
}
protected
void
SaveTag
(
SwfTagData
tagData
,
string
root
)
{
var
tagDir
=
Path
.
Combine
(
root
,
string
.
Format
(
"{0}"
,
tagData
.
Type
)
)
;
if
(
!
Directory
.
Exists
(
tagDir
)
)
{
Directory
.
CreateDirectory
(
tagDir
)
;
}
var
binFilepath
=
Path
.
Combine
(
tagDir
,
GetFileName
(
tagData
)
)
;
using
(
var
bin
=
File
.
Open
(
binFilepath
,
FileMode
.
Create
)
)
{
bin
.
Write
(
tagData
.
Data
,
0
,
tagData
.
Data
.
Length
)
;
bin
.
Flush
(
)
;
}
}
protected
IEnumerable
<
SwfTagData
>
IterateTags
(
string
path
)
{
var
stream
=
File
.
Open
(
path
,
FileMode
.
Open
)
;
return
IterateTags
(
stream
)
;
}
protected
IEnumerable
<
SwfTagData
>
IterateTags
(
Stream
stream
)
{
var
file
=
new
SwfFile
(
)
;
var
reader
=
new
SwfStreamReader
(
stream
)
;
file
.
FileInfo
=
reader
.
ReadSwfFileInfo
(
)
;
reader
=
GetSwfStreamReader
(
file
.
FileInfo
,
stream
)
;
file
.
Header
=
reader
.
ReadSwfHeader
(
)
;
while
(
!
reader
.
IsEOF
)
{
var
tagData
=
reader
.
ReadTagData
(
)
;
yield
return
tagData
;
}
}
protected
string
GetFileName
(
SwfTagData
tagData
)
{
return
string
.
Format
(
"{0}.bin"
,
GetTagHash
(
tagData
)
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL