From 6522c255cd93327f279f10ab7eca0c014e7cd3b5 Mon Sep 17 00:00:00 2001
From: Quaternions <krakow20@gmail.com>
Date: Tue, 4 Feb 2025 09:04:40 -0800
Subject: [PATCH] remove common

---
 src/common.rs | 75 ---------------------------------------------------
 src/main.rs   |  3 ---
 2 files changed, 78 deletions(-)
 delete mode 100644 src/common.rs

diff --git a/src/common.rs b/src/common.rs
deleted file mode 100644
index 95744c9..0000000
--- a/src/common.rs
+++ /dev/null
@@ -1,75 +0,0 @@
-use std::path::PathBuf;
-use std::io::{Read,Seek};
-use anyhow::Result as AResult;
-
-fn load_image<R:Read+Seek+std::io::BufRead>(input:&mut R)->AResult<image::DynamicImage>{
-	let mut fourcc=[0u8;4];
-	input.read_exact(&mut fourcc)?;
-	input.rewind()?;
-	match &fourcc{
-		b"\x89PNG"=>Ok(image::load(input,image::ImageFormat::Png)?),
-		b"\xFF\xD8\xFF\xE0"=>Ok(image::load(input,image::ImageFormat::Jpeg)?),//JFIF
-		b"<rob"=>Err(anyhow::Error::msg("Roblox xml garbage is not supported yet")),
-		other=>Err(anyhow::Error::msg(format!("Unknown texture format {:?}",other))),
-	}
-}
-
-fn convert(file_thing:std::fs::DirEntry) -> AResult<()>{
-	let mut input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
-
-	let image=load_image(&mut input)?.to_rgba8();//this sets a=255, arcane is actually supposed to look like that
-
-	let format=if image.width()%4!=0||image.height()%4!=0{
-		image_dds::ImageFormat::Rgba8UnormSrgb
-	}else{
-		image_dds::ImageFormat::BC7RgbaUnormSrgb
-	};
-	//this fails if the image dimensions are not a multiple of 4
-	let dds = image_dds::dds_from_image(
-		&image,
-		format,
-		image_dds::Quality::Slow,
-		image_dds::Mipmaps::GeneratedAutomatic,
-	)?;
-
-	//write dds
-	let mut dest=PathBuf::from("textures");
-	dest.push(file_thing.file_name());
-	dest.set_extension("dds");
-	let mut writer = std::io::BufWriter::new(std::fs::File::create(dest)?);
-	dds.write(&mut writer)?;
-
-	//move file to processed
-	let mut dest=PathBuf::from("textures/processed");
-	dest.push(file_thing.file_name());
-	std::fs::rename(file_thing.path(), dest)?;
-	Ok(())
-}
-pub fn convert_textures() -> AResult<()>{
-	std::fs::create_dir_all("textures/unprocessed")?;
-	std::fs::create_dir_all("textures/processed")?;
-	let start = std::time::Instant::now();
-	let mut threads=Vec::new();
-	for entry in std::fs::read_dir("textures/unprocessed")? {
-		let file_thing=entry?;
-		threads.push(std::thread::spawn(move ||{
-			let file_name=format!("{:?}",file_thing);
-			let result=convert(file_thing);
-			if let Err(e)=result{
-				println!("error processing file:{:?} error message:{:?}",file_name,e);
-			}
-		}));
-	}
-	let mut i=0;
-	let n_threads=threads.len();
-	for thread in threads{
-		i+=1;
-		if let Err(e)=thread.join(){
-			println!("thread error: {:?}",e);
-		}else{
-			println!("{}/{}",i,n_threads);
-		}
-	}
-	println!("{:?}", start.elapsed());
-	Ok(())
-}
diff --git a/src/main.rs b/src/main.rs
index e54d7b1..9b43f9e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,3 @@
-mod common;
 mod roblox;
 mod source;
 
@@ -19,7 +18,6 @@ enum Commands{
 	Roblox(roblox::Commands),
 	#[command(flatten)]
 	Source(source::Commands),
-	ConvertTextures,
 }
 
 fn main() -> AResult<()> {
@@ -27,6 +25,5 @@ fn main() -> AResult<()> {
 	match cli.command{
 		Commands::Roblox(commands)=>commands.run(),
 		Commands::Source(commands)=>commands.run(),
-		Commands::ConvertTextures=>common::convert_textures(),
 	}
 }