diff --git a/agent/src/main.rs b/agent/src/main.rs index 681df21..de3d9d1 100644 --- a/agent/src/main.rs +++ b/agent/src/main.rs @@ -23,6 +23,33 @@ use anyhow::Result; use tracing::{info, error, Level}; use tracing_subscriber::FmtSubscriber; +/// Extract a 6-digit support code from the executable's filename. +/// Looks for patterns like "GuruConnect-123456.exe" or "123456.exe" +fn extract_code_from_filename() -> Option { + // Get the path to the current executable + let exe_path = std::env::current_exe().ok()?; + let filename = exe_path.file_stem()?.to_str()?; + + // Look for a 6-digit number in the filename + // Try common patterns: "Name-123456", "Name_123456", "123456" + for part in filename.split(|c| c == '-' || c == '_' || c == '.') { + let trimmed = part.trim(); + if trimmed.len() == 6 && trimmed.chars().all(|c| c.is_ascii_digit()) { + return Some(trimmed.to_string()); + } + } + + // Also check if the last 6 characters are digits (e.g., "GuruConnect123456") + if filename.len() >= 6 { + let last_six = &filename[filename.len() - 6..]; + if last_six.chars().all(|c| c.is_ascii_digit()) { + return Some(last_six.to_string()); + } + } + + None +} + #[tokio::main] async fn main() -> Result<()> { // Initialize logging @@ -34,21 +61,12 @@ async fn main() -> Result<()> { info!("GuruConnect Agent v{}", env!("CARGO_PKG_VERSION")); - // Parse command line arguments - let args: Vec = std::env::args().collect(); - let support_code = if args.len() > 1 { - let code = args[1].trim().to_string(); - // Validate it looks like a 6-digit code - if code.len() == 6 && code.chars().all(|c| c.is_ascii_digit()) { - info!("Support code provided: {}", code); - Some(code) - } else { - info!("Invalid support code format, ignoring: {}", code); - None - } - } else { - None - }; + // Extract support code from executable filename + // e.g., GuruConnect-123456.exe -> 123456 + let support_code = extract_code_from_filename(); + if let Some(ref code) = support_code { + info!("Support code from filename: {}", code); + } // Load configuration let mut config = config::Config::load()?;