Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated dependencies #111

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
980 changes: 561 additions & 419 deletions Cargo.lock

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ categories = ["api-bindings", "games"]
homepage = "https://github.com/EqualGames/game-scanner"
repository = "https://github.com/EqualGames/game-scanner"
readme = "README.md"
include = [
"src/**/*.proto",
"src/**/*.rs",
"build.rs",
"Cargo.toml",
]
include = ["src/**/*.proto", "src/**/*.rs", "build.rs", "Cargo.toml"]

[lib]
name = "game_scanner"
Expand All @@ -27,27 +22,32 @@ name = "list"
harness = false

[dependencies]
serde = { version = "1.0.139", features = ["derive"] }
serde_json = { version = "1.0.82" }
serde_yaml = { version = "0.8.26" }
url = { version = "2.2.2" }
sysinfo = { version = "0.24.6" }
prost = { version = "0.10.4" }
prost-types = { version = "0.10.1" }
bytes = { version = "1.1.0" }
chrono = { version = "0.4.19" }
directories = { version = "4.0.1" }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1" }
serde_yaml = { version = "0.9" }
url = { version = "2" }
sysinfo = { version = "0.30" }
prost = { version = "0.12" }
prost-types = { version = "0.12" }
bytes = { version = "1" }
chrono = { version = "0.4" }
directories = { version = "5" }

[target.'cfg(unix)'.dependencies]
rusqlite = { version = "0.28.0", features = ["bundled"] }
rusqlite = { version = "0.31", features = ["bundled"] }

[target.'cfg(windows)'.dependencies]
case = { version = "1.0.0" }
winreg = { version = "0.10.1" }
rusqlite = { version = "0.28.0", features = ["bundled-windows"] }
case = { version = "1" }
winreg = { version = "0.52" }
rusqlite = { version = "0.31", features = ["bundled-windows"] }

[dev-dependencies]
criterion = { version = "0.3.6" }
criterion = { version = "0.5" }

[build-dependencies]
prost-build = { version = "0.10.4" }
prost-build = { version = "0.12" }

[lints.clippy]
pedantic = "warn"
nursery = "warn"
cargo = "warn"
18 changes: 9 additions & 9 deletions benches/list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::*;
use criterion::{criterion_group, criterion_main, Criterion};

fn list(c: &mut Criterion) {
let mut group = c.benchmark_group("list");
Expand All @@ -8,63 +8,63 @@ fn list(c: &mut Criterion) {
b.iter(|| {
let games = game_scanner::amazon::games().unwrap();
assert_ne!(games.len(), 0);
})
});
});

#[cfg(not(target_os = "linux"))]
group.bench_function("blizzard::games", |b| {
b.iter(|| {
let games = game_scanner::blizzard::games().unwrap();
assert_ne!(games.len(), 0);
})
});
});

#[cfg(not(target_os = "linux"))]
group.bench_function("epicgames::games", |b| {
b.iter(|| {
let games = game_scanner::epicgames::games().unwrap();
assert_ne!(games.len(), 0);
})
});
});

#[cfg(not(target_os = "linux"))]
group.bench_function("gog::games", |b| {
b.iter(|| {
let games = game_scanner::gog::games().unwrap();
assert_ne!(games.len(), 0);
})
});
});

#[cfg(not(target_os = "linux"))]
group.bench_function("origin::games", |b| {
b.iter(|| {
let games = game_scanner::origin::games().unwrap();
assert_ne!(games.len(), 0);
})
});
});

#[cfg(not(target_os = "linux"))]
group.bench_function("riotgames::games", |b| {
b.iter(|| {
let games = game_scanner::riotgames::games().unwrap();
assert_ne!(games.len(), 0);
})
});
});

#[cfg(not(target_os = "linux"))]
group.bench_function("steam::games", |b| {
b.iter(|| {
let games = game_scanner::steam::games().unwrap();
assert_ne!(games.len(), 0);
})
});
});

#[cfg(target_os = "windows")]
group.bench_function("ubisoft::games", |b| {
b.iter(|| {
let games = game_scanner::ubisoft::games().unwrap();
assert_ne!(games.len(), 0);
})
});
});

group.finish();
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {

println!("Compiling protos...");
prost_build::Config::new()
.btree_map(&["."])
.btree_map(["."])
.out_dir(&blizzard_proto_path)
.compile_protos(
&[blizzard_proto_path.join("product_db.proto")],
Expand Down
10 changes: 3 additions & 7 deletions examples/executable.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
fn main() {
let executable = game_scanner::steam::executable();

match executable {
match game_scanner::steam::executable() {
Ok(value) => {
println!("{:#?}", value);
println!("{value:#?}");
}
Err(error) => {
println!("{:#?}", error);
eprintln!("{error:#?}");
}
}

()
}
10 changes: 3 additions & 7 deletions examples/find.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
use game_scanner::steam;

fn main() {
let games = steam::games().unwrap();

match games.get(0) {
match steam::games().unwrap().first() {
Some(game) => {
match steam::find(&game.id) {
Ok(game) => {
println!("{:#?}", game);
println!("{game:#?}");
}
Err(error) => {
println!("{:#?}", error);
eprintln!("{error:#?}");
}
};
}
None => {
println!("Library is empty");
}
}

()
}
10 changes: 3 additions & 7 deletions examples/launch_and_close.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
use std::io::Error;
use std::thread;
use std::time;
use std::{thread, time};

fn main() -> Result<(), Error> {
fn main() {
let game = game_scanner::steam::games()
.unwrap()
.iter()
.find(|app| app.state.installed)
.map(|app| app.clone())
.cloned()
.unwrap();

game_scanner::manager::launch_game(&game).unwrap();

thread::sleep(time::Duration::from_secs(30));

game_scanner::manager::close_game(&game).unwrap();

Ok(())
}
10 changes: 3 additions & 7 deletions examples/list.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
fn main() {
let games = game_scanner::steam::games();

match games {
match game_scanner::steam::games() {
Ok(value) => {
println!("{:#?}", value);
println!("{value:#?}");
}
Err(error) => {
println!("{:#?}", error);
eprintln!("{error:#?}");
}
}

()
}
5 changes: 5 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum_discrim_align_threshold = 10
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
imports_layout = "HorizontalVertical"
struct_field_align_threshold = 10
5 changes: 3 additions & 2 deletions src/amazon/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#[cfg(not(target_os = "windows"))]
use std::path::PathBuf;

#[cfg(target_os = "windows")]
pub use self::windows::*;
#[cfg(not(target_os = "windows"))]
use crate::{
error::{Error, ErrorKind, Result},
prelude::Game,
};
#[cfg(not(target_os = "windows"))]
use std::path::PathBuf;

#[cfg(target_os = "windows")]
mod sqlite;
Expand Down
79 changes: 32 additions & 47 deletions src/amazon/sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
use std::path::{Path, PathBuf};

use rusqlite::{Connection, OpenFlags, Row};

use crate::{
error::{Error, ErrorKind, Result},
prelude::{Game, GameType},
};
use rusqlite::{Connection, OpenFlags, Row};
use std::path::{Path, PathBuf};

pub fn read_all(file: &Path, launcher_executable: &Path) -> Result<Vec<Game>> {
let conn =
Connection::open_with_flags(&file, OpenFlags::SQLITE_OPEN_READ_ONLY).map_err(|error| {
Connection::open_with_flags(file, OpenFlags::SQLITE_OPEN_READ_ONLY).map_err(|error| {
Error::new(
ErrorKind::InvalidManifest,
format!("Invalid Amazon Games manifest: {}", error.to_string()),
format!("Invalid Amazon Games manifest: {error}"),
)
})?;

let mut stmt = conn.prepare("SELECT * FROM DbSet").map_err(|error| {
Error::new(
ErrorKind::InvalidManifest,
format!(
"Error to read the Amazon Games manifest: {}",
error.to_string()
),
format!("Error to read the Amazon Games manifest: {error}"),
)
})?;

Expand All @@ -35,14 +34,11 @@ pub fn read_all(file: &Path, launcher_executable: &Path) -> Result<Vec<Game>> {
.map_err(|error| match error {
rusqlite::Error::QueryReturnedNoRows => Error::new(
ErrorKind::LibraryNotFound,
format!("Amazon library could be empty"),
"Amazon library could be empty".to_string(),
),
_ => Error::new(
ErrorKind::InvalidManifest,
format!(
"Error to read the Amazon Games manifest: {}",
error.to_string()
),
format!("Error to read the Amazon Games manifest: {error}"),
),
})?;

Expand All @@ -52,15 +48,15 @@ pub fn read_all(file: &Path, launcher_executable: &Path) -> Result<Vec<Game>> {
games.push(game?);
}

return Ok(games);
Ok(games)
}

pub fn read(id: &str, file: &Path, launcher_executable: &Path) -> Result<Game> {
let conn =
Connection::open_with_flags(&file, OpenFlags::SQLITE_OPEN_READ_ONLY).map_err(|error| {
Connection::open_with_flags(file, OpenFlags::SQLITE_OPEN_READ_ONLY).map_err(|error| {
Error::new(
ErrorKind::InvalidManifest,
format!("Invalid Amazon Games manifest: {}", error.to_string()),
format!("Invalid Amazon Games manifest: {error}"),
)
})?;

Expand All @@ -69,10 +65,7 @@ pub fn read(id: &str, file: &Path, launcher_executable: &Path) -> Result<Game> {
.map_err(|error| {
Error::new(
ErrorKind::InvalidManifest,
format!(
"Error to read the Amazon Games manifest: {}",
error.to_string()
),
format!("Error to read the Amazon Games manifest: {error}"),
)
})?;

Expand All @@ -82,37 +75,29 @@ pub fn read(id: &str, file: &Path, launcher_executable: &Path) -> Result<Game> {
.map(String::from)
.collect::<Vec<String>>();

return stmt
.query_row(&[(":id", id)], |row| {
parse_row(&columns, row, launcher_executable)
})
.map_err(|error| match error {
rusqlite::Error::QueryReturnedNoRows => Error::new(
ErrorKind::GameNotFound,
format!("Amazon game with id ({}) does not exist", id),
),
_ => Error::new(
ErrorKind::InvalidManifest,
format!(
"Error to read the Amazon Games manifest: {}",
error.to_string()
),
),
});
stmt.query_row(&[(":id", id)], |row| {
parse_row(&columns, row, launcher_executable)
})
.map_err(|error| match error {
rusqlite::Error::QueryReturnedNoRows => Error::new(
ErrorKind::GameNotFound,
format!("Amazon game with id ({id}) does not exist"),
),
_ => Error::new(
ErrorKind::InvalidManifest,
format!("Error to read the Amazon Games manifest: {error}"),
),
})
}

fn parse_row(
columns: &Vec<String>,
row: &Row,
launcher_executable: &Path,
) -> rusqlite::Result<Game> {
let mut game = Game::default();
game._type = GameType::AmazonGames.to_string();
fn parse_row(columns: &[String], row: &Row, launcher_executable: &Path) -> rusqlite::Result<Game> {
let mut game = Game {
type_: GameType::AmazonGames.to_string(),
..Default::default()
};

for col in 0..columns.len() {
let name = columns.get(col).unwrap();

match name.as_str() {
match columns.get(col).unwrap().as_str() {
"Id" => game.id = row.get(col)?,
"ProductTitle" => game.name = row.get(col)?,
"InstallDirectory" => game.path = row.get::<_, String>(col).map(PathBuf::from).ok(),
Expand Down
Loading