2017-06-08 20:21:29 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : ExtentsConverter.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : XML metadata.
|
2017-06-08 20:21:29 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Converts extents to/from XML.
|
2017-06-08 20:21:29 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This library 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
|
|
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2017-06-08 20:21:29 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 19:33:46 +00:00
|
|
|
|
|
2017-06-08 20:21:29 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
using System.Linq;
|
2017-06-08 20:21:29 +01:00
|
|
|
|
using Extents;
|
|
|
|
|
|
using Schemas;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Metadata
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class ExtentsConverter
|
|
|
|
|
|
{
|
2017-06-08 22:01:06 +01:00
|
|
|
|
public static ExtentType[] ToMetadata(ExtentsULong extents)
|
2017-06-08 20:21:29 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(extents == null) return null;
|
|
|
|
|
|
|
2017-06-08 22:01:06 +01:00
|
|
|
|
Tuple<ulong, ulong>[] tuples = extents.ToArray();
|
2018-06-22 08:08:38 +01:00
|
|
|
|
ExtentType[] array = new ExtentType[tuples.Length];
|
2017-06-08 20:21:29 +01:00
|
|
|
|
|
2017-06-08 22:01:06 +01:00
|
|
|
|
for(ulong i = 0; i < (ulong)array.LongLength; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
array[i] = new ExtentType {Start = tuples[i].Item1, End = tuples[i].Item2};
|
2017-06-08 20:21:29 +01:00
|
|
|
|
|
|
|
|
|
|
return array;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-08 22:01:06 +01:00
|
|
|
|
public static ExtentsULong FromMetadata(ExtentType[] extents)
|
2017-06-08 20:21:29 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(extents == null) return null;
|
2017-06-08 20:21:29 +01:00
|
|
|
|
|
2017-12-24 03:03:13 +00:00
|
|
|
|
List<Tuple<ulong, ulong>> tuples =
|
|
|
|
|
|
extents.Select(extent => new Tuple<ulong, ulong>(extent.Start, extent.End)).ToList();
|
2017-06-08 20:21:29 +01:00
|
|
|
|
|
2017-06-08 22:01:06 +01:00
|
|
|
|
return new ExtentsULong(tuples);
|
2017-06-08 20:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|