core: Add SwfMovie::uncompressed_len

This commit is contained in:
Mike Welsh 2021-05-22 19:23:34 -07:00
parent 077c7f045e
commit 172ad82aa5
4 changed files with 17 additions and 15 deletions

View File

@ -769,7 +769,7 @@ fn get_bytes_loaded<'gc>(
let bytes_loaded = if movie_clip.is_root() { let bytes_loaded = if movie_clip.is_root() {
movie_clip movie_clip
.movie() .movie()
.map(|mv| mv.header().uncompressed_len()) .map(|mv| mv.uncompressed_len())
.unwrap_or_default() .unwrap_or_default()
} else { } else {
movie_clip.tag_stream_len() as u32 movie_clip.tag_stream_len() as u32
@ -787,7 +787,7 @@ fn get_bytes_total<'gc>(
let bytes_total = if movie_clip.is_root() { let bytes_total = if movie_clip.is_root() {
movie_clip movie_clip
.movie() .movie()
.map(|mv| mv.header().uncompressed_len()) .map(|mv| mv.uncompressed_len())
.unwrap_or_default() .unwrap_or_default()
} else { } else {
movie_clip.tag_stream_len() as u32 movie_clip.tag_stream_len() as u32

View File

@ -114,7 +114,7 @@ pub fn get_progress<'gc>(
"bytesLoaded", "bytesLoaded",
movieclip movieclip
.movie() .movie()
.map(|mv| (mv.header().uncompressed_len()).into()) .map(|mv| (mv.uncompressed_len()).into())
.unwrap_or(Value::Undefined), .unwrap_or(Value::Undefined),
Attribute::empty(), Attribute::empty(),
); );
@ -123,7 +123,7 @@ pub fn get_progress<'gc>(
"bytesTotal", "bytesTotal",
movieclip movieclip
.movie() .movie()
.map(|mv| (mv.header().uncompressed_len()).into()) .map(|mv| (mv.uncompressed_len()).into())
.unwrap_or(Value::Undefined), .unwrap_or(Value::Undefined),
Attribute::empty(), Attribute::empty(),
); );

View File

@ -107,11 +107,9 @@ pub fn bytes_total<'gc>(
if let Some(this) = this { if let Some(this) = this {
if let Some(loader_stream) = this.as_loader_stream() { if let Some(loader_stream) = this.as_loader_stream() {
match &*loader_stream { match &*loader_stream {
LoaderStream::Stage => { LoaderStream::Stage => return Ok(activation.context.swf.compressed_len().into()),
return Ok(activation.context.swf.compressed_length().into())
}
LoaderStream::Swf(movie, _) => { LoaderStream::Swf(movie, _) => {
return Ok(movie.compressed_length().into()); return Ok(movie.compressed_len().into());
} }
} }
} }

View File

@ -34,7 +34,7 @@ pub struct SwfMovie {
encoding: &'static swf::Encoding, encoding: &'static swf::Encoding,
/// The compressed length of the entire datastream /// The compressed length of the entire datastream
compressed_length: usize, compressed_len: usize,
} }
impl SwfMovie { impl SwfMovie {
@ -47,7 +47,7 @@ impl SwfMovie {
loader_url: None, loader_url: None,
parameters: Vec::new(), parameters: Vec::new(),
encoding: swf::UTF_8, encoding: swf::UTF_8,
compressed_length: 0, compressed_len: 0,
} }
} }
@ -64,7 +64,7 @@ impl SwfMovie {
loader_url: source.loader_url.clone(), loader_url: source.loader_url.clone(),
parameters: source.parameters.clone(), parameters: source.parameters.clone(),
encoding: source.encoding, encoding: source.encoding,
compressed_length: source.compressed_length, compressed_len: source.compressed_len,
} }
} }
@ -86,7 +86,7 @@ impl SwfMovie {
url: Option<String>, url: Option<String>,
loader_url: Option<String>, loader_url: Option<String>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let compressed_length = swf_data.len(); let compressed_len = swf_data.len();
let swf_buf = swf::read::decompress_swf(swf_data)?; let swf_buf = swf::read::decompress_swf(swf_data)?;
let encoding = swf::SwfStr::encoding_for_version(swf_buf.header.version()); let encoding = swf::SwfStr::encoding_for_version(swf_buf.header.version());
Ok(Self { Ok(Self {
@ -96,7 +96,7 @@ impl SwfMovie {
loader_url, loader_url,
parameters: Vec::new(), parameters: Vec::new(),
encoding, encoding,
compressed_length, compressed_len,
}) })
} }
@ -149,8 +149,12 @@ impl SwfMovie {
self.parameters.extend(params); self.parameters.extend(params);
} }
pub fn compressed_length(&self) -> usize { pub fn compressed_len(&self) -> usize {
self.compressed_length self.compressed_len
}
pub fn uncompressed_len(&self) -> u32 {
self.header.uncompressed_len()
} }
pub fn avm_type(&self) -> AvmType { pub fn avm_type(&self) -> AvmType {