### Iterate over all Steam libraries and apps using Rust Source: https://github.com/williamvenner/steamlocate-rs/blob/master/README.md This example shows how to iterate through all Steam libraries on the system and then list all applications within each library. It starts by locating the Steam directory, then iterates over `libraries()` and subsequently `apps()` for each library. Each app's ID and name are printed. ```rust let steam_dir = steamlocate::SteamDir::locate()?; for library in steam_dir.libraries()? { let library = library?; println!("Library - {}", library.path().display()); for app in library.apps() { let app = app?; println!(" App {} - {:?}", app.app_id, app.name); } } ``` -------------------------------- ### Locate Steam installation and a specific game using Rust Source: https://github.com/williamvenner/steamlocate-rs/blob/master/README.md Demonstrates how to find the Steam installation directory and then locate a specific game by its App ID. It uses `SteamDir::locate()` to get the Steam directory and `find_app()` to search for the game. Error handling with `?` is used, and the output shows the Steam path and game details. ```rust let steam_dir = steamlocate::SteamDir::locate()?; println!("Steam installation - {}", steam_dir.path().display()); const GMOD_APP_ID: u32 = 4_000; let (garrys_mod, _lib) = steam_dir .find_app(GMOD_APP_ID)? .expect("Of course we have G Mod"); assert_eq!(garrys_mod.name.as_ref().unwrap(), "Garry's Mod"); println!("{garrys_mod:#?}"); ``` -------------------------------- ### Create SteamDir from Known Path (Rust) Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt Creates a SteamDir instance from a known installation directory path. This is useful when you already know where Steam is installed. ```rust use steamlocate::SteamDir; use std::path::Path; fn main() -> Result<(), steamlocate::Error> { // Create SteamDir from a known path let steam_path = Path::new("/home/user/.local/share/Steam"); let steam_dir = SteamDir::from_dir(steam_path)?; println!("Using Steam at: {}", steam_dir.path().display()); // Output: Using Steam at: /home/user/.local/share/Steam Ok(()) } ``` -------------------------------- ### Iterate All Steam Libraries (Rust) Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt Returns an iterator over all Steam libraries in the installation. Each library can contain multiple installed apps. ```rust use steamlocate::SteamDir; fn main() -> Result<(), steamlocate::Error> { let steam_dir = SteamDir::locate()?; // Iterate through all libraries for library_result in steam_dir.libraries()? { match library_result { Ok(library) => { println!("Library: {}", library.path().display()); println!(" App IDs: {:?}", library.app_ids()); println!(" App count: {}", library.app_ids().len()); } Err(e) => eprintln!("Failed to read library: {}", e), } } // Output: // Library: /home/user/.local/share/Steam // App IDs: [4000, 391540, 1493710] // App count: 3 // Library: /mnt/games/SteamLibrary // App IDs: [599140, 230410] // App count: 2 Ok(()) } ``` -------------------------------- ### Locate Steam Installation Directory (Rust) Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt Automatically locates the Steam installation directory on the current system using platform-specific methods. This is the primary entry point for the API. ```rust use steamlocate::SteamDir; fn main() -> Result<(), steamlocate::Error> { // Locate Steam installation automatically let steam_dir = SteamDir::locate()?; // Get the Steam installation path println!("Steam installation: {}", steam_dir.path().display()); // Output: Steam installation: C:\Program Files (x86)\Steam // Or on Linux: Steam installation: /home/user/.local/share/Steam Ok(()) } ``` -------------------------------- ### Resolve App Installation Path (Rust) Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt Resolves the full filesystem path to an application's installation directory within a Steam library. This function uses the steamlocate crate and returns a Result, allowing for easy access to game files. ```rust use steamlocate::SteamDir; fn main() -> Result<(), steamlocate::Error> { let steam_dir = SteamDir::locate()?; const GRAVEYARD_KEEPER: u32 = 599140; if let Some((app, library)) = steam_dir.find_app(GRAVEYARD_KEEPER)? { // Get the full path to the game's installation let app_dir = library.resolve_app_dir(&app); println!("Graveyard Keeper installation: {}", app_dir.display()); // Output: Graveyard Keeper installation: /home/user/.local/share/Steam/steamapps/common/Graveyard Keeper // Check if specific files exist let executable = app_dir.join("Graveyard Keeper.exe"); println!("Executable exists: {}", executable.exists()); } Ok(()) } ``` -------------------------------- ### Access Complete App Metadata - Rust Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt Demonstrates how to retrieve and display comprehensive metadata for a specific Steam application using its App ID. This includes basic information, size, download status, universe, update behavior, state flags, and installed depots. It requires a located Steam directory and the app's ID. ```rust use steamlocate::{SteamDir, App}; use steamlocate::app::{StateFlags, StateFlag, AutoUpdateBehavior, Universe}; fn main() -> Result<(), steamlocate::Error> { let steam_dir = SteamDir::locate()?; const WARFRAME: u32 = 230410; if let Some((app, _)) = steam_dir.find_app(WARFRAME)? { // Basic info println!("App ID: {}", app.app_id); println!("Name: {:?}", app.name); println!("Install dir: {}", app.install_dir); // Size and download info println!("Size on disk: {:?} bytes", app.size_on_disk); println!("Bytes downloaded: {:?}", app.bytes_downloaded); println!("Build ID: {:?}", app.build_id); // Universe (Public, Beta, Internal, etc.) if let Some(universe) = &app.universe { match universe { Universe::Public => println!("Universe: Public"), Universe::Beta => println!("Universe: Beta"), _ => println!("Universe: {:?}", universe), } } // Update behavior if let Some(auto_update) = &app.auto_update_behavior { match auto_update { AutoUpdateBehavior::KeepUpToDate => println!("Updates: Always"), AutoUpdateBehavior::OnlyUpdateOnLaunch => println!("Updates: On launch"), AutoUpdateBehavior::UpdateWithHighPriority => println!("Updates: High priority"), _ => {} // Ignore other behaviors for brevity } } // State flags if let Some(state_flags) = app.state_flags { print!("State: "); for flag in state_flags.flags() { match flag { StateFlag::FullyInstalled => print!("Installed "), StateFlag::UpdateRequired => print!("NeedsUpdate "), StateFlag::Downloading => print!("Downloading "), _ => {} // Ignore other flags for brevity } } println!(); } // Installed depots println!("Installed depots: {}", app.installed_depots.len()); for (depot_id, depot) in &app.installed_depots { println!(" Depot {}: {} bytes, manifest {}", depot_id, depot.size, depot.manifest); } } // Output: // App ID: 230410 // Name: Some("Warframe") // Install dir: Warframe // Size on disk: Some(35000000000) bytes // Bytes downloaded: Some(30804429728) // Build ID: Some(12345678) // Universe: Public // Updates: On launch // State: Installed // Installed depots: 3 // Depot 230411: 30000000000 bytes, manifest 1234567890123456789 Ok(()) } ``` -------------------------------- ### Get Steam Compatibility Tool Mappings - Rust Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt Retrieves a mapping of Steam application IDs to their configured compatibility tools (e.g., Proton). This function is useful for understanding which compatibility layers are set for specific games. It requires a located Steam directory. ```rust use steamlocate::SteamDir; fn main() -> Result<(), steamlocate::Error> { let steam_dir = SteamDir::locate()?; // Get compatibility tool mappings let compat_mapping = steam_dir.compat_tool_mapping()?; println!("Compatibility Tool Mappings:"); for (app_id, compat_tool) in &compat_mapping { if let Some(name) = &compat_tool.name { println!(" App {} -> {}", app_id, name); } } // Output: // Compatibility Tool Mappings: // App 4000 -> proton_experimental // App 599140 -> proton_8 // Check if a specific app uses Proton const GMOD: u32 = 4000; if let Some(tool) = compat_mapping.get(&GMOD) { println!("Garry's Mod uses: {:?}", tool.name); } Ok(()) } ``` -------------------------------- ### Iterate Apps in Steam Library (Rust) Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt Iterates over all installed applications within a Steam library, retrieving full app metadata for each. This function requires the steamlocate crate and returns a Result indicating success or a steamlocate::Error. ```rust use steamlocate::SteamDir; fn main() -> Result<(), steamlocate::Error> { let steam_dir = SteamDir::locate()?; for library_result in steam_dir.libraries()? { let library = library_result?; println!("Library: {}", library.path().display()); // Iterate all apps in this library for app_result in library.apps() { match app_result { Ok(app) => { println!(" {} - {} ({})", app.app_id, app.name.as_deref().unwrap_or(""), app.install_dir ); } Err(e) => eprintln!(" Failed to read app: {}", e), } } } // Output: // Library: /home/user/.local/share/Steam // 4000 - Garry's Mod (GarrysMod) // 391540 - Undertale (Undertale) // 1493710 - Proton Experimental (Proton Experimental) Ok(()) } ``` -------------------------------- ### Get Single App from Library by ID (Rust) Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt Retrieves a specific application from a Steam library using its App ID. This method is more efficient than iterating when the App ID is known. It depends on the steamlocate crate and returns a Result. ```rust use steamlocate::SteamDir; fn main() -> Result<(), steamlocate::Error> { let steam_dir = SteamDir::locate()?; const UNDERTALE: u32 = 391540; for library_result in steam_dir.libraries()? { let library = library_result?; // Try to get Undertale from this library if let Some(app_result) = library.app(UNDERTALE) { let app = app_result?; println!("Found Undertale in: {}", library.path().display()); println!(" Name: {:?}", app.name); println!(" Build ID: {:?}", app.build_id); println!(" Last updated: {:?}", app.last_updated); println!(" Auto-update: {:?}", app.auto_update_behavior); break; } } // Output: // Found Undertale in: /home/user/.local/share/Steam // Name: Some("Undertale") // Build ID: Some(3765283) // Last updated: Some(SystemTime { tv_sec: 1672176869, tv_nsec: 0 }) // Auto-update: Some(OnlyUpdateOnLaunch) Ok(()) } ``` -------------------------------- ### Add steamlocate dependency with Cargo Source: https://github.com/williamvenner/steamlocate-rs/blob/master/README.md This command adds the steamlocate crate as a dependency to your Rust project using Cargo, the Rust package manager. Ensure you have Cargo installed. ```console cargo add steamlocate ``` -------------------------------- ### Steamlocate-rs Error Handling - Rust Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt Illustrates robust error handling for the steamlocate-rs crate. It shows how to differentiate and handle various error types, including failure to locate Steam, invalid Steam directory structures, IO errors during file operations, and parsing errors from app manifest files. This allows for more graceful failure and informative user feedback. ```rust use steamlocate::{SteamDir, Error}; fn main() { match SteamDir::locate() { Ok(steam_dir) => { println!("Found Steam at: {}", steam_dir.path().display()); // Handle app lookup errors match steam_dir.find_app(12345) { Ok(Some((app, _))) => println!("Found: {:?}", app.name), Ok(None) => println!("App not installed"), Err(Error::Io { inner, path }) => { eprintln!("IO error at {}: {}", path.display(), inner); } Err(Error::Parse { kind, error, path }) => { eprintln!("Parse error ({:?}) at {}: {}", kind, path.display(), error); } Err(e) => eprintln!("Error: {}", e), } } Err(Error::FailedLocate(locate_err)) => { eprintln!("Could not locate Steam: {}", locate_err); } Err(Error::InvalidSteamDir(validation_err)) => { eprintln!("Invalid Steam directory: {}", validation_err); } Err(e) => eprintln!("Unexpected error: {}", e), } } ``` -------------------------------- ### Find Specific App by ID (Rust) Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt Searches through all Steam libraries to find a specific application by its Steam App ID. Returns both the app metadata and the library it was found in. ```rust use steamlocate::SteamDir; fn main() -> Result<(), steamlocate::Error> { let steam_dir = SteamDir::locate()?; // Find Garry's Mod (App ID: 4000) const GMOD_APP_ID: u32 = 4000; match steam_dir.find_app(GMOD_APP_ID)? { Some((app, library)) => { println!("Found: {} (ID: {})", app.name.as_deref().unwrap_or("Unknown"), app.app_id); println!("Install dir: {}", app.install_dir); println!("Library path: {}", library.path().display()); println!("Full path: {}", library.resolve_app_dir(&app).display()); if let Some(size) = app.size_on_disk { println!("Size on disk: {} bytes", size); } // Output: // Found: Garry's Mod (ID: 4000) // Install dir: GarrysMod // Library path: /home/user/.local/share/Steam // Full path: /home/user/.local/share/Steam/steamapps/common/GarrysMod // Size on disk: 18426478592 bytes } None => println!("App {} not found", GMOD_APP_ID), } Ok(()) } ``` -------------------------------- ### List Non-Steam Game Shortcuts (Rust) Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt Iterates over all non-Steam games (shortcuts) added by the user to their Steam library. This function utilizes the steamlocate crate and returns a Result, providing details for each shortcut. ```rust use steamlocate::SteamDir; fn main() -> Result<(), steamlocate::Error> { let steam_dir = SteamDir::locate()?; println!("Non-Steam Games (Shortcuts):"); for shortcut_result in steam_dir.shortcuts()? { match shortcut_result { Ok(shortcut) => { println!(" {} (ID: {})", shortcut.app_name, shortcut.app_id); println!(" Executable: {}", shortcut.executable); println!(" Start dir: {}", shortcut.start_dir); println!(" Steam ID: {}", shortcut.steam_id()); } Err(e) => eprintln!(" Failed to read shortcut: {}", e), } } // Output: // Non-Steam Games (Shortcuts): // Moonlighter (ID: 2786274309) // Executable: "/home/user/Games/Moonlighter/start.sh" // Start dir: "/home/user/Games/Moonlighter/" // Steam ID: 16683427638587392000 Ok(()) } ``` -------------------------------- ### Add steamlocate Dependency via Cargo Command Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt This snippet demonstrates how to add the steamlocate crate as a dependency using the cargo add command. ```bash cargo add steamlocate ``` -------------------------------- ### Add steamlocate Dependency to Cargo.toml Source: https://context7.com/williamvenner/steamlocate-rs/llms.txt This snippet shows how to add the steamlocate crate as a dependency to your Rust project's Cargo.toml file. ```toml [dependencies] steamlocate = "2.0" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.