Skip to content

Commit

Permalink
Added new command to help to convert PPEs to UTF8.
Browse files Browse the repository at this point in the history
Makes working on linux much easier.
  • Loading branch information
mkrueger committed Jan 20, 2025
1 parent a7aff03 commit 84838ed
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
60 changes: 59 additions & 1 deletion crates/icbsetup/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use app::new_main_window;
use argh::FromArgs;
use chrono::Local;
use codepages::tables::write_with_bom;
use color_eyre::Result;
use create::IcyBoardCreator;
use icy_board_engine::icy_board::IcyBoard;
use icy_board_engine::icy_board::{read_with_encoding_detection, IcyBoard};
use icy_board_tui::{get_text_args, print_error, term};
use import::{console_logger::ConsoleLogger, PCBoardImporter};
use semver::Version;
use walkdir::WalkDir;
use std::{
collections::HashMap,
fs,
Expand Down Expand Up @@ -45,6 +47,7 @@ struct Cli {
enum Commands {
Import(Import),
Create(Create),
PPEConvert(PPEConvert),
}

#[derive(FromArgs, PartialEq, Debug)]
Expand All @@ -69,6 +72,15 @@ struct Create {
file: PathBuf,
}

#[derive(FromArgs, PartialEq, Debug)]
/// Converts a path to UTF-8
#[argh(subcommand, name = "ppe-convert")]
struct PPEConvert {
/// directory to convert
#[argh(positional)]
path: PathBuf,
}

fn main() -> Result<()> {
fern::Dispatch::new()
// Perform allocation-free log formatting
Expand Down Expand Up @@ -126,6 +138,52 @@ fn main() -> Result<()> {
}
return Ok(());
}

Some(Commands::PPEConvert(PPEConvert { path })) => {
println!("Converting PPE data files in {}", path.display());
println!("Caution - this command is used for converting CP437 to UTF-8 in a directory.");

println!("Converting directories to lower case...");
for entry in WalkDir::new(path).into_iter().filter_map(|e| e.ok()) {
if !entry.path().is_dir() {
continue;
}
let lower_case = entry.path().to_string_lossy().to_string().to_lowercase();
if lower_case == "." || lower_case == ".." {
continue;
}
println!("Rename directory {} to {}", entry.path().display(), lower_case);
if fs::rename(entry.path(), lower_case).is_err() {
println!("Error renaming directory {}", entry.path().display());
}
}
println!("Converting files...");
let convert_ext = ["ANS", "PCB", "CFG", "DOC", "NFO", "ASC", "TXT", "PPX", "PPS", "PPD", "LST", "XXX"];
for entry in WalkDir::new(path).into_iter().filter_map(|e| e.ok()) {
if !entry.path().is_file() {
continue;
}
let lower_case = entry.path().to_string_lossy().to_string().to_lowercase();
if lower_case == entry.path().to_string_lossy().to_string() {
continue;
}
if let Some(extension) = entry.path().extension() {
if convert_ext.contains(&extension.to_str().unwrap()) {
println!("Converting {} to utf8...", entry.path().display());
if let Ok(data) = read_with_encoding_detection(&entry.path()) {
if write_with_bom(&entry.path(), &data).is_err() {
println!("Error writing {}", entry.path().display());
}
}
}
}
println!("Rename {} to {}", entry.path().display(), lower_case);
if fs::rename(entry.path(), lower_case).is_err() {
println!("Error renaming {}", entry.path().display());
}
}
return Ok(());
}
_ => {}
}
let mut file = arguments.file.clone().unwrap_or(PathBuf::from("."));
Expand Down
2 changes: 1 addition & 1 deletion crates/icy_board_engine/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub enum VMError {
NoObjectFound(u8),
}

#[derive(Clone, Copy, PartialEq)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum TerminalTarget {
Both,
User,
Expand Down

0 comments on commit 84838ed

Please sign in to comment.