Skip to content

Commit

Permalink
Fix .dsk bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeust committed Jun 1, 2024
1 parent 189c920 commit 9f3caca
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 46 deletions.
71 changes: 33 additions & 38 deletions apple2/src/ui/disks_window.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
use std::path::Path;
use std::path::{Path};
use eframe::egui::{Align, Color32, Label, Layout, RichText, ScrollArea, Ui, Vec2};
use ignore::Walk;
use ignore::{DirEntry, Walk};
use rfd::FileDialog;
use crate::constants::{BUGGY_DISKS, DISKS_SUFFIXES};
use crate::disk::disk::Disk;
use crate::disk::disk_controller::{DiskController};
use crate::disk::disk_info::DiskInfo;
use crate::disk::disk_info::DiskType::{Dsk, Woz1, Woz2};
use crate::messages::ToCpu::LoadDisk;
use crate::ui::ui::{MyEguiApp, ui_log};

#[derive(Clone)]
pub(crate) struct DisplayedDisk {
file_name: String,
path: String,
}

impl DisplayedDisk {
fn new(d: DirEntry) -> DisplayedDisk {
DisplayedDisk {
file_name: d.file_name().to_str().unwrap().to_string(),
path: d.path().to_str().unwrap().to_string(),
}
}
}

impl MyEguiApp {
fn is_buggy(name: &str) -> bool {
BUGGY_DISKS.iter().any(|d| {
Expand All @@ -23,16 +35,12 @@ impl MyEguiApp {

use rayon::prelude::*;
self.disks_displayed_disks = disks.par_iter().filter_map(|d| {
if self.disks_filter.is_empty() || d.path().to_lowercase().contains(&self.disks_filter) {
#[allow(clippy::if_same_then_else)]
if d.disk_type == Woz1 && self.disks_woz1 { Some(d.clone()) }
else if d.disk_type == Woz2 && self.disks_woz2 { Some(d.clone()) }
else if d.disk_type == Dsk && self.disks_dsk { Some(d.clone()) }
else { None }
if self.disks_filter.is_empty() || d.file_name.to_lowercase().contains(&self.disks_filter) {
Some(d.clone())
} else {
None
}
}).collect::<Vec<DiskInfo>>();
}).collect::<Vec<DisplayedDisk>>();
}

pub fn create_disks_window(&mut self, ui: &mut Ui) {
Expand All @@ -48,23 +56,23 @@ impl MyEguiApp {
.min_scrolled_height(600.0).show(ui, |ui| {
let disks = self.disks_displayed_disks.clone();
if ! disks.is_empty() {
for disk_info in &self.disks_displayed_disks {
for displayed_disk in &self.disks_displayed_disks {
ui.horizontal(|ui| {
//
// Drive 1 / Drive 2
//
let mut drive_label = |index: usize, label: &str| {
let mut drive_label = RichText::new(label);
if let Some(di) = &self.disk_infos[index] {
if *di.path == disk_info.path {
if *di.path == *displayed_disk.path {
drive_label = RichText::new(label)
.background_color(Color32::DARK_BLUE);
}
}

if ui.button(drive_label).clicked() {
let disk = DiskController::
load_disk_new(&disk_info.path(), None);
load_disk_new(&displayed_disk.path, None);
if let Ok(disk) = disk {
self.sender.send(
LoadDisk(index, disk.disk_info().clone())).unwrap();
Expand All @@ -77,17 +85,17 @@ impl MyEguiApp {
//
// Name of the disk, in the correct color
//
let color = if Self::is_buggy(disk_info.name()) {
let color = if Self::is_buggy(&displayed_disk.file_name) {
Color32::RED
} else if disk_info.path().to_lowercase().ends_with("woz") {
} else if displayed_disk.file_name.to_lowercase().ends_with("woz") {
Color32::YELLOW
} else {
Color32::LIGHT_BLUE
};
ui.scope(|ui| {
ui.set_max_width(150.0);
let max = std::cmp::min(60, disk_info.name().len());
let n = &disk_info.name()[0..max];
let max = std::cmp::min(60, displayed_disk.file_name.len());
let n = &displayed_disk.file_name[0..max];
ui.add(Label::new(RichText::new(n).color(color)));
// let r = Rect::from_min_size(Pos2::new(0.0, 0.0), Vec2::new(300.0, 15.0));
// ui.put(r, Label::new(RichText::new(disk_info.name()).color(color)));
Expand Down Expand Up @@ -134,15 +142,6 @@ impl MyEguiApp {
}
});
});
if ui.checkbox(&mut self.disks_woz1, "Woz v1").clicked() {
self.recalculate_disks();
}
if ui.checkbox(&mut self.disks_woz2, "Woz v2").clicked() {
self.recalculate_disks();
}
if ui.checkbox(&mut self.disks_dsk, "Dsk").clicked() {
self.recalculate_disks();
}
});
});
});
Expand All @@ -168,8 +167,8 @@ impl MyEguiApp {
}
}

pub fn read_disks_directories(directories: &[String]) -> Vec<DiskInfo> {
let mut result: Vec<DiskInfo> = Vec::new();
pub fn read_disks_directories(directories: &[String]) -> Vec<DisplayedDisk> {
let mut result: Vec<DisplayedDisk> = Vec::new();
for path in directories.iter() {
let builder = Walk::new(path).filter(|f| {
if let Ok(de) = f {
Expand All @@ -188,20 +187,16 @@ impl MyEguiApp {
});
for file in builder {
if let Ok(f) = file {
let p = f.into_path().to_str().unwrap().to_string();
if let Ok(disk) = Disk::new(&p, true /* quick */, None) {
result.push(disk.disk_info().clone());
} else {
ui_log(&format!("Error getting disk_info: {p}"));
}
result.push(DisplayedDisk::new(f));
} else {
ui_log(&format!("Error in file {:?}", file));
}
}
};

result.sort_by(|a, b| a.name().to_lowercase().partial_cmp(&b.name().to_lowercase()).unwrap());
result.dedup_by(|a, b| a.name() == b.name());
result.sort_by(|a, b| a.file_name.to_lowercase().partial_cmp(
&b.file_name.to_lowercase()).unwrap());
result.dedup_by(|a, b| a.file_name == b.file_name);
result
}
}
Expand Down
12 changes: 4 additions & 8 deletions apple2/src/ui/ui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::{VecDeque};
use std::fs::{DirEntry, File};
use crossbeam::channel::{Receiver, Sender};
use std::time::{SystemTime};

Expand All @@ -19,6 +20,7 @@ use crate::disk::drive::{DriveStatus};
use crate::ui::container::{Container};
use crate::memory_constants::*;
use crate::messages::ToMiniFb::Buffer;
use crate::ui::disks_window::DisplayedDisk;
use crate::ui::hires_screen::{AColor, HiresScreen};

#[derive(Clone, Copy, Default, PartialEq)]
Expand Down Expand Up @@ -138,13 +140,10 @@ pub struct MyEguiApp {

/// Disks window
/// The content of the directory
pub(crate) disks_all_disks: Vec<DiskInfo>,
pub(crate) disks_all_disks: Vec<DisplayedDisk>,
/// The disks we are actually displaying (might be filtered)
pub(crate) disks_displayed_disks: Vec<DiskInfo>,
pub(crate) disks_displayed_disks: Vec<DisplayedDisk>,
pub(crate) disks_filter: String,
pub(crate) disks_woz1: bool,
pub(crate) disks_woz2: bool,
pub(crate) disks_dsk: bool,

/// If true, activate trace
pub(crate) trace: bool,
Expand Down Expand Up @@ -458,9 +457,6 @@ impl MyEguiApp {
disks_displayed_disks: disks.clone(),
disks_all_disks: disks,
disks_filter: "".to_string(),
disks_woz1: true,
disks_woz2: true,
disks_dsk: true,

trace: false,
disassemble_from: "0".to_string(),
Expand Down

0 comments on commit 9f3caca

Please sign in to comment.