2023-10-07 17:52:48 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Symbian.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Symbian plugin.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Identifies Symbian installer (.sis) packages and shows information.
|
|
|
|
|
//
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2023-10-07 17:56:58 +01:00
|
|
|
using System;
|
2023-10-08 16:49:43 +01:00
|
|
|
using System.IO;
|
|
|
|
|
using System.IO.Compression;
|
2023-10-07 18:27:21 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2023-10-07 18:33:45 +01:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2023-10-07 18:30:16 +01:00
|
|
|
using Aaru.CommonTypes.Structs;
|
2023-10-07 18:33:45 +01:00
|
|
|
using Aaru.Filters;
|
2023-10-07 21:29:49 +01:00
|
|
|
using Aaru.Helpers.IO;
|
2023-10-07 18:30:16 +01:00
|
|
|
using FileAttributes = System.IO.FileAttributes;
|
2023-10-07 17:56:58 +01:00
|
|
|
|
2023-10-07 17:52:48 +01:00
|
|
|
namespace Aaru.Archives;
|
|
|
|
|
|
|
|
|
|
public sealed partial class Symbian
|
|
|
|
|
{
|
|
|
|
|
#region IArchive Members
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2023-10-07 18:27:21 +01:00
|
|
|
public int NumberOfEntries => Opened ? _files.Count : -1;
|
2023-10-07 17:52:48 +01:00
|
|
|
|
2023-10-07 17:54:57 +01:00
|
|
|
/// <inheritdoc />
|
2023-10-07 18:27:21 +01:00
|
|
|
public ErrorNumber GetFilename(int entryNumber, out string fileName)
|
2023-10-07 17:54:57 +01:00
|
|
|
{
|
2023-10-07 18:27:21 +01:00
|
|
|
fileName = null;
|
|
|
|
|
|
|
|
|
|
if(!Opened)
|
|
|
|
|
return ErrorNumber.NotOpened;
|
2023-10-07 17:54:57 +01:00
|
|
|
|
|
|
|
|
if(entryNumber < 0 || entryNumber >= _files.Count)
|
2023-10-07 18:27:21 +01:00
|
|
|
return ErrorNumber.OutOfRange;
|
|
|
|
|
|
|
|
|
|
fileName = _files[entryNumber].destinationName;
|
2023-10-07 17:54:57 +01:00
|
|
|
|
2023-10-07 18:27:21 +01:00
|
|
|
return ErrorNumber.NoError;
|
2023-10-07 17:54:57 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-07 17:56:58 +01:00
|
|
|
/// <inheritdoc />
|
2023-10-07 18:27:21 +01:00
|
|
|
public ErrorNumber GetEntryNumber(string fileName, bool caseInsensitiveMatch, out int entryNumber)
|
2023-10-07 17:56:58 +01:00
|
|
|
{
|
2023-10-07 18:27:21 +01:00
|
|
|
entryNumber = -1;
|
|
|
|
|
|
|
|
|
|
if(!Opened)
|
|
|
|
|
return ErrorNumber.NotOpened;
|
2023-10-07 17:56:58 +01:00
|
|
|
|
|
|
|
|
if(string.IsNullOrEmpty(fileName))
|
2023-10-07 18:27:21 +01:00
|
|
|
return ErrorNumber.InvalidArgument;
|
|
|
|
|
|
|
|
|
|
entryNumber = _files.FindIndex(x => caseInsensitiveMatch
|
|
|
|
|
? x.destinationName.Equals(fileName,
|
|
|
|
|
StringComparison.CurrentCultureIgnoreCase)
|
|
|
|
|
: x.destinationName.Equals(fileName, StringComparison.CurrentCulture));
|
2023-10-07 17:56:58 +01:00
|
|
|
|
2023-10-07 18:27:21 +01:00
|
|
|
return entryNumber < 0 ? ErrorNumber.NoSuchFile : ErrorNumber.NoError;
|
2023-10-07 17:56:58 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-07 17:58:09 +01:00
|
|
|
/// <inheritdoc />
|
2023-10-07 18:27:21 +01:00
|
|
|
public ErrorNumber GetCompressedSize(int entryNumber, out long length)
|
2023-10-07 17:58:09 +01:00
|
|
|
{
|
2023-10-07 18:27:21 +01:00
|
|
|
length = -1;
|
|
|
|
|
if(!Opened)
|
|
|
|
|
return ErrorNumber.NotOpened;
|
2023-10-07 17:58:09 +01:00
|
|
|
|
|
|
|
|
if(entryNumber < 0 || entryNumber >= _files.Count)
|
2023-10-07 18:27:21 +01:00
|
|
|
return ErrorNumber.OutOfRange;
|
2023-10-07 17:58:09 +01:00
|
|
|
|
2023-10-07 18:27:21 +01:00
|
|
|
length = _files[entryNumber].length;
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
2023-10-07 17:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-07 17:59:42 +01:00
|
|
|
/// <inheritdoc />
|
2023-10-07 18:27:21 +01:00
|
|
|
public ErrorNumber GetUncompressedSize(int entryNumber, out long length)
|
2023-10-07 17:59:42 +01:00
|
|
|
{
|
2023-10-07 18:27:21 +01:00
|
|
|
length = -1;
|
|
|
|
|
if(!Opened)
|
|
|
|
|
return ErrorNumber.NotOpened;
|
2023-10-07 17:59:42 +01:00
|
|
|
|
|
|
|
|
if(entryNumber < 0 || entryNumber >= _files.Count)
|
2023-10-07 18:27:21 +01:00
|
|
|
return ErrorNumber.OutOfRange;
|
|
|
|
|
|
|
|
|
|
length = _compressed ? _files[entryNumber].originalLength : _files[entryNumber].length;
|
2023-10-07 17:59:42 +01:00
|
|
|
|
2023-10-07 18:27:21 +01:00
|
|
|
return ErrorNumber.NoError;
|
2023-10-07 17:59:42 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-07 18:01:30 +01:00
|
|
|
/// <inheritdoc />
|
2023-10-07 18:27:21 +01:00
|
|
|
public ErrorNumber GetAttributes(int entryNumber, out FileAttributes attributes)
|
2023-10-07 18:01:30 +01:00
|
|
|
{
|
2023-10-07 18:27:21 +01:00
|
|
|
attributes = FileAttributes.None;
|
|
|
|
|
|
|
|
|
|
if(!Opened)
|
|
|
|
|
return ErrorNumber.NotOpened;
|
2023-10-07 18:01:30 +01:00
|
|
|
|
|
|
|
|
if(entryNumber < 0 || entryNumber >= _files.Count)
|
2023-10-07 18:27:21 +01:00
|
|
|
return ErrorNumber.OutOfRange;
|
|
|
|
|
|
|
|
|
|
attributes = FileAttributes.Normal;
|
2023-10-07 18:01:30 +01:00
|
|
|
|
2023-10-07 18:27:21 +01:00
|
|
|
return ErrorNumber.NoError;
|
2023-10-07 18:01:30 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-07 18:30:16 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber Stat(int entryNumber, out FileEntryInfo stat)
|
|
|
|
|
{
|
|
|
|
|
stat = null;
|
|
|
|
|
|
|
|
|
|
if(!Opened)
|
|
|
|
|
return ErrorNumber.NotOpened;
|
|
|
|
|
|
|
|
|
|
if(entryNumber < 0 || entryNumber >= _files.Count)
|
|
|
|
|
return ErrorNumber.OutOfRange;
|
|
|
|
|
|
|
|
|
|
stat = new FileEntryInfo
|
|
|
|
|
{
|
|
|
|
|
Length = _compressed ? _files[entryNumber].originalLength : _files[entryNumber].length,
|
|
|
|
|
Attributes = CommonTypes.Structs.FileAttributes.File,
|
|
|
|
|
Inode = (ulong)entryNumber
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-07 18:33:45 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber GetEntry(int entryNumber, out IFilter filter)
|
|
|
|
|
{
|
|
|
|
|
filter = null;
|
|
|
|
|
if(!Opened)
|
|
|
|
|
return ErrorNumber.NotOpened;
|
|
|
|
|
|
|
|
|
|
if(entryNumber < 0 || entryNumber >= _files.Count)
|
|
|
|
|
return ErrorNumber.OutOfRange;
|
|
|
|
|
|
2023-10-08 16:49:43 +01:00
|
|
|
Stream stream = new OffsetStream(new NonClosableStream(_stream), _files[entryNumber].pointer,
|
|
|
|
|
_files[entryNumber].pointer + _files[entryNumber].length);
|
|
|
|
|
|
|
|
|
|
ErrorNumber errno;
|
2023-10-07 18:33:45 +01:00
|
|
|
if(_compressed)
|
2023-10-08 16:49:43 +01:00
|
|
|
{
|
|
|
|
|
if(_files[entryNumber].originalLength == 0)
|
|
|
|
|
stream = new MemoryStream(Array.Empty<byte>());
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
stream = new ForcedSeekStream<ZLibStream>(_files[entryNumber].originalLength, stream,
|
|
|
|
|
CompressionMode.Decompress);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-07 18:33:45 +01:00
|
|
|
|
|
|
|
|
filter = new ZZZNoFilter();
|
2023-10-08 16:49:43 +01:00
|
|
|
errno = filter.Open(stream);
|
2023-10-07 18:33:45 +01:00
|
|
|
|
|
|
|
|
if(errno == ErrorNumber.NoError)
|
|
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
|
2023-10-08 16:49:43 +01:00
|
|
|
stream.Close();
|
2023-10-07 18:33:45 +01:00
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-07 17:52:48 +01:00
|
|
|
#endregion
|
|
|
|
|
}
|