Skip to content

Commit

Permalink
clippy + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rfvgyhn committed Nov 6, 2023
1 parent 8b13742 commit 5e54eb2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const INDENT_WIDTH: usize = 4;

pub struct CompatToolConfig(BTreeMap<String, Vec<App>>);
impl Display for CompatToolConfig {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
for (i, (compat_tool, apps)) in self.0.iter().enumerate() {
writeln!(f, "{}", compat_tool)?;

Expand All @@ -23,7 +23,7 @@ impl Display for CompatToolConfig {
}

if i < self.0.len() - 1 {
writeln!(f, "")?;
writeln!(f)?;
}
}

Expand Down Expand Up @@ -75,7 +75,7 @@ impl Display for LaunchOptionsConfig {
)?;

if i < apps.len() - 1 {
writeln!(f, "")?;
writeln!(f)?;
}
}
}
Expand Down Expand Up @@ -121,12 +121,12 @@ pub fn parse_launch_options(steam_home: &Path) -> Result<LaunchOptionsConfig> {

LaunchOptions {
app,
value: (&l.options).to_string(),
value: l.options.to_string(),
}
})
.collect();
o.sort_by(|a, b| a.app.name.cmp(&b.app.name));
let username = steam::get_display_name(&steam_home, &id)?;
let username = steam::get_display_name(steam_home, &id)?;
result.insert(username, o);
}
Ok(LaunchOptionsConfig(result))
Expand Down Expand Up @@ -207,7 +207,7 @@ fn get_app_names(
.difference(&HashSet::from_iter(app_names.keys()))
.copied()
.collect::<Vec<&AppId>>();
shortcuts = steam::shortcuts::parse_names(&steam_home, &missing_names)?;
shortcuts = steam::shortcuts::parse_names(steam_home, &missing_names)?;
log::debug!("Found {} name(s) from shortcuts.vdf", shortcuts.len());
app_names.extend(shortcuts.clone());
}
Expand Down Expand Up @@ -242,7 +242,7 @@ where
let file = fs::File::open(path)?;
let lines = std::io::BufReader::new(file)
.lines()
.filter_map(std::result::Result::ok);
.map_while(std::result::Result::ok);

Ok(lines)
}
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{Parser, Subcommand, ArgAction};
use clap::{ArgAction, Parser, Subcommand};
use proton_usage::{parse_launch_options, parse_tool_mapping};
use std::path::PathBuf;

Expand All @@ -23,7 +23,7 @@ enum Command {
Proton,

/// Lists apps with overridden launch options
LaunchOptions
LaunchOptions,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -49,7 +49,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some(Command::LaunchOptions) => {
let config = parse_launch_options(&steam_path)?;
println!("{}", &config);
},
}
};

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/steam/app_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const POSSIBLE_KEYS: [&str; 1] = ["name"];
pub fn parse_names(file_path: &Path, app_ids: &[&AppId]) -> Result<HashMap<AppId, String>> {
let mut result = HashMap::new();

match std::fs::read(&file_path) {
match std::fs::read(file_path) {
Ok(contents) => {
let names = parse_names_from_bin_vdf(&contents, &POSSIBLE_KEYS, app_ids);
result.extend(names);
Expand Down
2 changes: 1 addition & 1 deletion src/steam/local_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct LaunchOptions {
fn parse_launch_options(options: &str, app_id: &AppId, map: &mut Vec<LaunchOptions>) {
if app_id != &DEFAULT_PROTON_APP_ID {
map.push(LaunchOptions {
app_id: app_id.clone(),
app_id: *app_id,
options: options.to_string(),
});
}
Expand Down
22 changes: 16 additions & 6 deletions src/steam/login_users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use std::path::Path;
fn parse_display_name(id: &SteamId64, config_lines: impl Iterator<Item = String>) -> String {
config_lines
.skip_while(|line| line.trim_start() != format!("\"{}\"", id))
.skip_while(|line| !line.trim_start().starts_with("\"PersonaName"))
.next()
.and_then(|line| line.rsplit_terminator("\"").next().map(|s| s.to_string()))
.find(|line| line.trim_start().starts_with("\"PersonaName"))
.and_then(|line| line.rsplit_terminator('"').next().map(|s| s.to_string()))
.unwrap_or_else(|| id.to_string())
}

Expand All @@ -30,10 +29,21 @@ mod tests {
let lines = r#"
"users"
{
"123"
{
"AccountName" "Account Name1"
"PersonaName" "Display Name1"
"RememberPassword" "1"
"WantsOfflineMode" "0"
"SkipOfflineModeWarning" "0"
"AllowAutoLogin" "1"
"mostrecent" "1"
"Timestamp" "123456789"
}
"12345678901234567"
{
"AccountName" "Account Name"
"PersonaName" "Display Name"
"AccountName" "Account Name1"
"PersonaName" "Display Name1"
"RememberPassword" "1"
"WantsOfflineMode" "0"
"SkipOfflineModeWarning" "0"
Expand All @@ -48,7 +58,7 @@ mod tests {

let display_name = parse_display_name(&ID, lines);

assert_eq!(display_name, "Display Name", "")
assert_eq!(display_name, "Display Name1", "")
}

#[test]
Expand Down

0 comments on commit 5e54eb2

Please sign in to comment.