Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ struct Opt {
/// Frame rate of the output SWF.
#[arg(long, default_value_t = 24.0, help_heading = "Generated SWF Options")]
frame_rate: f32,

/// Whether the SWF uses the network sandbox.
/// If set, the SWF is allowed to make network requests but cannot access local files.
/// If not set, the SWF can access local files but cannot make network requests.
#[arg(long, help_heading = "Generated SWF Options")]
use_network_sandbox: bool,
}

fn main() -> Result<()> {
Expand Down Expand Up @@ -97,7 +103,11 @@ fn main() -> Result<()> {
.output
.or_else(|| opt.script.first().map(|s| s.with_extension("swf")))
.unwrap_or_else(|| PathBuf::from("output.swf"));
let swf = pcode.to_swf(&SwfOptions::default().with_frame_rate(opt.frame_rate))?;
let swf = pcode.to_swf(
&SwfOptions::default()
.with_frame_rate(opt.frame_rate)
.with_network_sandbox(opt.use_network_sandbox),
)?;
fs::write(&output_path, swf)?;
Ok(())
}
7 changes: 7 additions & 0 deletions crates/rascal/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct SwfOptions {
pub(crate) stage_y_min: f64,
pub(crate) stage_x_max: f64,
pub(crate) stage_y_max: f64,
pub(crate) use_network_sandbox: bool,
}

impl Default for SwfOptions {
Expand All @@ -26,6 +27,7 @@ impl Default for SwfOptions {
stage_y_min: 0.0,
stage_x_max: 100.0,
stage_y_max: 100.0,
use_network_sandbox: false,
}
}
}
Expand All @@ -49,6 +51,11 @@ impl SwfOptions {
self.stage_y_max = stage_y_max;
self
}

pub fn with_network_sandbox(mut self, use_network_sandbox: bool) -> Self {
self.use_network_sandbox = use_network_sandbox;
self
}
}

#[derive(Debug, Clone, Serialize)]
Expand Down
13 changes: 11 additions & 2 deletions crates/rascal/src/swf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::io::Result;
use std::io::Write;
use swf::write::SwfWriteExt;
use swf::{CharacterId, ExportedAsset, Fixed8, Sprite, SwfStr, Tag, Twips};
use swf::{CharacterId, ExportedAsset, FileAttributes, Fixed8, Sprite, SwfStr, Tag, Twips};

impl<'a> ActionEncoder<'a> {}

Expand Down Expand Up @@ -38,7 +38,16 @@ pub(crate) fn pcode_to_swf(
modules.push((format!("__Packages.{}", name), result.output));
}

let mut tags = vec![Tag::SetBackgroundColor(swf::Color::WHITE)];
let mut file_attributes = FileAttributes::empty();
file_attributes.set(
FileAttributes::USE_NETWORK_SANDBOX,
swf_options.use_network_sandbox,
);

let mut tags = vec![
Tag::FileAttributes(file_attributes),
Tag::SetBackgroundColor(swf::Color::WHITE),
];
for initializer in &initializers {
tags.push(Tag::DoAction(initializer))
}
Expand Down