mirror of
https://github.com/G2-Games/minidisc-cli.git
synced 2025-04-19 03:32:53 -05:00
Ran cargo fmt
This commit is contained in:
parent
1d188c335d
commit
33feb301e8
6 changed files with 345 additions and 318 deletions
|
@ -4,7 +4,7 @@ use std::error::Error;
|
|||
use std::time::Duration;
|
||||
|
||||
// USB stuff
|
||||
use nusb::transfer::{Control, ControlType, Recipient, RequestBuffer, ControlIn, ControlOut};
|
||||
use nusb::transfer::{Control, ControlIn, ControlOut, ControlType, Recipient, RequestBuffer};
|
||||
use nusb::{Device, DeviceInfo, Interface};
|
||||
|
||||
const DEFAULT_TIMEOUT: Duration = Duration::new(10000, 0);
|
||||
|
@ -146,16 +146,19 @@ impl NetMD {
|
|||
/// of the previous command, or the status
|
||||
pub async fn poll(&mut self) -> Result<(u16, [u8; 4]), Box<dyn Error>> {
|
||||
// Create an array to store the result of the poll
|
||||
let poll_result = match self.usb_interface.control_in(
|
||||
ControlIn {
|
||||
let poll_result = match self
|
||||
.usb_interface
|
||||
.control_in(ControlIn {
|
||||
control_type: ControlType::Vendor,
|
||||
recipient: Recipient::Interface,
|
||||
request: 0x01,
|
||||
value: 0,
|
||||
index: 0,
|
||||
length: 4,
|
||||
}
|
||||
).await.into_result() {
|
||||
})
|
||||
.await
|
||||
.into_result()
|
||||
{
|
||||
Ok(size) => size,
|
||||
Err(error) => return Err(error.into()),
|
||||
};
|
||||
|
@ -198,22 +201,28 @@ impl NetMD {
|
|||
true => 0xff,
|
||||
};
|
||||
|
||||
match self.usb_interface.control_out(
|
||||
ControlOut {
|
||||
match self
|
||||
.usb_interface
|
||||
.control_out(ControlOut {
|
||||
control_type: ControlType::Vendor,
|
||||
recipient: Recipient::Interface,
|
||||
request,
|
||||
value: 0,
|
||||
index: 0,
|
||||
data: &command,
|
||||
}
|
||||
).await.into_result() {
|
||||
})
|
||||
.await
|
||||
.into_result()
|
||||
{
|
||||
Ok(_) => Ok(()),
|
||||
Err(error) => Err(error.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn read_reply(&mut self, override_length: Option<i32>) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
pub async fn read_reply(
|
||||
&mut self,
|
||||
override_length: Option<i32>,
|
||||
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
self._read_reply(false, override_length).await
|
||||
}
|
||||
|
||||
|
@ -253,16 +262,18 @@ impl NetMD {
|
|||
};
|
||||
|
||||
// Create a buffer to fill with the result
|
||||
let reply = self.usb_interface.control_in(
|
||||
ControlIn {
|
||||
let reply = self
|
||||
.usb_interface
|
||||
.control_in(ControlIn {
|
||||
control_type: ControlType::Vendor,
|
||||
recipient: Recipient::Interface,
|
||||
request,
|
||||
value: 0,
|
||||
index: 0,
|
||||
length,
|
||||
}
|
||||
).await.into_result()?;
|
||||
})
|
||||
.await
|
||||
.into_result()?;
|
||||
|
||||
Ok(reply)
|
||||
}
|
||||
|
@ -292,7 +303,10 @@ impl NetMD {
|
|||
done -= to_read;
|
||||
let buffer = RequestBuffer::new(to_read);
|
||||
|
||||
let res = match self.usb_interface.bulk_in(BULK_READ_ENDPOINT, buffer).await
|
||||
let res = match self
|
||||
.usb_interface
|
||||
.bulk_in(BULK_READ_ENDPOINT, buffer)
|
||||
.await
|
||||
.into_result()
|
||||
{
|
||||
Ok(result) => result,
|
||||
|
@ -306,10 +320,11 @@ impl NetMD {
|
|||
}
|
||||
|
||||
pub async fn write_bulk(&mut self, data: Vec<u8>) -> Result<usize, Box<dyn Error>> {
|
||||
Ok(
|
||||
self.usb_interface.bulk_out(BULK_WRITE_ENDPOINT, data).await
|
||||
Ok(self
|
||||
.usb_interface
|
||||
.bulk_out(BULK_WRITE_ENDPOINT, data)
|
||||
.await
|
||||
.into_result()?
|
||||
.actual_length(),
|
||||
)
|
||||
.actual_length())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -346,7 +346,11 @@ impl NetMDInterface {
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
async fn send_command(&mut self, query: &mut Vec<u8>, test: bool) -> Result<(), Box<dyn Error>> {
|
||||
async fn send_command(
|
||||
&mut self,
|
||||
query: &mut Vec<u8>,
|
||||
test: bool,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let status_byte = match test {
|
||||
true => Status::GeneralInquiry,
|
||||
false => Status::Control,
|
||||
|
@ -966,7 +970,11 @@ impl NetMDInterface {
|
|||
}
|
||||
|
||||
// Sets the title of the disc
|
||||
pub async fn set_disc_title(&mut self, title: String, wchar: bool) -> Result<(), Box<dyn Error>> {
|
||||
pub async fn set_disc_title(
|
||||
&mut self,
|
||||
title: String,
|
||||
wchar: bool,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let current_title = self.raw_disc_title(wchar).await?;
|
||||
if current_title == title {
|
||||
return Err("Title is already the same".into());
|
||||
|
@ -1099,7 +1107,12 @@ impl NetMDInterface {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn raw_track_info(&mut self, track: u16, p1: i32, p2: i32) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
async fn raw_track_info(
|
||||
&mut self,
|
||||
track: u16,
|
||||
p1: i32,
|
||||
p2: i32,
|
||||
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::OpenRead);
|
||||
|
||||
let mut query = format_query(
|
||||
|
@ -1167,7 +1180,10 @@ impl NetMDInterface {
|
|||
}
|
||||
|
||||
/// Gets the length of a track as a `std::time::Duration`
|
||||
pub async fn track_length(&mut self, track: u16) -> Result<std::time::Duration, Box<dyn Error>> {
|
||||
pub async fn track_length(
|
||||
&mut self,
|
||||
track: u16,
|
||||
) -> Result<std::time::Duration, Box<dyn Error>> {
|
||||
Ok(self.track_lengths([track].into()).await?[0])
|
||||
}
|
||||
|
||||
|
@ -1381,7 +1397,10 @@ impl NetMDInterface {
|
|||
Ok(res[0].to_vec().unwrap())
|
||||
}
|
||||
|
||||
pub async fn session_key_exchange(&mut self, hostnonce: Vec<u8>) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
pub async fn session_key_exchange(
|
||||
&mut self,
|
||||
hostnonce: Vec<u8>,
|
||||
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
if hostnonce.len() != 8 {
|
||||
return Err("Supplied host nonce length wrong".into());
|
||||
}
|
||||
|
|
|
@ -193,7 +193,6 @@ lazy_static! {
|
|||
("。".to_string(), "。".to_string()),
|
||||
("、".to_string(), "、".to_string())
|
||||
]);
|
||||
|
||||
pub static ref MAPPINGS_RU: HashMap<String, String> = HashMap::from([
|
||||
("а".to_string(), "a".to_string()),
|
||||
("б".to_string(), "b".to_string()),
|
||||
|
@ -262,7 +261,6 @@ lazy_static! {
|
|||
("Ю".to_string(), "Iu".to_string()),
|
||||
("Я".to_string(), "Ia".to_string())
|
||||
]);
|
||||
|
||||
pub static ref MAPPINGS_DE: HashMap<String, String> = HashMap::from([
|
||||
("Ä".to_string(), "Ae".to_string()),
|
||||
("ä".to_string(), "ae".to_string()),
|
||||
|
@ -272,7 +270,6 @@ lazy_static! {
|
|||
("ü".to_string(), "ue".to_string()),
|
||||
("ß".to_string(), "ss".to_string())
|
||||
]);
|
||||
|
||||
pub static ref MAPPINGS_HW: HashMap<String, String> = HashMap::from([
|
||||
("-".to_string(), "-".to_string()),
|
||||
("ー".to_string(), "-".to_string()),
|
||||
|
@ -553,6 +550,5 @@ lazy_static! {
|
|||
("ゝ".to_string(), "ヽ".to_string()),
|
||||
("ゞ".to_string(), "ヾ".to_string()),
|
||||
]);
|
||||
|
||||
pub static ref ALLOWED_HW_KANA: Vec<String> = MAPPINGS_HW.values().cloned().collect();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
|
||||
mod base;
|
||||
pub mod interface;
|
||||
mod mappings;
|
||||
mod query_utils;
|
||||
mod utils;
|
||||
mod mappings;
|
||||
|
|
|
@ -44,10 +44,7 @@ impl QueryValue {
|
|||
}
|
||||
|
||||
/// Formats a query using a standard input to send to the player
|
||||
pub fn format_query(
|
||||
format: String,
|
||||
args: Vec<QueryValue>,
|
||||
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
pub fn format_query(format: String, args: Vec<QueryValue>) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
if DEBUG {
|
||||
println!("SENT>>> F: {}", format);
|
||||
}
|
||||
|
|
|
@ -59,9 +59,7 @@ pub fn half_width_to_full_width_range(range: &str) -> String {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn get_bytes<const S: usize>(
|
||||
iterator: &mut IntoIter<u8>,
|
||||
) -> Result<[u8; S], Box<dyn Error>> {
|
||||
pub fn get_bytes<const S: usize>(iterator: &mut IntoIter<u8>) -> Result<[u8; S], Box<dyn Error>> {
|
||||
let byte_vec: Vec<u8> = iterator.take(S).collect();
|
||||
let bytes: [u8; S] = byte_vec.try_into().unwrap();
|
||||
|
||||
|
@ -170,5 +168,7 @@ pub fn agressive_sanitize_title(title: &str) -> String {
|
|||
|
||||
pub fn time_to_duration(time: &Vec<u64>) -> std::time::Duration {
|
||||
assert_eq!(time.len(), 4);
|
||||
std::time::Duration::from_micros((time[0] * 3600000000) + (time[1] * 60000000) + (time[2] * 1000000) + (time[3] * 11600))
|
||||
std::time::Duration::from_micros(
|
||||
(time[0] * 3600000000) + (time[1] * 60000000) + (time[2] * 1000000) + (time[3] * 11600),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue