AFS file format loading seems to work OK so far...

This commit is contained in:
Michael Becker 2019-11-15 12:10:22 -05:00
parent db78228129
commit c1a0f9f590
No known key found for this signature in database
GPG Key ID: 389DFF5D73781A12
5 changed files with 172 additions and 0 deletions

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<UniversalEditor Version="4.0">
<Associations>
<Association>
<Filters>
<Filter Title="AFS archive">
<FileNameFilters>
<FileNameFilter>*.afs</FileNameFilter>
</FileNameFilters>
<MagicByteSequences>
<MagicByteSequence>
<MagicByte Type="String">AFS</MagicByte>
</MagicByteSequence>
</MagicByteSequences>
</Filter>
</Filters>
<ObjectModels>
<ObjectModel TypeName="UniversalEditor.ObjectModels.FileSystem.FileSystemObjectModel" />
</ObjectModels>
<DataFormats>
<DataFormat TypeName="UniversalEditor.DataFormats.FileSystem.AFS.AFSDataFormat" />
</DataFormats>
</Association>
</Associations>
</UniversalEditor>

View File

@ -651,6 +651,7 @@
<Content Include="Extensions\GameDeveloper\Associations\FileSystem\SlightlyMadStudiosBFF.uexml" />
<Content Include="Extensions\GameDeveloper\Associations\FileSystem\SquareSoftLGP.uexml" />
<Content Include="Extensions\GameDeveloper\Associations\FileSystem\CRICPK.uexml" />
<Content Include="Extensions\FileSystem\Associations\AFS.uexml" />
</ItemGroup>
<ItemGroup>
<Content Include="Configuration\Application.upl" />

View File

@ -0,0 +1,111 @@
//
// AFSDataFormat.cs
//
// Author:
// Mike Becker <alcexhim@gmail.com>
//
// Copyright (c) 2019 Mike Becker
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using UniversalEditor.IO;
using UniversalEditor.ObjectModels.FileSystem;
namespace UniversalEditor.DataFormats.FileSystem.AFS
{
public class AFSDataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
protected override DataFormatReference MakeReferenceInternal()
{
if (_dfr == null)
{
_dfr = base.MakeReferenceInternal();
_dfr.Capabilities.Add(typeof(FileSystemObjectModel), DataFormatCapabilities.All);
}
return _dfr;
}
protected override void LoadInternal(ref ObjectModel objectModel)
{
FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel);
if (fsom == null)
throw new ObjectModelNotSupportedException();
Reader reader = Accessor.Reader;
string afs = reader.ReadFixedLengthString(4);
if (afs != "AFS\0")
throw new InvalidDataFormatException("file does not begin with \"AFS\\0\"");
uint fileCount = reader.ReadUInt32();
AFSFileInfo[] fileinfos = new AFSFileInfo[fileCount];
for (int i = 0; i < fileCount; i++)
{
fileinfos[i].offset = reader.ReadUInt32();
fileinfos[i].length = reader.ReadUInt32();
}
uint tocOffset = 0u;
while (Accessor.Position < fileinfos[0].offset && tocOffset == 0)
{
tocOffset = reader.ReadUInt32();
uint num3 = reader.ReadUInt32();
}
if (tocOffset == 0)
{
throw new InvalidDataFormatException("table of contents not found");
}
else
{
reader.Seek(tocOffset, SeekOrigin.Begin);
for (int j = 0; j < fileCount; j++)
{
fileinfos[j].name = reader.ReadFixedLengthString(32).TrimNull();
ushort year = reader.ReadUInt16();
ushort month = reader.ReadUInt16();
ushort day = reader.ReadUInt16();
ushort hour = reader.ReadUInt16();
ushort minute = reader.ReadUInt16();
ushort second = reader.ReadUInt16();
fileinfos[j].datetime = new DateTime(year, month, day, hour, minute, second);
fileinfos[j].length2 = reader.ReadUInt32();
File f = fsom.AddFile(fileinfos[j].name);
f.Properties.Add("fileinfo", fileinfos[j]);
f.Size = fileinfos[j].length;
f.ModificationTimestamp = fileinfos[j].datetime;
f.DataRequest += f_DataRequest;
}
}
}
void f_DataRequest(object sender, DataRequestEventArgs e)
{
File f = (sender as File);
AFSFileInfo fileinfo = (AFSFileInfo)f.Properties["fileinfo"];
Accessor.Seek(fileinfo.offset, SeekOrigin.Begin);
e.Data = Accessor.Reader.ReadBytes(fileinfo.length);
}
protected override void SaveInternal(ObjectModel objectModel)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,32 @@
//
// AFSFileInfo.cs
//
// Author:
// Mike Becker <alcexhim@gmail.com>
//
// Copyright (c) 2019 Mike Becker
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.DataFormats.FileSystem.AFS
{
public struct AFSFileInfo
{
public string name;
public uint offset;
public DateTime datetime;
public uint length;
public uint length2;
}
}

View File

@ -232,6 +232,8 @@
<Compile Include="DataFormats\FileSystem\WinAce\ACEHeaderFlags.cs" />
<Compile Include="DataFormats\FileSystem\SlightlyMadStudios\BFFDataFormat.cs" />
<Compile Include="DataFormats\FileSystem\SlightlyMadStudios\BFFCompressionType.cs" />
<Compile Include="DataFormats\FileSystem\AFS\AFSDataFormat.cs" />
<Compile Include="DataFormats\FileSystem\AFS\AFSFileInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Core\UniversalEditor.Core.csproj">
@ -270,6 +272,7 @@
<Folder Include="DataFormats\FileSystem\HA\" />
<Folder Include="DataFormats\FileSystem\HyperArchiver\" />
<Folder Include="DataFormats\FileSystem\SlightlyMadStudios\" />
<Folder Include="DataFormats\FileSystem\AFS\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.