Skip to content

Commit

Permalink
convert-all-flts: Delete tiny (garbage) .flt & .flt.cnt files
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkline committed Oct 19, 2021
1 parent 4d76a83 commit eb22872
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ in seconds, not minutes.
or by running BMS with `-acmi`. BMS should no longer pause to convert
recordings when you exit 3D.

4. Close BMS (if you're running with `-acmi`, BMS often holds tiny
FLT files open in 2D, preventing these tools from doing their jobs.)

4. Run `convert-all-flts.exe` to convert all FLT files to VHS,
with names based on the times they were created.
Or drag a FLT file file onto `flt2vhs.exe` to convert one at a time.
Expand Down
46 changes: 44 additions & 2 deletions convert-all-flts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,47 @@ fn run() -> Result<()> {
})?;
}

if !args.keep {
delete_garbage_files()?;
}
rename_and_convert(&args)
}

fn delete_garbage_files() -> Result<()> {
let delete_fail_warning = |path: &Path, e| {
warn!(
"Couldn't remove {} (are you running BMS?): {}",
path.display(),
e
)
};

let cwd = env::current_dir()?;
for f in fs::read_dir(cwd)? {
let entry = f?;
let path = entry.path();
let meta = entry
.metadata()
.with_context(|| format!("Couldn't stat {}", path.display()))?;

if path.to_str().map(|s| s.ends_with(".flt.cnt")).unwrap_or(false) && meta.is_file() {
fs::remove_file(&path).unwrap_or_else(|e| delete_fail_warning(&path, e));
info!("Deleted {}", path.display());
continue;
}

// With -acmi, BMS 4.35 likes to spit out a bunch of tiny useless files in 2D.
if path.extension() == Some(OsStr::new("flt")) && meta.is_file() {
let length = meta.len();
if length <= 34 {
fs::remove_file(&path).unwrap_or_else(|e| delete_fail_warning(&path, e));
info!("Deleted tiny {}-byte garbage {}", length, path.display());
}
}
}
Ok(())
}

fn rename_and_convert(args: &Args) -> Result<()> {
let mut to_rename = Vec::new();

Expand All @@ -76,11 +114,16 @@ fn rename_and_convert(args: &Args) -> Result<()> {
let entry = f?;
let path = entry.path();
if path.extension() == Some(OsStr::new("flt")) && entry.metadata()?.is_file() {
trace!("Found .flt file {}", path.display());
trace!("Found {} to rename and convert", path.display());
to_rename.push(path);
}
}

if to_rename.is_empty() {
info!("Nothing to convert!");
return Ok(());
}

let mut renamed_flights = to_rename
.iter()
.map(|f| rename_flt(f))
Expand All @@ -96,7 +139,6 @@ fn rename_and_convert(args: &Args) -> Result<()> {

fn rename_flt(to_rename: &Path) -> Result<PathBuf> {
let rename_to = timestamp_name(to_rename);
debug!("Trying to rename {}...", to_rename.display());
fs::rename(&to_rename, &rename_to)
.with_context(|| format!("Renaming {} failed", to_rename.display()))?;
info!("Renamed {} to {}", to_rename.display(), rename_to.display());
Expand Down

0 comments on commit eb22872

Please sign in to comment.