From 40d21125a1821c7a0014dee1676552132d5dcf2f Mon Sep 17 00:00:00 2001 From: 13xforever Date: Mon, 22 Jan 2024 20:39:42 +0500 Subject: [PATCH] implement ps3 fw update filter --- Ps3DiscDumper/Dumper.cs | 13 +++++++------ Ps3DiscDumper/Settings.cs | 18 ++++++++++++++++-- UI.Avalonia/ViewModels/ViewModelBase.cs | 4 ++++ UI.Avalonia/Views/Settings.axaml | 22 +++++++++++++++++++++- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Ps3DiscDumper/Dumper.cs b/Ps3DiscDumper/Dumper.cs index 071eac1..701af33 100644 --- a/Ps3DiscDumper/Dumper.cs +++ b/Ps3DiscDumper/Dumper.cs @@ -298,9 +298,9 @@ public void DetectDisc(string inDir = "", Func outputDirFormatte // todo: maybe use discutils instead to read TOC as one block var files = IOEx.GetFilepaths(InputDevicePath, "*", SearchOption.AllDirectories); - if (!SettingsProvider.Settings.CopyBdmv) + if (SettingsProvider.Settings.FilterRequired) { - var prefixList = Settings.BdmvFolders + var prefixList = SettingsProvider.Settings.FilterDirList .Select(f => Path.Combine(InputDevicePath, f) + Path.DirectorySeparatorChar) .ToArray(); files = files.Where(f => !prefixList.Any(f.StartsWith)); @@ -527,15 +527,16 @@ public async Task DumpAsync(string output) if (filesystemStructure is null) { (filesystemStructure, emptyDirStructure) = GetFilesystemStructure(); - var prefixList = Settings.BdmvFolders.Select(f => f + Path.DirectorySeparatorChar).ToArray(); - if (!SettingsProvider.Settings.CopyBdmv) + var filterDirList = SettingsProvider.Settings.FilterDirList; + var prefixList = filterDirList.Select(f => f + Path.DirectorySeparatorChar).ToArray(); + if (SettingsProvider.Settings.FilterRequired) { filesystemStructure = filesystemStructure - .Where(r => !Settings.BdmvFolders.Any(f => r.TargetFileName == f) && + .Where(r => !filterDirList.Any(f => r.TargetFileName == f) && !prefixList.Any(p => r.TargetFileName.StartsWith(p))) .ToList(); emptyDirStructure = emptyDirStructure - .Where(r => !Settings.BdmvFolders.Any(f => r.TargetDirName == f) && + .Where(r => !filterDirList.Any(f => r.TargetDirName == f) && !prefixList.Any(p => r.TargetDirName.StartsWith(p))) .ToList(); } diff --git a/Ps3DiscDumper/Settings.cs b/Ps3DiscDumper/Settings.cs index a580065..53008d2 100644 --- a/Ps3DiscDumper/Settings.cs +++ b/Ps3DiscDumper/Settings.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using System.Text.Json.Serialization; using Ps3DiscDumper.Utils; @@ -12,7 +13,8 @@ public struct Settings public Settings() { } [JsonIgnore] public const string DefaultPattern = $"%{Patterns.Title}% [%{Patterns.ProductCode}%]"; - [JsonIgnore] public static readonly string[] BdmvFolders = ["BDMV", "AACS", "CERTIFICATE"]; + [JsonIgnore] public static readonly string[] BdmvFolders = ["BDMV", "AACS", "CERTIFICATE"]; + [JsonIgnore] public static readonly string[] Ps3UpdateFolder = ["PS3_UPDATE"]; public string OutputDir { get; set; } = "."; public string IrdDir { get; set; } = Path.Combine(Environment.GetFolderPath(SpecialFolder.ApplicationData) ,"ps3-iso-dumper", "ird"); @@ -22,6 +24,16 @@ public Settings() { } public bool PreferSystemAccent { get; set; } = !OperatingSystem.IsWindows(); public bool StayOnTop { get; set; } = false; public bool CopyBdmv { get; set; } = false; + public bool CopyPs3Update { get; set; } = false; + + [JsonIgnore] public bool FilterRequired => !CopyBdmv || !CopyPs3Update; + [JsonIgnore] public string[] FilterDirList => (CopyBdmv, CopyPs3Update) switch + { + (false, false) => BdmvFolders.Concat(Ps3UpdateFolder).ToArray(), + (false, true) => BdmvFolders, + (true, false) => Ps3UpdateFolder, + _ => Array.Empty(), + }; private static StringComparison Comparison => OperatingSystem.IsWindows() ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; private static StringComparer Comparer => OperatingSystem.IsWindows() ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal; @@ -37,7 +49,8 @@ public bool Equals(Settings other) && EnableTransparency == other.EnableTransparency && PreferSystemAccent == other.PreferSystemAccent && StayOnTop == other.StayOnTop - && CopyBdmv == other.CopyBdmv; + && CopyBdmv == other.CopyBdmv + && CopyPs3Update == other.CopyPs3Update; public override int GetHashCode() { @@ -50,6 +63,7 @@ public override int GetHashCode() hashCode.Add(PreferSystemAccent); hashCode.Add(StayOnTop); hashCode.Add(CopyBdmv); + hashCode.Add(CopyPs3Update); return hashCode.ToHashCode(); } } \ No newline at end of file diff --git a/UI.Avalonia/ViewModels/ViewModelBase.cs b/UI.Avalonia/ViewModels/ViewModelBase.cs index 412f150..c8ca35b 100644 --- a/UI.Avalonia/ViewModels/ViewModelBase.cs +++ b/UI.Avalonia/ViewModels/ViewModelBase.cs @@ -31,6 +31,7 @@ public partial class ViewModelBase: ObservableObject [ObservableProperty] private static bool preferSystemAccent = SettingsProvider.Settings.PreferSystemAccent; [ObservableProperty] private static bool stayOnTop = SettingsProvider.Settings.StayOnTop; [ObservableProperty] private static bool copyBdmv = SettingsProvider.Settings.CopyBdmv; + [ObservableProperty] private static bool copyPs3Update = SettingsProvider.Settings.CopyPs3Update; [ObservableProperty] private static string dimTextColor = "#00ff00"; //ThemeConsts.LightThemeDimGray; [ObservableProperty] private static IPalette colorPalette = ThemeConsts.Debug; @@ -142,6 +143,9 @@ partial void OnStayOnTopChanged(bool value) partial void OnCopyBdmvChanged(bool value) => SettingsProvider.Settings = SettingsProvider.Settings with { CopyBdmv = value }; + partial void OnCopyPs3UpdateChanged(bool value) + => SettingsProvider.Settings = SettingsProvider.Settings with { CopyPs3Update = value }; + private static Color ChangeColorLuminosity(Color color, double luminosityFactor) { var red = (double)color.R; diff --git a/UI.Avalonia/Views/Settings.axaml b/UI.Avalonia/Views/Settings.axaml index 51088e0..14a2f22 100644 --- a/UI.Avalonia/Views/Settings.axaml +++ b/UI.Avalonia/Views/Settings.axaml @@ -140,7 +140,27 @@ Processing - + + + + + + Copy PS3 firmware update + + Only useful for preservation purposes + + + + + + + + +