2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-09-05 17:37:31 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : ZZZNoFilter.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Filters.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Provides a filter to open single files.
|
|
|
|
|
//
|
|
|
|
|
// --[ 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
|
2016-09-05 17:37:31 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Filters
|
|
|
|
|
{
|
2017-12-23 04:06:02 +00:00
|
|
|
/// <summary>
|
2017-12-24 02:43:49 +00:00
|
|
|
/// No filter for reading files not recognized by any filter
|
2017-12-23 04:06:02 +00:00
|
|
|
/// </summary>
|
2017-12-26 06:05:12 +00:00
|
|
|
public class ZZZNoFilter : IFilter
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
string basePath;
|
2016-09-05 17:37:31 +01:00
|
|
|
DateTime creationTime;
|
2018-06-22 08:08:38 +01:00
|
|
|
Stream dataStream;
|
2017-12-24 02:43:49 +00:00
|
|
|
DateTime lastWriteTime;
|
2018-06-22 08:08:38 +01:00
|
|
|
bool opened;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public string Name => "No filter";
|
2018-06-22 08:08:38 +01:00
|
|
|
public Guid Id => new Guid("12345678-AAAA-BBBB-CCCC-123456789000");
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public void Close()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
2017-12-22 16:17:40 +00:00
|
|
|
dataStream?.Close();
|
2016-09-05 17:37:31 +01:00
|
|
|
dataStream = null;
|
2018-06-22 08:08:38 +01:00
|
|
|
basePath = null;
|
|
|
|
|
opened = false;
|
2016-09-05 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public string GetBasePath()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return basePath;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public Stream GetDataForkStream()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return dataStream;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public string GetPath()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return basePath;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public Stream GetResourceForkStream()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool HasResourceFork()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
// TODO: Implement support for xattrs/ADS
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool Identify(byte[] buffer)
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return buffer != null && buffer.Length > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool Identify(Stream stream)
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return stream != null && stream.Length > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool Identify(string path)
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return File.Exists(path);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public void Open(byte[] buffer)
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
dataStream = new MemoryStream(buffer);
|
|
|
|
|
basePath = null;
|
|
|
|
|
creationTime = DateTime.UtcNow;
|
2016-09-05 17:37:31 +01:00
|
|
|
lastWriteTime = creationTime;
|
2018-06-22 08:08:38 +01:00
|
|
|
opened = true;
|
2016-09-05 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public void Open(Stream stream)
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
dataStream = stream;
|
|
|
|
|
basePath = null;
|
|
|
|
|
creationTime = DateTime.UtcNow;
|
2016-09-05 17:37:31 +01:00
|
|
|
lastWriteTime = creationTime;
|
2018-06-22 08:08:38 +01:00
|
|
|
opened = true;
|
2016-09-05 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public void Open(string path)
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
dataStream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
2018-06-22 08:08:38 +01:00
|
|
|
basePath = Path.GetFullPath(path);
|
2016-09-05 17:37:31 +01:00
|
|
|
FileInfo fi = new FileInfo(path);
|
2018-06-22 08:08:38 +01:00
|
|
|
creationTime = fi.CreationTimeUtc;
|
2016-09-05 17:37:31 +01:00
|
|
|
lastWriteTime = fi.LastWriteTimeUtc;
|
2018-06-22 08:08:38 +01:00
|
|
|
opened = true;
|
2016-09-05 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public DateTime GetCreationTime()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return creationTime;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public long GetDataForkLength()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return dataStream.Length;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public DateTime GetLastWriteTime()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return lastWriteTime;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public long GetLength()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return dataStream.Length;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public long GetResourceForkLength()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public string GetFilename()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
2017-12-22 16:17:40 +00:00
|
|
|
return Path.GetFileName(basePath);
|
2016-09-05 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public string GetParentFolder()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return Path.GetDirectoryName(basePath);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool IsOpened()
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
return opened;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|