2019-11-17 15:54:19 +00:00
|
|
|
|
// /***************************************************************************
|
2017-05-31 01:00:58 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : XGD.cs
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-05-31 01:00:58 +01:00
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Core algorithms.
|
2017-05-31 01:00:58 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Dumps Xbox Game Discs.
|
2017-05-31 01:00:58 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
2017-05-31 01:00:58 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 03:50:57 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2018-01-19 01:21:01 +00:00
|
|
|
|
using System.Linq;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using System.Xml.Serialization;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Enums;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Extents;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
2019-11-17 15:54:19 +00:00
|
|
|
|
using DiscImageChef.CommonTypes.Interop;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Metadata;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Structs;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
using DiscImageChef.Console;
|
|
|
|
|
|
using DiscImageChef.Core.Logging;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.Decoders.DVD;
|
|
|
|
|
|
using DiscImageChef.Decoders.SCSI;
|
|
|
|
|
|
using DiscImageChef.Decoders.Xbox;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
using DiscImageChef.Devices;
|
|
|
|
|
|
using Schemas;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using MediaType = DiscImageChef.CommonTypes.MediaType;
|
2019-11-17 15:54:19 +00:00
|
|
|
|
using PlatformID = DiscImageChef.CommonTypes.Interop.PlatformID;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using TrackType = DiscImageChef.CommonTypes.Enums.TrackType;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Core.Devices.Dumping
|
|
|
|
|
|
{
|
2019-11-16 19:15:51 +00:00
|
|
|
|
/// <summary>Implements dumping an Xbox Game Disc using a Kreon drive</summary>
|
2019-04-19 18:54:25 +01:00
|
|
|
|
partial class Dump
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-11-16 19:15:51 +00:00
|
|
|
|
/// <summary>Dumps an Xbox Game Disc using a Kreon drive</summary>
|
2018-01-19 01:21:01 +00:00
|
|
|
|
/// <param name="mediaTags">Media tags as retrieved in MMC layer</param>
|
2017-12-23 01:46:08 +00:00
|
|
|
|
/// <param name="dskType">Disc type as detected in MMC layer</param>
|
2019-04-20 13:23:58 +01:00
|
|
|
|
internal void Xgd(Dictionary<MediaTagType, byte[]> mediaTags, ref MediaType dskType)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2018-01-19 01:21:01 +00:00
|
|
|
|
bool sense;
|
|
|
|
|
|
const uint BLOCK_SIZE = 2048;
|
|
|
|
|
|
uint blocksToRead = 64;
|
|
|
|
|
|
DateTime start;
|
|
|
|
|
|
DateTime end;
|
2018-04-09 20:21:42 +01:00
|
|
|
|
double totalDuration = 0;
|
|
|
|
|
|
double currentSpeed = 0;
|
|
|
|
|
|
double maxSpeed = double.MinValue;
|
|
|
|
|
|
double minSpeed = double.MaxValue;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-11-17 15:54:19 +00:00
|
|
|
|
if(DetectOS.GetRealPlatformID() != PlatformID.Win32NT)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
bool isAdmin = _dev.IsRemote ? _dev.IsRemoteAdmin : DetectOS.IsAdmin;
|
2019-11-17 15:54:19 +00:00
|
|
|
|
|
|
|
|
|
|
if(!isAdmin)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.
|
|
|
|
|
|
ErrorWriteLine("Because of the commands sent to a device, dumping XGD must be done with administrative privileges. Cannot continue.");
|
2019-11-18 20:59:16 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot dump XGD without administrative privileges.");
|
2019-11-17 15:54:19 +00:00
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-11-18 20:59:16 +00:00
|
|
|
|
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(mediaTags.ContainsKey(MediaTagType.DVD_PFI))
|
|
|
|
|
|
mediaTags.Remove(MediaTagType.DVD_PFI);
|
|
|
|
|
|
|
|
|
|
|
|
if(mediaTags.ContainsKey(MediaTagType.DVD_DMI))
|
|
|
|
|
|
mediaTags.Remove(MediaTagType.DVD_DMI);
|
2018-01-19 01:21:01 +00:00
|
|
|
|
|
2019-11-16 20:17:24 +00:00
|
|
|
|
// Drive shall move to lock state when a new disc is inserted. Old kreon versions do not lock correctly so save this
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadCapacity(out byte[] coldReadCapacity, out byte[] senseBuf, _dev.Timeout, out _);
|
2019-11-16 20:17:24 +00:00
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot get disc capacity.");
|
2019-11-16 20:17:24 +00:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot get disc capacity.");
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Drive shall move to lock state when a new disc is inserted. Old kreon versions do not lock correctly so save this
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadDiscStructure(out byte[] coldPfi, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0,
|
|
|
|
|
|
MmcDiscStructureFormat.PhysicalInformation, 0, 0, out _);
|
2019-11-16 20:17:24 +00:00
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot get PFI.");
|
2019-11-16 20:17:24 +00:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot get PFI.");
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Reading Xbox Security Sector.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Reading Xbox Security Sector.");
|
|
|
|
|
|
sense = _dev.KreonExtractSs(out byte[] ssBuf, out senseBuf, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot get Xbox Security Sector, not continuing.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot get Xbox Security Sector, not continuing.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Decoding Xbox Security Sector.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Decoding Xbox Security Sector.");
|
2017-12-21 14:30:38 +00:00
|
|
|
|
SS.SecuritySector? xboxSs = SS.Decode(ssBuf);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(!xboxSs.HasValue)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot decode Xbox Security Sector, not continuing.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot decode Xbox Security Sector, not continuing.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-09 20:21:42 +01:00
|
|
|
|
byte[] tmpBuf = new byte[ssBuf.Length - 4];
|
2017-06-20 06:42:09 +01:00
|
|
|
|
Array.Copy(ssBuf, 4, tmpBuf, 0, ssBuf.Length - 4);
|
2018-01-19 01:21:01 +00:00
|
|
|
|
mediaTags.Add(MediaTagType.Xbox_SecuritySector, tmpBuf);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
// Get video partition size
|
|
|
|
|
|
DicConsole.DebugWriteLine("Dump-media command", "Getting video partition size");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Locking drive.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Locking drive.");
|
|
|
|
|
|
sense = _dev.KreonLock(out senseBuf, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot lock drive, not continuing.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot lock drive, not continuing.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Getting video partition size.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Getting video partition size.");
|
|
|
|
|
|
sense = _dev.ReadCapacity(out byte[] readBuffer, out senseBuf, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot get disc capacity.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot get disc capacity.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
ulong totalSize =
|
|
|
|
|
|
(ulong)((readBuffer[0] << 24) + (readBuffer[1] << 16) + (readBuffer[2] << 8) + readBuffer[3]);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Reading Physical Format Information.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Reading Physical Format Information.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadDiscStructure(out readBuffer, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0,
|
|
|
|
|
|
MmcDiscStructureFormat.PhysicalInformation, 0, 0, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot get PFI.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot get PFI.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2018-04-09 20:21:42 +01:00
|
|
|
|
tmpBuf = new byte[readBuffer.Length - 4];
|
2017-06-20 06:42:09 +01:00
|
|
|
|
Array.Copy(readBuffer, 4, tmpBuf, 0, readBuffer.Length - 4);
|
2018-01-19 01:21:01 +00:00
|
|
|
|
mediaTags.Add(MediaTagType.DVD_PFI, tmpBuf);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Dump-media command", "Video partition total size: {0} sectors", totalSize);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ulong l0Video =
|
|
|
|
|
|
(PFI.Decode(readBuffer).Value.Layer0EndPSN - PFI.Decode(readBuffer).Value.DataAreaStartPSN) + 1;
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ulong l1Video = (totalSize - l0Video) + 1;
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Reading Disc Manufacturing Information.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Reading Disc Manufacturing Information.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadDiscStructure(out readBuffer, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0,
|
|
|
|
|
|
MmcDiscStructureFormat.DiscManufacturingInformation, 0, 0, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-06-20 06:42:09 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot get DMI.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot get DMI.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-06-20 06:42:09 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2018-04-09 20:21:42 +01:00
|
|
|
|
tmpBuf = new byte[readBuffer.Length - 4];
|
2017-06-20 06:42:09 +01:00
|
|
|
|
Array.Copy(readBuffer, 4, tmpBuf, 0, readBuffer.Length - 4);
|
2018-01-19 01:21:01 +00:00
|
|
|
|
mediaTags.Add(MediaTagType.DVD_DMI, tmpBuf);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-11-16 20:17:24 +00:00
|
|
|
|
// Should be a safe value to detect the lock command was ignored, and we're indeed getting the whole size and not the locked one
|
|
|
|
|
|
if(totalSize > 300000)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateStatus?.Invoke("Video partition is too big, did lock work? Trying cold values.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Video partition is too big, did lock work? Trying cold values.");
|
2019-11-16 20:17:24 +00:00
|
|
|
|
|
|
|
|
|
|
totalSize = (ulong)((coldReadCapacity[0] << 24) + (coldReadCapacity[1] << 16) +
|
|
|
|
|
|
(coldReadCapacity[2] << 8) + coldReadCapacity[3]);
|
|
|
|
|
|
|
|
|
|
|
|
tmpBuf = new byte[coldPfi.Length - 4];
|
|
|
|
|
|
Array.Copy(coldPfi, 4, tmpBuf, 0, coldPfi.Length - 4);
|
|
|
|
|
|
mediaTags.Remove(MediaTagType.DVD_PFI);
|
|
|
|
|
|
mediaTags.Add(MediaTagType.DVD_PFI, tmpBuf);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Dump-media command", "Video partition total size: {0} sectors", totalSize);
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
l0Video = (PFI.Decode(coldPfi).Value.Layer0EndPSN - PFI.Decode(coldPfi).Value.DataAreaStartPSN) + 1;
|
2019-11-16 20:17:24 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
l1Video = (totalSize - l0Video) + 1;
|
2019-11-16 20:17:24 +00:00
|
|
|
|
|
|
|
|
|
|
if(totalSize > 300000)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot get video partition size, not continuing. Try to eject and reinsert the drive, if it keeps happening, contact support.");
|
2019-11-16 20:17:24 +00:00
|
|
|
|
|
|
|
|
|
|
StoppingErrorMessage?.
|
|
|
|
|
|
Invoke("Cannot get video partition size, not continuing. Try to eject and reinsert the drive, if it keeps happening, contact support.");
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
// Get game partition size
|
|
|
|
|
|
DicConsole.DebugWriteLine("Dump-media command", "Getting game partition size");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Unlocking drive (Xtreme).");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Unlocking drive (Xtreme).");
|
|
|
|
|
|
sense = _dev.KreonUnlockXtreme(out senseBuf, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot unlock drive, not continuing.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot unlock drive, not continuing.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Getting game partition size.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Getting game partition size.");
|
|
|
|
|
|
sense = _dev.ReadCapacity(out readBuffer, out senseBuf, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot get disc capacity.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot get disc capacity.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
ulong gameSize =
|
|
|
|
|
|
(ulong)((readBuffer[0] << 24) + (readBuffer[1] << 16) + (readBuffer[2] << 8) + readBuffer[3]) + 1;
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Dump-media command", "Game partition total size: {0} sectors", gameSize);
|
|
|
|
|
|
|
|
|
|
|
|
// Get middle zone size
|
|
|
|
|
|
DicConsole.DebugWriteLine("Dump-media command", "Getting middle zone size");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Unlocking drive (Wxripper).");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Unlocking drive (Wxripper).");
|
|
|
|
|
|
sense = _dev.KreonUnlockWxripper(out senseBuf, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot unlock drive, not continuing.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot unlock drive, not continuing.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Getting disc size.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Getting disc size.");
|
|
|
|
|
|
sense = _dev.ReadCapacity(out readBuffer, out senseBuf, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot get disc capacity.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot get disc capacity.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
|
totalSize = (ulong)((readBuffer[0] << 24) + (readBuffer[1] << 16) + (readBuffer[2] << 8) + readBuffer[3]);
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Reading Physical Format Information.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Reading Physical Format Information.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadDiscStructure(out readBuffer, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0,
|
|
|
|
|
|
MmcDiscStructureFormat.PhysicalInformation, 0, 0, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot get PFI.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot get PFI.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Dump-media command", "Unlocked total size: {0} sectors", totalSize);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
ulong blocks = totalSize + 1;
|
|
|
|
|
|
PFI.PhysicalFormatInformation wxRipperPfi = PFI.Decode(readBuffer).Value;
|
|
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.Invoke($"WxRipper PFI's Data Area Start PSN: {wxRipperPfi.DataAreaStartPSN} sectors");
|
|
|
|
|
|
UpdateStatus?.Invoke($"WxRipper PFI's Layer 0 End PSN: {wxRipperPfi.Layer0EndPSN} sectors");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine($"WxRipper PFI's Data Area Start PSN: {wxRipperPfi.DataAreaStartPSN} sectors");
|
|
|
|
|
|
_dumpLog.WriteLine($"WxRipper PFI's Layer 0 End PSN: {wxRipperPfi.Layer0EndPSN} sectors");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ulong middleZone =
|
|
|
|
|
|
(totalSize - ((wxRipperPfi.Layer0EndPSN - wxRipperPfi.DataAreaStartPSN) + 1) - gameSize) + 1;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2018-04-09 20:21:42 +01:00
|
|
|
|
tmpBuf = new byte[readBuffer.Length - 4];
|
2017-06-20 06:42:09 +01:00
|
|
|
|
Array.Copy(readBuffer, 4, tmpBuf, 0, readBuffer.Length - 4);
|
2018-01-19 01:21:01 +00:00
|
|
|
|
mediaTags.Add(MediaTagType.Xbox_PFI, tmpBuf);
|
2017-06-20 06:42:09 +01:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Reading Disc Manufacturing Information.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Reading Disc Manufacturing Information.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadDiscStructure(out readBuffer, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0,
|
|
|
|
|
|
MmcDiscStructureFormat.DiscManufacturingInformation, 0, 0, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-06-20 06:42:09 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot get DMI.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot get DMI.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-06-20 06:42:09 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2018-04-09 20:21:42 +01:00
|
|
|
|
tmpBuf = new byte[readBuffer.Length - 4];
|
2017-06-20 06:42:09 +01:00
|
|
|
|
Array.Copy(readBuffer, 4, tmpBuf, 0, readBuffer.Length - 4);
|
2018-01-19 01:21:01 +00:00
|
|
|
|
mediaTags.Add(MediaTagType.Xbox_DMI, tmpBuf);
|
2017-06-20 06:42:09 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
totalSize = l0Video + l1Video + (middleZone * 2) + gameSize;
|
|
|
|
|
|
ulong layerBreak = l0Video + middleZone + (gameSize / 2);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Video layer 0 size: {l0Video} sectors");
|
|
|
|
|
|
UpdateStatus?.Invoke($"Video layer 1 size: {l1Video} sectors");
|
|
|
|
|
|
UpdateStatus?.Invoke($"Middle zone size: {middleZone} sectors");
|
|
|
|
|
|
UpdateStatus?.Invoke($"Game data size: {gameSize} sectors");
|
|
|
|
|
|
UpdateStatus?.Invoke($"Total size: {totalSize} sectors");
|
|
|
|
|
|
UpdateStatus?.Invoke($"Real layer break: {layerBreak}");
|
|
|
|
|
|
UpdateStatus?.Invoke("");
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Video layer 0 size: {0} sectors", l0Video);
|
|
|
|
|
|
_dumpLog.WriteLine("Video layer 1 size: {0} sectors", l1Video);
|
|
|
|
|
|
_dumpLog.WriteLine("Middle zone 0 size: {0} sectors", middleZone);
|
|
|
|
|
|
_dumpLog.WriteLine("Game data 0 size: {0} sectors", gameSize);
|
|
|
|
|
|
_dumpLog.WriteLine("Total 0 size: {0} sectors", totalSize);
|
|
|
|
|
|
_dumpLog.WriteLine("Real layer break: {0}", layerBreak);
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
bool read12 = !_dev.Read12(out readBuffer, out senseBuf, 0, false, true, false, false, 0, BLOCK_SIZE, 0, 1,
|
|
|
|
|
|
false, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(!read12)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot read medium, aborting scan...");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot read medium, aborting scan...");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Using SCSI READ (12) command.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Using SCSI READ (12) command.");
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(read12)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Read12(out readBuffer, out senseBuf, 0, false, false, false, false, 0, BLOCK_SIZE, 0,
|
|
|
|
|
|
blocksToRead, false, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(sense || _dev.Error)
|
2019-11-16 19:15:51 +00:00
|
|
|
|
blocksToRead /= 2;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_dev.Error ||
|
2019-11-16 19:15:51 +00:00
|
|
|
|
blocksToRead == 1)
|
|
|
|
|
|
break;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_dev.Error)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device error {0} trying to guess ideal transfer length.", _dev.LastError);
|
|
|
|
|
|
StoppingErrorMessage?.Invoke($"Device error {_dev.LastError} trying to guess ideal transfer length.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_skip < blocksToRead)
|
|
|
|
|
|
_skip = blocksToRead;
|
2018-02-02 18:44:28 +00:00
|
|
|
|
|
2018-01-19 01:21:01 +00:00
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
|
|
|
|
foreach(MediaTagType tag in mediaTags.Keys)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_outputPlugin.SupportedMediaTags.Contains(tag))
|
2019-11-16 19:15:51 +00:00
|
|
|
|
continue;
|
2018-01-19 01:21:01 +00:00
|
|
|
|
|
|
|
|
|
|
ret = false;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine($"Output format does not support {tag}.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
ErrorMessage?.Invoke($"Output format does not support {tag}.");
|
2018-01-19 01:21:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!ret)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_force)
|
2019-04-20 03:06:30 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Several media tags not supported, continuing...");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
ErrorMessage?.Invoke("Several media tags not supported, continuing...");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Several media tags not supported, not continuing...");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Several media tags not supported, not continuing...");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2018-01-19 01:21:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Reading {0} sectors at a time.", blocksToRead);
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time.");
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
var mhddLog = new MhddLog(_outputPrefix + ".mhddlog.bin", _dev, blocks, BLOCK_SIZE, blocksToRead);
|
|
|
|
|
|
var ibgLog = new IbgLog(_outputPrefix + ".ibg", 0x0010);
|
|
|
|
|
|
ret = _outputPlugin.Create(_outputPath, dskType, _formatOptions, blocks, BLOCK_SIZE);
|
2018-01-19 01:21:01 +00:00
|
|
|
|
|
|
|
|
|
|
// Cannot create image
|
|
|
|
|
|
if(!ret)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Error creating output image, not continuing.");
|
|
|
|
|
|
_dumpLog.WriteLine(_outputPlugin.ErrorMessage);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Error creating output image, not continuing." + Environment.NewLine +
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.ErrorMessage);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2018-01-19 01:21:01 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2018-04-09 20:21:42 +01:00
|
|
|
|
start = DateTime.UtcNow;
|
2018-02-02 15:32:53 +00:00
|
|
|
|
double imageWriteDuration = 0;
|
2018-02-02 18:44:28 +00:00
|
|
|
|
|
2018-01-19 01:21:01 +00:00
|
|
|
|
double cmdDuration = 0;
|
|
|
|
|
|
uint saveBlocksToRead = blocksToRead;
|
|
|
|
|
|
DumpHardwareType currentTry = null;
|
|
|
|
|
|
ExtentsULong extents = null;
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ResumeSupport.Process(true, true, totalSize, _dev.Manufacturer, _dev.Model, _dev.Serial, _dev.PlatformId,
|
|
|
|
|
|
ref _resume, ref currentTry, ref extents);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
if(currentTry == null ||
|
|
|
|
|
|
extents == null)
|
2019-04-20 14:02:25 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Could not process resume file, not continuing...");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
(_outputPlugin as IWritableOpticalImage).SetTracks(new List<Track>
|
2018-02-05 18:23:53 +00:00
|
|
|
|
{
|
|
|
|
|
|
new Track
|
|
|
|
|
|
{
|
2019-11-16 19:15:51 +00:00
|
|
|
|
TrackBytesPerSector = (int)BLOCK_SIZE, TrackEndSector = blocks - 1, TrackSequence = 1,
|
|
|
|
|
|
TrackRawBytesPerSector = (int)BLOCK_SIZE, TrackSubchannelType = TrackSubchannelType.None,
|
|
|
|
|
|
TrackSession = 1, TrackType = TrackType.Data
|
2018-02-05 18:23:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2018-04-09 20:21:42 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ulong currentSector = _resume.NextBlock;
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_resume.NextBlock > 0)
|
2019-04-20 03:06:30 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
UpdateStatus?.Invoke($"Resuming from block {_resume.NextBlock}.");
|
|
|
|
|
|
_dumpLog.WriteLine("Resuming from block {0}.", _resume.NextBlock);
|
2019-04-20 03:06:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-10 02:39:41 +01:00
|
|
|
|
bool newTrim = false;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Reading game partition.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Reading game partition.");
|
2019-01-27 17:47:40 +00:00
|
|
|
|
DateTime timeSpeedStart = DateTime.UtcNow;
|
|
|
|
|
|
ulong sectorSpeedStart = 0;
|
2019-04-20 03:06:30 +01:00
|
|
|
|
InitProgress?.Invoke();
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
for(int e = 0; e <= 16; e++)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2017-06-20 05:48:09 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.NextBlock = currentSector;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Aborted!");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-06-20 05:48:09 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(currentSector >= blocks)
|
|
|
|
|
|
break;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
ulong extentStart, extentEnd;
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
// Extents
|
|
|
|
|
|
if(e < 16)
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(xboxSs.Value.Extents[e].StartPSN <= xboxSs.Value.Layer0EndPSN)
|
|
|
|
|
|
extentStart = xboxSs.Value.Extents[e].StartPSN - 0x30000;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
else
|
2019-12-25 18:07:05 +00:00
|
|
|
|
extentStart = ((xboxSs.Value.Layer0EndPSN + 1) * 2) -
|
2018-04-09 20:21:42 +01:00
|
|
|
|
((xboxSs.Value.Extents[e].StartPSN ^ 0xFFFFFF) + 1) - 0x30000;
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(xboxSs.Value.Extents[e].EndPSN <= xboxSs.Value.Layer0EndPSN)
|
|
|
|
|
|
extentEnd = xboxSs.Value.Extents[e].EndPSN - 0x30000;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
else
|
2019-12-25 18:07:05 +00:00
|
|
|
|
extentEnd = ((xboxSs.Value.Layer0EndPSN + 1) * 2) -
|
2018-04-09 20:21:42 +01:00
|
|
|
|
((xboxSs.Value.Extents[e].EndPSN ^ 0xFFFFFF) + 1) - 0x30000;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
// After last extent
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
extentStart = blocks;
|
2018-01-19 01:21:01 +00:00
|
|
|
|
extentEnd = blocks;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(currentSector > extentEnd)
|
|
|
|
|
|
continue;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
for(ulong i = currentSector; i < extentStart; i += blocksToRead)
|
|
|
|
|
|
{
|
|
|
|
|
|
saveBlocksToRead = blocksToRead;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2017-06-20 05:48:09 +01:00
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Aborted!");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
break;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
}
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(extentStart - i < blocksToRead)
|
|
|
|
|
|
blocksToRead = (uint)(extentStart - i);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2018-01-19 01:21:01 +00:00
|
|
|
|
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(currentSpeed > maxSpeed &&
|
|
|
|
|
|
currentSpeed != 0)
|
|
|
|
|
|
maxSpeed = currentSpeed;
|
|
|
|
|
|
|
|
|
|
|
|
if(currentSpeed < minSpeed &&
|
|
|
|
|
|
currentSpeed != 0)
|
|
|
|
|
|
minSpeed = currentSpeed;
|
2018-01-19 01:21:01 +00:00
|
|
|
|
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-20 23:05:49 +01:00
|
|
|
|
UpdateProgress?.Invoke($"Reading sector {i} of {totalSize} ({currentSpeed:F3} MiB/sec.)", (long)i,
|
2019-04-20 03:06:30 +01:00
|
|
|
|
(long)totalSize);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Read12(out readBuffer, out senseBuf, 0, false, false, false, false, (uint)i,
|
|
|
|
|
|
BLOCK_SIZE, 0, blocksToRead, false, _dev.Timeout, out cmdDuration);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
|
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(!sense &&
|
2019-12-25 18:07:05 +00:00
|
|
|
|
!_dev.Error)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
|
|
|
|
|
mhddLog.Write(i, cmdDuration);
|
|
|
|
|
|
ibgLog.Write(i, currentSpeed * 1024);
|
2018-02-02 15:32:53 +00:00
|
|
|
|
DateTime writeStart = DateTime.Now;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSectors(readBuffer, i, blocksToRead);
|
2018-02-02 15:32:53 +00:00
|
|
|
|
imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
extents.Add(i, blocksToRead, true);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// TODO: Reset device after X errors
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_stopOnError)
|
2019-11-16 19:15:51 +00:00
|
|
|
|
return; // TODO: Return more cleanly
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(i + _skip > blocks)
|
|
|
|
|
|
_skip = (uint)(blocks - i);
|
2018-04-09 20:21:42 +01:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
// Write empty data
|
2018-02-02 15:32:53 +00:00
|
|
|
|
DateTime writeStart = DateTime.Now;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSectors(new byte[BLOCK_SIZE * _skip], i, _skip);
|
2018-02-02 15:32:53 +00:00
|
|
|
|
imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
for(ulong b = i; b < i + _skip; b++)
|
|
|
|
|
|
_resume.BadBlocks.Add(b);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-23 17:41:23 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Dump-Media", "READ error:\n{0}", Sense.PrettifySense(senseBuf));
|
2017-12-21 23:00:30 +00:00
|
|
|
|
mhddLog.Write(i, cmdDuration < 500 ? 65535 : cmdDuration);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
ibgLog.Write(i, 0);
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Skipping {0} blocks from errored block {1}.", _skip, i);
|
|
|
|
|
|
i += _skip - blocksToRead;
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
string[] senseLines = Sense.PrettifySense(senseBuf).Split(new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
Environment.NewLine
|
|
|
|
|
|
}, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
|
|
|
|
|
|
foreach(string senseLine in senseLines)
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine(senseLine);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2018-04-10 02:39:41 +01:00
|
|
|
|
newTrim = true;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
blocksToRead = saveBlocksToRead;
|
|
|
|
|
|
currentSector = i + 1;
|
|
|
|
|
|
_resume.NextBlock = currentSector;
|
|
|
|
|
|
sectorSpeedStart += blocksToRead;
|
2019-01-27 17:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
double elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
if(elapsed < 1)
|
|
|
|
|
|
continue;
|
2019-01-27 17:47:40 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
currentSpeed = (sectorSpeedStart * BLOCK_SIZE) / (1048576 * elapsed);
|
2019-01-27 17:47:40 +00:00
|
|
|
|
sectorSpeedStart = 0;
|
|
|
|
|
|
timeSpeedStart = DateTime.UtcNow;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(ulong i = extentStart; i <= extentEnd; i += blocksToRead)
|
|
|
|
|
|
{
|
|
|
|
|
|
saveBlocksToRead = blocksToRead;
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2017-06-20 05:48:09 +01:00
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Aborted!");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
break;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
}
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(extentEnd - i < blocksToRead)
|
|
|
|
|
|
blocksToRead = (uint)(extentEnd - i) + 1;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
mhddLog.Write(i, cmdDuration);
|
|
|
|
|
|
ibgLog.Write(i, currentSpeed * 1024);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2018-01-19 01:21:01 +00:00
|
|
|
|
// Write empty data
|
2018-02-02 15:32:53 +00:00
|
|
|
|
DateTime writeStart = DateTime.Now;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSectors(new byte[BLOCK_SIZE * blocksToRead], i, blocksToRead);
|
2018-02-02 15:32:53 +00:00
|
|
|
|
imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
|
2018-02-02 18:44:28 +00:00
|
|
|
|
blocksToRead = saveBlocksToRead;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
extents.Add(i, blocksToRead, true);
|
2019-12-25 18:07:05 +00:00
|
|
|
|
currentSector = i + 1;
|
|
|
|
|
|
_resume.NextBlock = currentSector;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_aborted)
|
2019-11-16 19:15:51 +00:00
|
|
|
|
currentSector = extentEnd + 1;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
EndProgress?.Invoke();
|
|
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
// Middle Zone D
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Writing Middle Zone D (empty).");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Writing Middle Zone D (empty).");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
InitProgress?.Invoke();
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
|
for(ulong middle = currentSector - blocks - 1; middle < middleZone - 1; middle += blocksToRead)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2017-06-20 05:48:09 +01:00
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Aborted!");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
break;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
}
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(middleZone - 1 - middle < blocksToRead)
|
|
|
|
|
|
blocksToRead = (uint)(middleZone - 1 - middle);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-11-16 19:15:51 +00:00
|
|
|
|
UpdateProgress?.
|
|
|
|
|
|
Invoke($"Reading sector {middle + currentSector} of {totalSize} ({currentSpeed:F3} MiB/sec.)",
|
2019-04-20 23:05:49 +01:00
|
|
|
|
(long)(middle + currentSector), (long)totalSize);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
mhddLog.Write(middle + currentSector, cmdDuration);
|
2018-01-19 01:21:01 +00:00
|
|
|
|
ibgLog.Write(middle + currentSector, currentSpeed * 1024);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2018-01-19 01:21:01 +00:00
|
|
|
|
// Write empty data
|
2018-02-02 15:32:53 +00:00
|
|
|
|
DateTime writeStart = DateTime.Now;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSectors(new byte[BLOCK_SIZE * blocksToRead], middle + currentSector, blocksToRead);
|
|
|
|
|
|
imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
extents.Add(currentSector, blocksToRead, true);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
currentSector += blocksToRead;
|
|
|
|
|
|
_resume.NextBlock = currentSector;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
EndProgress?.Invoke();
|
|
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
blocksToRead = saveBlocksToRead;
|
|
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Locking drive.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Locking drive.");
|
|
|
|
|
|
sense = _dev.KreonLock(out senseBuf, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot lock drive, not continuing.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot lock drive, not continuing.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadCapacity(out readBuffer, out senseBuf, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot get disc capacity.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Video Layer 1
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Reading Video Layer 1.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Reading Video Layer 1.");
|
|
|
|
|
|
InitProgress?.Invoke();
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
for(ulong l1 = (currentSector - blocks - middleZone) + l0Video; l1 < l0Video + l1Video; l1 += blocksToRead)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2017-06-20 05:48:09 +01:00
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Aborted!");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
break;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
}
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if((l0Video + l1Video) - l1 < blocksToRead)
|
|
|
|
|
|
blocksToRead = (uint)((l0Video + l1Video) - l1);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2018-01-19 01:21:01 +00:00
|
|
|
|
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(currentSpeed > maxSpeed &&
|
|
|
|
|
|
currentSpeed != 0)
|
|
|
|
|
|
maxSpeed = currentSpeed;
|
|
|
|
|
|
|
|
|
|
|
|
if(currentSpeed < minSpeed &&
|
|
|
|
|
|
currentSpeed != 0)
|
|
|
|
|
|
minSpeed = currentSpeed;
|
2018-01-19 01:21:01 +00:00
|
|
|
|
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-20 23:05:49 +01:00
|
|
|
|
UpdateProgress?.Invoke($"Reading sector {currentSector} of {totalSize} ({currentSpeed:F3} MiB/sec.)",
|
2019-04-20 03:06:30 +01:00
|
|
|
|
(long)currentSector, (long)totalSize);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Read12(out readBuffer, out senseBuf, 0, false, false, false, false, (uint)l1, BLOCK_SIZE,
|
|
|
|
|
|
0, blocksToRead, false, _dev.Timeout, out cmdDuration);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
|
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(!sense &&
|
2019-12-25 18:07:05 +00:00
|
|
|
|
!_dev.Error)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
|
|
|
|
|
mhddLog.Write(currentSector, cmdDuration);
|
|
|
|
|
|
ibgLog.Write(currentSector, currentSpeed * 1024);
|
2018-02-02 15:32:53 +00:00
|
|
|
|
DateTime writeStart = DateTime.Now;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSectors(readBuffer, currentSector, blocksToRead);
|
2018-02-02 15:32:53 +00:00
|
|
|
|
imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
extents.Add(currentSector, blocksToRead, true);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// TODO: Reset device after X errors
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_stopOnError)
|
2019-11-16 19:15:51 +00:00
|
|
|
|
return; // TODO: Return more cleanly
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
// Write empty data
|
2018-02-02 15:32:53 +00:00
|
|
|
|
DateTime writeStart = DateTime.Now;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSectors(new byte[BLOCK_SIZE * _skip], currentSector, _skip);
|
2018-02-02 15:32:53 +00:00
|
|
|
|
imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
// TODO: Handle errors in video partition
|
|
|
|
|
|
//errored += blocksToRead;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
//resume.BadBlocks.Add(l1);
|
2017-12-23 17:41:23 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Dump-Media", "READ error:\n{0}", Sense.PrettifySense(senseBuf));
|
2017-12-21 23:00:30 +00:00
|
|
|
|
mhddLog.Write(l1, cmdDuration < 500 ? 65535 : cmdDuration);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
ibgLog.Write(l1, 0);
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Skipping {0} blocks from errored block {1}.", _skip, l1);
|
|
|
|
|
|
l1 += _skip - blocksToRead;
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
string[] senseLines = Sense.PrettifySense(senseBuf).Split(new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
Environment.NewLine
|
|
|
|
|
|
}, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
|
|
|
|
|
|
foreach(string senseLine in senseLines)
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine(senseLine);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
currentSector += blocksToRead;
|
|
|
|
|
|
_resume.NextBlock = currentSector;
|
|
|
|
|
|
sectorSpeedStart += blocksToRead;
|
2019-01-27 17:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
double elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
if(elapsed < 1)
|
|
|
|
|
|
continue;
|
2019-01-27 17:47:40 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
currentSpeed = (sectorSpeedStart * BLOCK_SIZE) / (1048576 * elapsed);
|
2019-01-27 17:47:40 +00:00
|
|
|
|
sectorSpeedStart = 0;
|
|
|
|
|
|
timeSpeedStart = DateTime.UtcNow;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
EndProgress?.Invoke();
|
|
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.Invoke("Unlocking drive (Wxripper).");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Unlocking drive (Wxripper).");
|
|
|
|
|
|
sense = _dev.KreonUnlockWxripper(out senseBuf, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot unlock drive, not continuing.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot unlock drive, not continuing.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadCapacity(out readBuffer, out senseBuf, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-04-20 03:06:30 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot get disc capacity.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
end = DateTime.UtcNow;
|
|
|
|
|
|
DicConsole.WriteLine();
|
|
|
|
|
|
mhddLog.Close();
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ibgLog.Close(_dev, blocks, BLOCK_SIZE, (end - start).TotalSeconds, currentSpeed * 1024,
|
|
|
|
|
|
(BLOCK_SIZE * (double)(blocks + 1)) / 1024 / (totalDuration / 1000),
|
|
|
|
|
|
_devicePath);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Dump finished in {(end - start).TotalSeconds} seconds.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.
|
2019-12-25 18:07:05 +00:00
|
|
|
|
Invoke($"Average dump speed {((double)BLOCK_SIZE * (double)(blocks + 1)) / 1024 / (totalDuration / 1000):F3} KiB/sec.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.
|
2019-12-25 18:07:05 +00:00
|
|
|
|
Invoke($"Average write speed {((double)BLOCK_SIZE * (double)(blocks + 1)) / 1024 / imageWriteDuration:F3} KiB/sec.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Dump finished in {0} seconds.", (end - start).TotalSeconds);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Average dump speed {0:F3} KiB/sec.",
|
|
|
|
|
|
((double)BLOCK_SIZE * (double)(blocks + 1)) / 1024 / (totalDuration / 1000));
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Average write speed {0:F3} KiB/sec.",
|
|
|
|
|
|
((double)BLOCK_SIZE * (double)(blocks + 1)) / 1024 / imageWriteDuration);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2018-04-10 02:39:41 +01:00
|
|
|
|
#region Trimming
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_resume.BadBlocks.Count > 0 &&
|
|
|
|
|
|
!_aborted &&
|
|
|
|
|
|
!_notrim &&
|
2019-11-16 19:15:51 +00:00
|
|
|
|
newTrim)
|
2018-04-10 02:39:41 +01:00
|
|
|
|
{
|
|
|
|
|
|
start = DateTime.UtcNow;
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Trimming bad sectors");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Trimming bad sectors");
|
2018-04-10 02:39:41 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ulong[] tmpArray = _resume.BadBlocks.ToArray();
|
2019-04-20 03:06:30 +01:00
|
|
|
|
InitProgress?.Invoke();
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2018-04-10 02:39:41 +01:00
|
|
|
|
foreach(ulong badSector in tmpArray)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2018-04-10 02:39:41 +01:00
|
|
|
|
{
|
|
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2018-04-10 02:39:41 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-20 23:05:49 +01:00
|
|
|
|
PulseProgress?.Invoke($"Trimming sector {badSector}");
|
2018-04-10 02:39:41 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Read12(out readBuffer, out senseBuf, 0, false, false, false, false, (uint)badSector,
|
|
|
|
|
|
BLOCK_SIZE, 0, 1, false, _dev.Timeout, out cmdDuration);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2018-04-10 02:39:41 +01:00
|
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(sense || _dev.Error)
|
2019-11-16 19:15:51 +00:00
|
|
|
|
continue;
|
2018-04-10 02:39:41 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.BadBlocks.Remove(badSector);
|
2018-04-10 02:39:41 +01:00
|
|
|
|
extents.Add(badSector);
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSector(readBuffer, badSector);
|
2018-04-10 02:39:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
EndProgress?.Invoke();
|
2018-04-10 02:39:41 +01:00
|
|
|
|
end = DateTime.UtcNow;
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Trimmming finished in {(end - start).TotalSeconds} seconds.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Trimmming finished in {0} seconds.", (end - start).TotalSeconds);
|
2018-04-10 02:39:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
#endregion Trimming
|
|
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
#region Error handling
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_resume.BadBlocks.Count > 0 &&
|
|
|
|
|
|
!_aborted &&
|
|
|
|
|
|
_retryPasses > 0)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
|
|
|
|
|
List<ulong> tmpList = new List<ulong>();
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
foreach(ulong ur in _resume.BadBlocks)
|
2018-01-19 01:21:01 +00:00
|
|
|
|
for(ulong i = ur; i < ur + blocksToRead; i++)
|
|
|
|
|
|
tmpList.Add(i);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
tmpList.Sort();
|
|
|
|
|
|
|
2018-04-10 02:47:08 +01:00
|
|
|
|
int pass = 1;
|
2018-01-19 01:21:01 +00:00
|
|
|
|
bool forward = true;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
bool runningPersistent = false;
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.BadBlocks = tmpList;
|
2018-04-10 03:37:52 +01:00
|
|
|
|
Modes.ModePage? currentModePage = null;
|
|
|
|
|
|
byte[] md6;
|
|
|
|
|
|
byte[] md10;
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_persistent)
|
2018-04-10 03:37:52 +01:00
|
|
|
|
{
|
|
|
|
|
|
Modes.ModePage_01_MMC pgMmc;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ModeSense6(out readBuffer, out _, false, ScsiModeSensePageControl.Current, 0x01,
|
|
|
|
|
|
_dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2018-04-10 03:37:52 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ModeSense10(out readBuffer, out _, false, ScsiModeSensePageControl.Current, 0x01,
|
|
|
|
|
|
_dev.Timeout, out _);
|
2018-04-10 03:37:52 +01:00
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
|
{
|
|
|
|
|
|
Modes.DecodedMode? dcMode10 =
|
|
|
|
|
|
Modes.DecodeMode10(readBuffer, PeripheralDeviceTypes.MultiMediaDevice);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
|
2018-04-10 03:37:52 +01:00
|
|
|
|
if(dcMode10.HasValue)
|
|
|
|
|
|
foreach(Modes.ModePage modePage in dcMode10.Value.Pages)
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(modePage.Page == 0x01 &&
|
|
|
|
|
|
modePage.Subpage == 0x00)
|
2018-06-22 08:08:38 +01:00
|
|
|
|
currentModePage = modePage;
|
2018-04-10 03:37:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Modes.DecodedMode? dcMode6 =
|
|
|
|
|
|
Modes.DecodeMode6(readBuffer, PeripheralDeviceTypes.MultiMediaDevice);
|
|
|
|
|
|
|
|
|
|
|
|
if(dcMode6.HasValue)
|
|
|
|
|
|
foreach(Modes.ModePage modePage in dcMode6.Value.Pages)
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(modePage.Page == 0x01 &&
|
|
|
|
|
|
modePage.Subpage == 0x00)
|
2018-04-10 03:37:52 +01:00
|
|
|
|
currentModePage = modePage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(currentModePage == null)
|
|
|
|
|
|
{
|
2019-11-16 19:15:51 +00:00
|
|
|
|
pgMmc = new Modes.ModePage_01_MMC
|
|
|
|
|
|
{
|
|
|
|
|
|
PS = false, ReadRetryCount = 0x20, Parameter = 0x00
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-04-10 03:37:52 +01:00
|
|
|
|
currentModePage = new Modes.ModePage
|
|
|
|
|
|
{
|
2018-12-31 13:17:27 +00:00
|
|
|
|
Page = 0x01, Subpage = 0x00, PageResponse = Modes.EncodeModePage_01_MMC(pgMmc)
|
2018-04-10 03:37:52 +01:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2018-06-22 08:08:38 +01:00
|
|
|
|
|
2019-11-16 19:15:51 +00:00
|
|
|
|
pgMmc = new Modes.ModePage_01_MMC
|
2018-04-10 03:37:52 +01:00
|
|
|
|
{
|
2019-11-16 19:15:51 +00:00
|
|
|
|
PS = false, ReadRetryCount = 255, Parameter = 0x20
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var md = new Modes.DecodedMode
|
|
|
|
|
|
{
|
|
|
|
|
|
Header = new Modes.ModeHeader(), Pages = new[]
|
2018-04-10 03:37:52 +01:00
|
|
|
|
{
|
|
|
|
|
|
new Modes.ModePage
|
|
|
|
|
|
{
|
2019-11-16 19:15:51 +00:00
|
|
|
|
Page = 0x01, Subpage = 0x00, PageResponse = Modes.EncodeModePage_01_MMC(pgMmc)
|
2018-04-10 03:37:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
md6 = Modes.EncodeMode6(md, _dev.ScsiType);
|
|
|
|
|
|
md10 = Modes.EncodeMode10(md, _dev.ScsiType);
|
2018-04-10 03:37:52 +01:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Sending MODE SELECT to drive (return damaged blocks).");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Sending MODE SELECT to drive (return damaged blocks).");
|
|
|
|
|
|
sense = _dev.ModeSelect(md6, out senseBuf, true, false, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
if(sense)
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ModeSelect10(md10, out senseBuf, true, false, _dev.Timeout, out _);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2018-04-10 03:37:52 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-11-16 19:15:51 +00:00
|
|
|
|
UpdateStatus?.
|
|
|
|
|
|
Invoke("Drive did not accept MODE SELECT command for persistent error reading, try another drive.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
|
2018-04-10 03:37:52 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Error: {0}", Sense.PrettifySense(senseBuf));
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.
|
2019-11-16 19:15:51 +00:00
|
|
|
|
WriteLine("Drive did not accept MODE SELECT command for persistent error reading, try another drive.");
|
2018-04-10 03:37:52 +01:00
|
|
|
|
}
|
2019-11-16 19:15:51 +00:00
|
|
|
|
else
|
|
|
|
|
|
runningPersistent = true;
|
2018-04-10 03:37:52 +01:00
|
|
|
|
}
|
2018-06-22 08:08:38 +01:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
InitProgress?.Invoke();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
repeatRetry:
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ulong[] tmpArray = _resume.BadBlocks.ToArray();
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
foreach(ulong badSector in tmpArray)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2017-06-20 05:48:09 +01:00
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Aborted!");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
break;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
}
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-20 23:05:49 +01:00
|
|
|
|
PulseProgress?.Invoke(string.Format("Retrying sector {0}, pass {1}, {3}{2}", badSector, pass,
|
2019-04-20 03:06:30 +01:00
|
|
|
|
forward ? "forward" : "reverse",
|
|
|
|
|
|
runningPersistent ? "recovering partial data, " : ""));
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Read12(out readBuffer, out senseBuf, 0, false, false, false, false, (uint)badSector,
|
|
|
|
|
|
BLOCK_SIZE, 0, 1, false, _dev.Timeout, out cmdDuration);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
|
|
2019-11-16 19:15:51 +00:00
|
|
|
|
if(!sense &&
|
2019-12-25 18:07:05 +00:00
|
|
|
|
!_dev.Error)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.BadBlocks.Remove(badSector);
|
2017-06-20 05:48:09 +01:00
|
|
|
|
extents.Add(badSector);
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSector(readBuffer, badSector);
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Correctly retried block {badSector} in pass {pass}.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Correctly retried block {0} in pass {1}.", badSector, pass);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
2019-11-16 19:15:51 +00:00
|
|
|
|
else if(runningPersistent)
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSector(readBuffer, badSector);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(pass < _retryPasses &&
|
|
|
|
|
|
!_aborted &&
|
|
|
|
|
|
_resume.BadBlocks.Count > 0)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
|
|
|
|
|
pass++;
|
|
|
|
|
|
forward = !forward;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.BadBlocks.Sort();
|
|
|
|
|
|
_resume.BadBlocks.Reverse();
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
goto repeatRetry;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-10 03:37:52 +01:00
|
|
|
|
if(runningPersistent && currentModePage.HasValue)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-11-16 19:15:51 +00:00
|
|
|
|
var md = new Modes.DecodedMode
|
2017-06-08 21:12:05 +01:00
|
|
|
|
{
|
2019-11-16 19:15:51 +00:00
|
|
|
|
Header = new Modes.ModeHeader(), Pages = new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
currentModePage.Value
|
|
|
|
|
|
}
|
2017-06-08 21:12:05 +01:00
|
|
|
|
};
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
md6 = Modes.EncodeMode6(md, _dev.ScsiType);
|
|
|
|
|
|
md10 = Modes.EncodeMode10(md, _dev.ScsiType);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Sending MODE SELECT to drive (return device to previous status).");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Sending MODE SELECT to drive (return device to previous status).");
|
|
|
|
|
|
sense = _dev.ModeSelect(md6, out senseBuf, true, false, _dev.Timeout, out _);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
if(sense)
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dev.ModeSelect10(md10, out senseBuf, true, false, _dev.Timeout, out _);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
EndProgress?.Invoke();
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
#endregion Error handling
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.BadBlocks.Sort();
|
2017-12-21 14:30:38 +00:00
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2018-01-19 01:21:01 +00:00
|
|
|
|
foreach(KeyValuePair<MediaTagType, byte[]> tag in mediaTags)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-08-10 14:35:14 +01:00
|
|
|
|
if(tag.Value is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error: Tag type {0} is null, skipping...", tag.Key);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-08-10 14:35:14 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ret = _outputPlugin.WriteMediaTag(tag.Value, tag.Key);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(ret || _force)
|
2019-11-16 19:15:51 +00:00
|
|
|
|
continue;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2018-01-19 01:21:01 +00:00
|
|
|
|
// Cannot write tag to image
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine($"Cannot write tag {tag.Key}.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-04-20 14:02:25 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke($"Cannot write tag {tag.Key}." + Environment.NewLine +
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.ErrorMessage);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-04-20 14:02:25 +01:00
|
|
|
|
return;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.BadBlocks.Sort();
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
foreach(ulong bad in _resume.BadBlocks)
|
|
|
|
|
|
_dumpLog.WriteLine("Sector {0} could not be read.", bad);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2018-02-01 01:20:41 +00:00
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.SetDumpHardware(_resume.Tries);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_preSidecar != null)
|
|
|
|
|
|
_outputPlugin.SetCicmMetadata(_preSidecar);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Closing output file.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Closing output file.");
|
2018-02-02 15:32:53 +00:00
|
|
|
|
DateTime closeStart = DateTime.Now;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.Close();
|
2018-02-02 15:32:53 +00:00
|
|
|
|
DateTime closeEnd = DateTime.Now;
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Closed in {(closeEnd - closeStart).TotalSeconds} seconds.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Closed in {0} seconds.", (closeEnd - closeStart).TotalSeconds);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Aborted!");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-02 22:03:19 +00:00
|
|
|
|
double totalChkDuration = 0;
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_nometadata)
|
2018-01-28 21:18:52 +00:00
|
|
|
|
{
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Creating sidecar.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Creating sidecar.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
var filters = new FiltersList();
|
2019-12-25 18:07:05 +00:00
|
|
|
|
IFilter filter = filters.GetFilter(_outputPath);
|
2018-02-02 22:03:19 +00:00
|
|
|
|
IMediaImage inputPlugin = ImageFormat.Detect(filter);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-04-20 14:02:25 +01:00
|
|
|
|
if(!inputPlugin.Open(filter))
|
|
|
|
|
|
{
|
|
|
|
|
|
StoppingErrorMessage?.Invoke("Could not open created image.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-04-20 14:02:25 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2018-01-28 21:18:52 +00:00
|
|
|
|
|
2019-04-20 18:11:02 +01:00
|
|
|
|
DateTime chkStart = DateTime.UtcNow;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_sidecarClass = new Sidecar(inputPlugin, _outputPath, filter.Id, _encoding);
|
|
|
|
|
|
_sidecarClass.InitProgressEvent += InitProgress;
|
|
|
|
|
|
_sidecarClass.UpdateProgressEvent += UpdateProgress;
|
|
|
|
|
|
_sidecarClass.EndProgressEvent += EndProgress;
|
|
|
|
|
|
_sidecarClass.InitProgressEvent2 += InitProgress2;
|
|
|
|
|
|
_sidecarClass.UpdateProgressEvent2 += UpdateProgress2;
|
|
|
|
|
|
_sidecarClass.EndProgressEvent2 += EndProgress2;
|
|
|
|
|
|
_sidecarClass.UpdateStatusEvent += UpdateStatus;
|
|
|
|
|
|
CICMMetadataType sidecar = _sidecarClass.Create();
|
2018-04-09 20:21:42 +01:00
|
|
|
|
end = DateTime.UtcNow;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_preSidecar != null)
|
2018-02-02 22:03:19 +00:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_preSidecar.OpticalDisc = sidecar.OpticalDisc;
|
|
|
|
|
|
sidecar = _preSidecar;
|
2018-02-02 22:03:19 +00:00
|
|
|
|
}
|
2017-06-20 05:48:09 +01:00
|
|
|
|
|
2018-04-09 20:21:42 +01:00
|
|
|
|
totalChkDuration = (end - chkStart).TotalMilliseconds;
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Sidecar created in {(end - chkStart).TotalSeconds} seconds.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.
|
2019-12-25 18:07:05 +00:00
|
|
|
|
Invoke($"Average checksum speed {((double)BLOCK_SIZE * (double)(blocks + 1)) / 1024 / (totalChkDuration / 1000):F3} KiB/sec.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Sidecar created in {0} seconds.", (end - chkStart).TotalSeconds);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Average checksum speed {0:F3} KiB/sec.",
|
|
|
|
|
|
((double)BLOCK_SIZE * (double)(blocks + 1)) / 1024 / (totalChkDuration / 1000));
|
2018-02-02 22:03:19 +00:00
|
|
|
|
|
|
|
|
|
|
foreach(KeyValuePair<MediaTagType, byte[]> tag in mediaTags)
|
2019-12-25 18:07:05 +00:00
|
|
|
|
AddMediaTagToSidecar(_outputPath, tag, ref sidecar);
|
2018-01-19 01:21:01 +00:00
|
|
|
|
|
2018-02-02 22:03:19 +00:00
|
|
|
|
List<(ulong start, string type)> filesystems = new List<(ulong start, string type)>();
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2018-02-02 22:03:19 +00:00
|
|
|
|
if(sidecar.OpticalDisc[0].Track != null)
|
|
|
|
|
|
filesystems.AddRange(from xmlTrack in sidecar.OpticalDisc[0].Track
|
|
|
|
|
|
where xmlTrack.FileSystemInformation != null
|
|
|
|
|
|
from partition in xmlTrack.FileSystemInformation
|
2019-11-16 19:15:51 +00:00
|
|
|
|
where partition.FileSystems != null from fileSystem in partition.FileSystems
|
2019-04-23 01:38:33 +01:00
|
|
|
|
select (partition.StartSector, fileSystem.Type));
|
2018-02-02 22:03:19 +00:00
|
|
|
|
|
|
|
|
|
|
if(filesystems.Count > 0)
|
2019-11-16 19:15:51 +00:00
|
|
|
|
foreach(var filesystem in filesystems.Select(o => new
|
|
|
|
|
|
{
|
|
|
|
|
|
o.start, o.type
|
|
|
|
|
|
}).Distinct())
|
2019-04-20 03:06:30 +01:00
|
|
|
|
{
|
|
|
|
|
|
UpdateStatus?.Invoke($"Found filesystem {filesystem.type} at sector {filesystem.start}");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Found filesystem {0} at sector {1}", filesystem.type, filesystem.start);
|
2019-04-20 03:06:30 +01:00
|
|
|
|
}
|
2018-02-02 22:03:19 +00:00
|
|
|
|
|
|
|
|
|
|
sidecar.OpticalDisc[0].Layers = new LayersType
|
|
|
|
|
|
{
|
2018-12-31 13:17:27 +00:00
|
|
|
|
type = LayersTypeType.OTP, typeSpecified = true, Sectors = new SectorsType[1]
|
2018-02-02 22:03:19 +00:00
|
|
|
|
};
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
sidecar.OpticalDisc[0].Layers.Sectors[0] = new SectorsType
|
|
|
|
|
|
{
|
|
|
|
|
|
Value = layerBreak
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
sidecar.OpticalDisc[0].Sessions = 1;
|
|
|
|
|
|
sidecar.OpticalDisc[0].Dimensions = Dimensions.DimensionsFromMediaType(dskType);
|
|
|
|
|
|
|
2019-11-18 20:59:16 +00:00
|
|
|
|
(string type, string subType) xmlType = CommonTypes.Metadata.MediaType.MediaTypeToString(dskType);
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-11-18 20:59:16 +00:00
|
|
|
|
sidecar.OpticalDisc[0].DiscType = xmlType.type;
|
|
|
|
|
|
sidecar.OpticalDisc[0].DiscSubType = xmlType.subType;
|
2018-02-02 22:03:19 +00:00
|
|
|
|
|
|
|
|
|
|
foreach(KeyValuePair<MediaTagType, byte[]> tag in mediaTags)
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_outputPlugin.SupportedMediaTags.Contains(tag.Key))
|
|
|
|
|
|
AddMediaTagToSidecar(_outputPath, tag, ref sidecar);
|
2018-02-02 22:03:19 +00:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("Writing metadata sidecar");
|
2018-02-02 22:03:19 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
var xmlFs = new FileStream(_outputPrefix + ".cicm.xml", FileMode.Create);
|
2018-02-02 22:03:19 +00:00
|
|
|
|
|
2019-11-16 19:15:51 +00:00
|
|
|
|
var xmlSer = new XmlSerializer(typeof(CICMMetadataType));
|
2018-02-02 22:03:19 +00:00
|
|
|
|
xmlSer.Serialize(xmlFs, sidecar);
|
|
|
|
|
|
xmlFs.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.
|
|
|
|
|
|
Invoke($"Took a total of {(end - start).TotalSeconds:F3} seconds ({totalDuration / 1000:F3} processing commands, {totalChkDuration / 1000:F3} checksumming, {imageWriteDuration:F3} writing, {(closeEnd - closeStart).TotalSeconds:F3} closing).");
|
|
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.
|
2019-12-25 18:07:05 +00:00
|
|
|
|
Invoke($"Average speed: {((double)BLOCK_SIZE * (double)(blocks + 1)) / 1048576 / (totalDuration / 1000):F3} MiB/sec.");
|
2019-11-16 19:15:51 +00:00
|
|
|
|
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Fastest speed burst: {maxSpeed:F3} MiB/sec.");
|
|
|
|
|
|
UpdateStatus?.Invoke($"Slowest speed burst: {minSpeed:F3} MiB/sec.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
UpdateStatus?.Invoke($"{_resume.BadBlocks.Count} sectors could not be read.");
|
2019-04-20 03:06:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("");
|
2018-02-02 15:32:53 +00:00
|
|
|
|
|
2017-06-20 05:48:09 +01:00
|
|
|
|
Statistics.AddMedia(dskType, true);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|