fixed shit with the renames

This commit is contained in:
l4kr
2026-07-04 12:01:13 +02:00
parent 1909b7152a
commit a322b6bb00
2 changed files with 27 additions and 44 deletions
+3 -43
View File
@@ -2,7 +2,6 @@ using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@@ -78,42 +77,6 @@ public partial class MainWindow : FluentWindow
// ── Helpers ────────────────────────────────────────────────────────────── // ── Helpers ──────────────────────────────────────────────────────────────
/// <summary>
/// If the file's parent folder has a bracketed prefix (e.g. "[neoHEVC] ")
/// and the file itself doesn't, renames the file on disk to include that
/// prefix and returns the new path. Returns the original path unchanged if
/// the condition isn't met or the rename fails.
/// </summary>
private static string TryApplyFolderPrefix(string filePath)
{
string? folder = Path.GetDirectoryName(filePath);
if (string.IsNullOrEmpty(folder)) return filePath;
string folderName = Path.GetFileName(folder);
var match = Regex.Match(folderName, @"^\[.+?\] ");
if (!match.Success) return filePath;
string prefix = match.Value;
string fileName = Path.GetFileName(filePath);
if (fileName.StartsWith(prefix, StringComparison.Ordinal)) return filePath;
string newFileName = prefix + fileName;
string newFilePath = Path.Combine(folder, newFileName);
if (File.Exists(newFilePath)) return filePath;
try
{
File.Move(filePath, newFilePath);
return newFilePath;
}
catch
{
return filePath;
}
}
private static void RestartApplication() private static void RestartApplication()
{ {
try try
@@ -249,23 +212,20 @@ public partial class MainWindow : FluentWindow
&& !_fileQueue.Any(q => string.Equals(q.FilePath, p, StringComparison.OrdinalIgnoreCase))) && !_fileQueue.Any(q => string.Equals(q.FilePath, p, StringComparison.OrdinalIgnoreCase)))
.ToList(); .ToList();
var addedPaths = new List<string>();
foreach (var path in newFiles) foreach (var path in newFiles)
{ {
string effectivePath = TryApplyFolderPrefix(path); var item = new QueuedFileItem(path);
var item = new QueuedFileItem(effectivePath);
item.PropertyChanged += QueuedFileItem_PropertyChanged; item.PropertyChanged += QueuedFileItem_PropertyChanged;
_fileQueue.Add(item); _fileQueue.Add(item);
_ = ScanFileItemAsync(item); _ = ScanFileItemAsync(item);
addedPaths.Add(effectivePath);
} }
UpdateLoadingOverlay(); UpdateLoadingOverlay();
if (addedPaths.Count > 0) if (newFiles.Count > 0)
{ {
var first = _fileQueue.FirstOrDefault(q => var first = _fileQueue.FirstOrDefault(q =>
string.Equals(q.FilePath, addedPaths[0], StringComparison.OrdinalIgnoreCase)); string.Equals(q.FilePath, newFiles[0], StringComparison.OrdinalIgnoreCase));
if (first != null) FileQueueList.SelectedItem = first; if (first != null) FileQueueList.SelectedItem = first;
} }
} }
+24 -1
View File
@@ -1,6 +1,7 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Text.RegularExpressions;
using System.Windows; using System.Windows;
using Futonizer.Models; using Futonizer.Models;
using Futonizer.Services; using Futonizer.Services;
@@ -110,6 +111,28 @@ public partial class ProgressWindow : FluentWindow
TotalBytesText.Text = $"{doneMb:F0} / {totalMb:F0} MB copied"; TotalBytesText.Text = $"{doneMb:F0} / {totalMb:F0} MB copied";
} }
/// <summary>
/// If the source file's parent folder starts with a bracketed tag
/// (e.g. "[KAA]" or "[neoHEVC]") and the file name doesn't already
/// start with that tag, returns the file name with the tag prepended
/// (e.g. "[KAA] episode.mkv"). Otherwise returns the file name unchanged.
/// Only applied to the output file — the source is never touched.
/// </summary>
private static string PrefixedFileName(string sourceFilePath, string fileName)
{
string? folder = Path.GetDirectoryName(sourceFilePath);
if (string.IsNullOrEmpty(folder)) return fileName;
string folderName = Path.GetFileName(folder);
var match = Regex.Match(folderName, @"^\[.+?\]");
if (!match.Success) return fileName;
string prefix = match.Value + " "; // e.g. "[KAA] "
if (fileName.StartsWith(match.Value, StringComparison.Ordinal)) return fileName;
return prefix + fileName;
}
private static long SafeFileLength(string path) private static long SafeFileLength(string path)
{ {
try { return new FileInfo(path).Length; } try { return new FileInfo(path).Length; }
@@ -159,7 +182,7 @@ public partial class ProgressWindow : FluentWindow
{ {
string outputFilePath = overwritingInPlace string outputFilePath = overwritingInPlace
? file.FilePath ? file.FilePath
: Path.Combine(_outputFolder, file.FileName); : Path.Combine(_outputFolder, PrefixedFileName(file.FilePath, file.FileName));
var videoIds = file.Tracks var videoIds = file.Tracks
.Where(t => t.Type == "video" && t.Copy) .Where(t => t.Type == "video" && t.Copy)