Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions PG.Commons/PG.Commons/PetroglyphCommons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@

using AnakinRaW.CommonUtilities.Hashing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using PG.Commons.Hashing;

namespace PG.Commons;

/// <summary>
/// Provides initialization routines for this library.
/// </summary>
public static class PetroglyphCommons
public static class PetroglyphCommons
{
/// <summary>
/// Adds all necessary services provided by this library to the specified <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="serviceCollection">The <see cref="IServiceCollection"/> to add services to.</param>
public static void ContributeServices(IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<IHashAlgorithmProvider>(new Crc32HashingProvider());
serviceCollection.AddSingleton<ICrc32HashingService>(sp => new Crc32HashingService(sp));
serviceCollection.TryAddSingleton<IHashAlgorithmProvider>(new Crc32HashingProvider());
serviceCollection.TryAddSingleton<IHashingService>(sp => new HashingService(sp));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providing the hashing service, for me, is also responsibility of the consumer

serviceCollection.TryAddSingleton<ICrc32HashingService>(sp => new Crc32HashingService(sp));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

using AnakinRaW.CommonUtilities.Hashing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using PG.Commons;
using PG.StarWarsGame.Files.DAT.Binary;
using PG.StarWarsGame.Files.DAT.Services;

namespace PG.StarWarsGame.Files.DAT;

/// <summary>
Expand All @@ -18,10 +22,13 @@ public static class DatServiceContribution
/// <param name="serviceCollection">The <see cref="IServiceCollection"/> to add services to.</param>
public static void SupportDAT(this IServiceCollection serviceCollection)
{
PetroglyphCommons.ContributeServices(serviceCollection);
serviceCollection.TryAddSingleton<IHashingService>(sp => new HashingService(sp));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providing the hashing service, for me, is also responsibility of the consumer


serviceCollection
.AddSingleton<IDatFileService>(sp => new DatFileService(sp))
.AddSingleton<IDatModelService>(sp => new DatModelService(sp))
.AddTransient<IDatFileReader>(sp => new DatFileReader(sp))
.AddTransient<IDatBinaryConverter>(sp => new DatBinaryConverter(sp));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

using System;
using Microsoft.Extensions.DependencyInjection;
using PG.StarWarsGame.Localisation.Languages;
using PG.Testing;
using Xunit;

namespace PG.StarWarsGame.Localisation.Baseline.Test;

public class BaselineTranslationProviderTest : PGTestBase
{
protected override void SetupServices(IServiceCollection serviceCollection)
{
base.SetupServices(serviceCollection);
serviceCollection.SupportLocalisationBaseline();
}

private IBaselineTranslationProvider Provider =>
ServiceProvider.GetRequiredService<IBaselineTranslationProvider>();

[Theory]

Check failure on line 23 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (ubuntu-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetMasterText_SingleLanguage_IsNonEmpty(game: FoC)

System.IO.DirectoryNotFoundException : Could not find a part of the path '/tmp/pg_baseline_a0c65ad2a03c4419a9ed4cb9dd2dca06.dat'.

Check failure on line 23 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (ubuntu-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetMasterText_SingleLanguage_IsNonEmpty(game: EaW)

System.IO.DirectoryNotFoundException : Could not find a part of the path '/tmp/pg_baseline_9e002f19c64641018e4027ad0c57c4a5.dat'.

Check failure on line 23 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (windows-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetMasterText_SingleLanguage_IsNonEmpty(game: EaW)

System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\runneradmin\AppData\Local\Temp\pg_baseline_dd301acc90eb40d98393bbbc30b53acd.dat'.

Check failure on line 23 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (windows-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetMasterText_SingleLanguage_IsNonEmpty(game: FoC)

System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\runneradmin\AppData\Local\Temp\pg_baseline_0ebe457f31cb44e2a81be67e0cbc3382.dat'.

Check failure on line 23 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (windows-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetMasterText_SingleLanguage_IsNonEmpty(game: EaW)

System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\runneradmin\AppData\Local\Temp\pg_baseline_012d8e8ca9d34057ad42d45d4d54807d.dat'.

Check failure on line 23 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (windows-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetMasterText_SingleLanguage_IsNonEmpty(game: FoC)

System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\runneradmin\AppData\Local\Temp\pg_baseline_27df0005e0ea42ea82cc75f8c3c271c1.dat'.
[InlineData(GameContext.EaW)]
[InlineData(GameContext.FoC)]
public void GetMasterText_SingleLanguage_IsNonEmpty(GameContext game)
{
var lang = new EnglishAlamoLanguageDefinition();
var db = Provider.GetMasterText(game, lang);
Assert.NotEmpty(db);
}

[Theory]

Check failure on line 33 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (ubuntu-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetCreditsText_SingleLanguage_IsNonEmpty(game: EaW)

System.IO.DirectoryNotFoundException : Could not find a part of the path '/tmp/pg_baseline_c68e087c2ea3423d95a2b1778a5e89c5.dat'.

Check failure on line 33 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (ubuntu-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetCreditsText_SingleLanguage_IsNonEmpty(game: FoC)

System.IO.DirectoryNotFoundException : Could not find a part of the path '/tmp/pg_baseline_7fcb5823b3424f43a6bb36900b13bd42.dat'.

Check failure on line 33 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (ubuntu-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetCreditsText_SingleLanguage_IsNonEmpty(game: EaW)

System.IO.DirectoryNotFoundException : Could not find a part of the path '/tmp/pg_baseline_a3c5ae3248404d94aecddd6a174da0c1.dat'.

Check failure on line 33 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (ubuntu-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetCreditsText_SingleLanguage_IsNonEmpty(game: FoC)

System.IO.DirectoryNotFoundException : Could not find a part of the path '/tmp/pg_baseline_4c6a58c25ff94fe883eaa42471a4aa9b.dat'.

Check failure on line 33 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (windows-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetCreditsText_SingleLanguage_IsNonEmpty(game: FoC)

System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\runneradmin\AppData\Local\Temp\pg_baseline_2f982ec982f247b29be905afa3ab8af1.dat'.

Check failure on line 33 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (windows-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetCreditsText_SingleLanguage_IsNonEmpty(game: EaW)

System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\runneradmin\AppData\Local\Temp\pg_baseline_06171603a33946c19b101ab0a30a38fb.dat'.

Check failure on line 33 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (windows-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetCreditsText_SingleLanguage_IsNonEmpty(game: EaW)

System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\runneradmin\AppData\Local\Temp\pg_baseline_cf90ba3f226d4e15ac80526a24900405.dat'.

Check failure on line 33 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (windows-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetCreditsText_SingleLanguage_IsNonEmpty(game: FoC)

System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\runneradmin\AppData\Local\Temp\pg_baseline_f2ea2580ec8a4a83bb7db07f066434c0.dat'.
[InlineData(GameContext.EaW)]
[InlineData(GameContext.FoC)]
public void GetCreditsText_SingleLanguage_IsNonEmpty(GameContext game)
{
var lang = new EnglishAlamoLanguageDefinition();
var db = Provider.GetCreditsText(game, lang);
Assert.NotEmpty(db);
}

[Fact]

Check failure on line 43 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (ubuntu-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetMasterText_MultiLanguage_ContainsAllRequestedLanguages

System.IO.DirectoryNotFoundException : Could not find a part of the path '/tmp/pg_baseline_cbc2fabe2db34cda866e6b88060c9e04.dat'.

Check failure on line 43 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (ubuntu-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetMasterText_MultiLanguage_ContainsAllRequestedLanguages

System.IO.DirectoryNotFoundException : Could not find a part of the path '/tmp/pg_baseline_5da2b3c25df9496589d1514fe9d027ba.dat'.

Check failure on line 43 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (windows-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetMasterText_MultiLanguage_ContainsAllRequestedLanguages

System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\runneradmin\AppData\Local\Temp\pg_baseline_9622f6e45b314564a0ee708f4cfe8560.dat'.
public void GetMasterText_MultiLanguage_ContainsAllRequestedLanguages()
{
var langs = new IAlamoLanguageDefinition[]
{
new EnglishAlamoLanguageDefinition(),
new GermanAlamoLanguageDefinition(),
};
var db = Provider.GetMasterText(GameContext.EaW, langs);
Assert.Equal(2, db.Languages.Count);
}

[Fact]

Check failure on line 55 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (ubuntu-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetMasterText_EaW_English_ContainsKnownKey

System.IO.DirectoryNotFoundException : Could not find a part of the path '/tmp/pg_baseline_ef502d5e93e54e568831889b2d496f7b.dat'.

Check failure on line 55 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (ubuntu-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetMasterText_EaW_English_ContainsKnownKey

System.IO.DirectoryNotFoundException : Could not find a part of the path '/tmp/pg_baseline_6789aaccb8b54624ae451c20d8496237.dat'.

Check failure on line 55 in PG.StarWarsGame.Localisation.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (windows-latest)

PG.StarWarsGame.Localisation.Baseline.Test.BaselineTranslationProviderTest.GetMasterText_EaW_English_ContainsKnownKey

System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\runneradmin\AppData\Local\Temp\pg_baseline_11efa13289bb46c2ad440b8ea63c14dd.dat'.
public void GetMasterText_EaW_English_ContainsKnownKey()
{
var lang = new EnglishAlamoLanguageDefinition();
var db = Provider.GetMasterText(GameContext.EaW, lang);
Assert.True(db.Count > 100);
}

[Fact]
public void GetMasterText_NullLanguage_Throws()
{
Assert.Throws<ArgumentNullException>(() => Provider.GetMasterText(GameContext.EaW, (IAlamoLanguageDefinition)null!));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<TargetFrameworks Condition="!$([MSBuild]::IsOsUnixLike())">$(TargetFrameworks);net481</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestable>true</IsTestable>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="3.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.5.1" />
<PackageReference Include="xunit.v3.mtp-v2" Version="3.2.2" />
<PackageReference Include="Microsoft.Testing.Platform" Version="2.2.3" />
<PackageReference Include="coverlet.msbuild" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\PG.Testing\PG.Testing.csproj" />
<ProjectReference Include="..\..\PG.StarWarsGame.Files.DAT\PG.StarWarsGame.Files.DAT\PG.StarWarsGame.Files.DAT.csproj" />
<ProjectReference Include="..\PG.StarWarsGame.Localisation.Baseline\PG.StarWarsGame.Localisation.Baseline.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

using Microsoft.Extensions.DependencyInjection;
using PG.StarWarsGame.Files.DAT;

namespace PG.StarWarsGame.Localisation.Baseline
{
/// <summary>
/// Provides initialization routines for the PG.StarWarsGame.Localisation.Baseline library.
/// </summary>
public static class BaselineServiceContribution
{
/// <summary>
/// Adds all services required by this library, including DAT and localisation core services.
/// </summary>
public static IServiceCollection SupportLocalisationBaseline(this IServiceCollection serviceCollection)
{
serviceCollection.SupportDAT();
serviceCollection.SupportLocalisation();

serviceCollection.AddSingleton<IBaselineTranslationProvider>(sp =>
new BaselineTranslationProvider(sp));

return serviceCollection;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using PG.Commons.Services;
using PG.StarWarsGame.Files.DAT.Services;
using PG.StarWarsGame.Localisation.Data;
using PG.StarWarsGame.Localisation.IO.Dat;
using PG.StarWarsGame.Localisation.Languages;

namespace PG.StarWarsGame.Localisation.Baseline
{
internal sealed class BaselineTranslationProvider : ServiceBase, IBaselineTranslationProvider
{
// The 5 western languages shipped with the original games have embedded baseline data.
// The remaining officially supported languages are mapped for future resource additions.
private static readonly IReadOnlyDictionary<string, (string Folder, string NameSuffix)> LanguageMap =
Comment thread
AnakinRaW marked this conversation as resolved.
new Dictionary<string, (string, string)>(StringComparer.OrdinalIgnoreCase)
{
["ENGLISH"] = ("en", "english"),
["GERMAN"] = ("de", "german"),
["SPANISH"] = ("es", "spanish"),
["FRENCH"] = ("fr", "french"),
["ITALIAN"] = ("it", "italian"),
["CHINESE"] = ("zh", "chinese"),
["POLISH"] = ("pl", "polish"),
["RUSSIAN"] = ("ru", "russian"),
["JAPANESE"] = ("ja", "japanese"),
["KOREAN"] = ("ko", "korean"),
["THAI"] = ("th", "thai"),
};

private readonly IDatFileService _datFileService;
private readonly IDatTranslationImporter _importer;
private readonly ITranslationDatabaseFactory _factory;

public BaselineTranslationProvider(IServiceProvider services) : base(services)
{
_datFileService = services.GetRequiredService<IDatFileService>();
_importer = services.GetRequiredService<IDatTranslationImporter>();
_factory = services.GetRequiredService<ITranslationDatabaseFactory>();
}

/// <inheritdoc/>
public IKeyedTranslationDatabase GetMasterText(GameContext game, IAlamoLanguageDefinition language)
{
if (language is null) throw new ArgumentNullException(nameof(language));
var db = _factory.CreateKeyed(new[] { language });
LoadInto(db, game, "mastertextfile", language);
return db;
}

/// <inheritdoc/>
public IKeyedTranslationDatabase GetMasterText(GameContext game, IReadOnlyList<IAlamoLanguageDefinition> languages)
{
if (languages is null) throw new ArgumentNullException(nameof(languages));
var db = _factory.CreateKeyed(languages);
foreach (var lang in languages)
LoadInto(db, game, "mastertextfile", lang);
return db;
}

/// <inheritdoc/>
public IOrderedTranslationDatabase GetCreditsText(GameContext game, IAlamoLanguageDefinition language)
{
if (language is null) throw new ArgumentNullException(nameof(language));
var db = _factory.CreateOrdered(new[] { language });
LoadInto(db, game, "creditstext", language);
return db;
}

/// <inheritdoc/>
public IOrderedTranslationDatabase GetCreditsText(GameContext game, IReadOnlyList<IAlamoLanguageDefinition> languages)
{
if (languages is null) throw new ArgumentNullException(nameof(languages));
var db = _factory.CreateOrdered(languages);
foreach (var lang in languages)
LoadInto(db, game, "creditstext", lang);
return db;
}

private void LoadInto(ITranslationDatabase db, GameContext game, string filePrefix, IAlamoLanguageDefinition language)
{
if (!LanguageMap.TryGetValue(language.LanguageIdentifier, out var map))
return;

var resourceName = BuildResourceName(game, map.Folder, $"{filePrefix}_{map.NameSuffix}.dat");
using var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
if (resourceStream is null) return;

var tempPath = FileSystem.Path.Combine(
FileSystem.Path.GetTempPath(),
$"pg_baseline_{Guid.NewGuid():N}.dat");

try
{
using (var fs = FileSystem.FileStream.New(tempPath, FileMode.Create, FileAccess.Write))
resourceStream.CopyTo(fs);

var datFile = _datFileService.Load(tempPath);
_importer.Import(datFile.Content, language, db);
}
finally
{
try
{
FileSystem.File.Delete(tempPath);
}
catch
{
// NOP
}
}
}

private static string BuildResourceName(GameContext game, string langFolder, string fileName)
{
var gameFolder = game == GameContext.EaW ? "EaW" : "FoC";
return $"PG.StarWarsGame.Localisation.Baseline.Resources.{gameFolder}.{langFolder}.{fileName}";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

using System.Collections.Generic;
using PG.StarWarsGame.Localisation.Data;
using PG.StarWarsGame.Localisation.Languages;

namespace PG.StarWarsGame.Localisation.Baseline
{
/// <summary>
/// Provides pre-loaded translation databases built from the official EaW and FoC game localisations.
/// </summary>
public interface IBaselineTranslationProvider
{
/// <summary>
/// Returns a keyed translation database (MasterText) for the given game and single language.
/// </summary>
/// <remarks>
/// Languages with no baseline data contribute no entries to the returned database.
/// </remarks>
/// <exception cref="System.ArgumentNullException"><paramref name="language"/> is <see langword="null"/>.</exception>
IKeyedTranslationDatabase GetMasterText(GameContext game, IAlamoLanguageDefinition language);

/// <summary>
/// Returns a keyed translation database (MasterText) merged from the given game and languages.
/// </summary>
/// <remarks>
/// Languages with no baseline data contribute no entries to the returned database.
/// </remarks>
/// <exception cref="System.ArgumentNullException"><paramref name="languages"/> is <see langword="null"/>.</exception>
IKeyedTranslationDatabase GetMasterText(GameContext game, IReadOnlyList<IAlamoLanguageDefinition> languages);

/// <summary>
/// Returns an ordered translation database (CreditsText) for the given game and single language.
/// </summary>
/// <remarks>
/// Languages with no baseline data contribute no entries to the returned database.
/// </remarks>
/// <exception cref="System.ArgumentNullException"><paramref name="language"/> is <see langword="null"/>.</exception>
IOrderedTranslationDatabase GetCreditsText(GameContext game, IAlamoLanguageDefinition language);

/// <summary>
/// Returns an ordered translation database (CreditsText) merged from the given game and languages.
/// </summary>
/// <remarks>
/// Languages with no baseline data contribute no entries to the returned database.
/// </remarks>
/// <exception cref="System.ArgumentNullException"><paramref name="languages"/> is <see langword="null"/>.</exception>
IOrderedTranslationDatabase GetCreditsText(GameContext game, IReadOnlyList<IAlamoLanguageDefinition> languages);
}
}
Loading
Loading