Skip to content

Commit

Permalink
Created new Testing Suite tool
Browse files Browse the repository at this point in the history
  • Loading branch information
siblount committed Jan 8, 2024
1 parent f207229 commit 9dd6ecd
Show file tree
Hide file tree
Showing 14 changed files with 2,199 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/DAZ_Installer.Core/DPArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,14 @@ public DPExtractionReport ExtractContentsToTemp(DPExtractSettings settings)
}

/// <summary>
/// Previews the archive by discovering files in this archive. If the archive is not on disk, then it will be extracted to default temp location.
/// Previews the archive by discovering files in this archive. If the archive is not on disk, then it will be first extracted to <paramref name="temp"/>.
/// If <paramref name="temp"/> is null, then it will be extracted to the temp directory.
/// </summary>
public void PeekContents()
/// <param name="temp">The temp path to extract if the archive is not on disk, otherwise it will extract to <see cref="IOPath.GetTempPath"/></param>
public void PeekContents(string? temp = null)
{
// Just extract to temp.
var settings = new DPExtractSettings(IOPath.GetTempPath(), Array.Empty<DPFile>(), archive: this);
var settings = new DPExtractSettings(temp ?? IOPath.GetTempPath(), Array.Empty<DPFile>(), archive: this);
if (!Extracted && !ExtractToTemp(settings))
throw new IOException("Archive was not on disk and could not be extracted.");
if (Extractor is null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<ForceDesignerDpiUnaware>true</ForceDesignerDpiUnaware>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DAZ_Installer.Core\DAZ_Installer.Core.csproj" />
<ProjectReference Include="..\DAZ_Installer.IO\DAZ_Installer.IO.csproj" />
</ItemGroup>

<Import Project="..\DAZ_Installer.Common\DAZ_Installer.Common.projitems" Label="Shared" />

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy &quot;$(SolutionDir)DAZ_Installer.Core\libs\UnRAR.dll&quot; &quot;$(OutDir)UnRAR.dll&quot;&#xD;&#xA;copy &quot;$(SolutionDir)DAZ_Installer.Core\External\7za.exe&quot; &quot;$(OutDir)7za.exe&quot;&#xD;&#xA;echo OutDir: $(OutDir)&#xD;&#xA;echo TargetDir: $(TargetDir)&#xD;&#xA;echo ProjectDir: $(ProjectDir)" />
</Target>

</Project>
93 changes: 93 additions & 0 deletions src/DAZ_Installer.TestingSuiteWindows/DPDestinationDeterminerEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using DAZ_Installer.Core;
using DAZ_Installer.Core.Extraction;
using Serilog;
using Serilog.Context;
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAZ_Installer.TestingSuiteWindows
{
/// <summary>
/// A destination determiner that uses <see cref="DPDestinationDeterminer"/> to determine the destination of each file in the archive.
/// The only difference here is that it extracts the meta files (such as manifest files) to temp before calling the base method.
/// </summary>
internal class DPDestinationDeterminerEx : DPDestinationDeterminer
{
private new ILogger Logger { get; } = Log.ForContext<DPDestinationDeterminerEx>();
public DPDestinationDeterminerEx() : base() { }
public override HashSet<DPFile> DetermineDestinations(DPArchive arc, DPProcessSettings settings)
{
// First, we need to extract the meta files to temp.
// In DPDestinationDeterminer, it does NOT extract any files. If the file is not on disk, it will not read Manifest.dsx files.
// So, we need to extract the meta files to temp.
ReadMetaFiles(arc, ref settings);

// Now, we can call the base method.
return base.DetermineDestinations(arc, settings);
}

/// <summary>
/// Reads the files listed in <see cref="DPArchive.DSXFiles"/>.
/// </summary>
private void ReadMetaFiles(DPArchive arc, ref DPProcessSettings settings)
{
// Extract the DAZ Files that have not been extracted.
var extractSettings = new DPExtractSettings(settings.TempPath,
arc!.DSXFiles.Where((f) => f.FileInfo is null || !f.FileInfo.Exists),
true, arc);
arc.ExtractContentsToTemp(extractSettings);
Stream? stream = null!;
foreach (DPDSXFile file in arc!.DSXFiles)
{
using (LogContext.PushProperty("File", file.Path))
// If it did not extract correctly we don't have acces, just skip it.
if (file.FileInfo is null || !file.FileInfo.Exists)
{
Logger.Warning("FileInfo was null or returned does not exist, skipping file to read meta data", file.Path);
Logger.Debug("FileInfo is null: {0}, FileInfo exists: {1}", file.FileInfo is null, file?.FileInfo?.Exists);
continue;
}
try
{
if (!file.FileInfo!.TryAndFixOpenRead(out stream, out Exception? ex))
{
Logger.Error(ex, "Failed to open read stream for file for reading meta");
continue;
}
if (stream is null)
{
Logger.Error("OpenRead returned successful but also returned null stream, skipping meta read");
continue;
}
if (stream.ReadByte() == 0x1F && stream.ReadByte() == 0x8B)
{
// It is gzipped compressed.
stream.Seek(0, SeekOrigin.Begin);
using var gstream = new GZipStream(stream, CompressionMode.Decompress);
using var streamReader = new StreamReader(gstream, Encoding.UTF8, true);
file.CheckContents(streamReader);
}
else
{
// It is normal text.
stream.Seek(0, SeekOrigin.Begin);
using var streamReader = new StreamReader(stream, Encoding.UTF8, true);
file.CheckContents(streamReader);
}
}
catch (Exception ex)
{
Logger.Error(ex, $"Unable to read contents of {file.Path}");
}
finally
{
stream?.Dispose();
}
}
}
}
}
Loading

0 comments on commit 9dd6ecd

Please sign in to comment.