Skip to content

Commit 6430d38

Browse files
committed
Changes required to make Count(NonZeroUsize) work.
1 parent 5cc915e commit 6430d38

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

exporter/src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ impl FromStr for FrameSelection {
5353
if s_lower == "all" {
5454
Ok(FrameSelection::All)
5555
} else if let Ok(n) = s.parse::<u32>() {
56-
Ok(FrameSelection::Count(n))
56+
let non_zero = NonZeroUsize::new(n as usize)
57+
.ok_or_else(|| "Frame count must be greater than 0".to_string())?;
58+
Ok(FrameSelection::Count(non_zero))
5759
} else {
5860
Err(format!("Invalid value for --frames: {s}"))
5961
}
@@ -153,7 +155,7 @@ fn take_screenshot(
153155
.and_then(|root_clip| root_clip.as_movie_clip())
154156
.map_or(1, |movie_clip| movie_clip.total_frames() as u32)
155157
}),
156-
FrameSelection::Count(n) => n + skipframes,
158+
FrameSelection::Count(n) => n.get() as u32 + skipframes,
157159
};
158160

159161
for i in 0..totalframes {
@@ -259,19 +261,19 @@ fn capture_single_swf(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()> {
259261
let output = opt.output_path.clone().unwrap_or_else(|| {
260262
let mut result = PathBuf::new();
261263
result.set_file_name(opt.swf.file_stem().unwrap());
262-
if matches!(opt.frames, FrameSelection::Count(1)) {
264+
if matches!(opt.frames, FrameSelection::Count(n) if n.get() == 1) {
263265
result.set_extension("png");
264266
}
265267
result
266268
});
267269

268-
if !matches!(opt.frames, FrameSelection::Count(1)) {
270+
if !matches!(opt.frames, FrameSelection::Count(n) if n.get() == 1) {
269271
let _ = create_dir_all(&output);
270272
}
271273

272274
let progress = if !opt.silent {
273275
let progress = match opt.frames {
274-
FrameSelection::Count(n) => ProgressBar::new(n as u64),
276+
FrameSelection::Count(n) => ProgressBar::new(n.get() as u64),
275277
_ => 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
276278
};
277279
progress.set_style(
@@ -358,7 +360,7 @@ fn capture_multiple_swfs(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()>
358360

359361
let progress = if !opt.silent {
360362
let progress = match opt.frames {
361-
FrameSelection::Count(n) => ProgressBar::new((files.len() as u64) * (n as u64)),
363+
FrameSelection::Count(n) => ProgressBar::new((files.len() as u64) * (n.get() as u64)),
362364
_ => ProgressBar::new(files.len() as u64),
363365
};
364366
progress.set_style(
@@ -423,7 +425,7 @@ fn capture_multiple_swfs(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()>
423425
})?;
424426

425427
let message = match opt.frames {
426-
FrameSelection::Count(1) => format!(
428+
FrameSelection::Count(n) if n.get() == 1 => format!(
427429
"Saved first frame of {} files to {}",
428430
files.len(),
429431
output.to_string_lossy()

0 commit comments

Comments
 (0)