Files
Aaru/Aaru.Filesystems/PCFX/Info.cs

129 lines
5.2 KiB
C#
Raw Normal View History

2018-02-08 21:13:23 +00:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
2018-02-08 21:13:23 +00:00
// ----------------------------------------------------------------------------
//
2022-12-07 13:07:31 +00:00
// Filename : Info.cs
2018-02-08 21:13:23 +00:00
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : NEC PC-FX plugin.
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies the NEC PC-FX track header 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/>.
//
// ----------------------------------------------------------------------------
2024-05-01 04:17:32 +01:00
// Copyright © 2011-2024 Natalia Portillo
2018-02-08 21:13:23 +00:00
// ****************************************************************************/
using System;
using System.Text;
using Aaru.CommonTypes.AaruMetadata;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
2020-07-20 15:43:52 +01:00
using Aaru.Helpers;
using Partition = Aaru.CommonTypes.Partition;
2018-02-08 21:13:23 +00:00
namespace Aaru.Filesystems;
2022-03-06 13:29:38 +00:00
// Not a filesystem, more like an executable header
/// <inheritdoc />
/// <summary>Implements detection of NEC PC-FX headers</summary>
2022-12-07 13:07:31 +00:00
public sealed partial class PCFX
2018-02-08 21:13:23 +00:00
{
#region IFilesystem Members
/// <inheritdoc />
2022-03-06 13:29:38 +00:00
public bool Identify(IMediaImage imagePlugin, Partition partition)
2018-02-08 21:13:23 +00:00
{
if(2 + partition.Start >= partition.End || imagePlugin.Info.MetadataMediaType != MetadataMediaType.OpticalDisc)
2022-03-06 13:29:38 +00:00
return false;
2018-02-08 21:13:23 +00:00
2022-03-06 13:29:38 +00:00
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, 2, out byte[] sector);
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return false;
2018-02-08 21:13:23 +00:00
2022-03-06 13:29:38 +00:00
var encoding = Encoding.GetEncoding("shift_jis");
2018-02-08 21:13:23 +00:00
2022-03-06 13:29:38 +00:00
return encoding.GetString(sector, 0, 16) == IDENTIFIER;
}
/// <inheritdoc />
public void GetInformation(IMediaImage imagePlugin, Partition partition, Encoding encoding, out string information,
out FileSystem metadata)
2022-03-06 13:29:38 +00:00
{
// Always Shift-JIS
encoding = Encoding.GetEncoding("shift_jis");
2022-03-06 13:29:38 +00:00
information = "";
metadata = new FileSystem();
2022-03-06 13:29:38 +00:00
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, 2, out byte[] sector);
2018-02-08 21:13:23 +00:00
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return;
2022-03-06 13:29:38 +00:00
Header header = Marshal.ByteArrayToStructureLittleEndian<Header>(sector);
string date;
DateTime dateTime = DateTime.MinValue;
try
2018-02-08 21:13:23 +00:00
{
date = encoding.GetString(header.date);
var year = int.Parse(date[..4]);
var month = int.Parse(date.Substring(4, 2));
var day = int.Parse(date.Substring(6, 2));
2022-03-06 13:29:38 +00:00
dateTime = new DateTime(year, month, day);
2018-02-08 21:13:23 +00:00
}
2022-03-06 13:29:38 +00:00
catch
2018-02-08 21:13:23 +00:00
{
2022-03-06 13:29:38 +00:00
date = null;
2018-02-08 21:13:23 +00:00
}
2022-03-06 13:29:38 +00:00
var sb = new StringBuilder();
sb.AppendLine(Localization.PC_FX_executable);
sb.AppendFormat(Localization.Identifier_0, StringHandlers.CToString(header.signature, encoding)).AppendLine();
sb.AppendFormat(Localization.Copyright_0, StringHandlers.CToString(header.copyright, encoding)).AppendLine();
sb.AppendFormat(Localization.Title_0, StringHandlers.CToString(header.title, encoding)).AppendLine();
sb.AppendFormat(Localization.Maker_ID_0, StringHandlers.CToString(header.makerId, encoding)).AppendLine();
sb.AppendFormat(Localization.Maker_name_0, StringHandlers.CToString(header.makerName, encoding)).AppendLine();
sb.AppendFormat(Localization.Volume_number_0, header.volumeNumber).AppendLine();
sb.AppendFormat(Localization.Country_code_0, header.country).AppendLine();
sb.AppendFormat(Localization.Version_0_1, header.minorVersion, header.majorVersion).AppendLine();
2022-03-06 13:29:38 +00:00
2024-05-01 04:05:22 +01:00
if(date != null) sb.AppendFormat(Localization.Dated_0, dateTime).AppendLine();
2022-03-06 13:29:38 +00:00
sb.AppendFormat(Localization.Load_0_sectors_from_sector_1, header.loadCount, header.loadOffset).AppendLine();
2022-03-06 13:29:38 +00:00
sb.AppendFormat(Localization.Load_at_0_and_jump_to_1, header.loadAddress, header.entryPoint).AppendLine();
2022-03-06 13:29:38 +00:00
information = sb.ToString();
metadata = new FileSystem
2022-03-06 13:29:38 +00:00
{
Type = FS_TYPE,
Clusters = partition.Length,
ClusterSize = 2048,
Bootable = true,
CreationDate = date != null ? dateTime : null,
PublisherIdentifier = StringHandlers.CToString(header.makerName, encoding),
VolumeName = StringHandlers.CToString(header.title, encoding),
SystemIdentifier = "PC-FX"
2022-03-06 13:29:38 +00:00
};
}
#endregion
2018-02-08 21:13:23 +00:00
}