@@ -11,7 +11,8 @@ use crate::backend::ui::{FileDialogResult, FileFilter};
11
11
use crate :: string:: { AvmString , StringContext } ;
12
12
use gc_arena:: barrier:: unlock;
13
13
use gc_arena:: lock:: Lock ;
14
- use gc_arena:: { Collect , Gc , Mutation } ;
14
+ use gc_arena:: { Collect , Gc } ;
15
+ use ruffle_macros:: istr;
15
16
use url:: Url ;
16
17
17
18
// There are two undocumented functions in FileReference: convertToPPT and deleteConvertedPPT.
@@ -30,58 +31,59 @@ impl<'gc> FileReferenceObject<'gc> {
30
31
pub fn init_from_dialog_result (
31
32
self ,
32
33
activation : & mut Activation < ' _ , ' gc > ,
33
- dialog_result : & dyn FileDialogResult ,
34
+ result : & dyn FileDialogResult ,
34
35
) {
36
+ let mc = activation. gc ( ) ;
37
+ let write = Gc :: write ( mc, self . 0 ) ;
38
+
35
39
self . 0 . is_initialised . set ( true ) ;
36
40
37
41
let date_proto = activation. context . avm1 . prototypes ( ) . date_constructor ;
38
- if let Some ( creation_time) = dialog_result . creation_time ( ) {
42
+ if let Some ( creation_time) = result . creation_time ( ) {
39
43
if let Ok ( Value :: Object ( obj) ) = date_proto. construct (
40
44
activation,
41
45
& [ ( creation_time. timestamp_millis ( ) as f64 ) . into ( ) ] ,
42
46
) {
43
- self . set_creation_date ( activation . gc ( ) , Some ( obj) ) ;
47
+ unlock ! ( write , FileReferenceData , creation_date ) . set ( Some ( obj) ) ;
44
48
}
45
49
}
46
50
47
- if let Some ( modification_time) = dialog_result . modification_time ( ) {
51
+ if let Some ( modification_time) = result . modification_time ( ) {
48
52
if let Ok ( Value :: Object ( obj) ) = date_proto. construct (
49
53
activation,
50
54
& [ ( modification_time. timestamp_millis ( ) as f64 ) . into ( ) ] ,
51
55
) {
52
- self . set_modification_date ( activation . gc ( ) , Some ( obj) ) ;
56
+ unlock ! ( write , FileReferenceData , modification_date ) . set ( Some ( obj) ) ;
53
57
}
54
58
}
55
59
56
- self . 0 . file_type . replace ( dialog_result. file_type ( ) ) ;
57
- self . 0 . name . replace ( dialog_result. file_name ( ) ) ;
58
- self . 0 . size . replace ( dialog_result. size ( ) ) ;
59
- self . 0 . creator . replace ( dialog_result. creator ( ) ) ;
60
- self . 0 . data . replace ( dialog_result. contents ( ) . to_vec ( ) ) ;
61
- }
60
+ let file_type = result. file_type ( ) . map ( |s| AvmString :: new_utf8 ( mc, s) ) ;
61
+ unlock ! ( write, FileReferenceData , file_type) . set ( file_type) ;
62
62
63
- fn set_creation_date ( self , gc : & ' gc Mutation < ' gc > , creation_date : Option < Object < ' gc > > ) {
64
- unlock ! ( Gc :: write( gc, self . 0 ) , FileReferenceData , creation_date) . set ( creation_date) ;
65
- }
63
+ let file_name = result. file_name ( ) . map ( |s| AvmString :: new_utf8 ( mc, s) ) ;
64
+ unlock ! ( write, FileReferenceData , name) . set ( file_name) ;
65
+
66
+ let creator = result. creator ( ) . map ( |s| AvmString :: new_utf8 ( mc, s) ) ;
67
+ unlock ! ( write, FileReferenceData , creator) . set ( creator) ;
66
68
67
- fn set_modification_date ( self , gc : & ' gc Mutation < ' gc > , modification_date : Option < Object < ' gc > > ) {
68
- unlock ! ( Gc :: write ( gc , self . 0 ) , FileReferenceData , modification_date ) . set ( modification_date ) ;
69
+ self . 0 . size . replace ( result . size ( ) ) ;
70
+ self . 0 . data . replace ( result . contents ( ) . to_vec ( ) ) ;
69
71
}
70
72
}
71
73
72
- #[ derive( Default , Clone , Collect ) ]
74
+ #[ derive( Clone , Default , Collect ) ]
73
75
#[ collect( no_drop) ]
74
76
pub struct FileReferenceData < ' gc > {
75
77
/// Has this object been initialised from a dialog
76
78
is_initialised : Cell < bool > ,
77
79
78
80
creation_date : Lock < Option < Object < ' gc > > > ,
79
- creator : RefCell < Option < String > > ,
81
+ creator : Lock < Option < AvmString < ' gc > > > ,
80
82
modification_date : Lock < Option < Object < ' gc > > > ,
81
- name : RefCell < Option < String > > ,
82
- post_data : RefCell < String > ,
83
+ name : Lock < Option < AvmString < ' gc > > > ,
84
+ post_data : Lock < Option < AvmString < ' gc > > > ,
83
85
size : Cell < Option < u64 > > ,
84
- file_type : RefCell < Option < String > > ,
86
+ file_type : Lock < Option < AvmString < ' gc > > > ,
85
87
86
88
/// The contents of the referenced file
87
89
/// We track this here so that it can be referenced in FileReference.upload
@@ -110,30 +112,21 @@ pub fn creation_date<'gc>(
110
112
_args : & [ Value < ' gc > ] ,
111
113
) -> Result < Value < ' gc > , Error < ' gc > > {
112
114
if let NativeObject :: FileReference ( file_ref) = this. native ( ) {
113
- return Ok ( file_ref
114
- . 0
115
- . creation_date
116
- . get ( )
117
- . map_or ( Value :: Undefined , |x| x. into ( ) ) ) ;
115
+ let creation_date = file_ref. 0 . creation_date . get ( ) ;
116
+ return Ok ( creation_date. map_or ( Value :: Undefined , Into :: into) ) ;
118
117
}
119
118
120
119
Ok ( Value :: Undefined )
121
120
}
122
121
123
122
pub fn creator < ' gc > (
124
- activation : & mut Activation < ' _ , ' gc > ,
123
+ _activation : & mut Activation < ' _ , ' gc > ,
125
124
this : Object < ' gc > ,
126
125
_args : & [ Value < ' gc > ] ,
127
126
) -> Result < Value < ' gc > , Error < ' gc > > {
128
127
if let NativeObject :: FileReference ( file_ref) = this. native ( ) {
129
- return Ok ( file_ref
130
- . 0
131
- . creator
132
- . borrow ( )
133
- . as_ref ( )
134
- . map_or ( Value :: Undefined , |x| {
135
- AvmString :: new_utf8 ( activation. gc ( ) , x) . into ( )
136
- } ) ) ;
128
+ let creator = file_ref. 0 . creator . get ( ) ;
129
+ return Ok ( creator. map_or ( Value :: Undefined , Into :: into) ) ;
137
130
}
138
131
139
132
Ok ( Value :: Undefined )
@@ -145,30 +138,20 @@ pub fn modification_date<'gc>(
145
138
_args : & [ Value < ' gc > ] ,
146
139
) -> Result < Value < ' gc > , Error < ' gc > > {
147
140
if let NativeObject :: FileReference ( file_ref) = this. native ( ) {
148
- return Ok ( file_ref
149
- . 0
150
- . modification_date
151
- . get ( )
152
- . map_or ( Value :: Undefined , |x| x. into ( ) ) ) ;
141
+ let modification_date = file_ref. 0 . modification_date . get ( ) ;
142
+ return Ok ( modification_date. map_or ( Value :: Undefined , Into :: into) ) ;
153
143
}
154
144
155
145
Ok ( Value :: Undefined )
156
146
}
157
147
158
148
pub fn name < ' gc > (
159
- activation : & mut Activation < ' _ , ' gc > ,
149
+ _activation : & mut Activation < ' _ , ' gc > ,
160
150
this : Object < ' gc > ,
161
151
_args : & [ Value < ' gc > ] ,
162
152
) -> Result < Value < ' gc > , Error < ' gc > > {
163
153
if let NativeObject :: FileReference ( file_ref) = this. native ( ) {
164
- return Ok ( file_ref
165
- . 0
166
- . name
167
- . borrow ( )
168
- . as_ref ( )
169
- . map_or ( Value :: Undefined , |x| {
170
- AvmString :: new_utf8 ( activation. gc ( ) , x) . into ( )
171
- } ) ) ;
154
+ return Ok ( file_ref. 0 . name . get ( ) . map_or ( Value :: Undefined , Into :: into) ) ;
172
155
}
173
156
174
157
Ok ( Value :: Undefined )
@@ -180,9 +163,8 @@ pub fn post_data<'gc>(
180
163
_args : & [ Value < ' gc > ] ,
181
164
) -> Result < Value < ' gc > , Error < ' gc > > {
182
165
if let NativeObject :: FileReference ( file_ref) = this. native ( ) {
183
- return Ok (
184
- AvmString :: new_utf8 ( activation. gc ( ) , file_ref. 0 . post_data . borrow ( ) . clone ( ) ) . into ( ) ,
185
- ) ;
166
+ let post_data = file_ref. 0 . post_data . get ( ) ;
167
+ return Ok ( post_data. unwrap_or_else ( || istr ! ( "" ) ) . into ( ) ) ;
186
168
}
187
169
188
170
Ok ( Value :: Undefined )
@@ -199,7 +181,8 @@ pub fn set_post_data<'gc>(
199
181
. coerce_to_string ( activation) ?;
200
182
201
183
if let NativeObject :: FileReference ( file_ref) = this. native ( ) {
202
- file_ref. 0 . post_data . replace ( post_data. to_string ( ) ) ;
184
+ let write = Gc :: write ( activation. gc ( ) , file_ref. 0 ) ;
185
+ unlock ! ( write, FileReferenceData , post_data) . set ( Some ( post_data) ) ;
203
186
}
204
187
205
188
Ok ( Value :: Undefined )
@@ -211,26 +194,21 @@ pub fn size<'gc>(
211
194
_args : & [ Value < ' gc > ] ,
212
195
) -> Result < Value < ' gc > , Error < ' gc > > {
213
196
if let NativeObject :: FileReference ( file_ref) = this. native ( ) {
214
- return Ok ( file_ref. 0 . size . get ( ) . map_or ( Value :: Undefined , |x| x. into ( ) ) ) ;
197
+ let size = file_ref. 0 . size . get ( ) ;
198
+ return Ok ( size. map_or ( Value :: Undefined , Into :: into) ) ;
215
199
}
216
200
217
201
Ok ( Value :: Undefined )
218
202
}
219
203
220
204
pub fn file_type < ' gc > (
221
- activation : & mut Activation < ' _ , ' gc > ,
205
+ _activation : & mut Activation < ' _ , ' gc > ,
222
206
this : Object < ' gc > ,
223
207
_args : & [ Value < ' gc > ] ,
224
208
) -> Result < Value < ' gc > , Error < ' gc > > {
225
209
if let NativeObject :: FileReference ( file_ref) = this. native ( ) {
226
- return Ok ( file_ref
227
- . 0
228
- . file_type
229
- . borrow ( )
230
- . as_ref ( )
231
- . map_or ( Value :: Undefined , |x| {
232
- AvmString :: new_utf8 ( activation. gc ( ) , x) . into ( )
233
- } ) ) ;
210
+ let file_type = file_ref. 0 . file_type . get ( ) ;
211
+ return Ok ( file_type. map_or ( Value :: Undefined , Into :: into) ) ;
234
212
}
235
213
236
214
Ok ( Value :: Undefined )
@@ -401,17 +379,17 @@ pub fn upload<'gc>(
401
379
_ => return Ok ( false . into ( ) ) ,
402
380
}
403
381
382
+ let file_name = match file_reference. 0 . name . get ( ) {
383
+ Some ( name) => name. to_string ( ) ,
384
+ None => "file" . to_string ( ) ,
385
+ } ;
386
+
404
387
let process = activation. context . load_manager . upload_file (
405
388
activation. context . player . clone ( ) ,
406
389
this,
407
390
url_string,
408
391
file_reference. 0 . data . borrow ( ) . clone ( ) ,
409
- file_reference
410
- . 0
411
- . name
412
- . borrow ( )
413
- . clone ( )
414
- . unwrap_or_else ( || "file" . to_string ( ) ) ,
392
+ file_name,
415
393
) ;
416
394
417
395
activation. context . navigator . spawn_future ( process) ;
0 commit comments