mirror of
https://github.com/ReneLergner/WPinternals.git
synced 2026-06-14 03:16:40 +10:00
fix issues with downloading files
This commit is contained in:
@@ -927,15 +927,16 @@ namespace WPinternals
|
||||
uint length = uint.Parse(info.Length.ToString());
|
||||
|
||||
int offset = 0;
|
||||
const int maximumBufferSize = 0x00240000;
|
||||
int maximumBufferSize = (int)Info.WriteBufferSize;
|
||||
|
||||
uint chunkCount = (uint)Math.Truncate((decimal)length / maximumBufferSize);
|
||||
|
||||
using FileStream MMOSFile = new(MMOSPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
|
||||
for (int i = 1; i <= (uint)Math.Truncate((decimal)length / maximumBufferSize); i++)
|
||||
for (int i = 0; i < chunkCount; i++)
|
||||
{
|
||||
Progress.IncreaseProgress(1);
|
||||
|
||||
byte[] data = new byte[maximumBufferSize];
|
||||
MMOSFile.Read(data, 0, maximumBufferSize);
|
||||
|
||||
@@ -950,6 +951,7 @@ namespace WPinternals
|
||||
|
||||
byte[] data = new byte[length - offset];
|
||||
MMOSFile.Read(data, 0, (int)(length - offset));
|
||||
|
||||
LoadMmosBinary(length, (uint)offset, false, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -116,12 +116,18 @@ namespace WPinternals
|
||||
internal void SwitchToMmosContext()
|
||||
{
|
||||
byte[] Request = new byte[7];
|
||||
ByteOperations.WriteAsciiString(Request, 0, SwitchModeSignature + "A");
|
||||
ExecuteRawVoidMethod(Request);
|
||||
ByteOperations.WriteAsciiString(Request, 0, $"{SwitchModeSignature}A");
|
||||
byte[] Response = ExecuteRawMethod(Request);
|
||||
if (ByteOperations.ReadAsciiString(Response, 0, 4) == "NOKU")
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
ResetDevice();
|
||||
|
||||
Dispose(true);
|
||||
UInt16 Error = (UInt16)((Response[6] << 8) + Response[7]);
|
||||
if (Error > 0)
|
||||
{
|
||||
throw new NotSupportedException("SwitchToPhoneInfoAppContext: Error 0x" + Error.ToString("X4"));
|
||||
}
|
||||
}
|
||||
|
||||
internal void SwitchToFlashAppContext()
|
||||
@@ -131,7 +137,7 @@ namespace WPinternals
|
||||
bool ModernFlashApp = info.VersionMajor >= 2;
|
||||
|
||||
byte[] Request = new byte[7];
|
||||
ByteOperations.WriteAsciiString(Request, 0, SwitchModeSignature + "F"); // This will stop charging the phone
|
||||
ByteOperations.WriteAsciiString(Request, 0, $"{SwitchModeSignature}F"); // This will stop charging the phone
|
||||
byte[] Response = ExecuteRawMethod(Request);
|
||||
if (ByteOperations.ReadAsciiString(Response, 0, 4) == "NOKU")
|
||||
{
|
||||
|
||||
@@ -723,7 +723,7 @@ namespace WPinternals
|
||||
|
||||
//_ = Client.DownloadFileAsync(Uri, Path.Combine(Folder, DownloadsViewModel.GetFileNameFromURL(Uri.LocalPath)), Client_DownloadProgressChanged, Client_DownloadFileCompleted);
|
||||
|
||||
Client = new(Folder, 4);
|
||||
Client = new(Folder, 4, false);
|
||||
|
||||
_ = Client.DownloadAsync([new FileDownloadInformation(URL, DownloadsViewModel.GetFileNameFromURL(Uri.LocalPath), Size, null, null)], this);
|
||||
}).Start();
|
||||
|
||||
@@ -275,12 +275,11 @@ namespace WPinternals
|
||||
|
||||
if (tmpFileInfo.Length == downloadFile.FileSize)
|
||||
{
|
||||
/*//Decrypted file should match estimated bytes.
|
||||
//Decrypted file should match estimated bytes.
|
||||
//Imagine if it crashed during hashing, the file may be valid.
|
||||
//So... lets rename this file so it can be verified.
|
||||
File.Move(tempFilePath, filePath);
|
||||
totalBytesRead = tmpFileInfo.Length;*/
|
||||
File.Delete(tempFilePath);
|
||||
totalBytesRead = tmpFileInfo.Length;
|
||||
}
|
||||
else if (tmpFileInfo.Length < downloadFile.FileSize)
|
||||
{
|
||||
@@ -384,8 +383,32 @@ namespace WPinternals
|
||||
|
||||
//just an assumption
|
||||
|
||||
_ = streamToWriteTo.Seek(0, SeekOrigin.Begin);
|
||||
return await HashWithProgress(streamToWriteTo);
|
||||
if (verifyFiles)
|
||||
{
|
||||
_ = streamToWriteTo.Seek(0, SeekOrigin.Begin);
|
||||
bool hashResult = await HashWithProgress(streamToWriteTo);
|
||||
|
||||
if (hashResult)
|
||||
{
|
||||
streamToWriteTo.Close();
|
||||
File.Move(tempFilePath, filePath);
|
||||
}
|
||||
|
||||
return hashResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
streamToWriteTo.Close();
|
||||
File.Move(tempFilePath, filePath);
|
||||
|
||||
downloadProgress?.Report(new FileDownloadStatus(downloadFile)
|
||||
{
|
||||
DownloadedBytes = totalBytesRead,
|
||||
FileStatus = FileStatus.Completed
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
while (currRange < contentLength.Value)
|
||||
|
||||
@@ -936,26 +936,33 @@ namespace WPinternals
|
||||
string TempFolder = $@"{Environment.GetEnvironmentVariable("TEMP")}\WPInternals";
|
||||
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
||||
|
||||
ModeSwitchProgressWrapper("Initializing Flash...", null);
|
||||
Task.Run(() =>
|
||||
{
|
||||
ModeSwitchProgressWrapper("Initializing Flash...", null);
|
||||
|
||||
string MMOSPath = Path.Combine(TempFolder, Name);
|
||||
string MMOSPath = Path.Combine(TempFolder, Name);
|
||||
|
||||
App.Config.AddSecWimToRepository(MMOSPath, Firmware);
|
||||
App.Config.AddSecWimToRepository(MMOSPath, Firmware);
|
||||
|
||||
PhoneNotifier.NewDeviceArrived += NewDeviceArrived;
|
||||
PhoneNotifier.NewDeviceArrived += NewDeviceArrived;
|
||||
|
||||
FileInfo info = new(MMOSPath);
|
||||
uint fileLength = uint.Parse(info.Length.ToString());
|
||||
const int maximumBufferSize = 0x00240000;
|
||||
uint chunkCount = (uint)Math.Truncate((decimal)fileLength / maximumBufferSize);
|
||||
LumiaFlashAppPhoneInfo Info = FlashModel.ReadPhoneInfo();
|
||||
|
||||
UIContext?.Post(d => SetWorkingStatus("Flashing Test Mode package...", MaxProgressValue: 100), null);
|
||||
FileInfo info = new(MMOSPath);
|
||||
uint length = uint.Parse(info.Length.ToString());
|
||||
|
||||
ProgressUpdater progressUpdater = new(chunkCount + 1, (int i, TimeSpan? time) => UIContext?.Post(d => UpdateWorkingStatus(null, CurrentProgressValue: (ulong)i), null));
|
||||
int maximumBufferSize = (int)Info.WriteBufferSize;
|
||||
|
||||
FlashModel.FlashMMOS(MMOSPath, progressUpdater);
|
||||
uint chunkCount = (uint)Math.Truncate((decimal)length / maximumBufferSize);
|
||||
|
||||
ModeSwitchProgressWrapper("And now booting phone to MMOS...", "If the phone stays on the lightning cog screen for a while, you may need to unplug and replug the phone to continue the boot process.");
|
||||
UIContext?.Post(d => SetWorkingStatus("Flashing Test Mode package...", MaxProgressValue: 100), null);
|
||||
|
||||
ProgressUpdater progressUpdater = new(chunkCount + 1, (int i, TimeSpan? time) => UpdateWorkingStatus(null, CurrentProgressValue: (ulong)i));
|
||||
|
||||
FlashModel.FlashMMOS(MMOSPath, progressUpdater);
|
||||
|
||||
ModeSwitchProgressWrapper("And now booting phone to MMOS...", "If the phone stays on the lightning cog screen for a while, you may need to unplug and replug the phone to continue the boot process.");
|
||||
});
|
||||
}
|
||||
|
||||
private void SwitchFromPhoneInfoToMassStorageMode(bool Continuation = false)
|
||||
|
||||
Reference in New Issue
Block a user