From 221deb64c618d91643cccddaca90c4c372aaf868 Mon Sep 17 00:00:00 2001 From: Cara Date: Fri, 21 Jul 2023 23:01:03 +0930 Subject: [PATCH] add format for textures in analysis (#55) * add format for textures in analysis * requested changes * Update CharacterAnalyzer.cs --- MareSynchronos/Services/CharacterAnalyzer.cs | 27 ++++++++++++++++++++ MareSynchronos/UI/DataAnalysisUi.cs | 13 +++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/MareSynchronos/Services/CharacterAnalyzer.cs b/MareSynchronos/Services/CharacterAnalyzer.cs index dc57c6d..ed27c3b 100644 --- a/MareSynchronos/Services/CharacterAnalyzer.cs +++ b/MareSynchronos/Services/CharacterAnalyzer.cs @@ -5,6 +5,8 @@ using MareSynchronos.Services.Mediator; using MareSynchronos.UI; using MareSynchronos.Utils; using Microsoft.Extensions.Logging; +using Lumina.Data; +using Lumina.Data.Files; namespace MareSynchronos.Services; @@ -176,5 +178,30 @@ public sealed class CharacterAnalyzer : MediatorSubscriberBase, IDisposable } public long OriginalSize { get; private set; } = OriginalSize; public long CompressedSize { get; private set; } = CompressedSize; + + public Lazy Format = new(() => + { + switch (FileType) + { + case "tex": + { + try + { + using var stream = new FileStream(FilePaths[0], FileMode.Open, FileAccess.Read, FileShare.Read); + using var reader = new BinaryReader(stream); + reader.BaseStream.Position = 4; + var format = (TexFile.TextureFormat)reader.ReadInt32(); + return format.ToString(); + } + catch + { + return "Unknown"; + } + + } + default: + return string.Empty; + } + }); } } diff --git a/MareSynchronos/UI/DataAnalysisUi.cs b/MareSynchronos/UI/DataAnalysisUi.cs index f64a439..5b54ac2 100644 --- a/MareSynchronos/UI/DataAnalysisUi.cs +++ b/MareSynchronos/UI/DataAnalysisUi.cs @@ -240,7 +240,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase private void DrawTable(IGrouping fileGroup) { - using var table = ImRaii.Table("Analysis", 5, ImGuiTableFlags.Sortable | ImGuiTableFlags.RowBg | ImGuiTableFlags.ScrollY | ImGuiTableFlags.SizingFixedFit, + using var table = ImRaii.Table("Analysis", fileGroup.Key == "tex" ? 6 : 5, ImGuiTableFlags.Sortable | ImGuiTableFlags.RowBg | ImGuiTableFlags.ScrollY | ImGuiTableFlags.SizingFixedFit, new Vector2(0, 300)); if (!table.Success) return; ImGui.TableSetupColumn("Hash"); @@ -248,6 +248,7 @@ new Vector2(0, 300)); ImGui.TableSetupColumn("Gamepaths"); ImGui.TableSetupColumn("Original Size"); ImGui.TableSetupColumn("Compressed Size"); + if (fileGroup.Key == "tex") ImGui.TableSetupColumn("Format"); ImGui.TableSetupScrollFreeze(0, 1); ImGui.TableHeadersRow(); @@ -276,6 +277,10 @@ new Vector2(0, 300)); _cachedAnalysis![_selectedObjectTab] = _cachedAnalysis[_selectedObjectTab].OrderBy(k => k.Value.CompressedSize).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal); if (idx == 4 && sortSpecs.Specs.SortDirection == ImGuiSortDirection.Descending) _cachedAnalysis![_selectedObjectTab] = _cachedAnalysis[_selectedObjectTab].OrderByDescending(k => k.Value.CompressedSize).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal); + if (fileGroup.Key == "tex" && idx == 5 && sortSpecs.Specs.SortDirection == ImGuiSortDirection.Ascending) + _cachedAnalysis![_selectedObjectTab] = _cachedAnalysis[_selectedObjectTab].OrderBy(k => k.Value.Format).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal); + if (fileGroup.Key == "tex" && idx == 5 && sortSpecs.Specs.SortDirection == ImGuiSortDirection.Descending) + _cachedAnalysis![_selectedObjectTab] = _cachedAnalysis[_selectedObjectTab].OrderByDescending(k => k.Value.Format).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal); sortSpecs.SpecsDirty = false; } @@ -309,6 +314,12 @@ new Vector2(0, 300)); ImGui.TableNextColumn(); ImGui.TextUnformatted(UiSharedService.ByteToString(item.CompressedSize)); if (ImGui.IsItemClicked()) _selectedHash = item.Hash; + if (fileGroup.Key == "tex") + { + ImGui.TableNextColumn(); + ImGui.TextUnformatted(item.Format.Value); + if (ImGui.IsItemClicked()) _selectedHash = item.Hash; + } } } }