misc: get rid of some errors from Cargo lol
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
use std::sync::Arc;
|
||||
use std::{
|
||||
sync::mpsc::{self, Receiver, Sender},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
use std::sync::mpsc::{self, Receiver, Sender};
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use crate::emulator::misc::rpc::{Activity, RpcClient};
|
||||
|
||||
@@ -218,89 +218,89 @@ impl Editor {
|
||||
|
||||
fn handle_file_dialogs(&mut self, ctx: &egui::Context) {
|
||||
// Handle open dialog
|
||||
if let Some(dialog) = &mut self.open_file_dialog {
|
||||
if dialog.show(ctx).selected() {
|
||||
if let Some(file) = dialog.path() {
|
||||
// check if the file is a binary file
|
||||
if file.extension().is_some_and(|ext| ext == "dsb") {
|
||||
match std::fs::read(file) {
|
||||
Ok(content) => {
|
||||
let mut res = String::new();
|
||||
for (i, b) in content.iter().enumerate() {
|
||||
_ = write!(res, "{b:02x}");
|
||||
if i % 4 == 3 {
|
||||
res.push('\n');
|
||||
}
|
||||
}
|
||||
self.text = res.clone();
|
||||
self.buffer = res;
|
||||
self.path = Some(file.to_path_buf());
|
||||
self.unsaved = false;
|
||||
self.error = None;
|
||||
}
|
||||
Err(e) => {
|
||||
self.error = Some(format!("Failed to read file: {e}"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
match std::fs::read_to_string(file) {
|
||||
Ok(content) => {
|
||||
self.text = content.clone();
|
||||
self.buffer = content;
|
||||
self.path = Some(file.to_path_buf());
|
||||
self.unsaved = false;
|
||||
self.error = None;
|
||||
}
|
||||
Err(e) => {
|
||||
self.error = Some(format!("Failed to read file: {e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.open_file_dialog = None;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle save dialog
|
||||
if let Some(dialog) = &mut self.save_file_dialog {
|
||||
if dialog.show(ctx).selected() {
|
||||
if let Some(file) = dialog.path() {
|
||||
self.buffer = self.text.clone();
|
||||
|
||||
let content = if file.extension().is_some_and(|ext| ext == "dsb") {
|
||||
let mut res = Vec::new();
|
||||
for line in self.text.lines() {
|
||||
for line in line.split_whitespace() {
|
||||
match u32::from_str_radix(line, 16) {
|
||||
Ok(num) => res.push(num),
|
||||
Err(e) => {
|
||||
self.error =
|
||||
Some(format!("Failed to parse file: {e}"));
|
||||
return;
|
||||
}
|
||||
if let Some(dialog) = &mut self.open_file_dialog
|
||||
&& dialog.show(ctx).selected()
|
||||
{
|
||||
if let Some(file) = dialog.path() {
|
||||
// check if the file is a binary file
|
||||
if file.extension().is_some_and(|ext| ext == "dsb") {
|
||||
match std::fs::read(file) {
|
||||
Ok(content) => {
|
||||
let mut res = String::new();
|
||||
for (i, b) in content.iter().enumerate() {
|
||||
_ = write!(res, "{b:02x}");
|
||||
if i % 4 == 3 {
|
||||
res.push('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
res.into_iter()
|
||||
.flat_map(u32::to_be_bytes)
|
||||
.collect::<Vec<u8>>()
|
||||
} else {
|
||||
self.text.clone().as_bytes().to_vec()
|
||||
};
|
||||
|
||||
match std::fs::write(file, content) {
|
||||
Ok(()) => {
|
||||
self.text = res.clone();
|
||||
self.buffer = res;
|
||||
self.path = Some(file.to_path_buf());
|
||||
self.unsaved = false;
|
||||
self.error = None;
|
||||
}
|
||||
Err(e) => {
|
||||
self.error = Some(format!("Failed to save file: {e}"));
|
||||
self.error = Some(format!("Failed to read file: {e}"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
match std::fs::read_to_string(file) {
|
||||
Ok(content) => {
|
||||
self.text = content.clone();
|
||||
self.buffer = content;
|
||||
self.path = Some(file.to_path_buf());
|
||||
self.unsaved = false;
|
||||
self.error = None;
|
||||
}
|
||||
Err(e) => {
|
||||
self.error = Some(format!("Failed to read file: {e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
self.save_file_dialog = None;
|
||||
}
|
||||
self.open_file_dialog = None;
|
||||
}
|
||||
|
||||
// Handle save dialog
|
||||
if let Some(dialog) = &mut self.save_file_dialog
|
||||
&& dialog.show(ctx).selected()
|
||||
{
|
||||
if let Some(file) = dialog.path() {
|
||||
self.buffer = self.text.clone();
|
||||
|
||||
let content = if file.extension().is_some_and(|ext| ext == "dsb") {
|
||||
let mut res = Vec::new();
|
||||
for line in self.text.lines() {
|
||||
for line in line.split_whitespace() {
|
||||
match u32::from_str_radix(line, 16) {
|
||||
Ok(num) => res.push(num),
|
||||
Err(e) => {
|
||||
self.error =
|
||||
Some(format!("Failed to parse file: {e}"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
res.into_iter()
|
||||
.flat_map(u32::to_be_bytes)
|
||||
.collect::<Vec<u8>>()
|
||||
} else {
|
||||
self.text.clone().as_bytes().to_vec()
|
||||
};
|
||||
|
||||
match std::fs::write(file, content) {
|
||||
Ok(()) => {
|
||||
self.path = Some(file.to_path_buf());
|
||||
self.unsaved = false;
|
||||
self.error = None;
|
||||
}
|
||||
Err(e) => {
|
||||
self.error = Some(format!("Failed to save file: {e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
self.save_file_dialog = None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -115,24 +115,24 @@ impl Loader {
|
||||
|
||||
fn handle_file_dialogs(&mut self, ctx: &egui::Context) {
|
||||
// Handle open dialog
|
||||
if let Some(dialog) = &mut self.open_file_dialog {
|
||||
if dialog.show(ctx).selected() {
|
||||
if let Some(file) = dialog.path() {
|
||||
// check if the file is a binary file
|
||||
if file.extension().is_some_and(|ext| ext == "dsb") {
|
||||
match std::fs::read(file) {
|
||||
Ok(content) => {
|
||||
self.output = content;
|
||||
self.error = None;
|
||||
}
|
||||
Err(e) => {
|
||||
self.error = Some(format!("Failed to read file: {e}"));
|
||||
}
|
||||
if let Some(dialog) = &mut self.open_file_dialog
|
||||
&& dialog.show(ctx).selected()
|
||||
{
|
||||
if let Some(file) = dialog.path() {
|
||||
// check if the file is a binary file
|
||||
if file.extension().is_some_and(|ext| ext == "dsb") {
|
||||
match std::fs::read(file) {
|
||||
Ok(content) => {
|
||||
self.output = content;
|
||||
self.error = None;
|
||||
}
|
||||
Err(e) => {
|
||||
self.error = Some(format!("Failed to read file: {e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
self.open_file_dialog = None;
|
||||
}
|
||||
self.open_file_dialog = None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user