Skip to content

Commit 9f3caca

Browse files
committed
Fix .dsk bug
1 parent 189c920 commit 9f3caca

File tree

2 files changed

+37
-46
lines changed

2 files changed

+37
-46
lines changed

apple2/src/ui/disks_window.rs

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
use std::path::Path;
1+
use std::path::{Path};
22
use eframe::egui::{Align, Color32, Label, Layout, RichText, ScrollArea, Ui, Vec2};
3-
use ignore::Walk;
3+
use ignore::{DirEntry, Walk};
44
use rfd::FileDialog;
55
use crate::constants::{BUGGY_DISKS, DISKS_SUFFIXES};
6-
use crate::disk::disk::Disk;
76
use crate::disk::disk_controller::{DiskController};
8-
use crate::disk::disk_info::DiskInfo;
9-
use crate::disk::disk_info::DiskType::{Dsk, Woz1, Woz2};
107
use crate::messages::ToCpu::LoadDisk;
118
use crate::ui::ui::{MyEguiApp, ui_log};
129

10+
#[derive(Clone)]
11+
pub(crate) struct DisplayedDisk {
12+
file_name: String,
13+
path: String,
14+
}
15+
16+
impl DisplayedDisk {
17+
fn new(d: DirEntry) -> DisplayedDisk {
18+
DisplayedDisk {
19+
file_name: d.file_name().to_str().unwrap().to_string(),
20+
path: d.path().to_str().unwrap().to_string(),
21+
}
22+
}
23+
}
24+
1325
impl MyEguiApp {
1426
fn is_buggy(name: &str) -> bool {
1527
BUGGY_DISKS.iter().any(|d| {
@@ -23,16 +35,12 @@ impl MyEguiApp {
2335

2436
use rayon::prelude::*;
2537
self.disks_displayed_disks = disks.par_iter().filter_map(|d| {
26-
if self.disks_filter.is_empty() || d.path().to_lowercase().contains(&self.disks_filter) {
27-
#[allow(clippy::if_same_then_else)]
28-
if d.disk_type == Woz1 && self.disks_woz1 { Some(d.clone()) }
29-
else if d.disk_type == Woz2 && self.disks_woz2 { Some(d.clone()) }
30-
else if d.disk_type == Dsk && self.disks_dsk { Some(d.clone()) }
31-
else { None }
38+
if self.disks_filter.is_empty() || d.file_name.to_lowercase().contains(&self.disks_filter) {
39+
Some(d.clone())
3240
} else {
3341
None
3442
}
35-
}).collect::<Vec<DiskInfo>>();
43+
}).collect::<Vec<DisplayedDisk>>();
3644
}
3745

3846
pub fn create_disks_window(&mut self, ui: &mut Ui) {
@@ -48,23 +56,23 @@ impl MyEguiApp {
4856
.min_scrolled_height(600.0).show(ui, |ui| {
4957
let disks = self.disks_displayed_disks.clone();
5058
if ! disks.is_empty() {
51-
for disk_info in &self.disks_displayed_disks {
59+
for displayed_disk in &self.disks_displayed_disks {
5260
ui.horizontal(|ui| {
5361
//
5462
// Drive 1 / Drive 2
5563
//
5664
let mut drive_label = |index: usize, label: &str| {
5765
let mut drive_label = RichText::new(label);
5866
if let Some(di) = &self.disk_infos[index] {
59-
if *di.path == disk_info.path {
67+
if *di.path == *displayed_disk.path {
6068
drive_label = RichText::new(label)
6169
.background_color(Color32::DARK_BLUE);
6270
}
6371
}
6472

6573
if ui.button(drive_label).clicked() {
6674
let disk = DiskController::
67-
load_disk_new(&disk_info.path(), None);
75+
load_disk_new(&displayed_disk.path, None);
6876
if let Ok(disk) = disk {
6977
self.sender.send(
7078
LoadDisk(index, disk.disk_info().clone())).unwrap();
@@ -77,17 +85,17 @@ impl MyEguiApp {
7785
//
7886
// Name of the disk, in the correct color
7987
//
80-
let color = if Self::is_buggy(disk_info.name()) {
88+
let color = if Self::is_buggy(&displayed_disk.file_name) {
8189
Color32::RED
82-
} else if disk_info.path().to_lowercase().ends_with("woz") {
90+
} else if displayed_disk.file_name.to_lowercase().ends_with("woz") {
8391
Color32::YELLOW
8492
} else {
8593
Color32::LIGHT_BLUE
8694
};
8795
ui.scope(|ui| {
8896
ui.set_max_width(150.0);
89-
let max = std::cmp::min(60, disk_info.name().len());
90-
let n = &disk_info.name()[0..max];
97+
let max = std::cmp::min(60, displayed_disk.file_name.len());
98+
let n = &displayed_disk.file_name[0..max];
9199
ui.add(Label::new(RichText::new(n).color(color)));
92100
// let r = Rect::from_min_size(Pos2::new(0.0, 0.0), Vec2::new(300.0, 15.0));
93101
// ui.put(r, Label::new(RichText::new(disk_info.name()).color(color)));
@@ -134,15 +142,6 @@ impl MyEguiApp {
134142
}
135143
});
136144
});
137-
if ui.checkbox(&mut self.disks_woz1, "Woz v1").clicked() {
138-
self.recalculate_disks();
139-
}
140-
if ui.checkbox(&mut self.disks_woz2, "Woz v2").clicked() {
141-
self.recalculate_disks();
142-
}
143-
if ui.checkbox(&mut self.disks_dsk, "Dsk").clicked() {
144-
self.recalculate_disks();
145-
}
146145
});
147146
});
148147
});
@@ -168,8 +167,8 @@ impl MyEguiApp {
168167
}
169168
}
170169

171-
pub fn read_disks_directories(directories: &[String]) -> Vec<DiskInfo> {
172-
let mut result: Vec<DiskInfo> = Vec::new();
170+
pub fn read_disks_directories(directories: &[String]) -> Vec<DisplayedDisk> {
171+
let mut result: Vec<DisplayedDisk> = Vec::new();
173172
for path in directories.iter() {
174173
let builder = Walk::new(path).filter(|f| {
175174
if let Ok(de) = f {
@@ -188,20 +187,16 @@ impl MyEguiApp {
188187
});
189188
for file in builder {
190189
if let Ok(f) = file {
191-
let p = f.into_path().to_str().unwrap().to_string();
192-
if let Ok(disk) = Disk::new(&p, true /* quick */, None) {
193-
result.push(disk.disk_info().clone());
194-
} else {
195-
ui_log(&format!("Error getting disk_info: {p}"));
196-
}
190+
result.push(DisplayedDisk::new(f));
197191
} else {
198192
ui_log(&format!("Error in file {:?}", file));
199193
}
200194
}
201195
};
202196

203-
result.sort_by(|a, b| a.name().to_lowercase().partial_cmp(&b.name().to_lowercase()).unwrap());
204-
result.dedup_by(|a, b| a.name() == b.name());
197+
result.sort_by(|a, b| a.file_name.to_lowercase().partial_cmp(
198+
&b.file_name.to_lowercase()).unwrap());
199+
result.dedup_by(|a, b| a.file_name == b.file_name);
205200
result
206201
}
207202
}

apple2/src/ui/ui.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::{VecDeque};
2+
use std::fs::{DirEntry, File};
23
use crossbeam::channel::{Receiver, Sender};
34
use std::time::{SystemTime};
45

@@ -19,6 +20,7 @@ use crate::disk::drive::{DriveStatus};
1920
use crate::ui::container::{Container};
2021
use crate::memory_constants::*;
2122
use crate::messages::ToMiniFb::Buffer;
23+
use crate::ui::disks_window::DisplayedDisk;
2224
use crate::ui::hires_screen::{AColor, HiresScreen};
2325

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

139141
/// Disks window
140142
/// The content of the directory
141-
pub(crate) disks_all_disks: Vec<DiskInfo>,
143+
pub(crate) disks_all_disks: Vec<DisplayedDisk>,
142144
/// The disks we are actually displaying (might be filtered)
143-
pub(crate) disks_displayed_disks: Vec<DiskInfo>,
145+
pub(crate) disks_displayed_disks: Vec<DisplayedDisk>,
144146
pub(crate) disks_filter: String,
145-
pub(crate) disks_woz1: bool,
146-
pub(crate) disks_woz2: bool,
147-
pub(crate) disks_dsk: bool,
148147

149148
/// If true, activate trace
150149
pub(crate) trace: bool,
@@ -458,9 +457,6 @@ impl MyEguiApp {
458457
disks_displayed_disks: disks.clone(),
459458
disks_all_disks: disks,
460459
disks_filter: "".to_string(),
461-
disks_woz1: true,
462-
disks_woz2: true,
463-
disks_dsk: true,
464460

465461
trace: false,
466462
disassemble_from: "0".to_string(),

0 commit comments

Comments
 (0)