WiiSaveBanner.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2009 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "DiscIO/WiiSaveBanner.h"
  4. #include <iterator>
  5. #include <string>
  6. #include <vector>
  7. #include "Common/ColorUtil.h"
  8. #include "Common/CommonTypes.h"
  9. #include "Common/IOFile.h"
  10. #include "Common/NandPaths.h"
  11. #include "Common/StringUtil.h"
  12. namespace DiscIO
  13. {
  14. constexpr u32 ICON_WIDTH = 48;
  15. constexpr u32 ICON_HEIGHT = 48;
  16. constexpr u32 ICON_SIZE = ICON_WIDTH * ICON_HEIGHT * 2;
  17. WiiSaveBanner::WiiSaveBanner(u64 title_id)
  18. : WiiSaveBanner(Common::GetTitleDataPath(title_id, Common::FromWhichRoot::Configured) +
  19. "/banner.bin")
  20. {
  21. }
  22. WiiSaveBanner::WiiSaveBanner(const std::string& path) : m_path(path)
  23. {
  24. constexpr u32 BANNER_SIZE = BANNER_WIDTH * BANNER_HEIGHT * 2;
  25. constexpr size_t MINIMUM_SIZE = sizeof(Header) + BANNER_SIZE + ICON_SIZE;
  26. File::IOFile file(path, "rb");
  27. if (!file.ReadArray(&m_header, 1))
  28. {
  29. m_header = {};
  30. m_valid = false;
  31. }
  32. else if (file.GetSize() < MINIMUM_SIZE)
  33. {
  34. m_valid = false;
  35. }
  36. }
  37. std::string WiiSaveBanner::GetName() const
  38. {
  39. return UTF16BEToUTF8(m_header.name, std::size(m_header.name));
  40. }
  41. std::string WiiSaveBanner::GetDescription() const
  42. {
  43. return UTF16BEToUTF8(m_header.description, std::size(m_header.description));
  44. }
  45. std::vector<u32> WiiSaveBanner::GetBanner(u32* width, u32* height) const
  46. {
  47. *width = 0;
  48. *height = 0;
  49. File::IOFile file(m_path, "rb");
  50. if (!file.Seek(sizeof(Header), File::SeekOrigin::Begin))
  51. return std::vector<u32>();
  52. std::vector<u16> banner_data(BANNER_WIDTH * BANNER_HEIGHT);
  53. if (!file.ReadArray(banner_data.data(), banner_data.size()))
  54. return std::vector<u32>();
  55. std::vector<u32> image_buffer(BANNER_WIDTH * BANNER_HEIGHT);
  56. Common::Decode5A3Image(image_buffer.data(), banner_data.data(), BANNER_WIDTH, BANNER_HEIGHT);
  57. *width = BANNER_WIDTH;
  58. *height = BANNER_HEIGHT;
  59. return image_buffer;
  60. }
  61. } // namespace DiscIO