From e66b3f440283669f9c82fe9fb33438ee968047c8 Mon Sep 17 00:00:00 2001 From: sr55 Date: Thu, 21 Feb 2019 20:00:21 +0000 Subject: [PATCH] WinGui: Attempt to be smarter with the Autonaming when dealing with directories with ".". Fixes #1917 --- .../HandBrakeWPF/ViewModels/MainViewModel.cs | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 6bbeee2ed..ddabf080e 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -421,20 +421,19 @@ namespace HandBrakeWPF.ViewModels get { // Sanity Check - if (ScannedSource == null || ScannedSource.ScanPath == null) + if (this.ScannedSource == null || this.ScannedSource.ScanPath == null || this.selectedTitle == null) { return string.Empty; } - // The title that is selected has a source name. This means it's part of a batch scan. - if (selectedTitle != null && !string.IsNullOrEmpty(selectedTitle.SourceName) && !selectedTitle.SourceName.EndsWith("\\")) + if (File.Exists(this.ScannedSource.ScanPath)) // Scan Path is a File. { - return Path.GetFileNameWithoutExtension(selectedTitle.SourceName); + return Path.GetFileNameWithoutExtension(this.ScannedSource.ScanPath); } - // Check if we have a Folder, if so, check if it's a DVD / Bluray drive and get the label. - if (ScannedSource.ScanPath.EndsWith("\\")) + if (Directory.Exists(this.ScannedSource.ScanPath)) // Scan Path is a folder. { + // Check to see if it's a Drive. If yes, use the volume label. foreach (DriveInformation item in DriveUtilities.GetDrives()) { if (item.RootDirectory.Contains(this.ScannedSource.ScanPath.Replace("\\\\", "\\"))) @@ -442,12 +441,19 @@ namespace HandBrakeWPF.ViewModels return item.VolumeLabel; } } - } - if (Path.GetFileNameWithoutExtension(this.ScannedSource.ScanPath) != "VIDEO_TS") - return Path.GetFileNameWithoutExtension(this.ScannedSource.ScanPath); + // Otherwise, it may be a path of files. + if (!string.IsNullOrEmpty(this.selectedTitle.SourceName) && File.Exists(this.selectedTitle.SourceName)) // Selected Title is a file + { + return Path.GetFileNameWithoutExtension(this.selectedTitle.SourceName); + } + else if (Directory.Exists(this.selectedTitle.SourceName)) // Selected Title is a structured source. + { + return Path.GetFileName(this.ScannedSource.ScanPath); + } + } - return Path.GetFileNameWithoutExtension(Path.GetDirectoryName(this.ScannedSource.ScanPath)); + return null; } } -- 2.40.0