Skip to content
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ thread-id = "4.2.1"
colored = "2.1.0"
sentry-log = "0.33.0"

[target.'cfg(target_os = "linux")'.dependencies]
keyvalues-parser = "0.2.0"

[target.'cfg(target_os = "windows")'.dependencies]
winconsole = "0.11.1"
winreg = "0.52.0"
Expand Down
59 changes: 45 additions & 14 deletions src/helper/linux.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::fs::read_to_string;
use log::{debug, error};
use log::{debug, error, warn, trace};
use crate::BeansError;
use crate::helper::format_directory_path;
use keyvalues_parser::Vdf;

/// all possible known directory where steam *might* be
/// only is used on linux, since windows will use the registry.
Expand All @@ -10,6 +11,15 @@ pub const STEAM_POSSIBLE_DIR: &'static [&'static str] = &[
"~/.var/app/com.valvesoftware.Steam/.steam/registry.vdf"
];

// Registry keys
const REGISTRY_KEYS: [&str; 5] = [
"HKCU",
"Software",
"Valve",
"Steam",
"SourceModInstallPath"
];

/// find sourcemod path on linux.
/// fetches the fake registry that steam uses from find_steam_reg_path
/// and gets the value of Registry/HKCU/Software/Valve/Steam/SourceModInstallPath
Expand All @@ -29,18 +39,39 @@ pub fn find_sourcemod_path() -> Result<String, BeansError>
}
};

for line in reg_content.lines() {
if line.contains("SourceModInstallPath")
{
let split = &line.split("\"SourceModInstallPath\"");
let last = split.clone()
.last()
.expect("Failed to find SourceModInstallPath")
.trim()
.replace("\"", "");
return Ok(format_directory_path(last));
}
}
match Vdf::parse(&reg_content)
{
Ok(vdf) => {
let mut vdf_obj = vdf.value.get_obj();

let mut it = REGISTRY_KEYS.into_iter().peekable();
while let Some(x) = it.next() {
match vdf_obj {
Some(s) => {
if let Some(elem) = s.get(x) {
if let Some(entry) = elem.last() {
if it.peek().is_none() {
if let Some(sourcemod_path) = entry.get_str() {
return Ok(format_directory_path(sourcemod_path.to_string()));
}
}
else {
vdf_obj = entry.get_obj();
continue;
}
}
}
},
None => {},
}
break;
}
},
Err(e) => {
trace!("{:#?}", e);
warn!("[find_sourcemod_path] failed to parse vdf content {:}", e);
},
};

return Err(BeansError::SourceModLocationNotFound);
}
Expand Down Expand Up @@ -73,4 +104,4 @@ fn find_steam_reg_path() -> Result<String, BeansError>
}
error!("Couldn't find any of the locations in STEAM_POSSIBLE_DIR");
return Err(BeansError::SteamNotFound);
}
}