From f935999938fc5c505f8c3d23617fbc538b7db0b3 Mon Sep 17 00:00:00 2001 From: Thibault Delattre Date: Sun, 24 Aug 2025 11:10:11 +0200 Subject: [PATCH 1/2] upgrade deps, remove unused --- Cargo.toml | 16 ++++++++-------- src/main.rs | 7 ++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3ebee10..b78bb16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,13 +7,13 @@ edition = "2018" [dependencies] -lazy_static = "1.4.0" -strum = "0.24" -strum_macros = "0.24" +# lazy_static = "1.4.0" +# strum = "0.24" +# strum_macros = "0.24" structopt = { version = "0.3.13" } -websocket = "0.26.2" -serde = { version = "1", features = ["derive"] } -serde_json = "1.0" +# websocket = "0.26.2" +# serde = { version = "1", features = ["derive"] } +# serde_json = "1.0" scan_fmt = "0.2.6" -rusb2snes = "0.1.1" -tungstenite = "0.19" \ No newline at end of file +rusb2snes = "0.2.1" +# tungstenite = "0.27" diff --git a/src/main.rs b/src/main.rs index 8cdfd26..3d30c39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,15 +19,16 @@ */ use scan_fmt::scan_fmt; -use std::fs; use std::fs::File; use std::io::prelude::*; use std::thread::sleep; use std::time::Duration; +use std::{error::Error, fs}; + use structopt::StructOpt; use rusb2snes::{SyncClient, USB2SnesFileType}; -use tungstenite::Error; +// use tungstenite::Error; #[derive(StructOpt, Debug)] #[structopt( @@ -88,7 +89,7 @@ struct Opt { devel: bool, } -fn main() -> Result<(), Error> { +fn main() -> Result<(), Box> { let opt = Opt::from_args(); let mut usb2snes; From 575292331d2e775282e243cfd3c84be4c2484ed9 Mon Sep 17 00:00:00 2001 From: Thibault Delattre Date: Sun, 24 Aug 2025 13:26:55 +0200 Subject: [PATCH 2/2] rustify and update action ? --- .github/workflows/windows.yml | 2 +- src/main.rs | 37 ++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 3dc9a2e..ed2749a 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -36,7 +36,7 @@ jobs: run: cargo build --release --verbose - name: Upload exe - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: usb2snes-cli.exe path: target/release/usb2snes-cli.exe diff --git a/src/main.rs b/src/main.rs index 3d30c39..1ac91e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,6 @@ use std::{error::Error, fs}; use structopt::StructOpt; use rusb2snes::{SyncClient, USB2SnesFileType}; -// use tungstenite::Error; #[derive(StructOpt, Debug)] #[structopt( @@ -100,7 +99,7 @@ fn main() -> Result<(), Box> { } println!("Connected to the Usb2snes server"); usb2snes.set_name(String::from("usb2snes-cli"))?; - println!("Server version is : {:?}", usb2snes.app_version()); + println!("Server version is : {}", usb2snes.app_version()?); let mut devices = usb2snes.list_device()?; @@ -112,8 +111,7 @@ fn main() -> Result<(), Box> { } } if devices.is_empty() { - println!("No device found"); - std::process::exit(1); + return Err("No Device Found.".into()); } else { if opt.list_device { println!("Listing devices :"); @@ -126,12 +124,16 @@ fn main() -> Result<(), Box> { dev, info.dev_type, info.version, info.game, info.flags ); } - std::process::exit(0); + return Ok(()); } - let device = opt.device.unwrap_or_else(|| devices[0].clone()); + + let device = match opt.device { + Some(d) => d, + None => return Err("Error parsing device".into()), + }; + // let device = opt.device.unwrap_or_else(|| devices[0].clone()); if !devices.contains(&device) { - println!("Can't find the specified device <{:?}>", &device); - std::process::exit(1); + return Err(format!("Can't find the specified device <{:?}>", &device).into()); } usb2snes.attach(&device)?; let info = usb2snes.info()?; @@ -140,14 +142,12 @@ fn main() -> Result<(), Box> { || opt.file_to_upload.is_some() || opt.ls_path.is_some()) { - println!("The device does not support file commands"); - std::process::exit(1); + return Err("The device does not support file commands".into()); } if info.flags.contains(&String::from("NO_CONTROL_CMD")) && (opt.menu || opt.reset || opt.boot.is_some()) { - println!("The device does not support control command (menu/reset/boot)"); - std::process::exit(1); + return Err("The device does not support control command (menu/reset/boot)".into()); } if opt.get_address.is_some() { let toget = opt.get_address.unwrap(); @@ -194,8 +194,7 @@ fn main() -> Result<(), Box> { } if opt.file_to_upload.is_some() { if opt.path.is_none() { - println!("You need to provide a --path to upload a file"); - std::process::exit(1); + return Err("You need to provide a --path to upload a file".into()); } let local_path = opt.file_to_upload.unwrap(); let data = fs::read(local_path).expect("Error opening the file or reading the content"); @@ -203,8 +202,14 @@ fn main() -> Result<(), Box> { usb2snes.send_file(&path, data)?; } if opt.file_to_download.is_some() { - let path: String = opt.file_to_download.unwrap(); - let local_path = path.split('/').last().unwrap(); + let path: String = match opt.file_to_download { + Some(p) => p, + None => return Err("File Not Found".into()), + }; + let local_path = match path.split('/').next_back() { + Some(p) => p, + None => return Err("Could not parse local_path.".into()), + }; println!("Downloading : {:?} , local file {:?}", path, local_path); let data = usb2snes.get_file(&path)?; let f = File::create(local_path);