ace/Source/ACE.DatLoader/DatDatabase.cs
Mag-nus 51e72b4893 Major migration from .net framework 4.6.1 to .net standard/core 2.0 (#573)
* Remove files not referenced by their project (rogue files)

These existed in the repo but weren't included in the ACE.Entity project:
ACE.Entity\ILandBlock.cs
ACE.Entity\WeenieAnimationOverride.cs
ACE.Entity\WeeniePalletOverride.cs
ACE.Entity\WeenieTextureMapOverride.cs

When converting to .net standard, these files will be included in the projects again due to the way .net core/standard project files behave. They include all files in the local paths. Unlike .net framework csproj files, there is no list of files the project maintains.

* Remove Settings.StyleCop from child folders

I believe only the Settings.StyleCop in the root folder is needed, and will take effect for all child projects in the solution.

* ACE.Common and ACE.Entity converted to .net standard 2.0

* ACE.DatLoader switched to .net standard 2.0

This includes the removal of:
ACE.DatLoader\default.ruleset which I believe to be a rogue file.

* ACE.CmdLineLauncher now .net core 2.0

To launch it from a command line use:
dotnet ACE.CmdLineLauncher.dll

This commit also removes AnyCPU from ACE.Common, ACE.DatLoader and ACE.Entity

* ACE.DatLoader.Tests converted to .net standard 2.0

The project icon for ACE.DatLoader.Tests is no longer a C# icon with a half full flask. Not sure if there is any significance with that.

* ACE.Tests converted to .net standard 2.0

Just like the other test project I converted, the C# Flask icon for the project is gone and now it's just a C# icon.

* ACE.Database.Tests converted to .net standard 2

Same project icon issue as noted in the previous test conversions.

* ACE.Database converted to .net standard 2.0

ACE.Database\Redeploy.cs -> CheckLocalDataPath()
File permission checking has been commented out as it's not supported in .net standard/core.

ACE: MySql.Data package updated to 6.10.4

* ACE: Remove GameMessageMotion.cs (rogue file)

* ACE: Remove ACE.Diagnostics reference

ACE.Diagnostics is a winforms app and not available to .net core 2.0

We need a better way to expose diagnostic information anyway. ACE should not be referencing ACE.Diagnostics

* ACE.Tests changed to a .net core 2.0 project

When ACE is changed to .net core 2.0, it's test must also be .net core 2.0.

* ACE.Database: Remove MySqlResult

MySqlResult inherited from DataTable and added a property and a couple functions, but they were never used, thus, MySqlResult isn't needed.

* Update remaining MySql.Data references to 6.10.1

* Force appveyor to use VS 2017

* Remove unused System.Net.Http reference from projects.

ACE.Api.Common
ACE.Api.Host
ACE.Api
ACE.AuthApi.Host
ACE.AuthApi
Ace

* Fix appveyor test paths.

* ACE: DataTableExtensions added with Load fix for .net core 2.0

* Changelog

* AppVeyor test fix maybe

* Change ACE.Database.Tests and ACE.DatLoader.Tests to .net core 2.0 + test NuGet dependancies

* ACE.Database: DataTableExtensions improved

Rawaho method is better than Mag-nus method.

* AppVeyor fix that's just cosmetic. Tests still don't actually exec.

* AppVeyor test

* Appveyor test

* AppVeyor test

* Switch AppVeyor from vstest.console to dotnet test

* AppVeyor another test

* AppVeyor test

* AppVeyor final fix maybe?

* AppVeyor: Went wrong way with directories...

* AppVeyor almost there...

* AppVeyor fatt fingers maybe?

* ACE.CmdLineLauncher -> ACE.ACClientLauncher
2017-12-04 19:10:33 -05:00

68 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using log4net;
namespace ACE.DatLoader
{
public class DatDatabase
{
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public DatDirectory RootDirectory { get; private set; }
public Dictionary<uint, DatFile> AllFiles { get; private set; }
// So we can cache the read files. The read methods in the FileTypes will handle the caching and casting.
public Dictionary<uint, object> FileCache { get; private set; } = new Dictionary<uint, object>();
public DatDatabaseType DatType { get; private set; }
public string FilePath { get; private set; }
public uint SectorSize { get; private set; }
public DatDatabase(string filePath, DatDatabaseType type)
{
if (!File.Exists(filePath))
{
throw new FileNotFoundException(filePath);
}
this.FilePath = filePath;
DatType = type;
using (FileStream stream = new FileStream(filePath, FileMode.Open))
{
byte[] sectorSizeBuffer = new byte[4];
stream.Seek(0x144u, SeekOrigin.Begin);
stream.Read(sectorSizeBuffer, 0, sizeof(uint));
this.SectorSize = BitConverter.ToUInt32(sectorSizeBuffer, 0);
stream.Seek(0x160u, SeekOrigin.Begin);
byte[] firstDirBuffer = new byte[4];
stream.Read(firstDirBuffer, 0, sizeof(uint));
uint firstDirectoryOffset = BitConverter.ToUInt32(firstDirBuffer, 0);
RootDirectory = new DatDirectory(firstDirectoryOffset, Convert.ToInt32(this.SectorSize), stream, DatType);
}
AllFiles = new Dictionary<uint, DatFile>();
RootDirectory.AddFilesToList(AllFiles);
}
public DatReader GetReaderForFile(uint object_id)
{
if (AllFiles.ContainsKey(object_id))
{
DatReader dr = new DatReader(FilePath, AllFiles[object_id].FileOffset, AllFiles[object_id].FileSize, SectorSize);
return dr;
}
else
{
log.InfoFormat("Unable to find object_id {0} in {1}", object_id.ToString(), Enum.GetName(typeof(DatDatabaseType), DatType));
return null;
}
}
}
}