profile_discovery/
profile_discovery.rs

1//! Firefox profile discovery example
2//!
3//! This example demonstrates how to find and list all Firefox profiles
4//! on the current system.
5
6use ffcv::{list_profiles, ProfileInfo};
7use std::fs;
8
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    println!("Firefox Profile Discovery");
11    println!("{:-<80}", "");
12
13    // Find all Firefox profiles
14    let profiles = list_profiles(None)?;
15
16    if profiles.is_empty() {
17        println!("No Firefox profiles found on this system.");
18        return Ok(());
19    }
20
21    println!("\nFound {} Firefox profile(s):\n", profiles.len());
22
23    for (index, profile) in profiles.iter().enumerate() {
24        display_profile(index + 1, profile);
25    }
26
27    // Show the default profile
28    let default_profiles: Vec<&ProfileInfo> = profiles.iter().filter(|p| p.is_default).collect();
29
30    if !default_profiles.is_empty() {
31        println!("{:-<80}", "");
32        println!("Default Profile(s):");
33        for profile in default_profiles {
34            println!("  {} -> {}", profile.name, profile.path.display());
35        }
36    }
37
38    Ok(())
39}
40
41fn display_profile(index: usize, profile: &ProfileInfo) {
42    println!("Profile #{}", index);
43    println!("  Name:          {}", profile.name);
44    println!("  Path:          {}", profile.path.display());
45    println!("  Is Default:    {}", profile.is_default);
46    println!("  Relative:      {}", profile.is_relative);
47
48    if let Some(ref locked) = profile.locked_to_install {
49        println!("  Locked To:      {}", locked);
50    }
51
52    // Check if prefs.js exists
53    let prefs_path = profile.path.join("prefs.js");
54    let prefs_exists = prefs_path.exists();
55    println!(
56        "  prefs.js:      {}",
57        if prefs_exists {
58            "✓ Found"
59        } else {
60            "✗ Not found"
61        }
62    );
63
64    if prefs_exists {
65        // Get file size
66        if let Ok(metadata) = fs::metadata(&prefs_path) {
67            let size_kb = metadata.len() / 1024;
68            println!("  File Size:     {} KB", size_kb);
69        }
70    }
71
72    println!();
73}