From 51f659ce37ed365da64c9d375cbdaa0d38b627c3 Mon Sep 17 00:00:00 2001 From: Gustave Monce Date: Sat, 12 Oct 2024 15:14:24 +0200 Subject: [PATCH] Some cleanup --- WPinternals/App.xaml.cs | 1 + WPinternals/CommandLine.cs | 1 + .../EmergencyFileEntry.cs | 2 +- .../{WPinternalsConfig => Config}/FFUEntry.cs | 2 +- .../FlashProfile.cs | 2 +- .../Registration.cs | 2 +- .../SecWimEntry.cs | 2 +- WPinternals/{ => Config}/WPinternalsConfig.cs | 14 +-- .../{ => HelperClasses}/HelperClasses.cs | 4 +- WPinternals/HelperClasses/Paragraph.cs | 2 +- .../BootMgr/LumiaBootManagerAppModel.cs | 1 - .../UEFIApps/Flash/LumiaFlashAppModel.cs | 3 +- WPinternals/Models/UEFIApps/NokiaUEFIModel.cs | 1 + .../PhoneInfo/LumiaPhoneInfoAppModel.cs | 1 - WPinternals/{ => Terminal}/Terminal.cs | 6 +- .../ViewModels/LumiaUnlockBootViewModel.cs | 1 + .../ViewModels/LumiaV2UnlockBootViewModel.cs | 1 + WPinternals/ViewModels/MainViewModel.cs | 1 + WPinternals/ViewModels/NokiaLabelViewModel.cs | 3 +- .../ViewModels/RegistrationViewModel.cs | 1 + WPinternals/Views/About.xaml | 9 +- WPinternals/Views/BackupView.xaml | 45 +++---- .../Views/BootRestoreResourcesView.xaml | 47 ++++---- WPinternals/Views/BusyView.xaml | 11 +- WPinternals/Views/DisclaimerAndNdaView.xaml | 9 +- WPinternals/Views/DisclaimerView.xaml | 9 +- WPinternals/Views/DumpRomView.xaml | 11 +- WPinternals/Views/Empty.xaml | 31 ++--- WPinternals/Views/FlashResourcesView.xaml | 87 +++++++------- WPinternals/Views/FlashRomView.xaml | 59 ++++----- WPinternals/Views/GettingStartedView.xaml | 113 +++++++++--------- WPinternals/Views/LumiaDownloadView.xaml | 43 +++---- .../LumiaUndoRootTargetSelectionView.xaml | 17 +-- .../LumiaUnlockRootTargetSelectionView.xaml | 25 ++-- WPinternals/Views/MessageView.xaml | 3 +- WPinternals/Views/NokiaBootloaderView.xaml | 69 +++++------ WPinternals/Views/NokiaFlashView.xaml | 75 ++++++------ WPinternals/Views/NokiaLabelView.xaml | 25 ++-- WPinternals/Views/NokiaMassStorageView.xaml | 9 +- .../Views/NokiaModeBootloaderView.xaml | 19 +-- WPinternals/Views/NokiaModeFlashView.xaml | 19 +-- WPinternals/Views/NokiaModeLabelView.xaml | 15 +-- .../Views/NokiaModeMassStorageView.xaml | 23 ++-- WPinternals/Views/NokiaModeNormalView.xaml | 15 +-- WPinternals/Views/NokiaModePhoneInfoView.xaml | 19 +-- WPinternals/Views/NokiaNormalView.xaml | 33 ++--- WPinternals/Views/NokiaPhoneInfoView.xaml | 33 ++--- WPinternals/Views/RegistrationView.xaml | 9 +- WPinternals/Views/RestoreView.xaml | 17 +-- WPinternals/Views/StartupWindow.xaml.cs | 1 + 50 files changed, 493 insertions(+), 458 deletions(-) rename WPinternals/{WPinternalsConfig => Config}/EmergencyFileEntry.cs (98%) rename WPinternals/{WPinternalsConfig => Config}/FFUEntry.cs (97%) rename WPinternals/{WPinternalsConfig => Config}/FlashProfile.cs (98%) rename WPinternals/{WPinternalsConfig => Config}/Registration.cs (99%) rename WPinternals/{WPinternalsConfig => Config}/SecWimEntry.cs (97%) rename WPinternals/{ => Config}/WPinternalsConfig.cs (91%) rename WPinternals/{ => HelperClasses}/HelperClasses.cs (97%) rename WPinternals/{ => Terminal}/Terminal.cs (94%) diff --git a/WPinternals/App.xaml.cs b/WPinternals/App.xaml.cs index 17c5400..653753d 100644 --- a/WPinternals/App.xaml.cs +++ b/WPinternals/App.xaml.cs @@ -23,6 +23,7 @@ using System.Threading; using System.Windows; using WPinternals.HelperClasses; +using WPinternals.Config; namespace WPinternals { diff --git a/WPinternals/CommandLine.cs b/WPinternals/CommandLine.cs index 9c0b724..ad5e992 100644 --- a/WPinternals/CommandLine.cs +++ b/WPinternals/CommandLine.cs @@ -26,6 +26,7 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; +using WPinternals.Config; using WPinternals.HelperClasses; using WPinternals.Models.UEFIApps.BootMgr; using WPinternals.Models.UEFIApps.Flash; diff --git a/WPinternals/WPinternalsConfig/EmergencyFileEntry.cs b/WPinternals/Config/EmergencyFileEntry.cs similarity index 98% rename from WPinternals/WPinternalsConfig/EmergencyFileEntry.cs rename to WPinternals/Config/EmergencyFileEntry.cs index 64a188b..c643d75 100644 --- a/WPinternals/WPinternalsConfig/EmergencyFileEntry.cs +++ b/WPinternals/Config/EmergencyFileEntry.cs @@ -22,7 +22,7 @@ using System.Xml.Serialization; using WPinternals.HelperClasses; -namespace WPinternals.WPinternalsConfig +namespace WPinternals.Config { public class EmergencyFileEntry { diff --git a/WPinternals/WPinternalsConfig/FFUEntry.cs b/WPinternals/Config/FFUEntry.cs similarity index 97% rename from WPinternals/WPinternalsConfig/FFUEntry.cs rename to WPinternals/Config/FFUEntry.cs index 5e62a04..1ae15c3 100644 --- a/WPinternals/WPinternalsConfig/FFUEntry.cs +++ b/WPinternals/Config/FFUEntry.cs @@ -20,7 +20,7 @@ using System.IO; -namespace WPinternals.WPinternalsConfig +namespace WPinternals.Config { public class FFUEntry { diff --git a/WPinternals/WPinternalsConfig/FlashProfile.cs b/WPinternals/Config/FlashProfile.cs similarity index 98% rename from WPinternals/WPinternalsConfig/FlashProfile.cs rename to WPinternals/Config/FlashProfile.cs index 7484cb2..f3025d3 100644 --- a/WPinternals/WPinternalsConfig/FlashProfile.cs +++ b/WPinternals/Config/FlashProfile.cs @@ -21,7 +21,7 @@ using System; using System.Xml.Serialization; -namespace WPinternals.WPinternalsConfig +namespace WPinternals.Config { public class FlashProfile { diff --git a/WPinternals/WPinternalsConfig/Registration.cs b/WPinternals/Config/Registration.cs similarity index 99% rename from WPinternals/WPinternalsConfig/Registration.cs rename to WPinternals/Config/Registration.cs index bcbc234..ea9f39a 100644 --- a/WPinternals/WPinternalsConfig/Registration.cs +++ b/WPinternals/Config/Registration.cs @@ -23,7 +23,7 @@ using System.Security.Cryptography; using System.Windows; -namespace WPinternals +namespace WPinternals.Config { internal static class Registration { diff --git a/WPinternals/WPinternalsConfig/SecWimEntry.cs b/WPinternals/Config/SecWimEntry.cs similarity index 97% rename from WPinternals/WPinternalsConfig/SecWimEntry.cs rename to WPinternals/Config/SecWimEntry.cs index 57f88a6..f5eab27 100644 --- a/WPinternals/WPinternalsConfig/SecWimEntry.cs +++ b/WPinternals/Config/SecWimEntry.cs @@ -20,7 +20,7 @@ using System.IO; -namespace WPinternals +namespace WPinternals.Config { public class SecWimEntry { diff --git a/WPinternals/WPinternalsConfig.cs b/WPinternals/Config/WPinternalsConfig.cs similarity index 91% rename from WPinternals/WPinternalsConfig.cs rename to WPinternals/Config/WPinternalsConfig.cs index 2d4dd92..0de38c0 100644 --- a/WPinternals/WPinternalsConfig.cs +++ b/WPinternals/Config/WPinternalsConfig.cs @@ -25,7 +25,7 @@ using System.Xml.Serialization; using WPinternals.HelperClasses; -namespace WPinternals +namespace WPinternals.Config { public class WPinternalsConfig @@ -65,7 +65,7 @@ internal void WriteConfig() FileWriter.Close(); } - internal void SetProfile(string Type, string PlatformID, string ProductCode, string PhoneFirmware, string FfuFirmware, UInt32 FillSize, UInt32 HeaderSize, bool AssumeImageHeaderFallsInGap, bool AllocateAsyncBuffersOnPhone) + internal void SetProfile(string Type, string PlatformID, string ProductCode, string PhoneFirmware, string FfuFirmware, uint FillSize, uint HeaderSize, bool AssumeImageHeaderFallsInGap, bool AllocateAsyncBuffersOnPhone) { FlashProfile Profile = GetProfile(PlatformID, PhoneFirmware, FfuFirmware); if (Profile == null) @@ -91,7 +91,7 @@ internal void SetProfile(string Type, string PlatformID, string ProductCode, str internal FlashProfile GetProfile(string PlatformID, string PhoneFirmware, string FfuFirmware = null) { - return FlashProfiles.Find(p => string.Equals(p.PlatformID, PlatformID, StringComparison.CurrentCultureIgnoreCase) && string.Equals(p.PhoneFirmware, PhoneFirmware, StringComparison.CurrentCultureIgnoreCase) && ((FfuFirmware == null) || string.Equals(p.FfuFirmware, FfuFirmware, StringComparison.CurrentCultureIgnoreCase))); + return FlashProfiles.Find(p => string.Equals(p.PlatformID, PlatformID, StringComparison.CurrentCultureIgnoreCase) && string.Equals(p.PhoneFirmware, PhoneFirmware, StringComparison.CurrentCultureIgnoreCase) && (FfuFirmware == null || string.Equals(p.FfuFirmware, FfuFirmware, StringComparison.CurrentCultureIgnoreCase))); } public List FlashProfiles = []; @@ -111,7 +111,7 @@ internal void AddFfuToRepository(string FFUPath) internal void AddFfuToRepository(string FFUPath, string PlatformID, string FirmwareVersion, string OSVersion) { - FFUEntry Entry = FFURepository.Find(e => (e.PlatformID == PlatformID) && (e.FirmwareVersion == FirmwareVersion) && string.Equals(e.Path, FFUPath, StringComparison.CurrentCultureIgnoreCase)); + FFUEntry Entry = FFURepository.Find(e => e.PlatformID == PlatformID && e.FirmwareVersion == FirmwareVersion && string.Equals(e.Path, FFUPath, StringComparison.CurrentCultureIgnoreCase)); if (Entry == null) { LogFile.Log("Adding FFU to repository: " + FFUPath, LogType.FileAndConsole); @@ -165,7 +165,7 @@ internal void RemoveFfuFromRepository(string FFUPath) internal void AddSecWimToRepository(string SecWimPath, string FirmwareVersion) { - SecWimEntry Entry = SecWimRepository.Find(e => (e.FirmwareVersion == FirmwareVersion) && string.Equals(e.Path, SecWimPath, StringComparison.CurrentCultureIgnoreCase)); + SecWimEntry Entry = SecWimRepository.Find(e => e.FirmwareVersion == FirmwareVersion && string.Equals(e.Path, SecWimPath, StringComparison.CurrentCultureIgnoreCase)); if (Entry == null) { LogFile.Log("Adding Secure WIM to repository: " + SecWimPath, LogType.FileAndConsole); @@ -213,8 +213,8 @@ internal void RemoveSecWimFromRepository(string SecWimPath) internal void AddEmergencyToRepository(string Type, string ProgrammerPath, string PayloadPath) { - EmergencyFileEntry Entry = EmergencyRepository.Find(e => (e.Type == Type) && string.Equals(e.ProgrammerPath, ProgrammerPath, StringComparison.CurrentCultureIgnoreCase)); - if ((Entry != null) && (PayloadPath != null) && (!string.Equals(Entry.PayloadPath, PayloadPath, StringComparison.CurrentCultureIgnoreCase))) + EmergencyFileEntry Entry = EmergencyRepository.Find(e => e.Type == Type && string.Equals(e.ProgrammerPath, ProgrammerPath, StringComparison.CurrentCultureIgnoreCase)); + if (Entry != null && PayloadPath != null && !string.Equals(Entry.PayloadPath, PayloadPath, StringComparison.CurrentCultureIgnoreCase)) { LogFile.Log("Updating emergency payload path in repository: " + PayloadPath, LogType.FileAndConsole); Entry.PayloadPath = PayloadPath; diff --git a/WPinternals/HelperClasses.cs b/WPinternals/HelperClasses/HelperClasses.cs similarity index 97% rename from WPinternals/HelperClasses.cs rename to WPinternals/HelperClasses/HelperClasses.cs index 6b4cdce..43c0af5 100644 --- a/WPinternals/HelperClasses.cs +++ b/WPinternals/HelperClasses/HelperClasses.cs @@ -21,9 +21,7 @@ // Some of the classes and functions in this file were found online. // Where possible the original authors are referenced. -using WPinternals.HelperClasses; - -namespace WPinternals +namespace WPinternals.HelperClasses { internal delegate void SetWorkingStatus(string Message, string SubMessage = null, ulong? MaxProgressValue = null, bool ShowAnimation = true, WPinternalsStatus Status = WPinternalsStatus.Undefined); internal delegate void UpdateWorkingStatus(string Message, string SubMessage = null, ulong? CurrentProgressValue = null, WPinternalsStatus Status = WPinternalsStatus.Undefined); diff --git a/WPinternals/HelperClasses/Paragraph.cs b/WPinternals/HelperClasses/Paragraph.cs index e1ac970..f47cbd0 100644 --- a/WPinternals/HelperClasses/Paragraph.cs +++ b/WPinternals/HelperClasses/Paragraph.cs @@ -28,7 +28,7 @@ namespace WPinternals.HelperClasses { // Overloaded Paragraph class to remove empty Run-elements, caused by auto-formatting new-lines in the XAML - // Use local:Paragraph in a FlowDocument + // Use helpers:Paragraph in a FlowDocument // This correction only works at run-time public class Paragraph : System.Windows.Documents.Paragraph { diff --git a/WPinternals/Models/UEFIApps/BootMgr/LumiaBootManagerAppModel.cs b/WPinternals/Models/UEFIApps/BootMgr/LumiaBootManagerAppModel.cs index d865e2b..9c4a406 100644 --- a/WPinternals/Models/UEFIApps/BootMgr/LumiaBootManagerAppModel.cs +++ b/WPinternals/Models/UEFIApps/BootMgr/LumiaBootManagerAppModel.cs @@ -158,7 +158,6 @@ internal LumiaBootManagerPhoneInfo ReadPhoneInfoBootManager() ushort SubblockLength = BigEndian.ToUInt16(Response, SubblockOffset + 0x01); int SubblockPayloadOffset = SubblockOffset + 3; - byte SubblockVersion; switch (SubblockID) { case 0x01: diff --git a/WPinternals/Models/UEFIApps/Flash/LumiaFlashAppModel.cs b/WPinternals/Models/UEFIApps/Flash/LumiaFlashAppModel.cs index fe59dfe..dae995e 100644 --- a/WPinternals/Models/UEFIApps/Flash/LumiaFlashAppModel.cs +++ b/WPinternals/Models/UEFIApps/Flash/LumiaFlashAppModel.cs @@ -22,6 +22,7 @@ using System.IO; using System.Linq; using WPinternals.HelperClasses; +using WPinternals.Terminal; namespace WPinternals.Models.UEFIApps.Flash { @@ -443,7 +444,7 @@ public TerminalResponse GetTerminalResponse() if (TerminalResponse?.Length > 0x20 && BigEndian.ToUInt32(TerminalResponse, 0x14) == TerminalResponse.Length - 0x18 && BitConverter.ToUInt32(TerminalResponse, 0x1C) == TerminalResponse.Length - 0x20) { // Parse Terminal Response from offset 0x18 - return Terminal.Parse(TerminalResponse, 0x18); + return Terminal.Terminal.Parse(TerminalResponse, 0x18); } else { diff --git a/WPinternals/Models/UEFIApps/NokiaUEFIModel.cs b/WPinternals/Models/UEFIApps/NokiaUEFIModel.cs index d6dde5a..6dea0ec 100644 --- a/WPinternals/Models/UEFIApps/NokiaUEFIModel.cs +++ b/WPinternals/Models/UEFIApps/NokiaUEFIModel.cs @@ -19,6 +19,7 @@ // DEALINGS IN THE SOFTWARE. using System; +using WPinternals.HelperClasses; namespace WPinternals.Models.UEFIApps { diff --git a/WPinternals/Models/UEFIApps/PhoneInfo/LumiaPhoneInfoAppModel.cs b/WPinternals/Models/UEFIApps/PhoneInfo/LumiaPhoneInfoAppModel.cs index 7c46199..d906319 100644 --- a/WPinternals/Models/UEFIApps/PhoneInfo/LumiaPhoneInfoAppModel.cs +++ b/WPinternals/Models/UEFIApps/PhoneInfo/LumiaPhoneInfoAppModel.cs @@ -201,7 +201,6 @@ internal LumiaPhoneInfoAppPhoneInfo ReadPhoneInfoPhoneInfoApp() ushort SubblockLength = BigEndian.ToUInt16(Response, SubblockOffset + 0x01); int SubblockPayloadOffset = SubblockOffset + 3; - byte SubblockVersion; switch (SubblockID) { case 0x20: diff --git a/WPinternals/Terminal.cs b/WPinternals/Terminal/Terminal.cs similarity index 94% rename from WPinternals/Terminal.cs rename to WPinternals/Terminal/Terminal.cs index 6b5b7bd..a5b290b 100644 --- a/WPinternals/Terminal.cs +++ b/WPinternals/Terminal/Terminal.cs @@ -20,7 +20,7 @@ using System; -namespace WPinternals +namespace WPinternals.Terminal { internal static class Terminal { @@ -29,13 +29,13 @@ public static TerminalResponse Parse(byte[] Buffer, int Offset) TerminalResponse Response = new(); // Get root node - if (Buffer.Length >= (Offset + 8)) + if (Buffer.Length >= Offset + 8) { int NodeNumber = BitConverter.ToInt32(Buffer, Offset); int NodeSize = BitConverter.ToInt32(Buffer, Offset + 4); int End = NodeSize + Offset + 8; int Index = Offset + 8; - if ((NodeNumber == 0x10000) && (End <= Buffer.Length)) + if (NodeNumber == 0x10000 && End <= Buffer.Length) { // Get subnodes while (Index < End) diff --git a/WPinternals/ViewModels/LumiaUnlockBootViewModel.cs b/WPinternals/ViewModels/LumiaUnlockBootViewModel.cs index eb4c815..0ffcec3 100644 --- a/WPinternals/ViewModels/LumiaUnlockBootViewModel.cs +++ b/WPinternals/ViewModels/LumiaUnlockBootViewModel.cs @@ -24,6 +24,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using WPinternals.Config; using WPinternals.HelperClasses; using WPinternals.Models.UEFIApps.Flash; using WPinternals.Models.UEFIApps.PhoneInfo; diff --git a/WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs b/WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs index c925303..a6bbd86 100644 --- a/WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs +++ b/WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs @@ -25,6 +25,7 @@ using System.IO.Compression; using System.Linq; using System.Threading.Tasks; +using WPinternals.Config; using WPinternals.HelperClasses; using WPinternals.Models.UEFIApps; using WPinternals.Models.UEFIApps.BootMgr; diff --git a/WPinternals/ViewModels/MainViewModel.cs b/WPinternals/ViewModels/MainViewModel.cs index 6a2b7cd..6f60fc2 100644 --- a/WPinternals/ViewModels/MainViewModel.cs +++ b/WPinternals/ViewModels/MainViewModel.cs @@ -26,6 +26,7 @@ using System.Threading.Tasks; using System.Windows.Input; using WPinternals.HelperClasses; +using WPinternals.Config; namespace WPinternals { diff --git a/WPinternals/ViewModels/NokiaLabelViewModel.cs b/WPinternals/ViewModels/NokiaLabelViewModel.cs index 67bd3e6..31de39a 100644 --- a/WPinternals/ViewModels/NokiaLabelViewModel.cs +++ b/WPinternals/ViewModels/NokiaLabelViewModel.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.Threading; using WPinternals.HelperClasses; +using WPinternals.Terminal; namespace WPinternals { @@ -93,7 +94,7 @@ private void StartLoadDeviceInfo() byte[] TerminalResponseBytes = CurrentModel.ExecuteJsonMethodAsBytes("TerminalChallenge", Params, "TerminalResponse"); if (TerminalResponseBytes != null) { - TerminalResponse TerminalResponse = Terminal.Parse(TerminalResponseBytes, 0); + TerminalResponse TerminalResponse = Terminal.Terminal.Parse(TerminalResponseBytes, 0); if (TerminalResponse != null) { PublicID = TerminalResponse.PublicId; diff --git a/WPinternals/ViewModels/RegistrationViewModel.cs b/WPinternals/ViewModels/RegistrationViewModel.cs index f897b05..cf765c4 100644 --- a/WPinternals/ViewModels/RegistrationViewModel.cs +++ b/WPinternals/ViewModels/RegistrationViewModel.cs @@ -20,6 +20,7 @@ using System; using System.Windows; +using WPinternals.Config; using WPinternals.HelperClasses; namespace WPinternals diff --git a/WPinternals/Views/About.xaml b/WPinternals/Views/About.xaml index 9dd4ba7..9e13ce7 100644 --- a/WPinternals/Views/About.xaml +++ b/WPinternals/Views/About.xaml @@ -26,6 +26,7 @@ DEALINGS IN THE SOFTWARE. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:WPinternals" + xmlns:helpers="clr-namespace:WPinternals.HelperClasses" mc:Ignorable="d" d:DesignWidth="700"> @@ -39,9 +40,9 @@ DEALINGS IN THE SOFTWARE. - + - + @@ -88,9 +89,9 @@ DEALINGS IN THE SOFTWARE. license - + - + diff --git a/WPinternals/Views/BackupView.xaml b/WPinternals/Views/BackupView.xaml index fdc8bb4..ac7fbda 100644 --- a/WPinternals/Views/BackupView.xaml +++ b/WPinternals/Views/BackupView.xaml @@ -26,15 +26,16 @@ DEALINGS IN THE SOFTWARE. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:WPinternals" + xmlns:helpers="clr-namespace:WPinternals.HelperClasses" mc:Ignorable="d" d:DesignWidth="700"> - + - + @@ -45,7 +46,7 @@ DEALINGS IN THE SOFTWARE. - + @@ -57,12 +58,12 @@ DEALINGS IN THE SOFTWARE. - - - - + + + + - +