mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-02-04 05:36:12 +00:00
Compare commits
184 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27a9b12bbf | ||
|
|
11319c3341 | ||
|
|
4de061e0d1 | ||
|
|
258e894c30 | ||
|
|
8658eaf4e0 | ||
|
|
6d341abc75 | ||
|
|
4821d63b4a | ||
|
|
0617bf3170 | ||
|
|
425d13a2ac | ||
|
|
8a1e90f537 | ||
|
|
ddc00948ed | ||
|
|
c96ee81f06 | ||
|
|
f6201e2c35 | ||
|
|
d63fcfcf7f | ||
|
|
dcc50c4c23 | ||
|
|
60e46e580d | ||
|
|
0638998773 | ||
|
|
ad3113987b | ||
|
|
f2f0d0f2e7 | ||
|
|
f7fd2f6f65 | ||
|
|
281c18e21d | ||
|
|
1a9c8b5392 | ||
|
|
831a272f4b | ||
|
|
f47e68b9ba | ||
|
|
eaabd2ee77 | ||
|
|
a269edd6ea | ||
|
|
3bb501ce0c | ||
|
|
d0006a4653 | ||
|
|
c48a1394bc | ||
|
|
fcf7fcfd44 | ||
|
|
cca08e7103 | ||
|
|
b908732f5c | ||
|
|
4ee4a6e85f | ||
|
|
7990f11bab | ||
|
|
427f7c9136 | ||
|
|
f938f1593d | ||
|
|
480a1834ed | ||
|
|
df5acc648c | ||
|
|
10569e6aa1 | ||
|
|
e5103b4830 | ||
|
|
513646fc53 | ||
|
|
27f723bf2f | ||
|
|
6511ecb5ad | ||
|
|
7bf6e6f344 | ||
|
|
d3e340ae39 | ||
|
|
22167a9617 | ||
|
|
48bea55133 | ||
|
|
42239919e5 | ||
|
|
4840d9df6e | ||
|
|
1378b87ea6 | ||
|
|
6b48164b97 | ||
|
|
50b09aa249 | ||
|
|
ecbd147f6d | ||
|
|
c13df79848 | ||
|
|
48bcc1de5b | ||
|
|
d082f5de25 | ||
|
|
c2321669b6 | ||
|
|
e382635b85 | ||
|
|
b4e02d7f8c | ||
|
|
0dc8a0b6c0 | ||
|
|
171834986d | ||
|
|
97af686b73 | ||
|
|
7d627ffc6f | ||
|
|
d924f25eb2 | ||
|
|
abd8ef3b1f | ||
|
|
e9b8dba3a6 | ||
|
|
aaff7e7332 | ||
|
|
2fa00d1a16 | ||
|
|
8a2a2ecd12 | ||
|
|
98517bdd8c | ||
|
|
dfe76f7e7e | ||
|
|
a2e24b1f5f | ||
|
|
6a4e76e245 | ||
|
|
1ebec97e0e | ||
|
|
b9f03b02f0 | ||
|
|
2c06760778 | ||
|
|
3f0ee70b71 | ||
|
|
05b34f158b | ||
|
|
e08db935b4 | ||
|
|
47da068bd3 | ||
|
|
9de669606d | ||
|
|
a02d50e61d | ||
|
|
069dab7fba | ||
|
|
d65edadbbb | ||
|
|
6307a51c0a | ||
|
|
d27c602bdf | ||
|
|
59fe9cb113 | ||
|
|
b4b7ba75cb | ||
|
|
d02e0c16c4 | ||
|
|
4aa0eb54b7 | ||
|
|
c4f73abcb6 | ||
|
|
73dec51a4d | ||
|
|
b7c3c094ae | ||
|
|
97702ab3d5 | ||
|
|
a9b5fe706c | ||
|
|
198d48610c | ||
|
|
c0e0344914 | ||
|
|
d49b2f1b60 | ||
|
|
ec7172466b | ||
|
|
d75a512ead | ||
|
|
af8b6906b6 | ||
|
|
96bc301e6d | ||
|
|
c10749f34d | ||
|
|
0e4235c8ba | ||
|
|
b2d31bb87e | ||
|
|
3ee88793da | ||
|
|
ad0f01c3ef | ||
|
|
63a96a7cf8 | ||
|
|
b8d8ca9a5c | ||
|
|
6b0fca31ae | ||
|
|
c147b12b10 | ||
|
|
7884b0b775 | ||
|
|
9f3c263328 | ||
|
|
b830ce3d73 | ||
|
|
e8b7f33bf0 | ||
|
|
eae75c5943 | ||
|
|
c1f5ebcae1 | ||
|
|
acb8e98fe2 | ||
|
|
a24a92e97c | ||
|
|
f2d2fe97bb | ||
|
|
705252eec7 | ||
|
|
69ae0456f0 | ||
|
|
f07bd07cce | ||
|
|
9db2d2ca05 | ||
|
|
85248b0135 | ||
|
|
8663edc7df | ||
|
|
b9cc9e40fd | ||
|
|
5ce085ad2b | ||
|
|
d24f8a2fce | ||
|
|
a73e830209 | ||
|
|
146fb42fd0 | ||
|
|
5b54ed719e | ||
|
|
02d011228e | ||
|
|
07adfd20a3 | ||
|
|
1d00abd6cc | ||
|
|
36c2cc2f15 | ||
|
|
27cf01ce84 | ||
|
|
1e94163693 | ||
|
|
db1f94775b | ||
|
|
ce394eb4e9 | ||
|
|
15109bed88 | ||
|
|
8a18c8de34 | ||
|
|
2f093a80c7 | ||
|
|
5df1af9c17 | ||
|
|
d5ab37a5a6 | ||
|
|
ed9ecf0da9 | ||
|
|
4fc17197ca | ||
|
|
94a9cf0c3f | ||
|
|
1d9e12183f | ||
|
|
aaa8bbe709 | ||
|
|
805d1b9ad8 | ||
|
|
d24d3e5adb | ||
|
|
d3a7d552c3 | ||
|
|
9f1c5e2bd2 | ||
|
|
1ec4ea8354 | ||
|
|
e4fab52489 | ||
|
|
e029fa4833 | ||
|
|
2c3f229a6a | ||
|
|
3558d3532c | ||
|
|
ad5314dc22 | ||
|
|
eaa5bb5662 | ||
|
|
fcdc703595 | ||
|
|
ef9fa562ab | ||
|
|
ac285c48fe | ||
|
|
e57ad65210 | ||
|
|
0fc3a30422 | ||
|
|
49f6704694 | ||
|
|
6df712c538 | ||
|
|
bda3076a30 | ||
|
|
89e8e7c706 | ||
|
|
c10835d221 | ||
|
|
a6801350ea | ||
|
|
c7a5a62041 | ||
|
|
749b35e5cb | ||
|
|
3c520d33eb | ||
|
|
635170a051 | ||
|
|
9619311d11 | ||
|
|
4bee14835c | ||
|
|
f44059e16a | ||
|
|
bfb206a06d | ||
|
|
6b7b05eb31 | ||
|
|
a9a2a04332 | ||
|
|
50459645dd | ||
|
|
564386038f |
74
.github/workflows/build_and_test.yml
vendored
74
.github/workflows/build_and_test.yml
vendored
@@ -1,40 +1,48 @@
|
||||
name: Build and Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
push:
|
||||
branches: ["main"]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: |
|
||||
6.0.x
|
||||
8.0.x
|
||||
9.0.x
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test
|
||||
|
||||
- name: Run publish script
|
||||
run: ./publish-nix.sh -d
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Upload to rolling
|
||||
uses: ncipollo/release-action@v1.14.0
|
||||
with:
|
||||
allowUpdates: True
|
||||
artifacts: "*.nupkg,*.snupkg,*.zip"
|
||||
body: 'Last built commit: ${{ github.sha }}'
|
||||
name: 'Rolling Release'
|
||||
prerelease: True
|
||||
replacesArtifacts: True
|
||||
tag: "rolling"
|
||||
updateOnlyUnreleased: True
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v5
|
||||
with:
|
||||
dotnet-version: |
|
||||
8.0.x
|
||||
9.0.x
|
||||
10.0.x
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test
|
||||
|
||||
- name: Run publish script
|
||||
run: ./publish-nix.sh -d
|
||||
|
||||
- name: Update rolling tag
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag -f rolling
|
||||
git push origin :refs/tags/rolling || true
|
||||
git push origin rolling --force
|
||||
|
||||
- name: Upload to rolling
|
||||
uses: ncipollo/release-action@v1.20.0
|
||||
with:
|
||||
allowUpdates: True
|
||||
artifacts: "*.nupkg,*.snupkg,*.zip"
|
||||
body: "Last built commit: ${{ github.sha }}"
|
||||
name: "Rolling Release"
|
||||
prerelease: True
|
||||
replacesArtifacts: True
|
||||
tag: "rolling"
|
||||
updateOnlyUnreleased: True
|
||||
|
||||
34
.github/workflows/check_pr.yml
vendored
34
.github/workflows/check_pr.yml
vendored
@@ -3,21 +3,21 @@ name: Build PR
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: |
|
||||
6.0.x
|
||||
8.0.x
|
||||
9.0.x
|
||||
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v5
|
||||
with:
|
||||
dotnet-version: |
|
||||
8.0.x
|
||||
9.0.x
|
||||
10.0.x
|
||||
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
||||
[submodule "SabreTools.Serialization/_EXTERNAL/stormlibsharp"]
|
||||
path = SabreTools.Serialization/_EXTERNAL/stormlibsharp
|
||||
url = https://github.com/robpaveza/stormlibsharp.git
|
||||
14
.vscode/launch.json
vendored
14
.vscode/launch.json
vendored
@@ -1,16 +1,16 @@
|
||||
{
|
||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||
// Use hover for the description of the existing attributes
|
||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||
// Use hover for the description of the existing attributes
|
||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (ExtractionTool)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// If you have changed target frameworks, make sure to update the program path.
|
||||
"program": "${workspaceFolder}/ExtractionTool/bin/Debug/net9.0/ExtractionTool.dll",
|
||||
"program": "${workspaceFolder}/ExtractionTool/bin/Debug/net10.0/ExtractionTool.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
@@ -24,7 +24,7 @@
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// If you have changed target frameworks, make sure to update the program path.
|
||||
"program": "${workspaceFolder}/InfoPrint/bin/Debug/net9.0/InfoPrint.dll",
|
||||
"program": "${workspaceFolder}/InfoPrint/bin/Debug/net10.0/InfoPrint.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
|
||||
<OutputType>Exe</OutputType>
|
||||
<CheckEolTargetFramework>false</CheckEolTargetFramework>
|
||||
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
|
||||
@@ -10,7 +10,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>2.0.0</Version>
|
||||
<Version>2.2.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Support All Frameworks -->
|
||||
@@ -20,28 +20,15 @@
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`)) OR $(TargetFramework.StartsWith(`net10`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Set a build flag for Windows specifically -->
|
||||
<PropertyGroup Condition="'$(RuntimeIdentifier)'=='win-x86'">
|
||||
<DefineConstants>$(DefineConstants);WINX86</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(RuntimeIdentifier)'=='win-x64'">
|
||||
<DefineConstants>$(DefineConstants);WINX64</DefineConstants>
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- These are needed for dealing with native Windows DLLs -->
|
||||
<ItemGroup Condition="'$(RuntimeIdentifier)'=='win-x86'">
|
||||
<ContentWithTargetPath Include="..\SabreTools.Serialization\runtimes\win-x86\native\CascLib.dll">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
|
||||
<TargetPath>CascLib.dll</TargetPath>
|
||||
</ContentWithTargetPath>
|
||||
<ContentWithTargetPath Include="..\SabreTools.Serialization\runtimes\win-x86\native\StormLib.dll">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
|
||||
@@ -49,11 +36,6 @@
|
||||
</ContentWithTargetPath>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(RuntimeIdentifier)'=='win-x64'">
|
||||
<ContentWithTargetPath Include="..\SabreTools.Serialization\runtimes\win-x64\native\CascLib.dll">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
|
||||
<TargetPath>CascLib.dll</TargetPath>
|
||||
</ContentWithTargetPath>
|
||||
<ContentWithTargetPath Include="..\SabreTools.Serialization\runtimes\win-x64\native\StormLib.dll">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
|
||||
@@ -66,8 +48,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SabreTools.IO" Version="1.7.5" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.9" Condition="!$(TargetFramework.StartsWith(`net2`)) AND !$(TargetFramework.StartsWith(`net3`)) AND !$(TargetFramework.StartsWith(`net40`)) AND !$(TargetFramework.StartsWith(`net452`))" />
|
||||
<PackageReference Include="SabreTools.CommandLine" Version="[1.4.0]" />
|
||||
<PackageReference Include="SabreTools.IO" Version="[1.9.0]" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="10.0.0" Condition="!$(TargetFramework.StartsWith(`net2`)) AND !$(TargetFramework.StartsWith(`net3`)) AND !$(TargetFramework.StartsWith(`net40`)) AND !$(TargetFramework.StartsWith(`net452`))" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
340
ExtractionTool/Features/MainFeature.cs
Normal file
340
ExtractionTool/Features/MainFeature.cs
Normal file
@@ -0,0 +1,340 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SabreTools.CommandLine;
|
||||
using SabreTools.CommandLine.Inputs;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Serialization;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
|
||||
namespace ExtractionTool.Features
|
||||
{
|
||||
internal sealed class MainFeature : Feature
|
||||
{
|
||||
#region Feature Definition
|
||||
|
||||
public const string DisplayName = "main";
|
||||
|
||||
/// <remarks>Flags are unused</remarks>
|
||||
private static readonly string[] _flags = [];
|
||||
|
||||
/// <remarks>Description is unused</remarks>
|
||||
private const string _description = "";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Inputs
|
||||
|
||||
private const string _debugName = "debug";
|
||||
internal readonly FlagInput DebugInput = new(_debugName, ["-d", "--debug"], "Enable debug mode");
|
||||
|
||||
private const string _outputPathName = "output-path";
|
||||
internal readonly StringInput OutputPathInput = new(_outputPathName, ["-o", "--outdir"], "Set output path for extraction (required)");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Enable debug output for relevant operations
|
||||
/// </summary>
|
||||
public bool Debug { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Output path for archive extraction
|
||||
/// </summary>
|
||||
public string OutputPath { get; private set; } = string.Empty;
|
||||
|
||||
#endregion
|
||||
|
||||
public MainFeature()
|
||||
: base(DisplayName, _flags, _description)
|
||||
{
|
||||
RequiresInputs = true;
|
||||
|
||||
Add(DebugInput);
|
||||
Add(OutputPathInput);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Execute()
|
||||
{
|
||||
// Get the options from the arguments
|
||||
Debug = GetBoolean(_debugName);
|
||||
OutputPath = GetString(_outputPathName) ?? string.Empty;
|
||||
|
||||
// Validate the output path
|
||||
if (!ValidateExtractionPath())
|
||||
return false;
|
||||
|
||||
// Loop through the input paths
|
||||
for (int i = 0; i < Inputs.Count; i++)
|
||||
{
|
||||
string arg = Inputs[i];
|
||||
ExtractPath(arg);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool VerifyInputs() => Inputs.Count > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper to extract data for a single path
|
||||
/// </summary>
|
||||
/// <param name="path">File or directory path</param>
|
||||
private void ExtractPath(string path)
|
||||
{
|
||||
// Normalize by getting the full path
|
||||
path = Path.GetFullPath(path);
|
||||
Console.WriteLine($"Checking possible path: {path}");
|
||||
|
||||
// Check if the file or directory exists
|
||||
if (File.Exists(path))
|
||||
{
|
||||
ExtractFile(path);
|
||||
}
|
||||
else if (Directory.Exists(path))
|
||||
{
|
||||
foreach (string file in path.SafeEnumerateFiles("*", SearchOption.AllDirectories))
|
||||
{
|
||||
ExtractFile(file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{path} does not exist, skipping...");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print information for a single file, if possible
|
||||
/// </summary>
|
||||
/// <param name="path">File path</param>
|
||||
private void ExtractFile(string file)
|
||||
{
|
||||
Console.WriteLine($"Attempting to extract all files from {file}");
|
||||
using Stream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
|
||||
// Get the extension for certain checks
|
||||
string extension = Path.GetExtension(file).ToLower().TrimStart('.');
|
||||
|
||||
// Get the first 16 bytes for matching
|
||||
byte[] magic = new byte[16];
|
||||
try
|
||||
{
|
||||
int read = stream.Read(magic, 0, 16);
|
||||
stream.SeekIfPossible(0, SeekOrigin.Begin);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (Debug) Console.Error.WriteLine(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the file type
|
||||
WrapperType ft = WrapperFactory.GetFileType(magic, extension);
|
||||
var wrapper = WrapperFactory.CreateWrapper(ft, stream);
|
||||
|
||||
// Create the output directory
|
||||
Directory.CreateDirectory(OutputPath);
|
||||
|
||||
// Print the preamble
|
||||
Console.WriteLine($"Attempting to extract from '{wrapper?.Description() ?? "UNKNOWN"}'");
|
||||
Console.WriteLine();
|
||||
|
||||
switch (wrapper)
|
||||
{
|
||||
// 7-zip
|
||||
case SevenZip sz:
|
||||
sz.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// BFPK archive
|
||||
case BFPK bfpk:
|
||||
bfpk.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// BSP
|
||||
case BSP bsp:
|
||||
bsp.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// bzip2
|
||||
case BZip2 bzip2:
|
||||
bzip2.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// CD-ROM bin file
|
||||
case CDROM cdrom:
|
||||
cdrom.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// CFB
|
||||
case CFB cfb:
|
||||
cfb.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// GCF
|
||||
case GCF gcf:
|
||||
gcf.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// gzip
|
||||
case GZip gzip:
|
||||
gzip.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// InstallShield Archive V3 (Z)
|
||||
case InstallShieldArchiveV3 isv3:
|
||||
isv3.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// IS-CAB archive
|
||||
case InstallShieldCabinet iscab:
|
||||
iscab.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// ISO 9660 volume
|
||||
case ISO9660 iso9660:
|
||||
iso9660.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// LZ-compressed file, KWAJ variant
|
||||
case LZKWAJ kwaj:
|
||||
kwaj.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// LZ-compressed file, QBasic variant
|
||||
case LZQBasic qbasic:
|
||||
qbasic.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// LZ-compressed file, SZDD variant
|
||||
case LZSZDD szdd:
|
||||
szdd.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// Microsoft Cabinet archive
|
||||
case MicrosoftCabinet mscab:
|
||||
mscab.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// MoPaQ (MPQ) archive
|
||||
case MoPaQ mpq:
|
||||
mpq.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// New Executable
|
||||
case NewExecutable nex:
|
||||
nex.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// PAK
|
||||
case PAK pak:
|
||||
pak.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// PFF
|
||||
case PFF pff:
|
||||
pff.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// PKZIP
|
||||
case PKZIP pkzip:
|
||||
pkzip.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// Portable Executable
|
||||
case PortableExecutable pex:
|
||||
pex.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// Quantum
|
||||
case Quantum quantum:
|
||||
quantum.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// RAR
|
||||
case RAR rar:
|
||||
rar.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// SGA
|
||||
case SGA sga:
|
||||
sga.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// Tape Archive
|
||||
case TapeArchive tar:
|
||||
tar.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// VBSP
|
||||
case VBSP vbsp:
|
||||
vbsp.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// VPK
|
||||
case VPK vpk:
|
||||
vpk.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// WAD3
|
||||
case WAD3 wad:
|
||||
wad.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// xz
|
||||
case XZ xz:
|
||||
xz.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// XZP
|
||||
case XZP xzp:
|
||||
xzp.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// ZSTD
|
||||
case ZSTD zstd:
|
||||
zstd.Extract(OutputPath, Debug);
|
||||
break;
|
||||
|
||||
// Everything else
|
||||
default:
|
||||
Console.WriteLine("Not a supported extractable file format, skipping...");
|
||||
Console.WriteLine();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate the extraction path
|
||||
/// </summary>
|
||||
private bool ValidateExtractionPath()
|
||||
{
|
||||
// Null or empty output path
|
||||
if (string.IsNullOrEmpty(OutputPath))
|
||||
{
|
||||
Console.WriteLine("Output directory required for extraction!");
|
||||
Console.WriteLine();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Malformed output path or invalid location
|
||||
try
|
||||
{
|
||||
OutputPath = Path.GetFullPath(OutputPath);
|
||||
Directory.CreateDirectory(OutputPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Output directory could not be created!");
|
||||
Console.WriteLine();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace ExtractionTool
|
||||
{
|
||||
/// <summary>
|
||||
/// Set of options for the test executable
|
||||
/// </summary>
|
||||
internal sealed class Options
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Enable debug output for relevant operations
|
||||
/// </summary>
|
||||
public bool Debug { get; private set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Set of input paths to use for operations
|
||||
/// </summary>
|
||||
public List<string> InputPaths { get; private set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Output path for archive extraction
|
||||
/// </summary>
|
||||
public string OutputPath { get; private set; } = string.Empty;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Parse commandline arguments into an Options object
|
||||
/// </summary>
|
||||
public static Options? ParseOptions(string[] args)
|
||||
{
|
||||
// If we have invalid arguments
|
||||
if (args == null || args.Length == 0)
|
||||
return null;
|
||||
|
||||
// Create an Options object
|
||||
var options = new Options();
|
||||
|
||||
// Parse the options and paths
|
||||
for (int index = 0; index < args.Length; index++)
|
||||
{
|
||||
string arg = args[index];
|
||||
switch (arg)
|
||||
{
|
||||
case "-?":
|
||||
case "-h":
|
||||
case "--help":
|
||||
return null;
|
||||
|
||||
case "-d":
|
||||
case "--debug":
|
||||
options.Debug = true;
|
||||
break;
|
||||
|
||||
case "-o":
|
||||
case "--outdir":
|
||||
options.OutputPath = index + 1 < args.Length ? args[++index] : string.Empty;
|
||||
break;
|
||||
|
||||
default:
|
||||
options.InputPaths.Add(arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate we have any input paths to work on
|
||||
if (options.InputPaths.Count == 0)
|
||||
{
|
||||
Console.WriteLine("At least one path is required!");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Validate the output path
|
||||
bool validPath = ValidateExtractionPath(options);
|
||||
if (!validPath)
|
||||
return null;
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display help text
|
||||
/// </summary>
|
||||
public static void DisplayHelp()
|
||||
{
|
||||
Console.WriteLine("Extraction Tool");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("ExtractionTool.exe <options> file|directory ...");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Options:");
|
||||
Console.WriteLine("-?, -h, --help Display this help text and quit");
|
||||
Console.WriteLine("-d, --debug Enable debug mode");
|
||||
Console.WriteLine("-o, --outdir [PATH] Set output path for extraction (required)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate the extraction path
|
||||
/// </summary>
|
||||
private static bool ValidateExtractionPath(Options options)
|
||||
{
|
||||
// Null or empty output path
|
||||
if (string.IsNullOrEmpty(options.OutputPath))
|
||||
{
|
||||
Console.WriteLine("Output directory required for extraction!");
|
||||
Console.WriteLine();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Malformed output path or invalid location
|
||||
try
|
||||
{
|
||||
options.OutputPath = Path.GetFullPath(options.OutputPath);
|
||||
Directory.CreateDirectory(options.OutputPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Output directory could not be created!");
|
||||
Console.WriteLine();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,250 +1,79 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Serialization;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
using System.Collections.Generic;
|
||||
using ExtractionTool.Features;
|
||||
using SabreTools.CommandLine;
|
||||
using SabreTools.CommandLine.Features;
|
||||
|
||||
namespace ExtractionTool
|
||||
{
|
||||
class Program
|
||||
public static class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
// Register the codepages
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
#endif
|
||||
|
||||
// Get the options from the arguments
|
||||
var options = Options.ParseOptions(args);
|
||||
// Create the command set
|
||||
var mainFeature = new MainFeature();
|
||||
var commandSet = CreateCommands(mainFeature);
|
||||
|
||||
// If we have an invalid state
|
||||
if (options == null)
|
||||
// If we have no args, show the help and quit
|
||||
if (args == null || args.Length == 0)
|
||||
{
|
||||
Options.DisplayHelp();
|
||||
commandSet.OutputAllHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through the input paths
|
||||
foreach (string inputPath in options.InputPaths)
|
||||
// Cache the first argument and starting index
|
||||
string featureName = args[0];
|
||||
|
||||
// Try processing the standalone arguments
|
||||
var topLevel = commandSet.GetTopLevel(featureName);
|
||||
switch (topLevel)
|
||||
{
|
||||
ExtractPath(inputPath, options.OutputPath, options.Debug);
|
||||
}
|
||||
}
|
||||
// Standalone Options
|
||||
case Help help: help.ProcessArgs(args, 0, commandSet); return;
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper to extract data for a single path
|
||||
/// </summary>
|
||||
/// <param name="path">File or directory path</param>
|
||||
/// <param name="outputDirectory">Output directory path</param>
|
||||
/// <param name="includeDebug">Enable including debug information</param>
|
||||
private static void ExtractPath(string path, string outputDirectory, bool includeDebug)
|
||||
{
|
||||
// Normalize by getting the full path
|
||||
path = Path.GetFullPath(path);
|
||||
Console.WriteLine($"Checking possible path: {path}");
|
||||
|
||||
// Check if the file or directory exists
|
||||
if (File.Exists(path))
|
||||
{
|
||||
ExtractFile(path, outputDirectory, includeDebug);
|
||||
}
|
||||
else if (Directory.Exists(path))
|
||||
{
|
||||
foreach (string file in IOExtensions.SafeEnumerateFiles(path, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
ExtractFile(file, outputDirectory, includeDebug);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{path} does not exist, skipping...");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print information for a single file, if possible
|
||||
/// </summary>
|
||||
private static void ExtractFile(string file, string outputDirectory, bool includeDebug)
|
||||
{
|
||||
Console.WriteLine($"Attempting to extract all files from {file}");
|
||||
using Stream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
|
||||
// Get the extension for certain checks
|
||||
string extension = Path.GetExtension(file).ToLower().TrimStart('.');
|
||||
|
||||
// Get the first 16 bytes for matching
|
||||
byte[] magic = new byte[16];
|
||||
try
|
||||
{
|
||||
int read = stream.Read(magic, 0, 16);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (includeDebug) Console.Error.WriteLine(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the file type
|
||||
WrapperType ft = WrapperFactory.GetFileType(magic, extension);
|
||||
var wrapper = WrapperFactory.CreateWrapper(ft, stream);
|
||||
|
||||
// Create the output directory
|
||||
Directory.CreateDirectory(outputDirectory);
|
||||
|
||||
// Print the preamble
|
||||
Console.WriteLine($"Attempting to extract from '{wrapper?.Description() ?? "UNKNOWN"}'");
|
||||
Console.WriteLine();
|
||||
|
||||
switch (wrapper)
|
||||
{
|
||||
// 7-zip
|
||||
case SevenZip sz:
|
||||
sz.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// BFPK archive
|
||||
case BFPK bfpk:
|
||||
bfpk.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// BSP
|
||||
case BSP bsp:
|
||||
bsp.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// bzip2
|
||||
case BZip2 bzip2:
|
||||
bzip2.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// CFB
|
||||
case CFB cfb:
|
||||
cfb.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// GCF
|
||||
case GCF gcf:
|
||||
gcf.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// gzip
|
||||
case GZip gzip:
|
||||
gzip.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// InstallShield Archive V3 (Z)
|
||||
case InstallShieldArchiveV3 isv3:
|
||||
isv3.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// IS-CAB archive
|
||||
case InstallShieldCabinet iscab:
|
||||
iscab.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// LZ-compressed file, KWAJ variant
|
||||
case LZKWAJ kwaj:
|
||||
kwaj.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// LZ-compressed file, QBasic variant
|
||||
case LZQBasic qbasic:
|
||||
qbasic.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// LZ-compressed file, SZDD variant
|
||||
case LZSZDD szdd:
|
||||
szdd.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// Microsoft Cabinet archive
|
||||
case MicrosoftCabinet mscab:
|
||||
mscab.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// MoPaQ (MPQ) archive
|
||||
case MoPaQ mpq:
|
||||
mpq.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// New Executable
|
||||
case NewExecutable nex:
|
||||
nex.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// PAK
|
||||
case PAK pak:
|
||||
pak.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// PFF
|
||||
case PFF pff:
|
||||
pff.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// PKZIP
|
||||
case PKZIP pkzip:
|
||||
pkzip.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// Portable Executable
|
||||
case PortableExecutable pex:
|
||||
pex.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// Quantum
|
||||
case Quantum quantum:
|
||||
quantum.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// RAR
|
||||
case RAR rar:
|
||||
rar.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// SGA
|
||||
case SGA sga:
|
||||
sga.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// Tape Archive
|
||||
case TapeArchive tar:
|
||||
tar.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// VBSP
|
||||
case VBSP vbsp:
|
||||
vbsp.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// VPK
|
||||
case VPK vpk:
|
||||
vpk.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// WAD3
|
||||
case WAD3 wad:
|
||||
wad.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// xz
|
||||
case XZ xz:
|
||||
xz.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// XZP
|
||||
case XZP xzp:
|
||||
xzp.Extract(outputDirectory, includeDebug);
|
||||
break;
|
||||
|
||||
// Everything else
|
||||
// Default Behavior
|
||||
default:
|
||||
Console.WriteLine("Not a supported extractable file format, skipping...");
|
||||
Console.WriteLine();
|
||||
if (!mainFeature.ProcessArgs(args, 0))
|
||||
{
|
||||
commandSet.OutputAllHelp();
|
||||
return;
|
||||
}
|
||||
else if (!mainFeature.VerifyInputs())
|
||||
{
|
||||
Console.Error.WriteLine("At least one input is required");
|
||||
commandSet.OutputAllHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
mainFeature.Execute();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create the command set for the program
|
||||
/// </summary>
|
||||
private static CommandSet CreateCommands(MainFeature mainFeature)
|
||||
{
|
||||
List<string> header = [
|
||||
"Extraction Tool",
|
||||
string.Empty,
|
||||
"ExtractionTool <options> file|directory ...",
|
||||
string.Empty,
|
||||
];
|
||||
|
||||
var commandSet = new CommandSet(header);
|
||||
|
||||
commandSet.Add(new Help(["-?", "-h", "--help"]));
|
||||
commandSet.Add(mainFeature.DebugInput);
|
||||
commandSet.Add(mainFeature.OutputPathInput);
|
||||
|
||||
return commandSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
278
InfoPrint/Features/MainFeature.cs
Normal file
278
InfoPrint/Features/MainFeature.cs
Normal file
@@ -0,0 +1,278 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.CommandLine;
|
||||
using SabreTools.CommandLine.Inputs;
|
||||
using SabreTools.Hashing;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Serialization;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
|
||||
namespace InfoPrint.Features
|
||||
{
|
||||
internal sealed class MainFeature : Feature
|
||||
{
|
||||
#region Feature Definition
|
||||
|
||||
public const string DisplayName = "main";
|
||||
|
||||
/// <remarks>Flags are unused</remarks>
|
||||
private static readonly string[] _flags = [];
|
||||
|
||||
/// <remarks>Description is unused</remarks>
|
||||
private const string _description = "";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Inputs
|
||||
|
||||
private const string _debugName = "debug";
|
||||
internal readonly FlagInput DebugInput = new(_debugName, ["-d", "--debug"], "Enable debug mode");
|
||||
|
||||
private const string _fileOnlyName = "file-only";
|
||||
internal readonly FlagInput FileOnlyInput = new(_fileOnlyName, ["-f", "--file"], "Print to file only");
|
||||
|
||||
private const string _hashName = "hash";
|
||||
internal readonly FlagInput HashInput = new(_hashName, ["-c", "--hash"], "Output file hashes");
|
||||
|
||||
#if NETCOREAPP
|
||||
private const string _jsonName = "json";
|
||||
internal readonly FlagInput JsonInput = new(_jsonName, ["-j", "--json"], "Print info as JSON");
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Enable debug output for relevant operations
|
||||
/// </summary>
|
||||
public bool Debug { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Output information to file only, skip printing to console
|
||||
/// </summary>
|
||||
public bool FileOnly { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Print external file hashes
|
||||
/// </summary>
|
||||
public bool Hash { get; private set; }
|
||||
|
||||
#if NETCOREAPP
|
||||
/// <summary>
|
||||
/// Enable JSON output
|
||||
/// </summary>
|
||||
public bool Json { get; private set; }
|
||||
#endif
|
||||
|
||||
public MainFeature()
|
||||
: base(DisplayName, _flags, _description)
|
||||
{
|
||||
RequiresInputs = true;
|
||||
|
||||
Add(DebugInput);
|
||||
Add(HashInput);
|
||||
Add(FileOnlyInput);
|
||||
#if NETCOREAPP
|
||||
Add(JsonInput);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Execute()
|
||||
{
|
||||
// Get the options from the arguments
|
||||
Debug = GetBoolean(_debugName);
|
||||
Hash = GetBoolean(_hashName);
|
||||
FileOnly = GetBoolean(_fileOnlyName);
|
||||
#if NETCOREAPP
|
||||
Json = GetBoolean(_jsonName);
|
||||
#endif
|
||||
|
||||
// Loop through the input paths
|
||||
for (int i = 0; i < Inputs.Count; i++)
|
||||
{
|
||||
string arg = Inputs[i];
|
||||
PrintPathInfo(arg);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool VerifyInputs() => Inputs.Count > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper to print information for a single path
|
||||
/// </summary>
|
||||
/// <param name="path">File or directory path</param>
|
||||
private void PrintPathInfo(string path)
|
||||
{
|
||||
Console.WriteLine($"Checking possible path: {path}");
|
||||
|
||||
// Check if the file or directory exists
|
||||
if (File.Exists(path))
|
||||
{
|
||||
PrintFileInfo(path);
|
||||
}
|
||||
else if (Directory.Exists(path))
|
||||
{
|
||||
foreach (string file in path.SafeEnumerateFiles("*", SearchOption.AllDirectories))
|
||||
{
|
||||
PrintFileInfo(file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{path} does not exist, skipping...");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print information for a single file, if possible
|
||||
/// </summary>
|
||||
/// <param name="file">File path</param>
|
||||
private void PrintFileInfo(string file)
|
||||
{
|
||||
Console.WriteLine($"Attempting to print info for {file}");
|
||||
|
||||
// Get the base info output name
|
||||
string filenameBase = $"info-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}";
|
||||
|
||||
// If we have the hash flag
|
||||
if (Hash)
|
||||
{
|
||||
var hashBuilder = PrintHashInfo(file);
|
||||
if (hashBuilder != null)
|
||||
{
|
||||
// Create the output data
|
||||
string hashData = hashBuilder.ToString();
|
||||
|
||||
// Write the output data
|
||||
using var hsw = new StreamWriter(File.OpenWrite($"{filenameBase}.hashes"));
|
||||
hsw.WriteLine(hashData);
|
||||
hsw.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using Stream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
|
||||
// Read the first 8 bytes
|
||||
byte[] magic = stream.PeekBytes(8);
|
||||
|
||||
// Get the file type
|
||||
string extension = Path.GetExtension(file).TrimStart('.');
|
||||
WrapperType ft = WrapperFactory.GetFileType(magic ?? [], extension);
|
||||
|
||||
// Print out the file format
|
||||
Console.WriteLine($"File format found: {ft}");
|
||||
|
||||
// Setup the wrapper to print
|
||||
var wrapper = WrapperFactory.CreateWrapper(ft, stream);
|
||||
|
||||
// If we don't have a wrapper
|
||||
if (wrapper == null)
|
||||
{
|
||||
Console.WriteLine($"Either {ft} is not supported or something went wrong during parsing!");
|
||||
Console.WriteLine();
|
||||
return;
|
||||
}
|
||||
|
||||
#if NETCOREAPP
|
||||
// If we have the JSON flag
|
||||
if (Json)
|
||||
{
|
||||
// Create the output data
|
||||
string serializedData = wrapper.ExportJSON();
|
||||
|
||||
// Write the output data
|
||||
using var jsw = new StreamWriter(File.OpenWrite($"{filenameBase}.json"));
|
||||
jsw.WriteLine(serializedData);
|
||||
jsw.Flush();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create the output data
|
||||
var builder = wrapper.ExportStringBuilder();
|
||||
if (builder == null)
|
||||
{
|
||||
Console.WriteLine("No item information could be generated");
|
||||
return;
|
||||
}
|
||||
|
||||
// Only print to console if enabled
|
||||
if (!FileOnly)
|
||||
Console.WriteLine(builder);
|
||||
|
||||
using var sw = new StreamWriter(File.OpenWrite($"{filenameBase}.txt"));
|
||||
sw.WriteLine(file);
|
||||
sw.WriteLine();
|
||||
sw.WriteLine(builder.ToString());
|
||||
sw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(Debug ? ex : "[Exception opening file, please try again]");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print hash information for a single file, if possible
|
||||
/// </summary>
|
||||
/// <param name="file">File path</param>
|
||||
/// <returns>StringBuilder representing the hash information, if possible</returns>
|
||||
private StringBuilder? PrintHashInfo(string file)
|
||||
{
|
||||
// Ignore missing files
|
||||
if (!File.Exists(file))
|
||||
return null;
|
||||
|
||||
Console.WriteLine($"Attempting to hash {file}, this may take a while...");
|
||||
|
||||
try
|
||||
{
|
||||
// Get all file hashes for flexibility
|
||||
var hashes = HashTool.GetFileHashes(file);
|
||||
if (hashes == null)
|
||||
{
|
||||
if (Debug) Console.WriteLine($"Hashes for {file} could not be retrieved");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Output subset of available hashes
|
||||
var builder = new StringBuilder();
|
||||
if (hashes.TryGetValue(HashType.CRC16, out string? crc16) && crc16 != null)
|
||||
builder.AppendLine($"CRC-16 checksum: {crc16}");
|
||||
if (hashes.TryGetValue(HashType.CRC32, out string? crc32) && crc32 != null)
|
||||
builder.AppendLine($"CRC-32 checksum: {crc32}");
|
||||
if (hashes.TryGetValue(HashType.MD2, out string? md2) && md2 != null)
|
||||
builder.AppendLine($"MD2 hash: {md2}");
|
||||
if (hashes.TryGetValue(HashType.MD4, out string? md4) && md4 != null)
|
||||
builder.AppendLine($"MD4 hash: {md4}");
|
||||
if (hashes.TryGetValue(HashType.MD5, out string? md5) && md5 != null)
|
||||
builder.AppendLine($"MD5 hash: {md5}");
|
||||
if (hashes.TryGetValue(HashType.RIPEMD128, out string? ripemd128) && ripemd128 != null)
|
||||
builder.AppendLine($"RIPEMD-128 hash: {ripemd128}");
|
||||
if (hashes.TryGetValue(HashType.RIPEMD160, out string? ripemd160) && ripemd160 != null)
|
||||
builder.AppendLine($"RIPEMD-160 hash: {ripemd160}");
|
||||
if (hashes.TryGetValue(HashType.SHA1, out string? sha1) && sha1 != null)
|
||||
builder.AppendLine($"SHA-1 hash: {sha1}");
|
||||
if (hashes.TryGetValue(HashType.SHA256, out string? sha256) && sha256 != null)
|
||||
builder.AppendLine($"SHA-256 hash: {sha256}");
|
||||
if (hashes.TryGetValue(HashType.SHA384, out string? sha384) && sha384 != null)
|
||||
builder.AppendLine($"SHA-384 hash: {sha384}");
|
||||
if (hashes.TryGetValue(HashType.SHA512, out string? sha512) && sha512 != null)
|
||||
builder.AppendLine($"SHA-512 hash: {sha512}");
|
||||
|
||||
return builder;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(Debug ? ex : "[Exception opening file, please try again]");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
|
||||
<OutputType>Exe</OutputType>
|
||||
<CheckEolTargetFramework>false</CheckEolTargetFramework>
|
||||
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
|
||||
@@ -10,7 +10,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>2.0.0</Version>
|
||||
<Version>2.2.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Support All Frameworks -->
|
||||
@@ -20,11 +20,11 @@
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`)) OR $(TargetFramework.StartsWith(`net10`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -32,8 +32,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SabreTools.IO" Version="1.7.5" />
|
||||
<PackageReference Include="SabreTools.Hashing" Version="1.5.0" />
|
||||
<PackageReference Include="SabreTools.CommandLine" Version="[1.4.0]" />
|
||||
<PackageReference Include="SabreTools.Hashing" Version="[1.6.0]" />
|
||||
<PackageReference Include="SabreTools.IO" Version="[1.9.0]" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,141 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace InfoPrint
|
||||
{
|
||||
/// <summary>
|
||||
/// Set of options for the test executable
|
||||
/// </summary>
|
||||
internal sealed class Options
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Enable debug output for relevant operations
|
||||
/// </summary>
|
||||
public bool Debug { get; private set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Output information to file only, skip printing to console
|
||||
/// </summary>
|
||||
public bool FileOnly { get; private set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Print external file hashes
|
||||
/// </summary>
|
||||
public bool Hash { get; private set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Set of input paths to use for operations
|
||||
/// </summary>
|
||||
public List<string> InputPaths { get; private set; } = [];
|
||||
|
||||
#if NETCOREAPP
|
||||
/// <summary>
|
||||
/// Enable JSON output
|
||||
/// </summary>
|
||||
public bool Json { get; private set; } = false;
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Parse commandline arguments into an Options object
|
||||
/// </summary>
|
||||
public static Options? ParseOptions(string[] args)
|
||||
{
|
||||
// If we have invalid arguments
|
||||
if (args == null || args.Length == 0)
|
||||
return null;
|
||||
|
||||
// Create an Options object
|
||||
var options = new Options();
|
||||
|
||||
// Parse the features
|
||||
int index = 0;
|
||||
for (; index < args.Length; index++)
|
||||
{
|
||||
string arg = args[index];
|
||||
bool featureFound = false;
|
||||
switch (arg)
|
||||
{
|
||||
case "-?":
|
||||
case "-h":
|
||||
case "--help":
|
||||
return null;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// If the flag wasn't a feature
|
||||
if (!featureFound)
|
||||
break;
|
||||
}
|
||||
|
||||
// Parse the options and paths
|
||||
for (; index < args.Length; index++)
|
||||
{
|
||||
string arg = args[index];
|
||||
switch (arg)
|
||||
{
|
||||
case "-d":
|
||||
case "--debug":
|
||||
options.Debug = true;
|
||||
break;
|
||||
|
||||
case "-c":
|
||||
case "--hash":
|
||||
options.Hash = true;
|
||||
break;
|
||||
|
||||
case "-f":
|
||||
case "--file":
|
||||
options.FileOnly = true;
|
||||
break;
|
||||
|
||||
case "-j":
|
||||
case "--json":
|
||||
#if NETCOREAPP
|
||||
options.Json = true;
|
||||
#else
|
||||
Console.WriteLine("JSON output not available in .NET Framework");
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
options.InputPaths.Add(arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate we have any input paths to work on
|
||||
if (options.InputPaths.Count == 0)
|
||||
{
|
||||
Console.WriteLine("At least one path is required!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display help text
|
||||
/// </summary>
|
||||
public static void DisplayHelp()
|
||||
{
|
||||
Console.WriteLine("Information Printing Program");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("InfoPrint <options> file|directory ...");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Options:");
|
||||
Console.WriteLine("-?, -h, --help Display this help text and quit");
|
||||
Console.WriteLine("-d, --debug Enable debug mode");
|
||||
Console.WriteLine("-c, --hash Output file hashes");
|
||||
Console.WriteLine("-f, --file Print to file only");
|
||||
#if NETCOREAPP
|
||||
Console.WriteLine("-j, --json Print info as JSON");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.Hashing;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Serialization;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
using System.Collections.Generic;
|
||||
using InfoPrint.Features;
|
||||
using SabreTools.CommandLine;
|
||||
using SabreTools.CommandLine.Features;
|
||||
|
||||
namespace InfoPrint
|
||||
{
|
||||
@@ -12,199 +10,69 @@ namespace InfoPrint
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// Get the options from the arguments
|
||||
var options = Options.ParseOptions(args);
|
||||
// Create the command set
|
||||
var mainFeature = new MainFeature();
|
||||
var commandSet = CreateCommands(mainFeature);
|
||||
|
||||
// If we have an invalid state
|
||||
if (options == null)
|
||||
// If we have no args, show the help and quit
|
||||
if (args == null || args.Length == 0)
|
||||
{
|
||||
Options.DisplayHelp();
|
||||
commandSet.OutputAllHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through the input paths
|
||||
foreach (string inputPath in options.InputPaths)
|
||||
// Cache the first argument and starting index
|
||||
string featureName = args[0];
|
||||
|
||||
// Try processing the standalone arguments
|
||||
var topLevel = commandSet.GetTopLevel(featureName);
|
||||
switch (topLevel)
|
||||
{
|
||||
PrintPathInfo(inputPath, options);
|
||||
// Standalone Options
|
||||
case Help help: help.ProcessArgs(args, 0, commandSet); return;
|
||||
|
||||
// Default Behavior
|
||||
default:
|
||||
if (!mainFeature.ProcessArgs(args, 0))
|
||||
{
|
||||
commandSet.OutputAllHelp();
|
||||
return;
|
||||
}
|
||||
else if (!mainFeature.VerifyInputs())
|
||||
{
|
||||
Console.Error.WriteLine("At least one input is required");
|
||||
commandSet.OutputAllHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
mainFeature.Execute();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper to print information for a single path
|
||||
/// Create the command set for the program
|
||||
/// </summary>
|
||||
/// <param name="path">File or directory path</param>
|
||||
/// <param name="options">User-defined options</param>
|
||||
private static void PrintPathInfo(string path, Options options)
|
||||
private static CommandSet CreateCommands(MainFeature mainFeature)
|
||||
{
|
||||
Console.WriteLine($"Checking possible path: {path}");
|
||||
List<string> header = [
|
||||
"Information Printing Program",
|
||||
string.Empty,
|
||||
"InfoPrint <options> file|directory ...",
|
||||
string.Empty,
|
||||
];
|
||||
|
||||
// Check if the file or directory exists
|
||||
if (File.Exists(path))
|
||||
{
|
||||
PrintFileInfo(path, options);
|
||||
}
|
||||
else if (Directory.Exists(path))
|
||||
{
|
||||
foreach (string file in IOExtensions.SafeEnumerateFiles(path, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
PrintFileInfo(file, options);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{path} does not exist, skipping...");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print information for a single file, if possible
|
||||
/// </summary>
|
||||
/// <param name="file">File path</param>
|
||||
/// <param name="options">User-defined options</param>
|
||||
private static void PrintFileInfo(string file, Options options)
|
||||
{
|
||||
Console.WriteLine($"Attempting to print info for {file}");
|
||||
|
||||
// Get the base info output name
|
||||
string filenameBase = $"info-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}";
|
||||
|
||||
// If we have the hash flag
|
||||
if (options.Hash)
|
||||
{
|
||||
var hashBuilder = PrintHashInfo(file, options.Debug);
|
||||
if (hashBuilder != null)
|
||||
{
|
||||
// Create the output data
|
||||
string hashData = hashBuilder.ToString();
|
||||
|
||||
// Write the output data
|
||||
using var hsw = new StreamWriter(File.OpenWrite($"{filenameBase}.hashes"));
|
||||
hsw.WriteLine(hashData);
|
||||
hsw.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using Stream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
|
||||
// Read the first 8 bytes
|
||||
byte[]? magic = stream.ReadBytes(8);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Get the file type
|
||||
string extension = Path.GetExtension(file).TrimStart('.');
|
||||
WrapperType ft = WrapperFactory.GetFileType(magic ?? [], extension);
|
||||
|
||||
// Print out the file format
|
||||
Console.WriteLine($"File format found: {ft}");
|
||||
|
||||
// Setup the wrapper to print
|
||||
var wrapper = WrapperFactory.CreateWrapper(ft, stream);
|
||||
|
||||
// If we don't have a wrapper
|
||||
if (wrapper == null)
|
||||
{
|
||||
Console.WriteLine($"Either {ft} is not supported or something went wrong during parsing!");
|
||||
Console.WriteLine();
|
||||
return;
|
||||
}
|
||||
var commandSet = new CommandSet(header);
|
||||
|
||||
commandSet.Add(new Help(["-?", "-h", "--help"]));
|
||||
commandSet.Add(mainFeature.DebugInput);
|
||||
commandSet.Add(mainFeature.HashInput);
|
||||
commandSet.Add(mainFeature.FileOnlyInput);
|
||||
#if NETCOREAPP
|
||||
// If we have the JSON flag
|
||||
if (options.Json)
|
||||
{
|
||||
// Create the output data
|
||||
string serializedData = wrapper.ExportJSON();
|
||||
|
||||
// Write the output data
|
||||
using var jsw = new StreamWriter(File.OpenWrite($"{filenameBase}.json"));
|
||||
jsw.WriteLine(serializedData);
|
||||
jsw.Flush();
|
||||
}
|
||||
commandSet.Add(mainFeature.JsonInput);
|
||||
#endif
|
||||
|
||||
// Create the output data
|
||||
var builder = wrapper.ExportStringBuilder();
|
||||
if (builder == null)
|
||||
{
|
||||
Console.WriteLine("No item information could be generated");
|
||||
return;
|
||||
}
|
||||
|
||||
// Only print to console if enabled
|
||||
if (!options.FileOnly)
|
||||
Console.WriteLine(builder);
|
||||
|
||||
using var sw = new StreamWriter(File.OpenWrite($"{filenameBase}.txt"));
|
||||
sw.WriteLine(file);
|
||||
sw.WriteLine();
|
||||
sw.WriteLine(builder.ToString());
|
||||
sw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(options.Debug ? ex : "[Exception opening file, please try again]");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print hash information for a single file, if possible
|
||||
/// </summary>
|
||||
/// <param name="file">File path</param>
|
||||
/// <param name="debug">Enable debug output</param>
|
||||
/// <returns>StringBuilder representing the hash information, if possible</returns>
|
||||
private static StringBuilder? PrintHashInfo(string file, bool debug)
|
||||
{
|
||||
// Ignore missing files
|
||||
if (!File.Exists(file))
|
||||
return null;
|
||||
|
||||
Console.WriteLine($"Attempting to hash {file}, this may take a while...");
|
||||
|
||||
try
|
||||
{
|
||||
// Get all file hashes for flexibility
|
||||
var hashes = HashTool.GetFileHashes(file);
|
||||
if (hashes == null)
|
||||
{
|
||||
if (debug) Console.WriteLine($"Hashes for {file} could not be retrieved");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Output subset of available hashes
|
||||
var builder = new StringBuilder();
|
||||
if (hashes.TryGetValue(HashType.CRC16, out string? crc16) && crc16 != null)
|
||||
builder.AppendLine($"CRC-16 checksum: {crc16}");
|
||||
if (hashes.TryGetValue(HashType.CRC32, out string? crc32) && crc32 != null)
|
||||
builder.AppendLine($"CRC-32 checksum: {crc32}");
|
||||
if (hashes.TryGetValue(HashType.MD2, out string? md2) && md2 != null)
|
||||
builder.AppendLine($"MD2 hash: {md2}");
|
||||
if (hashes.TryGetValue(HashType.MD4, out string? md4) && md4 != null)
|
||||
builder.AppendLine($"MD4 hash: {md4}");
|
||||
if (hashes.TryGetValue(HashType.MD5, out string? md5) && md5 != null)
|
||||
builder.AppendLine($"MD5 hash: {md5}");
|
||||
if (hashes.TryGetValue(HashType.RIPEMD128, out string? ripemd128) && ripemd128 != null)
|
||||
builder.AppendLine($"RIPEMD-128 hash: {ripemd128}");
|
||||
if (hashes.TryGetValue(HashType.RIPEMD160, out string? ripemd160) && ripemd160 != null)
|
||||
builder.AppendLine($"RIPEMD-160 hash: {ripemd160}");
|
||||
if (hashes.TryGetValue(HashType.SHA1, out string? sha1) && sha1 != null)
|
||||
builder.AppendLine($"SHA-1 hash: {sha1}");
|
||||
if (hashes.TryGetValue(HashType.SHA256, out string? sha256) && sha256 != null)
|
||||
builder.AppendLine($"SHA-256 hash: {sha256}");
|
||||
if (hashes.TryGetValue(HashType.SHA384, out string? sha384) && sha384 != null)
|
||||
builder.AppendLine($"SHA-384 hash: {sha384}");
|
||||
if (hashes.TryGetValue(HashType.SHA512, out string? sha512) && sha512 != null)
|
||||
builder.AppendLine($"SHA-512 hash: {sha512}");
|
||||
|
||||
return builder;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(debug ? ex : "[Exception opening file, please try again]");
|
||||
return null;
|
||||
}
|
||||
return commandSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
README.MD
17
README.MD
@@ -8,8 +8,8 @@ Find the link to the Nuget package [here](https://www.nuget.org/packages/SabreTo
|
||||
|
||||
The following non-project libraries (or ports thereof) are used for file handling:
|
||||
|
||||
- [SharpCompress](https://github.com/adamhathcock/sharpcompress) - Common archive format extraction
|
||||
- [StormLibSharp](https://github.com/robpaveza/stormlibsharp) - MoPaQ extraction [Unused in .NET Framework 2.0/3.5/4.0 and non-Windows builds due to Windows-specific libraries]
|
||||
- [GrindCore.SharpCompress](https://github.com/Nanook/GrindCore.SharpCompress) - Common archive format extraction
|
||||
- [StormLibSharp](https://github.com/robpaveza/stormlibsharp) - MoPaQ extraction [Unused in non-Windows builds due to Windows-specific libraries]
|
||||
|
||||
The following projects have influenced this library:
|
||||
|
||||
@@ -30,7 +30,7 @@ For the latest WIP build here: [Rolling Release](https://github.com/SabreTools/S
|
||||
InfoPrint <options> file|directory ...
|
||||
|
||||
Options:
|
||||
-?, -h, --help Display this help text and quit
|
||||
-?, -h, --help Display this help text
|
||||
-d, --debug Enable debug mode
|
||||
-c, --hash Output file hashes
|
||||
-f, --file Print to file only
|
||||
@@ -42,10 +42,10 @@ Options:
|
||||
**ExtractionTool** is a reference implementation for the extraction features of the library, packaged as a standalone executable for all supported platforms. It will attempt to detect and extract many supported file types. See the table below for supported extraction functionality.
|
||||
|
||||
```text
|
||||
ExtractionTool.exe <options> file|directory ...
|
||||
ExtractionTool <options> file|directory ...
|
||||
|
||||
Options:
|
||||
-?, -h, --help Display this help text and quit
|
||||
-?, -h, --help Display this help text
|
||||
-d, --debug Enable debug mode
|
||||
-o, --outdir [PATH] Set output path for extraction (required)
|
||||
```
|
||||
@@ -55,7 +55,7 @@ Options:
|
||||
| 7-zip archive | .NET Framework 4.6.2 and greater |
|
||||
| BFPK custom archive format | |
|
||||
| bzip2 archive | .NET Framework 4.6.2 and greater |
|
||||
| Compound File Binary (CFB) | Only CFB common pieces extractable. .NET Framework 4.0 and greater |
|
||||
| Compound File Binary (CFB) | Only CFB common pieces extractable |
|
||||
| gzip archive | |
|
||||
| Half-Life Game Cache File (GCF) | |
|
||||
| Half-Life Level (BSP) | |
|
||||
@@ -66,7 +66,7 @@ Options:
|
||||
| InstallShield CAB | |
|
||||
| Microsoft cabinet file | Does not support LZX or Quantum compression |
|
||||
| Microsoft LZ-compressed files | KWAJ, QBasic, and SZDD variants |
|
||||
| MoPaQ game data archive (MPQ) | Currently not working. Windows only. .NET Framework 4.5.2 and above |
|
||||
| MoPaQ game data archive (MPQ) | Windows only |
|
||||
| New Exectuable | Embedded archives and executables in the overlay and Wise installer |
|
||||
| NovaLogic Game Archive Format (PFF) | |
|
||||
| PKZIP and derived files (ZIP, etc.) | .NET Framework 4.6.2 and greater |
|
||||
@@ -99,8 +99,8 @@ Below is a table representing the various non-conversion interfaces that are imp
|
||||
|
||||
| Interface Name | Purpose |
|
||||
| --- | --- |
|
||||
| `SabreTools.Data.Printers.IPrinter<TModel>` | Provides a formatted output for a `TModel` |
|
||||
| `SabreTools.Serialization.Wrappers.IExtractable` | Marks a wrapper as able to be extracted |
|
||||
| `SabreTools.Serialization.Wrappers.IPrintable` | Marks a wrapper as able to print model information |
|
||||
| `SabreTools.Serialization.Wrappers.IWrapper` | Represents an item with a description and JSON serializable state, allowing for extensions |
|
||||
| `SabreTools.Serialization.Wrappers.IWrapper<TModel>` | Wraps a model with source data, allowing for extensions |
|
||||
|
||||
@@ -114,7 +114,6 @@ Below is a table of all namespaces within the library and what they represent
|
||||
| `SabreTools.Data.Extensions` | Extension methods related to models |
|
||||
| `SabreTools.Data.Models` | Models representing different file and structure types |
|
||||
| `SabreTools.Data.ObjectIdentifier` | Object Identifier (OID) parsing |
|
||||
| `SabreTools.Data.Printers` | Export model information in a formatted manner |
|
||||
| `SabreTools.Serialization.CrossModel` | Convert between models; mainly used for metadata files converting to and from a common, `Dictionary`-based model |
|
||||
| `SabreTools.Serialization.Interfaces` | Interfaces used commonly throughout the library |
|
||||
| `SabreTools.Serialization.Readers` | Convert from external sources to models |
|
||||
|
||||
@@ -171,4 +171,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", file.Width);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,4 +109,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", row.FileIsAvailable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,4 +498,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", driver.Blit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,4 +108,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", rom.Date);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,4 +63,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", row.Size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using SabreTools.Serialization.CrossModel;
|
||||
using System;
|
||||
using SabreTools.Hashing;
|
||||
using SabreTools.Serialization.CrossModel;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Serialization.Test.CrossModel
|
||||
@@ -324,4 +324,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", spamsum.File);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,4 +125,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.True(row.NoGoodDumpKnown);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -876,4 +876,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", ramoption.Content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,4 +568,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", softwarelist.Filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -870,4 +870,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", ramoption.Content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -870,4 +870,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", ramoption.Content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,4 +448,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", image.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Original = original,
|
||||
Rom = sccpluscart,
|
||||
};
|
||||
|
||||
|
||||
var software = new Data.Models.OpenMSX.Software
|
||||
{
|
||||
Title = "XXXXXX",
|
||||
@@ -154,4 +154,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", rombase.Remark);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,4 +151,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", rom.MergeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,4 +180,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", row.Status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,4 +308,4 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", dipvalue.Default);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,4 +210,4 @@ namespace SabreTools.Serialization.Test.Extensions
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace SabreTools.Serialization.Test.ObjectIdentifier
|
||||
public void ASN1Notation_AlwaysNull()
|
||||
{
|
||||
ulong[]? values = null;
|
||||
string? actual = Parser.ParseOIDToASN1Notation(values);
|
||||
string? actual = Parser.ParseOIDToASN1Notation(values);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SabreTools.Serialization.Test.ObjectIdentifier
|
||||
public void DotNotation_NullValues_Null()
|
||||
{
|
||||
ulong[]? values = null;
|
||||
string? actual = Parser.ParseOIDToDotNotation(values);
|
||||
string? actual = Parser.ParseOIDToDotNotation(values);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace SabreTools.Serialization.Test.ObjectIdentifier
|
||||
public void DotNotation_EmptyValues_Null()
|
||||
{
|
||||
ulong[]? values = [];
|
||||
string? actual = Parser.ParseOIDToDotNotation(values);
|
||||
string? actual = Parser.ParseOIDToDotNotation(values);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace SabreTools.Serialization.Test.ObjectIdentifier
|
||||
{
|
||||
string expected = "0.1.2.3";
|
||||
ulong[]? values = [0, 1, 2, 3];
|
||||
string? actual = Parser.ParseOIDToDotNotation(values);
|
||||
string? actual = Parser.ParseOIDToDotNotation(values);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace SabreTools.Serialization.Test.ObjectIdentifier
|
||||
public void ModifiedOIDIRI_NullValues_Null()
|
||||
{
|
||||
ulong[]? values = null;
|
||||
string? actual = Parser.ParseOIDToModifiedOIDIRI(values);
|
||||
string? actual = Parser.ParseOIDToModifiedOIDIRI(values);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace SabreTools.Serialization.Test.ObjectIdentifier
|
||||
public void ModifiedOIDIRI_EmptyValues_Null()
|
||||
{
|
||||
ulong[]? values = [];
|
||||
string? actual = Parser.ParseOIDToModifiedOIDIRI(values);
|
||||
string? actual = Parser.ParseOIDToModifiedOIDIRI(values);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace SabreTools.Serialization.Test.ObjectIdentifier
|
||||
{
|
||||
string expected = "/ITU-T/[question]/2/3";
|
||||
ulong[]? values = [0, 1, 2, 3];
|
||||
string? actual = Parser.ParseOIDToModifiedOIDIRI(values);
|
||||
string? actual = Parser.ParseOIDToModifiedOIDIRI(values);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace SabreTools.Serialization.Test.ObjectIdentifier
|
||||
public void OIDIRI_NullValues_Null()
|
||||
{
|
||||
ulong[]? values = null;
|
||||
string? actual = Parser.ParseOIDToOIDIRINotation(values);
|
||||
string? actual = Parser.ParseOIDToOIDIRINotation(values);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace SabreTools.Serialization.Test.ObjectIdentifier
|
||||
public void OIDIRI_EmptyValues_Null()
|
||||
{
|
||||
ulong[]? values = [];
|
||||
string? actual = Parser.ParseOIDToOIDIRINotation(values);
|
||||
string? actual = Parser.ParseOIDToOIDIRINotation(values);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
@@ -102,10 +102,10 @@ namespace SabreTools.Serialization.Test.ObjectIdentifier
|
||||
{
|
||||
string expected = "/ITU-T/1/2/3";
|
||||
ulong[]? values = [0, 1, 2, 3];
|
||||
string? actual = Parser.ParseOIDToOIDIRINotation(values);
|
||||
string? actual = Parser.ParseOIDToOIDIRINotation(values);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,4 +149,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,4 +237,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", file.Width);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,4 +214,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -615,4 +615,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", driver.Blit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,4 +115,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,4 +174,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX XXXXXX", rom.Date);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,4 +129,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", row.Size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,4 +398,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", spamsum.File);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
73
SabreTools.Serialization.Test/Readers/ISO9660Tests.cs
Normal file
73
SabreTools.Serialization.Test/Readers/ISO9660Tests.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SabreTools.Serialization.Readers;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
public class ISO9660Tests
|
||||
{
|
||||
[Fact]
|
||||
public void NullArray_Null()
|
||||
{
|
||||
byte[]? data = null;
|
||||
int offset = 0;
|
||||
var deserializer = new ISO9660();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyArray_Null()
|
||||
{
|
||||
byte[]? data = [];
|
||||
int offset = 0;
|
||||
var deserializer = new ISO9660();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidArray_Null()
|
||||
{
|
||||
byte[]? data = [.. Enumerable.Repeat<byte>(0xFF, 1024)];
|
||||
int offset = 0;
|
||||
var deserializer = new ISO9660();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStream_Null()
|
||||
{
|
||||
Stream? data = null;
|
||||
var deserializer = new ISO9660();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([]);
|
||||
var deserializer = new ISO9660();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([.. Enumerable.Repeat<byte>(0xFF, 1024)]);
|
||||
var deserializer = new ISO9660();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SabreTools.Serialization.Readers;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
public class InstallShieldExecutableFileTests
|
||||
{
|
||||
[Fact]
|
||||
public void NullArray_Null()
|
||||
{
|
||||
byte[]? data = null;
|
||||
int offset = 0;
|
||||
var deserializer = new InstallShieldExecutableFile();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyArray_Null()
|
||||
{
|
||||
byte[]? data = [];
|
||||
int offset = 0;
|
||||
var deserializer = new InstallShieldExecutableFile();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidArray_Null()
|
||||
{
|
||||
byte[]? data = [.. Enumerable.Repeat<byte>(0xFF, 1024)];
|
||||
int offset = 0;
|
||||
var deserializer = new InstallShieldExecutableFile();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStream_Null()
|
||||
{
|
||||
Stream? data = null;
|
||||
var deserializer = new InstallShieldExecutableFile();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([]);
|
||||
var deserializer = new InstallShieldExecutableFile();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([.. Enumerable.Repeat<byte>(0xFF, 1024)]);
|
||||
var deserializer = new InstallShieldExecutableFile();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using Xunit;
|
||||
namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
public class LZQBasicTests
|
||||
|
||||
|
||||
{
|
||||
[Fact]
|
||||
public void NullArray_Null()
|
||||
@@ -71,4 +71,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,4 +264,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.True(row.NoGoodDumpKnown);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -943,4 +943,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", ramoption.Content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,4 +618,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", softwarelist.Filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -937,4 +937,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", ramoption.Content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -937,4 +937,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", ramoption.Content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,4 +514,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", image.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,4 +220,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", rombase.Remark);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,4 +217,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", rom.MergeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,4 +305,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", row.Status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,4 +374,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", dipvalue.Default);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,4 +36,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
73
SabreTools.Serialization.Test/Readers/XZTests.cs
Normal file
73
SabreTools.Serialization.Test/Readers/XZTests.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SabreTools.Serialization.Readers;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
public class XZTests
|
||||
{
|
||||
[Fact]
|
||||
public void NullArray_Null()
|
||||
{
|
||||
byte[]? data = null;
|
||||
int offset = 0;
|
||||
var deserializer = new XZ();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyArray_Null()
|
||||
{
|
||||
byte[]? data = [];
|
||||
int offset = 0;
|
||||
var deserializer = new XZ();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidArray_Null()
|
||||
{
|
||||
byte[]? data = [.. Enumerable.Repeat<byte>(0xFF, 1024)];
|
||||
int offset = 0;
|
||||
var deserializer = new XZ();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStream_Null()
|
||||
{
|
||||
Stream? data = null;
|
||||
var deserializer = new XZ();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([]);
|
||||
var deserializer = new XZ();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([.. Enumerable.Repeat<byte>(0xFF, 1024)]);
|
||||
var deserializer = new XZ();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,4 +35,4 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
|
||||
<IsPackable>false</IsPackable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
@@ -26,10 +26,10 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="SabreTools.Hashing" Version="1.5.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
|
||||
<PackageReference Include="SabreTools.Hashing" Version="[1.6.0]" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4">
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user