redguard-preservation 0.6.0

A CLI tool to preserve Redguard files
Documentation
use crate::opts::{ColArgs, ColFormat};
use color_eyre::Result;
use log::info;
use rgpre::import::{palette::Palette, palette_export};
use std::path::Path;

pub(crate) fn handle_col_convert(args: &ColArgs, output_path: &Path) -> Result<()> {
    let file_content = std::fs::read(&args.io.file)?;
    let palette = Palette::parse(&file_content).map_err(|e| color_eyre::eyre::eyre!("{e}"))?;

    let paths = palette_export::export_col_palette(&palette, output_path, args.compress_textures)
        .map_err(|e| color_eyre::eyre::eyre!("{e}"))?;

    match args.format {
        Some(ColFormat::Json) => {
            std::fs::remove_file(&paths.png_path).ok();
            info!(
                "Palette metadata exported to: {}",
                paths.json_path.display()
            );
        }
        Some(ColFormat::Png) => {
            std::fs::remove_file(&paths.json_path).ok();
            info!("Palette swatch exported to: {}", paths.png_path.display());
        }
        None => {
            info!("Palette swatch exported to: {}", paths.png_path.display());
            info!(
                "Palette metadata exported to: {}",
                paths.json_path.display()
            );
        }
    }

    Ok(())
}