2017-05-27 20:24:06 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Sidecar.cs
|
|
|
|
|
|
// Version : 1.0
|
|
|
|
|
|
// Author(s) : Natalia Portillo
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Component
|
|
|
|
|
|
//
|
|
|
|
|
|
// Revision : $Revision$
|
|
|
|
|
|
// Last change by : $Author$
|
|
|
|
|
|
// Date : $Date$
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Description
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
// Copyright (C) 2011-2015 Claunia.com
|
|
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
// //$Id$
|
2017-08-08 14:18:31 +01:00
|
|
|
|
|
2017-05-27 20:24:06 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using DiscImageChef.ImagePlugins;
|
|
|
|
|
|
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-10-12 23:54:02 +01:00
|
|
|
|
public static CICMMetadataType Create(ImagePlugin image, string imagePath, System.Guid filterId, System.Text.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-05-27 20:24:06 +01:00
|
|
|
|
while(position < (fi.Length - 1048576))
|
|
|
|
|
|
{
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
switch(image.ImageInfo.xmlMediaType)
|
|
|
|
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|