diff options
author | sr55 <[email protected]> | 2011-12-30 16:07:30 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2011-12-30 16:07:30 +0000 |
commit | 1a4342793d9c7054b1a70030787af46f77208288 (patch) | |
tree | 464f2a8c1aa385d6005339207efb38a07914883c /win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs | |
parent | 63afef0c041be7e6ae30150350d8b9753fc97917 (diff) |
WinGui: (WPF) Fix build, Audio / Subtitle Panel initial template design, Output settings on the Main UI Wired up.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4392 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs')
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs | 201 |
1 files changed, 100 insertions, 101 deletions
diff --git a/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs b/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs index 13095ce30..f0b942120 100644 --- a/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs @@ -54,121 +54,120 @@ namespace HandBrakeWPF.Helpers /// </returns>
public static string AutoName(EncodeTask task, string sourceOrLabelName)
{
- string autoNamePath = string.Empty;
- if (task.Title != 0) // TODO check.
+ string autoNamePath = string.Empty;
+ if (task.Title != 0) // TODO check.
+ {
+ // Get the Source Name and remove any invalid characters
+ string sourceName = Path.GetInvalidFileNameChars().Aggregate(sourceOrLabelName, (current, character) => current.Replace(character.ToString(), string.Empty));
+ sourceName = Path.GetFileNameWithoutExtension(sourceName);
+
+ // Remove Underscores
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.AutoNameRemoveUnderscore))
+ sourceName = sourceName.Replace("_", " ");
+
+ // Switch to "Title Case"
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.AutoNameTitleCase))
+ sourceName = sourceName.ToTitleCase();
+
+ // Get the Selected Title Number
+
+ string dvdTitle = task.Title.ToString();
+
+ // Get the Chapter Start and Chapter End Numbers
+ string chapterStart = task.StartPoint.ToString();
+ string chapterFinish = task.EndPoint.ToString();
+ string combinedChapterTag = chapterStart;
+ if (chapterFinish != chapterStart && chapterFinish != string.Empty)
+ combinedChapterTag = chapterStart + "-" + chapterFinish;
+
+ /*
+ * File Name
+ */
+ string destinationFilename;
+ if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat) != string.Empty)
{
- // Get the Source Name and remove any invalid characters
- string sourceName = Path.GetInvalidFileNameChars().Aggregate(sourceOrLabelName, (current, character) => current.Replace(character.ToString(), string.Empty));
- sourceName = Path.GetFileNameWithoutExtension(sourceName);
-
- // Remove Underscores
- if (userSettingService.GetUserSetting<bool>(UserSettingConstants.AutoNameRemoveUnderscore))
- sourceName = sourceName.Replace("_", " ");
-
- // Switch to "Title Case"
- if (userSettingService.GetUserSetting<bool>(UserSettingConstants.AutoNameTitleCase))
- sourceName = sourceName.ToTitleCase();
-
- // Get the Selected Title Number
-
- string dvdTitle = task.Title.ToString();
-
- // Get the Chapter Start and Chapter End Numbers
- string chapterStart = task.StartPoint.ToString();
- string chapterFinish = task.EndPoint.ToString();
- string combinedChapterTag = chapterStart;
- if (chapterFinish != chapterStart && chapterFinish != string.Empty)
- combinedChapterTag = chapterStart + "-" + chapterFinish;
-
- /*
- * File Name
- */
- string destinationFilename;
- if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat) != string.Empty)
- {
- destinationFilename = userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat);
- destinationFilename = destinationFilename.Replace("{source}", sourceName)
- .Replace("{title}", dvdTitle)
- .Replace("{chapters}", combinedChapterTag)
- .Replace("{date}", DateTime.Now.Date.ToShortDateString().Replace('/', '-'));
- }
- else
- destinationFilename = sourceName + "_T" + dvdTitle + "_C" + combinedChapterTag;
+ destinationFilename = userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat);
+ destinationFilename = destinationFilename.Replace("{source}", sourceName)
+ .Replace("{title}", dvdTitle)
+ .Replace("{chapters}", combinedChapterTag)
+ .Replace("{date}", DateTime.Now.Date.ToShortDateString().Replace('/', '-'));
+ }
+ else
+ destinationFilename = sourceName + "_T" + dvdTitle + "_C" + combinedChapterTag;
- /*
- * File Extension
- */
- if (task.OutputFormat == OutputFormat.Mp4 || task.OutputFormat == OutputFormat.M4V)
+ /*
+ * File Extension
+ */
+ if (task.OutputFormat == OutputFormat.Mp4 || task.OutputFormat == OutputFormat.M4V)
+ {
+ switch (userSettingService.GetUserSetting<int>(UserSettingConstants.UseM4v))
{
- switch (userSettingService.GetUserSetting<int>(UserSettingConstants.UseM4v))
- {
- case 0: // Automatic
- destinationFilename += task.IncludeChapterMarkers || task.RequiresM4v ? ".m4v" : ".mp4";
- break;
- case 1: // Always MP4
- destinationFilename += ".mp4";
- break;
- case 2: // Always M4V
- destinationFilename += ".m4v";
- break;
- }
+ case 0: // Automatic
+ destinationFilename += task.IncludeChapterMarkers || task.RequiresM4v ? ".m4v" : ".mp4";
+ break;
+ case 1: // Always MP4
+ destinationFilename += ".mp4";
+ break;
+ case 2: // Always M4V
+ destinationFilename += ".m4v";
+ break;
}
- else if (task.OutputFormat == OutputFormat.Mkv)
- destinationFilename += ".mkv";
+ }
+ else if (task.OutputFormat == OutputFormat.Mkv)
+ destinationFilename += ".mkv";
- /*
- * File Destination Path
- */
+ /*
+ * File Destination Path
+ */
- // If there is an auto name path, use it...
- if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim().StartsWith("{source_path}") && !string.IsNullOrEmpty(task.Source))
- {
- string savedPath = userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim().Replace("{source_path}\\", string.Empty).Replace("{source_path}", string.Empty);
-
- string directory = Directory.Exists(task.Source)
- ? task.Source
- : Path.GetDirectoryName(task.Source);
- string requestedPath = Path.Combine(directory, savedPath);
-
- autoNamePath = Path.Combine(requestedPath, destinationFilename);
- if (autoNamePath == task.Source)
- {
- // Append out_ to files that already exist or is the source file
- autoNamePath = Path.Combine(Path.GetDirectoryName(task.Source), "output_" + destinationFilename);
- }
- }
- else if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Contains("{source_folder_name}") && !string.IsNullOrEmpty(task.Source))
+ // If there is an auto name path, use it...
+ if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim().StartsWith("{source_path}") && !string.IsNullOrEmpty(task.Source))
+ {
+ string savedPath = userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim().Replace("{source_path}\\", string.Empty).Replace("{source_path}", string.Empty);
+
+ string directory = Directory.Exists(task.Source)
+ ? task.Source
+ : Path.GetDirectoryName(task.Source);
+ string requestedPath = Path.Combine(directory, savedPath);
+
+ autoNamePath = Path.Combine(requestedPath, destinationFilename);
+ if (autoNamePath == task.Source)
{
- // Second Case: We have a Path, with "{source_folder}" in it, therefore we need to replace it with the folder name from the source.
- string path = Path.GetDirectoryName(task.Source);
- if (!string.IsNullOrEmpty(path))
- {
- string[] filesArray = path.Split(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
- string sourceFolder = filesArray[filesArray.Length - 1];
-
- autoNamePath = Path.Combine(userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Replace("{source_folder_name}", sourceFolder), destinationFilename);
- }
+ // Append out_ to files that already exist or is the source file
+ autoNamePath = Path.Combine(Path.GetDirectoryName(task.Source), "output_" + destinationFilename);
}
- else if (!task.Destination.Contains(Path.DirectorySeparatorChar.ToString()))
+ }
+ else if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Contains("{source_folder_name}") && !string.IsNullOrEmpty(task.Source))
+ {
+ // Second Case: We have a Path, with "{source_folder}" in it, therefore we need to replace it with the folder name from the source.
+ string path = Path.GetDirectoryName(task.Source);
+ if (!string.IsNullOrEmpty(path))
{
- // Third case: If the destination box doesn't already contain a path, make one.
- if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim() != string.Empty &&
- userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim() != "Click 'Browse' to set the default location")
- {
- autoNamePath = Path.Combine(userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath), destinationFilename);
- }
- else // ...otherwise, output to the source directory
- autoNamePath = null;
+ string[] filesArray = path.Split(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
+ string sourceFolder = filesArray[filesArray.Length - 1];
+
+ autoNamePath = Path.Combine(userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Replace("{source_folder_name}", sourceFolder), destinationFilename);
}
- else // Otherwise, use the path that is already there.
+ }
+ else if (!task.Destination.Contains(Path.DirectorySeparatorChar.ToString()))
+ {
+ // Third case: If the destination box doesn't already contain a path, make one.
+ if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim() != string.Empty &&
+ userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim() != "Click 'Browse' to set the default location")
{
- // Use the path and change the file extension to match the previous destination
- autoNamePath = Path.Combine(Path.GetDirectoryName(task.Destination), destinationFilename);
+ autoNamePath = Path.Combine(userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath), destinationFilename);
}
+ else // ...otherwise, output to the source directory
+ autoNamePath = null;
+ }
+ else // Otherwise, use the path that is already there.
+ {
+ // Use the path and change the file extension to match the previous destination
+ autoNamePath = Path.Combine(Path.GetDirectoryName(task.Destination), destinationFilename);
}
-
- return autoNamePath;
}
+
+ return autoNamePath;
}
}
}
|