2025-08-23 07:01:16 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Files.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Zoo plugin.
|
|
|
|
|
//
|
|
|
|
|
// --[ 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-2025 Natalia Portillo
|
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2025-08-23 07:18:25 +01:00
|
|
|
using System;
|
2025-08-23 07:01:16 +01:00
|
|
|
using System.IO;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
using Aaru.Helpers;
|
|
|
|
|
|
|
|
|
|
namespace Aaru.Archives;
|
|
|
|
|
|
|
|
|
|
public sealed partial class Zoo
|
|
|
|
|
{
|
|
|
|
|
#region IArchive Members
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber GetFilename(int entryNumber, out string fileName)
|
|
|
|
|
{
|
|
|
|
|
fileName = null;
|
|
|
|
|
|
|
|
|
|
if(!Opened) return ErrorNumber.NotOpened;
|
|
|
|
|
|
|
|
|
|
if(entryNumber < 0 || entryNumber >= _files.Count) return ErrorNumber.OutOfRange;
|
|
|
|
|
|
|
|
|
|
Direntry entry = _files[entryNumber];
|
|
|
|
|
|
|
|
|
|
fileName = StringHandlers.CToString(entry.lfname ?? entry.fname, _encoding);
|
|
|
|
|
|
|
|
|
|
if(entry.dirname is null) return ErrorNumber.NoError;
|
|
|
|
|
|
|
|
|
|
string directoryName = StringHandlers.CToString(entry.dirname, _encoding);
|
|
|
|
|
|
|
|
|
|
// Path separators are UNIX in archive, change them
|
|
|
|
|
if(entry.system_id != 1 && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
directoryName = directoryName.Replace('/', '\\');
|
|
|
|
|
else
|
|
|
|
|
directoryName = directoryName.Replace('\\', '/');
|
|
|
|
|
|
|
|
|
|
fileName = Path.Combine(directoryName, fileName);
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-23 07:03:37 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber GetCompressedSize(int entryNumber, out long length)
|
|
|
|
|
{
|
|
|
|
|
length = -1;
|
|
|
|
|
|
|
|
|
|
if(!Opened) return ErrorNumber.NotOpened;
|
|
|
|
|
|
|
|
|
|
if(entryNumber < 0 || entryNumber >= _files.Count) return ErrorNumber.OutOfRange;
|
|
|
|
|
|
|
|
|
|
Direntry entry = _files[entryNumber];
|
|
|
|
|
|
|
|
|
|
length = entry.size_now;
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-23 07:04:52 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber GetUncompressedSize(int entryNumber, out long length)
|
|
|
|
|
{
|
|
|
|
|
length = -1;
|
|
|
|
|
|
|
|
|
|
if(!Opened) return ErrorNumber.NotOpened;
|
|
|
|
|
|
|
|
|
|
if(entryNumber < 0 || entryNumber >= _files.Count) return ErrorNumber.OutOfRange;
|
|
|
|
|
|
|
|
|
|
Direntry entry = _files[entryNumber];
|
|
|
|
|
|
|
|
|
|
length = entry.org_size;
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-23 07:06:42 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber GetAttributes(int entryNumber, out FileAttributes attributes)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Decode them
|
|
|
|
|
attributes = FileAttributes.None;
|
|
|
|
|
|
|
|
|
|
if(!Opened) return ErrorNumber.NotOpened;
|
|
|
|
|
|
|
|
|
|
if(entryNumber < 0 || entryNumber >= _files.Count) return ErrorNumber.OutOfRange;
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-23 07:18:25 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber GetEntryNumber(string fileName, bool caseInsensitiveMatch, out int entryNumber)
|
|
|
|
|
{
|
|
|
|
|
// This can be done faster, it's 7am, gimme a break
|
|
|
|
|
entryNumber = -1;
|
|
|
|
|
|
|
|
|
|
if(!Opened) return ErrorNumber.NotOpened;
|
|
|
|
|
|
|
|
|
|
StringComparison comparison = caseInsensitiveMatch
|
|
|
|
|
? StringComparison.CurrentCultureIgnoreCase
|
|
|
|
|
: StringComparison.CurrentCulture;
|
|
|
|
|
|
|
|
|
|
for(int i = 0, count = _files.Count; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
if(GetFilename(i, out string name) != ErrorNumber.NoError || !name.Equals(fileName, comparison)) continue;
|
|
|
|
|
|
|
|
|
|
entryNumber = i;
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoSuchFile;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-23 07:01:16 +01:00
|
|
|
#endregion
|
|
|
|
|
}
|