[VFS] Add set_* functions (eg. set_display_name) to XContentMetadata

This commit is contained in:
emoose 2020-01-11 18:19:54 +00:00 committed by illusion
parent 20c612cd42
commit 5c23c4043c
1 changed files with 62 additions and 14 deletions

View File

@ -10,6 +10,7 @@
#ifndef XENIA_VFS_DEVICES_STFS_CONTAINER_DEVICE_H_ #ifndef XENIA_VFS_DEVICES_STFS_CONTAINER_DEVICE_H_
#define XENIA_VFS_DEVICES_STFS_CONTAINER_DEVICE_H_ #define XENIA_VFS_DEVICES_STFS_CONTAINER_DEVICE_H_
#include <algorithm>
#include <map> #include <map>
#include <memory> #include <memory>
#include <string> #include <string>
@ -202,15 +203,15 @@ struct XContentMetadata {
uint8_t title_thumbnail[0x3D00]; uint8_t title_thumbnail[0x3D00];
wchar_t description_ex[3][0x80]; wchar_t description_ex[3][0x80];
std::wstring get_display_name(uint32_t locale) { std::wstring get_display_name(XLanguage lang) {
uint32_t locale_id = locale; uint32_t lang_id = (uint32_t)lang;
locale_id--; lang_id--;
wchar_t* str = 0; wchar_t* str = 0;
if (locale_id >= 0 && locale_id < 9) { if (lang_id >= 0 && lang_id < 9) {
str = display_name[locale_id]; str = display_name[lang_id];
} else if (locale_id >= 9 && locale_id < 12 && metadata_version >= 2) { } else if (lang_id >= 9 && lang_id < 12 && metadata_version >= 2) {
str = display_name_ex[locale_id - 9]; str = display_name_ex[lang_id - 9];
} }
if (!str) { if (!str) {
return L""; return L"";
@ -222,15 +223,15 @@ struct XContentMetadata {
return std::wstring(wstr.data()); return std::wstring(wstr.data());
} }
std::wstring get_description(uint32_t locale) { std::wstring get_description(XLanguage lang) {
uint32_t locale_id = locale; uint32_t lang_id = (uint32_t)lang;
locale_id--; lang_id--;
wchar_t* str = 0; wchar_t* str = 0;
if (locale_id >= 0 && locale_id < 9) { if (lang_id >= 0 && lang_id < 9) {
str = display_name[locale_id]; str = display_name[lang_id];
} else if (locale_id >= 9 && locale_id < 12 && metadata_version >= 2) { } else if (lang_id >= 9 && lang_id < 12 && metadata_version >= 2) {
str = display_name_ex[locale_id - 9]; str = display_name_ex[lang_id - 9];
} }
if (!str) { if (!str) {
return L""; return L"";
@ -256,6 +257,53 @@ struct XContentMetadata {
return std::wstring(wstr.data()); return std::wstring(wstr.data());
} }
bool set_display_name(const std::wstring& value, XLanguage lang) {
uint32_t lang_id = (uint32_t)lang;
lang_id--;
wchar_t* str = 0;
if (lang_id >= 0 && lang_id < 9) {
str = display_name[lang_id];
} else if (lang_id >= 9 && lang_id < 12 && metadata_version >= 2) {
str = display_name_ex[lang_id - 9];
}
if (!str) {
return false;
}
xe::copy_and_swap<wchar_t>(str, value.c_str(),
std::min(value.length(), (size_t)128));
return true;
}
bool set_description(const std::wstring& value, XLanguage lang) {
uint32_t lang_id = (uint32_t)lang;
lang_id--;
wchar_t* str = 0;
if (lang_id >= 0 && lang_id < 9) {
str = description[lang_id];
} else if (lang_id >= 9 && lang_id < 12 && metadata_version >= 2) {
str = description_ex[lang_id - 9];
}
if (!str) {
return false;
}
xe::copy_and_swap<wchar_t>(str, value.c_str(),
std::min(value.length(), (size_t)128));
return true;
}
bool set_publisher(const std::wstring& value) {
xe::copy_and_swap<wchar_t>(publisher, value.c_str(),
std::min(value.length(), (size_t)128));
return true;
}
bool set_title_name(const std::wstring& value) {
xe::copy_and_swap<wchar_t>(title_name, value.c_str(),
std::min(value.length(), (size_t)128));
return true;
}
}; };
static_assert_size(XContentMetadata, 0x93D6); static_assert_size(XContentMetadata, 0x93D6);
#pragma pack(pop) #pragma pack(pop)