mirror of
https://github.com/ReneLergner/WPinternals.git
synced 2026-06-14 03:16:40 +10:00
Rebuild the Backup to Custom ROM zip functionality to handle more partitions and be more flexible
This commit is contained in:
@@ -559,6 +559,15 @@ namespace WPinternals
|
|||||||
FileWriter.Close();
|
FileWriter.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void WritePartitions(Stream Stream)
|
||||||
|
{
|
||||||
|
XmlSerializer x = new(typeof(GPT), "");
|
||||||
|
|
||||||
|
XmlSerializerNamespaces ns = new();
|
||||||
|
ns.Add("", "");
|
||||||
|
x.Serialize(Stream, this, ns);
|
||||||
|
}
|
||||||
|
|
||||||
internal static GPT ReadPartitions(string Path)
|
internal static GPT ReadPartitions(string Path)
|
||||||
{
|
{
|
||||||
XmlSerializer x = new(typeof(GPT), "");
|
XmlSerializer x = new(typeof(GPT), "");
|
||||||
|
|||||||
@@ -32,6 +32,48 @@ namespace WPinternals
|
|||||||
private readonly Action Callback;
|
private readonly Action Callback;
|
||||||
private readonly Action SwitchToUnlockBoot;
|
private readonly Action SwitchToUnlockBoot;
|
||||||
|
|
||||||
|
private readonly static string[] KnownOSPartitions =
|
||||||
|
[
|
||||||
|
"EFIESP",
|
||||||
|
"HACK_EFIESP",
|
||||||
|
"VIRT_EFIESP",
|
||||||
|
"EFIESP_MUNGED",
|
||||||
|
"HACK_EFIESP_MUNGED",
|
||||||
|
"TEST-UI-MARKER",
|
||||||
|
"BOOT_EFI",
|
||||||
|
"MainOS",
|
||||||
|
"OSData",
|
||||||
|
"Data",
|
||||||
|
"BSP",
|
||||||
|
"PreInstalled",
|
||||||
|
"OSPool",
|
||||||
|
"WSP",
|
||||||
|
"IU_RESERVE",
|
||||||
|
"SERVICING_METADATA"
|
||||||
|
];
|
||||||
|
|
||||||
|
private readonly static string[] ProvisioningPartitions =
|
||||||
|
[
|
||||||
|
"DPP",
|
||||||
|
"MODEM_FSG",
|
||||||
|
"MODEM_FS1",
|
||||||
|
"MODEM_FS2",
|
||||||
|
"MODEM_FSC",
|
||||||
|
"DDR",
|
||||||
|
"SEC",
|
||||||
|
"APDP",
|
||||||
|
"MSADP",
|
||||||
|
"DPO",
|
||||||
|
"SSD",
|
||||||
|
"DBI",
|
||||||
|
"UEFI_BS_NV",
|
||||||
|
"UEFI_NV",
|
||||||
|
"UEFI_RT_NV",
|
||||||
|
"UEFI_RT_NV_RPMB",
|
||||||
|
"BOOTMODE",
|
||||||
|
"LIMITS"
|
||||||
|
];
|
||||||
|
|
||||||
internal BackupViewModel(PhoneNotifierViewModel PhoneNotifier, Action SwitchToUnlockBoot, Action Callback)
|
internal BackupViewModel(PhoneNotifierViewModel PhoneNotifier, Action SwitchToUnlockBoot, Action Callback)
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
@@ -234,7 +276,6 @@ namespace WPinternals
|
|||||||
ActivateSubContext(new BusyViewModel("Initializing backup..."));
|
ActivateSubContext(new BusyViewModel("Initializing backup..."));
|
||||||
|
|
||||||
ulong TotalSizeSectors = 0;
|
ulong TotalSizeSectors = 0;
|
||||||
const int PartitionCount = 3;
|
|
||||||
|
|
||||||
MassStorage Phone = (MassStorage)PhoneNotifier.CurrentModel;
|
MassStorage Phone = (MassStorage)PhoneNotifier.CurrentModel;
|
||||||
|
|
||||||
@@ -244,18 +285,15 @@ namespace WPinternals
|
|||||||
byte[] GPTBuffer = Phone.ReadSectors(1, 33);
|
byte[] GPTBuffer = Phone.ReadSectors(1, 33);
|
||||||
GPT GPT = new(GPTBuffer);
|
GPT GPT = new(GPTBuffer);
|
||||||
|
|
||||||
Partition Partition;
|
Partition[] Partitions = GPT.Partitions.Where(p => KnownOSPartitions.Any(x => x == p.Name)).ToArray();
|
||||||
|
int PartitionCount = Partitions.Length;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Partition = GPT.Partitions.First(p => p.Name == "EFIESP");
|
foreach (Partition Partition in Partitions)
|
||||||
TotalSizeSectors += Partition.SizeInSectors;
|
{
|
||||||
|
TotalSizeSectors += Partition.SizeInSectors;
|
||||||
Partition = GPT.Partitions.First(p => p.Name == "MainOS");
|
}
|
||||||
TotalSizeSectors += Partition.SizeInSectors;
|
|
||||||
|
|
||||||
Partition = GPT.Partitions.First(p => p.Name == "Data");
|
|
||||||
TotalSizeSectors += Partition.SizeInSectors;
|
|
||||||
}
|
}
|
||||||
catch (Exception Ex)
|
catch (Exception Ex)
|
||||||
{
|
{
|
||||||
@@ -271,17 +309,15 @@ namespace WPinternals
|
|||||||
|
|
||||||
using FileStream FileStream = new(ArchivePath, FileMode.Create);
|
using FileStream FileStream = new(ArchivePath, FileMode.Create);
|
||||||
using ZipArchive Archive = new(FileStream, ZipArchiveMode.Create);
|
using ZipArchive Archive = new(FileStream, ZipArchiveMode.Create);
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
if (Result)
|
if (Result)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Entry = Archive.CreateEntry("EFIESP.bin", CompressionLevel.Optimal);
|
Entry = Archive.CreateEntry("Partitions.xml", CompressionLevel.Optimal);
|
||||||
EntryStream = Entry.Open();
|
EntryStream = Entry.Open();
|
||||||
i++;
|
Busy.Message = "Create backup of partition tablle";
|
||||||
Busy.Message = "Create backup of partition EFIESP (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
GPT.WritePartitions(EntryStream);
|
||||||
Phone.BackupPartition("EFIESP", EntryStream, Updater);
|
|
||||||
}
|
}
|
||||||
catch (Exception Ex)
|
catch (Exception Ex)
|
||||||
{
|
{
|
||||||
@@ -295,47 +331,28 @@ namespace WPinternals
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Result)
|
for (int i = 0; i < PartitionCount; i++)
|
||||||
{
|
{
|
||||||
try
|
string Partition = Partitions[i].Name;
|
||||||
|
if (Result)
|
||||||
{
|
{
|
||||||
Entry = Archive.CreateEntry("MainOS.bin", CompressionLevel.Optimal);
|
try
|
||||||
EntryStream = Entry.Open();
|
{
|
||||||
i++;
|
Entry = Archive.CreateEntry(Partition + ".bin", CompressionLevel.Optimal);
|
||||||
Busy.Message = "Create backup of partition MainOS (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
EntryStream = Entry.Open();
|
||||||
Phone.BackupPartition("MainOS", EntryStream, Updater);
|
Busy.Message = "Create backup of partition " + Partition + " (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
||||||
}
|
Phone.BackupPartition(Partition, EntryStream, Updater);
|
||||||
catch (Exception Ex)
|
}
|
||||||
{
|
catch (Exception Ex)
|
||||||
LogFile.LogException(Ex);
|
{
|
||||||
Result = false;
|
LogFile.LogException(Ex);
|
||||||
}
|
Result = false;
|
||||||
finally
|
}
|
||||||
{
|
finally
|
||||||
EntryStream?.Close();
|
{
|
||||||
EntryStream = null;
|
EntryStream?.Close();
|
||||||
}
|
EntryStream = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Result)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Entry = Archive.CreateEntry("Data.bin", CompressionLevel.Optimal);
|
|
||||||
EntryStream = Entry.Open();
|
|
||||||
i++;
|
|
||||||
Busy.Message = "Create backup of partition Data (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
|
||||||
Phone.BackupPartition("Data", EntryStream, Updater);
|
|
||||||
}
|
|
||||||
catch (Exception Ex)
|
|
||||||
{
|
|
||||||
LogFile.LogException(Ex);
|
|
||||||
Result = false;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
EntryStream?.Close();
|
|
||||||
EntryStream = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,28 +372,6 @@ namespace WPinternals
|
|||||||
}).Start();
|
}).Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly static string[] ProvisioningPartitions = new string[]
|
|
||||||
{
|
|
||||||
"DPP",
|
|
||||||
"MODEM_FSG",
|
|
||||||
"MODEM_FS1",
|
|
||||||
"MODEM_FS2",
|
|
||||||
"MODEM_FSC",
|
|
||||||
"DDR",
|
|
||||||
"SEC",
|
|
||||||
"APDP",
|
|
||||||
"MSADP",
|
|
||||||
"DPO",
|
|
||||||
"SSD",
|
|
||||||
"DBI",
|
|
||||||
"UEFI_BS_NV",
|
|
||||||
"UEFI_NV",
|
|
||||||
"UEFI_RT_NV",
|
|
||||||
"UEFI_RT_NV_RPMB",
|
|
||||||
"BOOTMODE",
|
|
||||||
"LIMITS"
|
|
||||||
};
|
|
||||||
|
|
||||||
internal void BackupArchiveProvisioningTask(string ArchiveProvisioningPath)
|
internal void BackupArchiveProvisioningTask(string ArchiveProvisioningPath)
|
||||||
{
|
{
|
||||||
IsSwitchingInterface = false;
|
IsSwitchingInterface = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user