Skip to content

Commit

Permalink
fix: Handle empty flash part list
Browse files Browse the repository at this point in the history
This is used to clear the red flashing status we need to handle this differently for spec A
  • Loading branch information
gus33000 committed Aug 30, 2024
1 parent a6c0179 commit 0101477
Showing 1 changed file with 36 additions and 33 deletions.
69 changes: 36 additions & 33 deletions WPinternals/ViewModels/LumiaUnlockBootloaderViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2657,50 +2657,53 @@ private static void LumiaV1FlashParts(PhoneNotifierViewModel Notifier, List<Flas
UInt64 totalwritten = 0;
int ProgressPercentage = 0;

foreach (FlashPart Part in FlashParts)
if (FlashParts != null)
{
InputStreamLength += (ulong)Part.Stream.Length;
}

foreach (FlashPart Part in FlashParts)
{
Stream InputStream = new DecompressedStream(Part.Stream);
foreach (FlashPart Part in FlashParts)
{
InputStreamLength += (ulong)Part.Stream.Length;
}

if (InputStream != null)
foreach (FlashPart Part in FlashParts)
{
using (InputStream)
Stream InputStream = new DecompressedStream(Part.Stream);

if (InputStream != null)
{
const int FlashBufferSize = 0x200000; // Flash 8 GB phone -> buffersize 0x200000 = 11:45 min, buffersize 0x20000 = 12:30 min
byte[] FlashBuffer = new byte[FlashBufferSize];
int BytesRead;
UInt64 i = 0;
do
using (InputStream)
{
BytesRead = InputStream.Read(FlashBuffer, 0, FlashBufferSize);

byte[] FlashBufferFinalSize;
if (BytesRead > 0)
const int FlashBufferSize = 0x200000; // Flash 8 GB phone -> buffersize 0x200000 = 11:45 min, buffersize 0x20000 = 12:30 min
byte[] FlashBuffer = new byte[FlashBufferSize];
int BytesRead;
UInt64 i = 0;
do
{
if (BytesRead == FlashBufferSize)
{
FlashBufferFinalSize = FlashBuffer;
}
else
BytesRead = InputStream.Read(FlashBuffer, 0, FlashBufferSize);

byte[] FlashBufferFinalSize;
if (BytesRead > 0)
{
FlashBufferFinalSize = new byte[BytesRead];
Buffer.BlockCopy(FlashBuffer, 0, FlashBufferFinalSize, 0, BytesRead);
if (BytesRead == FlashBufferSize)
{
FlashBufferFinalSize = FlashBuffer;
}
else
{
FlashBufferFinalSize = new byte[BytesRead];
Buffer.BlockCopy(FlashBuffer, 0, FlashBufferFinalSize, 0, BytesRead);
}

FlashModel.FlashSectors((UInt32)(Part.StartSector + (i / 0x200)), FlashBufferFinalSize, ProgressPercentage);
}

FlashModel.FlashSectors((UInt32)(Part.StartSector + (i / 0x200)), FlashBufferFinalSize, ProgressPercentage);
}

UpdateWorkingStatus(Part.ProgressText, null, (uint)ProgressPercentage, WPinternalsStatus.Flashing);
totalwritten += (UInt64)FlashBuffer.Length / 0x200;
ProgressPercentage = (int)((double)totalwritten / (InputStreamLength / 0x200) * 100);
UpdateWorkingStatus(Part.ProgressText, null, (uint)ProgressPercentage, WPinternalsStatus.Flashing);
totalwritten += (UInt64)FlashBuffer.Length / 0x200;
ProgressPercentage = (int)((double)totalwritten / (InputStreamLength / 0x200) * 100);

i += FlashBufferSize;
i += FlashBufferSize;
}
while (BytesRead == FlashBufferSize);
}
while (BytesRead == FlashBufferSize);
}
}
}
Expand Down

0 comments on commit 0101477

Please sign in to comment.