From 90ac39a0bc1b33e5b01454d46814b30303200d1e Mon Sep 17 00:00:00 2001 From: Mike Swanson Date: Sun, 28 Dec 2025 14:35:05 -0700 Subject: [PATCH] Extract support code from executable filename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent now reads its own filename to extract the 6-digit code. User just downloads GuruConnect-123456.exe and double-clicks - no command line arguments or prompts needed. Supports patterns: - GuruConnect-123456.exe - GuruConnect_123456.exe - GuruConnect123456.exe 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- agent/src/main.rs | 48 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) 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()?;