Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

Commit 466a66b

Browse files
committed
Fixed some issues with zmodem upload.
Not 100% sure about the full duplex thing but made the zmodem implementation work on some more systems.
1 parent 63c1850 commit 466a66b

File tree

16 files changed

+233
-242
lines changed

16 files changed

+233
-242
lines changed

src/data/addresses.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl AddressBook {
368368
match input_text.parse::<Value>() {
369369
Ok(value) => self.parse_addresses(&value),
370370
Err(err) => {
371-
return Err(format!("Error parsing dialing_directory: {err}").into());
371+
return Err(anyhow::anyhow!("Error parsing dialing_directory: {err}"));
372372
}
373373
}
374374
Ok(())

src/features/auto_login.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ use web_time::Instant;
33
use crate::{
44
ui::connection::Connection, util::PatternRecognizer, Address, Options, TerminalResult,
55
};
6-
use std::{
7-
io::{self, ErrorKind},
8-
time::Duration,
9-
};
6+
use std::time::Duration;
107

118
use super::iemsi_com::IEmsi;
129

@@ -181,13 +178,10 @@ impl AutoLogin {
181178
}
182179
ch => {
183180
self.cur_expr_idx += 1; // escape
184-
return Err(Box::new(io::Error::new(
185-
ErrorKind::InvalidData,
186-
format!(
187-
"invalid escape sequence in autologin string: {:?}",
188-
char::from_u32(u32::from(*ch))
189-
),
190-
)));
181+
return Err(anyhow::anyhow!(
182+
"invalid escape sequence in autologin string: {:?}",
183+
*ch as char
184+
));
191185
}
192186
}
193187
self.cur_expr_idx += 1; // escape

src/features/iemsi_com.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#![allow(dead_code, clippy::wildcard_imports, clippy::needless_range_loop)]
22

33
// IEMSI autologin implementation http://ftsc.org/docs/fsc-0056.001
4-
use std::{
5-
fmt,
6-
io::{self, ErrorKind},
7-
};
4+
use std::fmt;
85

96
use icy_engine::{get_crc16, get_crc32, update_crc32};
107

@@ -304,10 +301,7 @@ impl EmsiICI {
304301
])?;
305302

306303
if data.len() > EmsiICI::MAX_SIZE {
307-
return Err(Box::new(io::Error::new(
308-
ErrorKind::OutOfMemory,
309-
"maximum size exceeded",
310-
)));
304+
return Err(anyhow::anyhow!("maximum size exceeded"));
311305
}
312306
let mut result = Vec::new();
313307
result.extend_from_slice(b"**EMSI_ICI");
@@ -651,10 +645,7 @@ fn parse_emsi_blocks(data: &[u8]) -> TerminalResult<Vec<String>> {
651645
i += 3;
652646
continue;
653647
}
654-
return Err(Box::new(io::Error::new(
655-
ErrorKind::InvalidData,
656-
"Escape char in emsi string invalid.",
657-
)));
648+
return Err(anyhow::anyhow!("Escape char in emsi string invalid."));
658649
}
659650

660651
str.push(char::from_u32(u32::from(data[i])).unwrap());
@@ -686,10 +677,7 @@ fn encode_emsi(data: &[&str]) -> TerminalResult<Vec<u8>> {
686677
}
687678
let val = ch as u32;
688679
if val > 255 {
689-
return Err(Box::new(io::Error::new(
690-
ErrorKind::InvalidData,
691-
"Unicode chars not supported",
692-
)));
680+
return Err(anyhow::anyhow!("Unicode chars not supported"));
693681
}
694682
// control codes.
695683
if val < 32 || val == 127 {

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
1313

1414
mod ui;
15-
use std::{error::Error, path::PathBuf};
15+
use std::path::PathBuf;
1616

1717
use directories::ProjectDirs;
1818
use eframe::egui;
1919
use lazy_static::lazy_static;
2020
use ui::MainWindow;
2121
use web_time::Instant;
22-
pub type TerminalResult<T> = Result<T, Box<dyn Error>>;
22+
pub type TerminalResult<T> = anyhow::Result<T>;
2323
use i18n_embed::fluent::{fluent_language_loader, FluentLanguageLoader};
2424
use log::LevelFilter;
2525
use log4rs::{

src/protocol/file_storage_handler.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ impl DiskStorageHandler {
102102
#[cfg(not(target_arch = "wasm32"))]
103103
pub fn new() -> TerminalResult<Self> {
104104
let Some(user_dirs) = directories::UserDirs::new() else {
105-
return Err("Failed to get user directories".into());
105+
return Err(anyhow::anyhow!("Failed to get user directories"));
106106
};
107107
let Some(output_path) = user_dirs.download_dir() else {
108-
return Err("Failed to get user directories".into());
108+
return Err(anyhow::anyhow!("Failed to get user directories"));
109109
};
110110

111111
Ok(Self {
@@ -122,15 +122,17 @@ impl DiskStorageHandler {
122122
impl FileStorageHandler for DiskStorageHandler {
123123
fn open_unnamed_file(&mut self) {
124124
let mut num = 0;
125-
let f = "no_name_file.0".to_string();
125+
let f = "x_modem_transferred_file.0".to_string();
126126
let mut file_name: PathBuf = self.output_path.join(f.clone());
127127

128128
while file_name.exists() {
129-
file_name = self.output_path.join(format!("no_name_file.{num}"));
129+
file_name = self
130+
.output_path
131+
.join(format!("x_modem_transferred_file.{num}"));
130132
num += 1;
131133
}
132134

133-
self.open_file(&format!("no_name_file.{num}"), 0);
135+
self.open_file(&format!("x_modem_transferred_file.{num}"), 0);
134136
}
135137

136138
fn open_file(&mut self, file_name: &str, total_size: usize) {

src/protocol/xymodem/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl super::Protocol for XYmodem {
7575
transfer_state: &mut TransferState,
7676
) -> TerminalResult<()> {
7777
if !self.config.is_ymodem() && files.len() != 1 {
78-
return Err(Box::new(TransmissionError::XModem1File));
78+
return Err(TransmissionError::XModem1File.into());
7979
}
8080

8181
let mut sy = sy::Sy::new(self.config);

src/protocol/xymodem/ry.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use icy_engine::get_crc16;
2-
use log4rs::append::file;
32
use std::{
4-
io::{self, ErrorKind},
53
sync::{Arc, Mutex},
64
thread,
75
};
@@ -86,10 +84,9 @@ impl Ry {
8684
com.send(vec![NAK])?;
8785
} else {
8886
self.cancel(com)?;
89-
return Err(Box::new(io::Error::new(
90-
ErrorKind::ConnectionAborted,
91-
"too many retries starting the communication",
92-
)));
87+
return Err(anyhow::anyhow!(
88+
"too many retries starting the communication"
89+
));
9390
}
9491
self.errors += 1;
9592
self.recv_state = RecvState::StartReceive(retries + 1);
@@ -183,10 +180,7 @@ impl Ry {
183180
com.send(vec![NAK])?;
184181
} else {
185182
self.cancel(com)?;
186-
return Err(Box::new(io::Error::new(
187-
ErrorKind::ConnectionAborted,
188-
"too many retries",
189-
)));
183+
return Err(anyhow::anyhow!("too many retries"));
190184
}
191185
self.errors += 1;
192186
self.recv_state = RecvState::ReadBlockStart(0, retries + 1);
@@ -227,10 +221,7 @@ impl Ry {
227221
self.recv_state = RecvState::ReadBlock(EXT_BLOCK_LENGTH, retries + 1);
228222
} else {
229223
self.cancel(com)?;
230-
return Err(Box::new(io::Error::new(
231-
ErrorKind::ConnectionAborted,
232-
"too many retries",
233-
)));
224+
return Err(anyhow::anyhow!("too many retries"));
234225
}
235226
self.recv_state = RecvState::ReadBlock(EXT_BLOCK_LENGTH, retries + 1);
236227
return Ok(());

src/protocol/xymodem/sy.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Sy {
123123
self.errors += 1;
124124
if retries > 5 {
125125
self.send_state = SendState::None;
126-
return Err(Box::new(TransmissionError::TooManyRetriesSendingHeader));
126+
return Err(TransmissionError::TooManyRetriesSendingHeader.into());
127127
}
128128
self.send_state = SendState::SendYModemHeader(retries + 1);
129129
return Ok(());
@@ -175,7 +175,7 @@ impl Sy {
175175
if can2 == CAN {
176176
self.send_state = SendState::None;
177177
//transfer_info.write("Got cancel ...".to_string());
178-
return Err(Box::new(TransmissionError::Cancel));
178+
return Err(TransmissionError::Cancel.into());
179179
}
180180
}
181181

@@ -191,7 +191,7 @@ impl Sy {
191191

192192
if retries > 5 {
193193
self.eot(com)?;
194-
return Err(Box::new(TransmissionError::TooManyRetriesSendingHeader));
194+
return Err(TransmissionError::TooManyRetriesSendingHeader.into());
195195
}
196196
self.send_state = SendState::SendData(cur_offset, retries + 1);
197197
return Ok(());
@@ -291,8 +291,8 @@ impl Sy {
291291
};
292292
Ok(())
293293
}
294-
CAN => Err(Box::new(TransmissionError::Cancel)),
295-
_ => Err(Box::new(TransmissionError::InvalidMode(ch))),
294+
CAN => Err(TransmissionError::Cancel.into()),
295+
_ => Err(TransmissionError::InvalidMode(ch).into()),
296296
}
297297
}
298298

0 commit comments

Comments
 (0)