2017-06-12 22:59:47 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : ResumeSupport.cs
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-06-12 22:59:47 +01:00
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Core algorithms.
|
2017-06-12 22:59:47 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Contains logic to support dump resuming.
|
2017-06-12 22:59:47 +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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2017-06-12 22:59:47 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 03:50:57 +00:00
|
|
|
|
|
|
|
|
|
|
using System;
|
2017-06-20 05:48:09 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using DiscImageChef.Metadata;
|
|
|
|
|
|
using Extents;
|
|
|
|
|
|
using Schemas;
|
|
|
|
|
|
|
2017-06-12 22:59:47 +01:00
|
|
|
|
namespace DiscImageChef.Core.Devices.Dumping
|
|
|
|
|
|
{
|
2017-12-20 02:08:37 +00:00
|
|
|
|
static class ResumeSupport
|
2017-06-12 22:59:47 +01:00
|
|
|
|
{
|
2017-12-20 02:08:37 +00:00
|
|
|
|
internal static void Process(bool isLba, bool removable, ulong blocks, string Manufacturer, string Model,
|
2017-12-19 20:33:03 +00:00
|
|
|
|
string Serial, Interop.PlatformID platform, ref Resume resume,
|
|
|
|
|
|
ref DumpHardwareType currentTry, ref ExtentsULong extents)
|
2017-06-12 22:59:47 +01:00
|
|
|
|
{
|
2017-06-20 05:48:09 +01:00
|
|
|
|
if(resume != null)
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(!isLba) throw new NotImplementedException("Resuming CHS devices is currently not supported.");
|
2017-06-20 05:48:09 +01:00
|
|
|
|
|
|
|
|
|
|
if(resume.Removable != removable)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
|
|
|
|
|
Exception(string.Format("Resume file specifies a {0} device but you're requesting to dump a {1} device, not continuing...",
|
|
|
|
|
|
resume.Removable ? "removable" : "non removable",
|
|
|
|
|
|
removable ? "removable" : "non removable"));
|
2017-06-20 05:48:09 +01:00
|
|
|
|
|
|
|
|
|
|
if(resume.LastBlock != blocks - 1)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
|
|
|
|
|
Exception(string.Format("Resume file specifies a device with {0} blocks but you're requesting to dump one with {1} blocks, not continuing...",
|
|
|
|
|
|
resume.LastBlock + 1, blocks));
|
2017-06-20 05:48:09 +01:00
|
|
|
|
|
|
|
|
|
|
foreach(DumpHardwareType oldtry in resume.Tries)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(oldtry.Manufacturer != Manufacturer && !removable)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
|
|
|
|
|
Exception(string.Format("Resume file specifies a device manufactured by {0} but you're requesting to dump one by {1}, not continuing...",
|
|
|
|
|
|
oldtry.Manufacturer, Manufacturer));
|
2017-06-20 05:48:09 +01:00
|
|
|
|
|
|
|
|
|
|
if(oldtry.Model != Model && !removable)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
|
|
|
|
|
Exception(string.Format("Resume file specifies a device model {0} but you're requesting to dump model {1}, not continuing...",
|
|
|
|
|
|
oldtry.Model, Model));
|
2017-06-20 05:48:09 +01:00
|
|
|
|
|
|
|
|
|
|
if(oldtry.Serial != Serial && !removable)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
|
|
|
|
|
Exception(string.Format("Resume file specifies a device with serial {0} but you're requesting to dump one with serial {1}, not continuing...",
|
|
|
|
|
|
oldtry.Serial, Serial));
|
2017-06-20 05:48:09 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(oldtry.Software == null) throw new Exception("Found corrupt resume file, cannot continue...");
|
2017-06-20 05:48:09 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(oldtry.Software.Name == "DiscImageChef" &&
|
|
|
|
|
|
oldtry.Software.OperatingSystem == platform.ToString() &&
|
|
|
|
|
|
oldtry.Software.Version == Version.GetVersion())
|
2017-06-20 05:48:09 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(removable && (oldtry.Manufacturer != Manufacturer || oldtry.Model != Model ||
|
|
|
|
|
|
oldtry.Serial != Serial)) continue;
|
|
|
|
|
|
|
2017-06-20 05:48:09 +01:00
|
|
|
|
currentTry = oldtry;
|
|
|
|
|
|
extents = ExtentsConverter.FromMetadata(currentTry.Extents);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(currentTry == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentTry = new DumpHardwareType
|
|
|
|
|
|
{
|
|
|
|
|
|
Software = Version.GetSoftwareType(platform),
|
|
|
|
|
|
Manufacturer = Manufacturer,
|
|
|
|
|
|
Model = Model,
|
|
|
|
|
|
Serial = Serial,
|
|
|
|
|
|
};
|
|
|
|
|
|
resume.Tries.Add(currentTry);
|
|
|
|
|
|
extents = new ExtentsULong();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
resume = new Resume
|
|
|
|
|
|
{
|
|
|
|
|
|
Tries = new List<DumpHardwareType>(),
|
|
|
|
|
|
CreationDate = DateTime.UtcNow,
|
|
|
|
|
|
BadBlocks = new List<ulong>(),
|
|
|
|
|
|
LastBlock = blocks - 1
|
|
|
|
|
|
};
|
|
|
|
|
|
currentTry = new DumpHardwareType
|
|
|
|
|
|
{
|
|
|
|
|
|
Software = Version.GetSoftwareType(platform),
|
|
|
|
|
|
Manufacturer = Manufacturer,
|
|
|
|
|
|
Model = Model,
|
|
|
|
|
|
Serial = Serial
|
|
|
|
|
|
};
|
|
|
|
|
|
resume.Tries.Add(currentTry);
|
|
|
|
|
|
extents = new ExtentsULong();
|
|
|
|
|
|
resume.Removable = removable;
|
|
|
|
|
|
}
|
2017-06-12 22:59:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|