diff --git a/CHANGELIST.md b/CHANGELIST.md
index 61931bae..706fe2be 100644
--- a/CHANGELIST.md
+++ b/CHANGELIST.md
@@ -86,6 +86,7 @@
- Move Enumerations to root of Core
- Move ToInternalDriveType to Drive
- Clean up EnumExtensions
+- Make FormattedVolumeLabel a method
### 3.1.9a (2024-05-21)
diff --git a/MPF.Core/Drive.cs b/MPF.Core/Drive.cs
index 85355891..2568f7af 100644
--- a/MPF.Core/Drive.cs
+++ b/MPF.Core/Drive.cs
@@ -55,55 +55,8 @@ namespace MPF.Core
#endregion
- #region Constants
-
- private const string DiscNotDetectedValue = "Disc Not Detected";
-
- #endregion
-
#region Derived Fields
- ///
- /// Media label as read by Windows, formatted to avoid odd outputs
- /// If no volume label present, use PSX or PS2 serial if valid
- /// Otherwise, use "track" as volume label
- ///
- public string? FormattedVolumeLabel
- {
- get
- {
- string? volumeLabel = DiscNotDetectedValue;
- if (!MarkedActive)
- return volumeLabel;
-
- if (!string.IsNullOrEmpty(VolumeLabel))
- {
- volumeLabel = VolumeLabel;
- }
- else
- {
- // No Volume Label found, fallback to something sensible
- switch (GetRedumpSystem(null))
- {
- case RedumpSystem.SonyPlayStation:
- case RedumpSystem.SonyPlayStation2:
- InfoTool.GetPlayStationExecutableInfo(Name, out string? serial, out _, out _);
- volumeLabel = serial ?? "track";
- break;
-
- default:
- volumeLabel = "track";
- break;
- }
- }
-
- foreach (char c in Path.GetInvalidFileNameChars())
- volumeLabel = volumeLabel?.Replace(c, '_');
-
- return volumeLabel;
- }
- }
-
///
/// Read-only access to the drive letter
///
diff --git a/MPF.Core/UI/ViewModels/MainViewModel.cs b/MPF.Core/UI/ViewModels/MainViewModel.cs
index 36489a6f..3f51b649 100644
--- a/MPF.Core/UI/ViewModels/MainViewModel.cs
+++ b/MPF.Core/UI/ViewModels/MainViewModel.cs
@@ -516,8 +516,9 @@ namespace MPF.Core.UI.ViewModels
#region Constants
+ private const string DiscNotDetectedValue = "Disc Not Detected";
private const string StartDumpingValue = "Start Dumping";
- public const string StopDumpingValue = "Stop Dumping";
+ private const string StopDumpingValue = "Stop Dumping";
#endregion
@@ -718,7 +719,7 @@ namespace MPF.Core.UI.ViewModels
this.CurrentProgram = InternalProgram.NONE;
}
else
- {
+ {
int currentIndex = InternalPrograms.FindIndex(m => m == internalProgram);
this.CurrentProgram = (currentIndex > -1 ? InternalPrograms[currentIndex].Value : InternalPrograms[0].Value);
}
@@ -1358,7 +1359,7 @@ namespace MPF.Core.UI.ViewModels
string programShort = program == "DiscImageCreator" ? "DIC" : program;
if (string.IsNullOrEmpty(programShort))
programShort = "Unknown Program";
- string label = this._currentDrive?.FormattedVolumeLabel ?? "track";
+ string label = GetFormattedVolumeLabel(_currentDrive) ?? "track";
if (string.IsNullOrEmpty(label))
label = "track";
string date = DateTime.Today.ToString("yyyyMMdd");
@@ -1397,7 +1398,7 @@ namespace MPF.Core.UI.ViewModels
// Set the output filename, if it's not already
if (string.IsNullOrEmpty(this.OutputPath))
{
- var label = this.CurrentDrive?.FormattedVolumeLabel ?? this.CurrentSystem.LongName();
+ var label = GetFormattedVolumeLabel(CurrentDrive) ?? this.CurrentSystem.LongName();
var directory = this.Options.DefaultOutputPath;
string filename = $"{label}{extension ?? ".bin"}";
@@ -1418,7 +1419,7 @@ namespace MPF.Core.UI.ViewModels
// Set the output filename, if we changed drives
else if (driveChanged)
{
- var label = this.CurrentDrive?.FormattedVolumeLabel ?? this.CurrentSystem.LongName();
+ var label = GetFormattedVolumeLabel(CurrentDrive) ?? this.CurrentSystem.LongName();
string oldPath = InfoTool.NormalizeOutputPaths(this.OutputPath, false);
string oldFilename = Path.GetFileNameWithoutExtension(oldPath);
var directory = Path.GetDirectoryName(oldPath);
@@ -1556,6 +1557,47 @@ namespace MPF.Core.UI.ViewModels
return (output, error);
}
+ ///
+ /// Media label as read by Windows, formatted to avoid odd outputs
+ /// If no volume label present, use PSX or PS2 serial if valid
+ /// Otherwise, use "track" as volume label
+ ///
+ private static string? GetFormattedVolumeLabel(Drive? drive)
+ {
+ if (drive == null)
+ return null;
+
+ string? volumeLabel = DiscNotDetectedValue;
+ if (!drive.MarkedActive)
+ return volumeLabel;
+
+ if (!string.IsNullOrEmpty(drive.VolumeLabel))
+ {
+ volumeLabel = drive.VolumeLabel;
+ }
+ else
+ {
+ // No Volume Label found, fallback to something sensible
+ switch (drive.GetRedumpSystem(null))
+ {
+ case RedumpSystem.SonyPlayStation:
+ case RedumpSystem.SonyPlayStation2:
+ InfoTool.GetPlayStationExecutableInfo(drive.Name, out string? serial, out _, out _);
+ volumeLabel = serial ?? "track";
+ break;
+
+ default:
+ volumeLabel = "track";
+ break;
+ }
+ }
+
+ foreach (char c in Path.GetInvalidFileNameChars())
+ volumeLabel = volumeLabel?.Replace(c, '_');
+
+ return volumeLabel;
+ }
+
///
/// Set the current disc type in the combo box
///