mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-11-16 01:10:25 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
451fc0b394 | ||
|
|
79ca9f617e | ||
|
|
a602686551 | ||
|
|
4083aed12f | ||
|
|
717de3608c |
@@ -10,7 +10,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Support All Frameworks -->
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Support All Frameworks -->
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
@@ -71,6 +71,12 @@ namespace SabreTools.Data.Models.Logiqx
|
||||
[XmlElement("publisher")]
|
||||
public string? Publisher { get; set; }
|
||||
|
||||
[XmlElement("serial")]
|
||||
public string? Serial { get; set; }
|
||||
|
||||
[XmlElement("version")]
|
||||
public string? Version { get; set; }
|
||||
|
||||
/// <remarks>No-Intro extension includes more than 1 instance</remarks>
|
||||
[XmlElement("category")]
|
||||
public string[]? Category { get; set; }
|
||||
|
||||
@@ -157,6 +157,8 @@ namespace SabreTools.Data.Models.Metadata
|
||||
|
||||
public string? Score { get; set; }
|
||||
|
||||
public string? Serial { get; set; }
|
||||
|
||||
public SharedFeat[]? SharedFeat { get; set; }
|
||||
|
||||
public Slot[]? Slot { get; set; }
|
||||
@@ -186,6 +188,8 @@ namespace SabreTools.Data.Models.Metadata
|
||||
|
||||
public string? Url { get; set; }
|
||||
|
||||
public string? Version { get; set; }
|
||||
|
||||
public Video[]? Video { get; set; }
|
||||
|
||||
public string? Year { get; set; }
|
||||
@@ -293,6 +297,7 @@ namespace SabreTools.Data.Models.Metadata
|
||||
obj.SampleOf = SampleOf;
|
||||
obj.SaveType = SaveType;
|
||||
obj.Score = Score;
|
||||
obj.Serial = Serial;
|
||||
if (SharedFeat is not null)
|
||||
obj.SharedFeat = Array.ConvertAll(SharedFeat, i => (SharedFeat)i.Clone());
|
||||
if (Slot is not null)
|
||||
@@ -311,6 +316,7 @@ namespace SabreTools.Data.Models.Metadata
|
||||
obj.Tags = Tags;
|
||||
obj.TitleID = TitleID;
|
||||
obj.Url = Url;
|
||||
obj.Version = Version;
|
||||
if (Video is not null)
|
||||
obj.Video = Array.ConvertAll(Video, i => (Video)i.Clone());
|
||||
obj.Year = Year;
|
||||
@@ -558,6 +564,11 @@ namespace SabreTools.Data.Models.Metadata
|
||||
else if (Score is not null && !Score.Equals(other.Score, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
if ((Serial is null) ^ (other.Serial is null))
|
||||
return false;
|
||||
else if (Serial is not null && !Serial.Equals(other.Serial, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
if ((Source is null) ^ (other.Source is null))
|
||||
return false;
|
||||
else if (Source is not null && !Source.Equals(other.Source, StringComparison.OrdinalIgnoreCase))
|
||||
@@ -606,6 +617,11 @@ namespace SabreTools.Data.Models.Metadata
|
||||
else if (Url is not null && !Url.Equals(other.Url, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
if ((Version is null) ^ (other.Version is null))
|
||||
return false;
|
||||
else if (Version is not null && !Version.Equals(other.Version, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
if ((Year is null) ^ (other.Year is null))
|
||||
return false;
|
||||
else if (Year is not null && !Year.Equals(other.Year, StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
10
SabreTools.Data.Models/Steam2Installer/Constants.cs
Normal file
10
SabreTools.Data.Models/Steam2Installer/Constants.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace SabreTools.Data.Models.Steam2Installer
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public static readonly byte[] SimSignatureBytes = [0x1F, 0x4C, 0xD0, 0x3F];
|
||||
|
||||
/// <remarks>All other values in the structure are little endian, assuming this is too</remarks>
|
||||
public const uint SimSignatureUInt32 = 0x3FD04C1F;
|
||||
}
|
||||
}
|
||||
71
SabreTools.Data.Models/Steam2Installer/FileEntry.cs
Normal file
71
SabreTools.Data.Models/Steam2Installer/FileEntry.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SabreTools.Data.Models.Steam2Installer
|
||||
{
|
||||
|
||||
public sealed class FileEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// Offset of the filename in the string bytes array
|
||||
/// </summary>
|
||||
public uint NameOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Offset of the path name in the string bytes array
|
||||
/// </summary>
|
||||
public uint PathOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Steam depot id of the depot the file is a part of
|
||||
/// </summary>
|
||||
public uint DepotId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Offset of the file within its sid volume
|
||||
/// </summary>
|
||||
public ulong Offset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Size of the file, in bytes
|
||||
/// </summary>
|
||||
public ulong Size { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Which # installer disc the file is on
|
||||
/// </summary>
|
||||
public byte DiscNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Which # sid volume the file is in
|
||||
/// </summary>
|
||||
public byte VolumeNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the file is encrypted or not
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This flag isn't entirely reliable, as sometimes the file is encrypted in the sid without this
|
||||
/// flag being set in the sid. The reverse is not currently known to be true, though, so there at
|
||||
/// least shouldn't be any false positives when using this flag.
|
||||
/// </remarks>
|
||||
public bool Encrypted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Unknown 1-byte value, likely just padding
|
||||
/// </summary>
|
||||
public byte Unknown { get; set; }
|
||||
|
||||
// The filename and path aren't stored in the fileentry structure in the .sim, but the offsets are,
|
||||
// so it just makes sense to also parse and store the strings for the file here too.
|
||||
|
||||
/// <summary>
|
||||
/// The filename
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The file path
|
||||
/// </summary>
|
||||
public string Path { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
30
SabreTools.Data.Models/Steam2Installer/Header.cs
Normal file
30
SabreTools.Data.Models/Steam2Installer/Header.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SabreTools.Data.Models.Steam2Installer
|
||||
{
|
||||
/// <summary>
|
||||
/// Header from the .sim file.
|
||||
/// </summary>
|
||||
public sealed class Header
|
||||
{
|
||||
/// <summary>
|
||||
/// .sim file magic value
|
||||
/// </summary>
|
||||
public uint Magic { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Version (0x00000001)
|
||||
/// </summary>
|
||||
public uint Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of discs
|
||||
/// </summary>
|
||||
public uint Discs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Size of the section containing file and path strings.
|
||||
/// </summary>
|
||||
public uint StringsSize { get; set; }
|
||||
}
|
||||
}
|
||||
31
SabreTools.Data.Models/Steam2Installer/SimFile.cs
Normal file
31
SabreTools.Data.Models/Steam2Installer/SimFile.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace SabreTools.Data.Models.Steam2Installer
|
||||
{
|
||||
/// <summary>
|
||||
/// .sim file for a .sim/.sid archive
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// While it is not known for sure what .sim stands for, it's assumed to mean Steam Installer Manifest.
|
||||
/// This contains information about the .sid data volumes. It's used for retail installer discs for
|
||||
/// Steam2 (Steam pre-Steam3/SteamPipe). Preceded by GCF (GCF and NCF are still used for actual game
|
||||
/// installs on Steam2, sim/sid just replaced GCF for retail discs. NCF was never directly stored on
|
||||
/// retail discs since sim/sid had already come out). Succeeded by csm/csd for Steam3/SteamPipe.
|
||||
/// Code is based on NickNine's python-based sim/sid extractor at https://pastebin.com/sj6F64XP
|
||||
/// While this was not referenced for any of the code in SabreTools, https://codeberg.org/CYBERDEV/SIDEx
|
||||
/// provides additional documentation if it is needed.
|
||||
/// </remarks>
|
||||
public sealed class SimFile
|
||||
{
|
||||
/// <summary>
|
||||
/// .sim file header
|
||||
/// </summary>
|
||||
public Header Header { get; set; } = new();
|
||||
|
||||
// The string bytes array would go here, but it gets parsed out into FileEntries during deserialization,
|
||||
// so there's no point storing it in the model. Same with the file entries size and count.
|
||||
|
||||
/// <summary>
|
||||
/// Array of file entries
|
||||
/// </summary>
|
||||
public FileEntry[] FileEntries { get; set; } = [];
|
||||
}
|
||||
}
|
||||
15
SabreTools.Data.Models/Steam2Installer/Steam2InstallerSet.cs
Normal file
15
SabreTools.Data.Models/Steam2Installer/Steam2InstallerSet.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace SabreTools.Data.Models.Steam2Installer
|
||||
{
|
||||
public class Steam2InstallerSet
|
||||
{
|
||||
/// <summary>
|
||||
/// The sim file
|
||||
/// </summary>
|
||||
public SimFile Sim { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// The set of sid file volumes
|
||||
/// </summary>
|
||||
// public SidFile[] Sid { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -326,6 +326,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
SampleOf = "sampleof",
|
||||
SaveType = "savetype",
|
||||
Score = "score",
|
||||
Serial = "serial",
|
||||
SharedFeat = [CreateMetadataSharedFeat()],
|
||||
Slot = [CreateMetadataSlot()],
|
||||
SoftwareList = [CreateMetadataSoftwareList()],
|
||||
@@ -340,6 +341,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Tags = "tags",
|
||||
TitleID = "titleid",
|
||||
Url = "url",
|
||||
Version = "version",
|
||||
Video = [CreateMetadataVideo()],
|
||||
Year = "year",
|
||||
};
|
||||
|
||||
@@ -435,6 +435,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.Equal("sampleof", machine.SampleOf);
|
||||
Assert.Equal("savetype", machine.SaveType);
|
||||
Assert.Equal("score", machine.Score);
|
||||
Assert.Equal("serial", machine.Serial);
|
||||
Assert.Equal("source", machine.Source);
|
||||
Assert.Equal("sourcefile", machine.SourceFile);
|
||||
Assert.Equal("sourcerom", machine.SourceRom);
|
||||
@@ -444,6 +445,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.Equal("system", machine.System);
|
||||
Assert.Equal("tags", machine.Tags);
|
||||
Assert.Equal("titleid", machine.TitleID);
|
||||
Assert.Equal("version", machine.Version);
|
||||
Assert.Equal("year", machine.Year);
|
||||
|
||||
Data.Models.Metadata.Adjuster[]? adjusters = machine.Adjuster;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
@@ -314,6 +314,12 @@ namespace SabreTools.Metadata.DatItems
|
||||
set => _internal.Score = value;
|
||||
}
|
||||
|
||||
public string? Serial
|
||||
{
|
||||
get => _internal.Serial;
|
||||
set => _internal.Serial = value;
|
||||
}
|
||||
|
||||
public string? Source
|
||||
{
|
||||
get => _internal.Source;
|
||||
@@ -374,6 +380,12 @@ namespace SabreTools.Metadata.DatItems
|
||||
set => _internal.Url = value;
|
||||
}
|
||||
|
||||
public string? Version
|
||||
{
|
||||
get => _internal.Version;
|
||||
set => _internal.Version = value;
|
||||
}
|
||||
|
||||
public string? Year
|
||||
{
|
||||
get => _internal.Year;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
@@ -1359,6 +1359,7 @@ namespace SabreTools.Metadata.Filter.Test
|
||||
SampleOf = "sampleof",
|
||||
SaveType = "savetype",
|
||||
Score = "score",
|
||||
Serial = "serial",
|
||||
Source = "source",
|
||||
SourceFile = "sourcefile",
|
||||
SourceRom = "sourcerom",
|
||||
@@ -1369,6 +1370,7 @@ namespace SabreTools.Metadata.Filter.Test
|
||||
Tags = "tags",
|
||||
TitleID = "titleid",
|
||||
Url = "url",
|
||||
Version = "version",
|
||||
Year = "year",
|
||||
};
|
||||
|
||||
|
||||
@@ -1600,6 +1600,9 @@ namespace SabreTools.Metadata.Filter
|
||||
case "score":
|
||||
checkValue = obj.Score;
|
||||
return true;
|
||||
case "serial":
|
||||
checkValue = obj.Serial;
|
||||
return true;
|
||||
case "source":
|
||||
checkValue = obj.Source;
|
||||
return true;
|
||||
@@ -1630,6 +1633,9 @@ namespace SabreTools.Metadata.Filter
|
||||
case "url":
|
||||
checkValue = obj.Url;
|
||||
return true;
|
||||
case "version":
|
||||
checkValue = obj.Version;
|
||||
return true;
|
||||
case "year":
|
||||
checkValue = obj.Year;
|
||||
return true;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
@@ -257,6 +257,8 @@ namespace SabreTools.Serialization.CrossModel.Test
|
||||
gameBase.Year = "year";
|
||||
gameBase.Manufacturer = "manufacturer";
|
||||
gameBase.Publisher = "publisher";
|
||||
gameBase.Serial = "serial";
|
||||
gameBase.Version = "version";
|
||||
gameBase.Category = ["category"];
|
||||
gameBase.Trurip = trurip;
|
||||
gameBase.Release = [release];
|
||||
@@ -387,6 +389,8 @@ namespace SabreTools.Serialization.CrossModel.Test
|
||||
Assert.Equal("year", gb.Year);
|
||||
Assert.Equal("manufacturer", gb.Manufacturer);
|
||||
Assert.Equal("publisher", gb.Publisher);
|
||||
Assert.Equal("serial", gb.Serial);
|
||||
Assert.Equal("version", gb.Version);
|
||||
|
||||
Assert.NotNull(gb.Category);
|
||||
string category = Assert.Single(gb.Category);
|
||||
|
||||
@@ -135,6 +135,8 @@ namespace SabreTools.Serialization.CrossModel
|
||||
gameBase.Year = item.Year;
|
||||
gameBase.Manufacturer = item.Manufacturer;
|
||||
gameBase.Publisher = item.Publisher;
|
||||
gameBase.Serial = item.Serial;
|
||||
gameBase.Version = item.Version;
|
||||
gameBase.Category = item.Category;
|
||||
|
||||
if (item.TitleID is not null
|
||||
|
||||
@@ -144,6 +144,8 @@ namespace SabreTools.Serialization.CrossModel
|
||||
Name = machineName,
|
||||
Players = item.Trurip?.Players,
|
||||
Publisher = item.Publisher ?? item.Trurip?.Publisher,
|
||||
Serial = item.Serial,
|
||||
Version = item.Version,
|
||||
Ratings = item.Trurip?.Ratings,
|
||||
RebuildTo = item.RebuildTo,
|
||||
RelatedTo = item.Trurip?.RelatedTo,
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
@@ -322,6 +322,8 @@ namespace SabreTools.Serialization.Readers.Test
|
||||
gameBase.Year = "year";
|
||||
gameBase.Manufacturer = "manufacturer";
|
||||
gameBase.Publisher = "publisher";
|
||||
gameBase.Serial = "serial";
|
||||
gameBase.Version = "version";
|
||||
gameBase.Category = ["category"];
|
||||
gameBase.Trurip = trurip;
|
||||
gameBase.Release = [release];
|
||||
@@ -437,6 +439,8 @@ namespace SabreTools.Serialization.Readers.Test
|
||||
Assert.Equal("year", gb.Year);
|
||||
Assert.Equal("manufacturer", gb.Manufacturer);
|
||||
Assert.Equal("publisher", gb.Publisher);
|
||||
Assert.Equal("serial", gb.Serial);
|
||||
Assert.Equal("version", gb.Version);
|
||||
|
||||
Assert.NotNull(gb.Category);
|
||||
string category = Assert.Single(gb.Category);
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Serialization.Readers.Test
|
||||
{
|
||||
public class Steam2InstallerTests
|
||||
{
|
||||
[Fact]
|
||||
public void NullArray_Null()
|
||||
{
|
||||
byte[]? data = null;
|
||||
int offset = 0;
|
||||
var deserializer = new Steam2Installer();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyArray_Null()
|
||||
{
|
||||
byte[]? data = [];
|
||||
int offset = 0;
|
||||
var deserializer = new Steam2Installer();
|
||||
|
||||
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 Steam2Installer();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStream_Null()
|
||||
{
|
||||
Stream? data = null;
|
||||
var deserializer = new Steam2Installer();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([]);
|
||||
var deserializer = new Steam2Installer();
|
||||
|
||||
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 Steam2Installer();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -587,6 +587,18 @@ namespace SabreTools.Serialization.Readers
|
||||
|
||||
obj.Publisher = reader.ReadElementContentAsString();
|
||||
break;
|
||||
case "serial":
|
||||
if (obj.Serial is not null && Debug)
|
||||
Console.WriteLine($"'{reader.Name}' element already found, overwriting");
|
||||
|
||||
obj.Serial = reader.ReadElementContentAsString();
|
||||
break;
|
||||
case "version":
|
||||
if (obj.Version is not null && Debug)
|
||||
Console.WriteLine($"'{reader.Name}' element already found, overwriting");
|
||||
|
||||
obj.Version = reader.ReadElementContentAsString();
|
||||
break;
|
||||
case "category":
|
||||
var category = reader.ReadElementContentAsString();
|
||||
if (category is not null)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
172
SabreTools.Serialization.Readers/Steam2Installer.cs
Normal file
172
SabreTools.Serialization.Readers/Steam2Installer.cs
Normal file
@@ -0,0 +1,172 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.Data.Models.Steam2Installer;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Numerics.Extensions;
|
||||
using SabreTools.Text.Extensions;
|
||||
|
||||
namespace SabreTools.Serialization.Readers
|
||||
{
|
||||
public class Steam2Installer : BaseBinaryReader<Steam2InstallerSet>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override Steam2InstallerSet? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data is null || !data.CanRead)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
// Cache the current offset
|
||||
long initialOffset = data.Position;
|
||||
|
||||
// Create a new Steam2 Installer set to populate
|
||||
var si = new Steam2InstallerSet();
|
||||
|
||||
// Try to parse the .sim file
|
||||
var sim = ParseSim(data);
|
||||
|
||||
// Make sure the sim was parsed properly
|
||||
if (sim == null)
|
||||
return null;
|
||||
|
||||
// Set the sim file
|
||||
si.Sim = sim;
|
||||
|
||||
return si;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore the actual error
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Sim file
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Sim on success, null on error</returns>
|
||||
public static SimFile? ParseSim(Stream data)
|
||||
{
|
||||
// Create a new Sim file to populate
|
||||
var si = new SimFile();
|
||||
|
||||
// Try to parse the .sim file header
|
||||
var header = ParseHeader(data);
|
||||
|
||||
// Make sure the magic is correct
|
||||
if (header.Magic != Constants.SimSignatureUInt32)
|
||||
return null;
|
||||
|
||||
// Make sure the version is correct
|
||||
if (header.Version != 1)
|
||||
return null;
|
||||
|
||||
// Make sure string bytes section doesn't go beyond EOF
|
||||
if (header.StringsSize > data.Length - data.Position)
|
||||
return null;
|
||||
|
||||
// Set the header
|
||||
si.Header = header;
|
||||
|
||||
// Read the string section bytes
|
||||
byte[] stringsBytes = data.ReadBytes((int)header.StringsSize);
|
||||
|
||||
// Read the size and number of file entries
|
||||
uint fileEntriesSize = data.ReadUInt32LittleEndian();
|
||||
uint fileEntriesCount = data.ReadUInt32LittleEndian();
|
||||
|
||||
// Make sure reading the file entries won't go beyond EOF
|
||||
if (fileEntriesSize > data.Length - data.Position)
|
||||
return null;
|
||||
|
||||
// Try to parse the entry table
|
||||
var table = ParseTable(data, fileEntriesCount, stringsBytes);
|
||||
if (table is null || table.Length != fileEntriesCount)
|
||||
return null;
|
||||
|
||||
// Set the entry table
|
||||
si.FileEntries = table;
|
||||
|
||||
return si;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Header on success, null on error</returns>
|
||||
public static Header ParseHeader(Stream data)
|
||||
{
|
||||
var obj = new Header();
|
||||
|
||||
obj.Magic = data.ReadUInt32LittleEndian();
|
||||
obj.Version = data.ReadUInt32LittleEndian();
|
||||
obj.Discs = data.ReadUInt32LittleEndian();
|
||||
obj.StringsSize = data.ReadUInt32LittleEndian();
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an entry table
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="count">Number of entries to parse</param>
|
||||
/// <returns>Filled entry table on success, null on error</returns>
|
||||
public static FileEntry[]? ParseTable(Stream data, uint count, byte[] stringsBytes)
|
||||
{
|
||||
if (count == 0)
|
||||
return [];
|
||||
|
||||
var obj = new FileEntry[count];
|
||||
for (uint i = 0; i < count; i++)
|
||||
{
|
||||
var fileEntry = ParseFileEntry(data, stringsBytes);
|
||||
if (fileEntry is null)
|
||||
return null;
|
||||
|
||||
obj[i] = fileEntry;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a FileEntry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled FileEntry on success, null on error</returns>
|
||||
public static FileEntry? ParseFileEntry(Stream data, byte[] stringsBytes)
|
||||
{
|
||||
var obj = new FileEntry();
|
||||
|
||||
obj.NameOffset = data.ReadUInt32LittleEndian();
|
||||
obj.PathOffset = data.ReadUInt32LittleEndian();
|
||||
obj.DepotId = data.ReadUInt32LittleEndian();
|
||||
obj.Offset = data.ReadUInt64LittleEndian();
|
||||
obj.Size = data.ReadUInt64LittleEndian();
|
||||
obj.DiscNumber = data.ReadByteValue();
|
||||
obj.VolumeNumber = data.ReadByteValue();
|
||||
obj.Encrypted = data.ReadByte() != 0;
|
||||
obj.Unknown = data.ReadByteValue();
|
||||
|
||||
// Read file path and name strings
|
||||
int nameOffset = (int)obj.NameOffset;
|
||||
string? name = stringsBytes.ReadNullTerminatedAnsiString(ref nameOffset); // Unsure on encoding, assumed ascii/ansi
|
||||
if (name is null)
|
||||
return null;
|
||||
|
||||
obj.Name = name;
|
||||
int pathOffset = (int)obj.PathOffset;
|
||||
string? path = stringsBytes.ReadNullTerminatedAnsiString(ref pathOffset); // Unsure on encoding, assumed ascii/ansi
|
||||
if (path is null)
|
||||
return null;
|
||||
|
||||
obj.Path = path;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,6 +373,8 @@ namespace SabreTools.Serialization.Writers
|
||||
writer.WriteOptionalElementString("year", obj.Year);
|
||||
writer.WriteOptionalElementString("manufacturer", obj.Manufacturer);
|
||||
writer.WriteOptionalElementString("publisher", obj.Publisher);
|
||||
writer.WriteOptionalElementString("serial", obj.Serial);
|
||||
writer.WriteOptionalElementString("version", obj.Version);
|
||||
|
||||
if (obj.Category is not null && obj.Category.Length > 0)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
60
SabreTools.Wrappers.Test/Steam2InstallerTests.cs
Normal file
60
SabreTools.Wrappers.Test/Steam2InstallerTests.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Wrappers.Test
|
||||
{
|
||||
public class Steam2InstallerTests
|
||||
{
|
||||
[Fact]
|
||||
public void NullArray_Null()
|
||||
{
|
||||
byte[]? data = null;
|
||||
int offset = 0;
|
||||
var actual = Steam2Installer.Create(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyArray_Null()
|
||||
{
|
||||
byte[]? data = [];
|
||||
int offset = 0;
|
||||
var actual = Steam2Installer.Create(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidArray_Null()
|
||||
{
|
||||
byte[]? data = [.. Enumerable.Repeat<byte>(0xFF, 1024)];
|
||||
int offset = 0;
|
||||
var actual = Steam2Installer.Create(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStream_Null()
|
||||
{
|
||||
Stream? data = null;
|
||||
var actual = Steam2Installer.Create(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([]);
|
||||
var actual = Steam2Installer.Create(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([.. Enumerable.Repeat<byte>(0xFF, 1024)]);
|
||||
var actual = Steam2Installer.Create(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = file.Name.Length == 0 ? $"file{index}" : file.Name;
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -66,6 +66,7 @@ namespace SabreTools.Wrappers
|
||||
return false;
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = Guid.NewGuid().ToString();
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -72,6 +72,7 @@ namespace SabreTools.Wrappers
|
||||
}
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -72,6 +72,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = file.Path ?? $"file{index}";
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -40,6 +40,7 @@ namespace SabreTools.Wrappers
|
||||
?? (Filename is not null ? Path.GetFileName(Filename).Replace(".gz", string.Empty) : null)
|
||||
?? $"extracted_file";
|
||||
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -95,6 +95,7 @@ namespace SabreTools.Wrappers
|
||||
return false;
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -266,6 +266,7 @@ namespace SabreTools.Wrappers
|
||||
#endif
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
var filename = entry.Path.TrimEnd('\0');
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace SabreTools.Wrappers
|
||||
filename += $".{FileExtension}";
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = "tempfile.bin";
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace SabreTools.Wrappers
|
||||
return false;
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -372,6 +372,7 @@ namespace SabreTools.Wrappers
|
||||
private FileStream GetFileStream(string filename, string outputDirectory)
|
||||
{
|
||||
// Ensure directory separators are consistent
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = directoryItem.ItemName.Length == 0 ? $"file{index}" : directoryItem.ItemName;
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace SabreTools.Wrappers
|
||||
{
|
||||
// Ensure directory separators are consistent
|
||||
string filename = segment.FileName ?? $"file{index}";
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -74,6 +74,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = entry.Key;
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -83,6 +83,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = entry.Name.Length == 0 ? $"FILE_{i}" : entry.Name;
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
@@ -601,6 +602,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = entry.Filename?.TrimEnd('\0') ?? $"FILE_{i}";
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -240,6 +240,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = entry.Key;
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -120,6 +120,7 @@ namespace SabreTools.Wrappers
|
||||
return false;
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.0.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = entry.Path.TrimEnd('\0');
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -211,6 +211,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = entry.Key;
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
97
SabreTools.Wrappers/Steam2Installer.cs
Normal file
97
SabreTools.Wrappers/Steam2Installer.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.IO;
|
||||
using SabreTools.Data.Models.Steam2Installer;
|
||||
|
||||
namespace SabreTools.Wrappers
|
||||
{
|
||||
public partial class Steam2Installer : WrapperBase<Steam2InstallerSet>
|
||||
{
|
||||
#region Descriptive Properties
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string DescriptionString => "Steam2 Installer Set";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Extension Properties
|
||||
|
||||
/// <inheritdoc cref="Steam2InstallerSet.Sim"/>
|
||||
public SimFile Sim => Model.Sim;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Steam2Installer(Steam2InstallerSet model, byte[] data) : base(model, data) { }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Steam2Installer(Steam2InstallerSet model, byte[] data, int offset) : base(model, data, offset) { }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Steam2Installer(Steam2InstallerSet model, byte[] data, int offset, int length) : base(model, data, offset, length) { }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Steam2Installer(Steam2InstallerSet model, Stream data) : base(model, data) { }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Steam2Installer(Steam2InstallerSet model, Stream data, long offset) : base(model, data, offset) { }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Steam2Installer(Steam2InstallerSet model, Stream data, long offset, long length) : base(model, data, offset, length) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a Steam2 Installer Set from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the sim file</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>A Steam2 Installer Set wrapper on success, null on failure</returns>
|
||||
public static Steam2Installer? Create(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data is null || data.Length == 0)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and use that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return Create(dataStream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a Steam2 Installer Set from a Stream
|
||||
/// </summary>
|
||||
/// <param name="data">Stream representing the sim file</param>
|
||||
/// <returns>A Steam2 Installer Set wrapper on success, null on failure</returns>
|
||||
public static Steam2Installer? Create(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data is null || !data.CanRead)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
// Cache the current offset
|
||||
long currentOffset = data.Position;
|
||||
|
||||
var model = new Serialization.Readers.Steam2Installer().Deserialize(data);
|
||||
if (model is null)
|
||||
return null;
|
||||
|
||||
return new Steam2Installer(model, data, currentOffset);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
entryDirectory = Path.Combine(outputDirectory, entryDirectory);
|
||||
entryDirectory = entryDirectory.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
entryDirectory = entryDirectory.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
@@ -136,6 +137,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = header.FileName?.TrimEnd('\0') ?? $"entry_{i}";
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -66,6 +66,7 @@ namespace SabreTools.Wrappers
|
||||
#pragma warning restore IDE0010
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -111,6 +111,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = $"{directoryItem.Name}.{directoryItem.Extension}";
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (!string.IsNullOrEmpty(directoryItem.Path))
|
||||
filename = Path.Combine(directoryItem.Path, filename);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = $"{lump.Name}.lmp";
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace SabreTools.Wrappers
|
||||
WrapperType.SkuSis => SkuSis.Create(data),
|
||||
WrapperType.SFFS => SFFS.Create(data),
|
||||
WrapperType.SGA => SGA.Create(data),
|
||||
WrapperType.Steam2Installer => Steam2Installer.Create(data),
|
||||
WrapperType.STFS => STFS.Create(data),
|
||||
WrapperType.TapeArchive => TapeArchive.Create(data),
|
||||
WrapperType.VBSP => VBSP.Create(data),
|
||||
@@ -938,6 +939,13 @@ namespace SabreTools.Wrappers
|
||||
|
||||
#endregion
|
||||
|
||||
#region Steam2Installer
|
||||
|
||||
if (magic.StartsWith(Data.Models.Steam2Installer.Constants.SimSignatureBytes))
|
||||
return WrapperType.Steam2Installer;
|
||||
|
||||
#endregion
|
||||
|
||||
#region STFS
|
||||
|
||||
// LIVE
|
||||
|
||||
@@ -257,6 +257,11 @@ namespace SabreTools.Wrappers
|
||||
/// </summary>
|
||||
SkuSis,
|
||||
|
||||
/// <summary>
|
||||
/// Steam2 Installer set (sim/sid)
|
||||
/// </summary>
|
||||
Steam2Installer,
|
||||
|
||||
/// <summary>
|
||||
/// Secure Transacted File System
|
||||
/// </summary>
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace SabreTools.Wrappers
|
||||
string filename = Filename is not null
|
||||
? Path.GetFileNameWithoutExtension(Filename)
|
||||
: Guid.NewGuid().ToString();
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
// Ensure directory separators are consistent
|
||||
string filename = directoryItem.Name ?? $"file{index}";
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace SabreTools.Wrappers
|
||||
{
|
||||
// Ensure directory separators are consistent
|
||||
string filename = string.IsNullOrEmpty(Filename) ? "filename" : Path.GetFileNameWithoutExtension(Filename);
|
||||
filename = filename.TrimStart(['\\', '/']);
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
filename = filename.Replace('/', '\\');
|
||||
else if (Path.DirectorySeparatorChar == '/')
|
||||
|
||||
Reference in New Issue
Block a user