Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
rusb2snes = "0.2.1"
# tungstenite = "0.27"
42 changes: 24 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
*/

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;

#[derive(StructOpt, Debug)]
#[structopt(
Expand Down Expand Up @@ -88,7 +88,7 @@ struct Opt {
devel: bool,
}

fn main() -> Result<(), Error> {
fn main() -> Result<(), Box<dyn Error>> {
let opt = Opt::from_args();

let mut usb2snes;
Expand All @@ -99,7 +99,7 @@ fn main() -> Result<(), Error> {
}
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()?;

Expand All @@ -111,8 +111,7 @@ fn main() -> Result<(), Error> {
}
}
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 :");
Expand All @@ -125,12 +124,16 @@ fn main() -> Result<(), Error> {
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()?;
Expand All @@ -139,14 +142,12 @@ fn main() -> Result<(), Error> {
|| 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();
Expand Down Expand Up @@ -193,17 +194,22 @@ fn main() -> Result<(), Error> {
}
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");
let path = opt.path.unwrap();
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);
Expand Down
Loading