Tons of cleanup. More useless git notices.

This commit is contained in:
Cutieguwu
2025-12-31 17:22:57 -05:00
parent ae3b5d8855
commit 2da0ab11e5
6 changed files with 155 additions and 140 deletions

View File

@@ -1,5 +1,7 @@
use std::fs::{File, OpenOptions};
use std::io::{self, Seek, SeekFrom};
use std::path::{Path, PathBuf};
use crate::cli::CONFIG;
use anyhow::Context;
@@ -17,28 +19,49 @@ pub fn get_stream_length<S: Seek>(stream: &mut S) -> io::Result<u64> {
len
}
/// Generates a file path if one not provided.
/// source_name for fallback name.
pub fn get_path<P>(
file_path: &Option<P>,
source_name: &P,
extension: &str,
) -> anyhow::Result<PathBuf>
where
P: AsRef<Path>,
{
if let Some(f) = file_path {
return Ok(f.as_ref().to_path_buf());
}
Ok(PathBuf::from(format!(
"{}.{}",
source_name
.as_ref()
.to_str()
.context("source_name path was not UTF-8 valid.")?,
extension
))
.as_path()
.to_owned())
pub fn load_input() -> anyhow::Result<File> {
OpenOptions::new()
.read(true)
.open(&CONFIG.input)
.with_context(|| format!("Failed to open input file: {}", &CONFIG.input.display()))
}
pub fn load_output() -> anyhow::Result<File> {
OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open(crate::path::OUTPUT_PATH.clone())
.with_context(|| {
format!(
"Failed to open/create output file at: {}",
crate::path::OUTPUT_PATH.display()
)
})
}
pub fn load_map_read() -> anyhow::Result<File> {
OpenOptions::new()
.read(true)
.open(crate::path::MAP_PATH.clone())
.with_context(|| {
format!(
"Failed to open/create mapping file at: {}",
crate::path::MAP_PATH.display()
)
})
}
pub fn load_map_write() -> anyhow::Result<File> {
OpenOptions::new()
.write(true)
.create(true)
.truncate(true) // Wipe old map. Should really make a backup first.
.open(crate::path::MAP_PATH.clone())
.with_context(|| {
format!(
"Failed to open map file at: {}",
crate::path::MAP_PATH.display()
)
})
}