diff --git a/src/Filee.Core/Presets/BuiltInData.cs b/src/Filee.Core/Presets/BuiltInData.cs index 1f7331330..8f130f15a 100644 --- a/src/Filee.Core/Presets/BuiltInData.cs +++ b/src/Filee.Core/Presets/BuiltInData.cs @@ -30,6 +30,9 @@ public static class BuiltInData public static bool AcceptsFolders(Preset preset) => !preset.IsGroup && (preset.IsCopyToFolder || SupportsFolderTarget(preset.TargetFormat)); + /// The preset that makes Valve textures (.vtf). + public const string VtfId = "to-vtf"; + /// Creates the default preset list. public static List CreatePresets() => [ @@ -47,6 +50,9 @@ public static List CreatePresets() => new() { Id = "to-gif", Name = "GIF", TargetFormat = "gif" }, new() { Id = "to-avif", Name = "AVIF", TargetFormat = "avif", Image = { Quality = 60 } }, new() { Id = "to-heic", Name = "HEIC", TargetFormat = "heic", Image = { Quality = 80 } }, + // Valve textures for Garry's Mod and other Source games (#1478, added to the library in settings schema 98): in + // the palette only, in the Games field (off in a new install). + new() { Id = VtfId, Name = "VTF", TargetFormat = "vtf" }, new() { Id = "half-size", NameKey = "preset.half_size", TargetFormat = SameAsSource, diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.cs index aa112de3d..0c9a4ad5d 100644 --- a/src/Filee.Core/Settings/AppSettings.cs +++ b/src/Filee.Core/Settings/AppSettings.cs @@ -170,7 +170,7 @@ public static bool IsFlipKeyAllowed(string key, IEnumerable gest public sealed class AppSettings { /// Current schema version. Increase when the format changes and add a migration. - public const int CurrentSchemaVersion = 97; + public const int CurrentSchemaVersion = 98; public int SchemaVersion { get; set; } = CurrentSchemaVersion; diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.cs index 4f32ff832..abf31c23c 100644 --- a/src/Filee.Core/Settings/UserDataStore.cs +++ b/src/Filee.Core/Settings/UserDataStore.cs @@ -1187,6 +1187,9 @@ public static bool ApplyToLibrary(int from, List presets, List p.Id != BuiltInData.VtfId)) + changed |= AddLikeNewLibrary(presets, BuiltInData.VtfId); return changed; } diff --git a/tests/Filee.Core.Tests/TranslatePresetMigrationTests.cs b/tests/Filee.Core.Tests/TranslatePresetMigrationTests.cs index 5d6147ca4..c2b51c93e 100644 --- a/tests/Filee.Core.Tests/TranslatePresetMigrationTests.cs +++ b/tests/Filee.Core.Tests/TranslatePresetMigrationTests.cs @@ -127,7 +127,7 @@ public void Translate_goes_after_the_built_in_preset_before_it() var defaults = BuiltInData.CreatePresets(); List Only(params string[] ids) => ids.Select(id => defaults.Single(p => p.Id == id)).ToList(); // Later steps add their own presets; what is checked here is where Translate lands. - static IEnumerable Ids(List presets) => presets.Select(p => p.Id).Where(id => id is not (BuiltInData.MetadataId or BuiltInData.UpscaleId or BuiltInData.RingtoneId or BuiltInData.PdfAId or "to-iso" or "to-gma")); + static IEnumerable Ids(List presets) => presets.Select(p => p.Id).Where(id => id is not (BuiltInData.MetadataId or BuiltInData.UpscaleId or BuiltInData.RingtoneId or BuiltInData.PdfAId or "to-iso" or "to-gma" or BuiltInData.VtfId)); List Profiles() { var profiles = BuiltInData.CreateProfiles(); diff --git a/tests/Filee.Core.Tests/VtfFormatTests.cs b/tests/Filee.Core.Tests/VtfFormatTests.cs index c851a013b..5dd46e0f7 100644 --- a/tests/Filee.Core.Tests/VtfFormatTests.cs +++ b/tests/Filee.Core.Tests/VtfFormatTests.cs @@ -47,4 +47,20 @@ public void Version_94_libraries_learn_vtf_without_taking_custom_claims() Assert.DoesNotContain("vtf", images.Extensions); // the user's own donut has it Assert.Equal("my-textures", ProfileSelector.Select(profiles, ["spray.vtf"])?.Id); } + + [Fact] + public void Version_97_libraries_get_the_vtf_preset_after_heic() + { + var presets = BuiltInData.CreatePresets(); + presets.RemoveAll(p => p.Id == BuiltInData.VtfId); + var profiles = BuiltInData.CreateProfiles(); + + Assert.True(SettingsMigrations.ApplyToLibrary(97, presets, profiles)); + Assert.Equal(BuiltInData.CreatePresets().Select(p => p.Id), presets.Select(p => p.Id)); // right after HEIC + Assert.Equal("vtf", presets.Single(p => p.Id == BuiltInData.VtfId).TargetFormat); + Assert.False(SettingsMigrations.ApplyToLibrary(97, presets, profiles)); + // In the palette only, not on a donut. + Assert.DoesNotContain(BuiltInData.CreateProfiles(), + p => p.PresetIds.Contains(BuiltInData.VtfId) || p.BackPresetIds?.Contains(BuiltInData.VtfId) == true); + } }