2017-05-27 20:24:06 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Sidecar.cs
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-05-27 20:24:06 +01:00
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Core algorithms.
|
2017-05-27 20:24:06 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Creates sidecar from dump.
|
2017-05-27 20:24:06 +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-05-27 20:24:06 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 03:50:57 +00:00
|
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using System;
|
2017-05-27 20:24:06 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using System.Text;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
using DiscImageChef.DiscImages;
|
2017-05-27 20:24:06 +01:00
|
|
|
|
using Schemas;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Core
|
|
|
|
|
|
{
|
2017-08-08 12:15:55 +01:00
|
|
|
|
public static partial class Sidecar
|
2017-05-27 20:24:06 +01:00
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
public static CICMMetadataType Create(ImagePlugin image, string imagePath, Guid filterId,
|
|
|
|
|
|
Encoding encoding)
|
2017-05-27 20:24:06 +01:00
|
|
|
|
{
|
|
|
|
|
|
CICMMetadataType sidecar = new CICMMetadataType();
|
|
|
|
|
|
PluginBase plugins = new PluginBase();
|
2017-10-12 23:54:02 +01:00
|
|
|
|
plugins.RegisterAllPlugins(encoding);
|
2017-05-27 20:24:06 +01:00
|
|
|
|
|
|
|
|
|
|
FileInfo fi = new FileInfo(imagePath);
|
|
|
|
|
|
FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
|
|
|
|
|
|
|
|
|
|
|
|
Checksum imgChkWorker = new Checksum();
|
|
|
|
|
|
|
|
|
|
|
|
// For fast debugging, skip checksum
|
|
|
|
|
|
//goto skipImageChecksum;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] data;
|
|
|
|
|
|
long position = 0;
|
2017-05-28 00:31:46 +01:00
|
|
|
|
InitProgress();
|
2017-12-20 17:26:28 +00:00
|
|
|
|
while(position < fi.Length - 1048576)
|
2017-05-27 20:24:06 +01:00
|
|
|
|
{
|
|
|
|
|
|
data = new byte[1048576];
|
|
|
|
|
|
fs.Read(data, 0, 1048576);
|
|
|
|
|
|
|
2017-05-28 00:31:46 +01:00
|
|
|
|
UpdateProgress("Hashing image file byte {0} of {1}", position, fi.Length);
|
2017-05-27 20:24:06 +01:00
|
|
|
|
|
|
|
|
|
|
imgChkWorker.Update(data);
|
|
|
|
|
|
|
|
|
|
|
|
position += 1048576;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data = new byte[fi.Length - position];
|
|
|
|
|
|
fs.Read(data, 0, (int)(fi.Length - position));
|
|
|
|
|
|
|
2017-05-28 00:31:46 +01:00
|
|
|
|
UpdateProgress("Hashing image file byte {0} of {1}", position, fi.Length);
|
2017-05-27 20:24:06 +01:00
|
|
|
|
|
|
|
|
|
|
imgChkWorker.Update(data);
|
|
|
|
|
|
|
|
|
|
|
|
// For fast debugging, skip checksum
|
|
|
|
|
|
//skipImageChecksum:
|
|
|
|
|
|
|
2017-05-28 00:31:46 +01:00
|
|
|
|
EndProgress();
|
2017-05-27 20:24:06 +01:00
|
|
|
|
fs.Close();
|
|
|
|
|
|
|
|
|
|
|
|
List<ChecksumType> imgChecksums = imgChkWorker.End();
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
switch(image.ImageInfo.XmlMediaType)
|
2017-05-27 20:24:06 +01:00
|
|
|
|
{
|
|
|
|
|
|
case XmlMediaType.OpticalDisc:
|
2017-08-08 13:40:32 +01:00
|
|
|
|
OpticalDisc(image, filterId, imagePath, fi, plugins, imgChecksums, ref sidecar);
|
|
|
|
|
|
break;
|
2017-05-27 20:24:06 +01:00
|
|
|
|
case XmlMediaType.BlockMedia:
|
2017-08-08 13:40:32 +01:00
|
|
|
|
BlockMedia(image, filterId, imagePath, fi, plugins, imgChecksums, ref sidecar);
|
|
|
|
|
|
break;
|
2017-05-27 20:24:06 +01:00
|
|
|
|
case XmlMediaType.LinearMedia:
|
2017-08-08 13:40:32 +01:00
|
|
|
|
LinearMedia(image, filterId, imagePath, fi, plugins, imgChecksums, ref sidecar);
|
|
|
|
|
|
break;
|
2017-05-27 20:24:06 +01:00
|
|
|
|
case XmlMediaType.AudioMedia:
|
2017-08-08 13:40:32 +01:00
|
|
|
|
AudioMedia(image, filterId, imagePath, fi, plugins, imgChecksums, ref sidecar);
|
|
|
|
|
|
break;
|
2017-05-27 20:24:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return sidecar;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|