From c9cb186462664c06fe17388d4d85e01bad2f3cd4 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 6 Feb 2026 21:28:46 -0600 Subject: [PATCH] [studio] Cleanup useless complexity --- .../studio/applib/src/popups/fileinfo.cpp | 110 ++++++++---------- .../studio/applib/src/popups/fileinfo.hpp | 15 +-- 2 files changed, 56 insertions(+), 69 deletions(-) diff --git a/src/olympic/studio/applib/src/popups/fileinfo.cpp b/src/olympic/studio/applib/src/popups/fileinfo.cpp index 8d831ae2..ac49221b 100644 --- a/src/olympic/studio/applib/src/popups/fileinfo.cpp +++ b/src/olympic/studio/applib/src/popups/fileinfo.cpp @@ -13,23 +13,26 @@ FileInfo::FileInfo(Context &sctx) noexcept: ox::Error FileInfo::open(ox::StringParam filePath) noexcept { m_filePath = std::move(filePath); auto &fs = m_sctx.project->romFs(); - auto const fileBuff = fs.read(m_filePath).or_value({}); - auto hdr = keel::readAssetHeader(fileBuff).or_value({}); - m_fileInfo = {}; - m_fileInfo.assetId.emplace(hdr.uuid.toString()); - m_fileInfo.typeName.emplace(std::move(hdr.clawHdr.typeName)); - m_fileInfo.typeVersion.emplace(hdr.clawHdr.typeVersion); - m_fileInfo.format.emplace([&hdr] { - switch (hdr.clawHdr.fmt) { - case ox::ClawFormat::Metal: - return ox::StringLiteral{"Metal Claw"}; - case ox::ClawFormat::Organic: - return ox::StringLiteral{"Organic Claw"}; - default: - return ox::StringLiteral{"Other"}; - } - }()); - m_fileInfo.dataSize.emplace(hdr.clawHdr.dataSize); + OX_REQUIRE(fileBuff, fs.read(m_filePath)); + auto [hdr, err] = keel::readAssetHeader(fileBuff); + if (!err) { + m_fileInfo.emplace(Info{ + .assetId = hdr.uuid.toString(), + .typeName = std::move(hdr.clawHdr.typeName), + .typeVersion = hdr.clawHdr.typeVersion, + .format = [&hdr] { + switch (hdr.clawHdr.fmt) { + case ox::ClawFormat::Metal: + return ox::StringLiteral{"Metal Claw"}; + case ox::ClawFormat::Organic: + return ox::StringLiteral{"Organic Claw"}; + default: + return ox::StringLiteral{"Other"}; + } + }(), + .dataSize = hdr.clawHdr.dataSize, + }); + } Popup::open(); return {}; } @@ -76,62 +79,45 @@ void FileInfo::draw(Context &sctx) noexcept { void FileInfo::drawTable() const noexcept { ig::IDStackItem const idStackItem{"FileInfo"}; ImGui::Text("%s", m_filePath.c_str()); - if (ImGui::BeginTable( + if (m_fileInfo && ImGui::BeginTable( "Table", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { ImGui::TableSetupColumn("Field", ImGuiTableColumnFlags_WidthFixed, 70); ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_NoHide); - bool somethingDrew = false; // asset id - if (m_fileInfo.assetId) { - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - ImGui::Text("Asset ID:"); - ImGui::TableSetColumnIndex(1); - ImGui::Text("%s", m_fileInfo.assetId->c_str()); - somethingDrew = true; - } + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + ImGui::Text("Asset ID:"); + ImGui::TableSetColumnIndex(1); + ImGui::Text("%s", m_fileInfo->assetId.c_str()); // typeName - if (m_fileInfo.typeName) { - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - ImGui::Text("Type Name:"); - ImGui::TableSetColumnIndex(1); - ImGui::Text("%s", m_fileInfo.typeName->c_str()); - somethingDrew = true; - } + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + ImGui::Text("Type Name:"); + ImGui::TableSetColumnIndex(1); + ImGui::Text("%s", m_fileInfo->typeName.c_str()); // typeVersion - if (m_fileInfo.typeVersion) { - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - ImGui::Text("Type Version:"); - ImGui::TableSetColumnIndex(1); - ImGui::Text("%d", *m_fileInfo.typeVersion); - somethingDrew = true; - } + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + ImGui::Text("Type Version:"); + ImGui::TableSetColumnIndex(1); + ImGui::Text("%d", m_fileInfo->typeVersion); // format - if (m_fileInfo.format) { - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - ImGui::Text("Format:"); - ImGui::TableSetColumnIndex(1); - ImGui::Text("%s", m_fileInfo.format->c_str()); - somethingDrew = true; - } + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + ImGui::Text("Format:"); + ImGui::TableSetColumnIndex(1); + ImGui::Text("%s", m_fileInfo->format.c_str()); // size - if (m_fileInfo.dataSize) { - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - ImGui::Text("Data Size:"); - ImGui::TableSetColumnIndex(1); - ImGui::Text("%lluB", *m_fileInfo.dataSize); - somethingDrew = true; - } + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + ImGui::Text("Data Size:"); + ImGui::TableSetColumnIndex(1); + ImGui::Text("%lluB", m_fileInfo->dataSize); ImGui::EndTable(); - if (!somethingDrew) { - ImGui::Text("No information available"); - } + } else { + ImGui::Text("No information available"); } } diff --git a/src/olympic/studio/applib/src/popups/fileinfo.hpp b/src/olympic/studio/applib/src/popups/fileinfo.hpp index 55c27619..b813e0f3 100644 --- a/src/olympic/studio/applib/src/popups/fileinfo.hpp +++ b/src/olympic/studio/applib/src/popups/fileinfo.hpp @@ -15,14 +15,15 @@ class FileInfo: public ig::Popup { private: Context &m_sctx; ox::String m_filePath; - struct { - ox::Optional assetId; - ox::Optional typeName; - ox::Optional typeVersion{}; - ox::Optional format; + struct Info { + ox::UUIDStr assetId; + ox::String typeName; + int typeVersion{}; + ox::StringLiteral format; // use manual sizing to work with %ull - ox::Optional dataSize{}; - } m_fileInfo; + unsigned long long dataSize{}; + }; + ox::Optional m_fileInfo; public: explicit FileInfo(Context &sctx) noexcept;