Skip to content

Commit b168565

Browse files
committed
Make requested changes
1 parent 933ed72 commit b168565

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

exporter/src/main.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ struct SizeOpt {
4141
#[derive(Debug, Clone, Copy)]
4242
enum FrameSelection {
4343
All,
44-
One,
45-
Count(u32),
44+
Count(NonZeroUsize),
4645
}
4746

4847
impl FromStr for FrameSelection {
@@ -53,11 +52,7 @@ impl FromStr for FrameSelection {
5352
if s_lower == "all" {
5453
Ok(FrameSelection::All)
5554
} else if let Ok(n) = s.parse::<u32>() {
56-
if n == 1 {
57-
Ok(FrameSelection::One)
58-
} else {
59-
Ok(FrameSelection::Count(n))
60-
}
55+
Ok(FrameSelection::Count(n))
6156
} else {
6257
Err(format!("Invalid value for --frames: {s}"))
6358
}
@@ -119,7 +114,7 @@ struct Opt {
119114
fn take_screenshot(
120115
descriptors: Arc<Descriptors>,
121116
swf_path: &Path,
122-
frames: FrameSelection,
117+
frames: FrameSelection, // TODO Figure out a way to get framecount before calling take_screenshot, so that we can have accurate progress bars when using --frames all
123118
skipframes: u32,
124119
progress: &Option<ProgressBar>,
125120
size: SizeOpt,
@@ -157,7 +152,6 @@ fn take_screenshot(
157152
.and_then(|root_clip| root_clip.as_movie_clip())
158153
.map_or(1, |movie_clip| movie_clip.total_frames() as u32)
159154
}),
160-
FrameSelection::One => 1 + skipframes,
161155
FrameSelection::Count(n) => n + skipframes,
162156
};
163157

@@ -264,20 +258,20 @@ fn capture_single_swf(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()> {
264258
let output = opt.output_path.clone().unwrap_or_else(|| {
265259
let mut result = PathBuf::new();
266260
result.set_file_name(opt.swf.file_stem().unwrap());
267-
if matches!(opt.frames, FrameSelection::One) {
261+
if matches!(opt.frames, FrameSelection::Count(1)) {
268262
result.set_extension("png");
269263
}
270264
result
271265
});
272266

273-
if !matches!(opt.frames, FrameSelection::One) {
267+
if !matches!(opt.frames, FrameSelection::Count(1)) {
274268
let _ = create_dir_all(&output);
275269
}
276270

277271
let progress = if !opt.silent {
278272
let progress = match opt.frames {
279273
FrameSelection::Count(n) => ProgressBar::new(n as u64),
280-
_ => ProgressBar::new_spinner(),
274+
_ => ProgressBar::new_spinner(), // TODO Once we figure out a way to get framecount before calling take_screenshot, then this can be changed back to a progress bar when using --frames all
281275
};
282276
progress.set_style(
283277
ProgressStyle::with_template(
@@ -428,7 +422,7 @@ fn capture_multiple_swfs(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()>
428422
})?;
429423

430424
let message = match opt.frames {
431-
FrameSelection::One => format!(
425+
FrameSelection::Count(1) => format!(
432426
"Saved first frame of {} files to {}",
433427
files.len(),
434428
output.to_string_lossy()

0 commit comments

Comments
 (0)