using System.IO; using System.Windows; using System.Windows.Input; namespace ytLive; /// Modal that lets the creator rename an auto-named recording before it is /// finalized. Returns the chosen file stem (no extension) via , /// or null when the creator cleared the box and hit Save (keep the auto name). /// DialogResult == false means DISCARD — the caller deletes the footage /// rather than saving it (CREATOR RULING 2026-09-26). Enter on the pre-filled default /// is a Save. public partial class RenameRecordingDialog : Window { private readonly string _autoStem; /// Stem (no extension) the creator chose, or null when the box was /// cleared on an explicit Save. Never set on Cancel. public string? ResultFileName { get; private set; } public RenameRecordingDialog(string autoStem) { InitializeComponent(); _autoStem = autoStem; NameBox.Text = autoStem; Loaded += (_, _) => { NameBox.Focus(); NameBox.SelectAll(); }; NameBox.KeyDown += OnKeyDown; } private void OnKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { Save(); e.Handled = true; } else if (e.Key == Key.Escape) { DialogResult = false; e.Handled = true; } } private void Cancel_Click(object sender, RoutedEventArgs e) => DialogResult = false; private void Save_Click(object sender, RoutedEventArgs e) => Save(); private void Save() { var name = NameBox.Text?.Trim(); if (string.IsNullOrEmpty(name)) { // Empty = keep the auto name. ResultFileName = null; DialogResult = true; return; } // Strip any accidental ".mp4" so we return a clean stem. if (name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase)) name = Path.GetFileNameWithoutExtension(name); // Reject characters that are illegal in Windows file names. if (name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { MessageBox.Show(this, "That name contains characters not allowed in file names.", "Invalid name", MessageBoxButton.OK, MessageBoxImage.Warning); NameBox.Focus(); return; } ResultFileName = name; DialogResult = true; } }