From e4cef38d95f72221b6437ef02e2db522f8c5720d Mon Sep 17 00:00:00 2001 From: x1nixmzeng Date: Thu, 7 Jan 2016 20:51:28 +0000 Subject: [PATCH] Formatting of changes As per the style guide --- src/xenia/emulator.cc | 43 ++++----- src/xenia/ui/window_win.cc | 27 +++--- src/xenia/xdbf/xdbf_utils.cc | 163 +++++++++++++++++------------------ src/xenia/xdbf/xdbf_utils.h | 157 +++++++++++++++++---------------- 4 files changed, 192 insertions(+), 198 deletions(-) diff --git a/src/xenia/emulator.cc b/src/xenia/emulator.cc index da8bfd71b..a4960c86c 100644 --- a/src/xenia/emulator.cc +++ b/src/xenia/emulator.cc @@ -514,28 +514,29 @@ X_STATUS Emulator::CompleteLaunch(const std::wstring& path, if (!main_xthread) { return X_STATUS_UNSUCCESSFUL; } - - // Try and load the resource database (xex only) - char title[9] = { 0 }; - sprintf(title, "%08X", module->title_id()); - - uint32_t resource_data = 0; - uint32_t resource_size = 0; - if (XSUCCEEDED(module->GetSection(title, &resource_data, &resource_size))) { - auto xdb_ptr = module->memory()->TranslateVirtual(resource_data); - if (xdb_ptr != nullptr) { - xe::xdbf::XdbfWrapper db; - if (db.initialize(xdb_ptr, static_cast(resource_size))) { - std::wstring title(xe::to_wstring(xe::xdbf::get_title(db))); - display_window_->set_title(title); - xe::xdbf::XdbfBlock icon_block = xe::xdbf::get_icon(db); - if (icon_block.buffer != nullptr) { - display_window_->set_icon_from_buffer(icon_block.buffer, icon_block.size); - } - } - } - } + // Try and load the resource database (xex only) + char title[9] = {0}; + sprintf(title, "%08X", module->title_id()); + + uint32_t resource_data = 0; + uint32_t resource_size = 0; + if (XSUCCEEDED(module->GetSection(title, &resource_data, &resource_size))) { + auto xdb_ptr = module->memory()->TranslateVirtual(resource_data); + if (xdb_ptr != nullptr) { + xe::xdbf::XdbfWrapper db; + if (db.initialize(xdb_ptr, static_cast(resource_size))) { + std::wstring title(xe::to_wstring(xe::xdbf::get_title(db))); + display_window_->set_title(title); + + xe::xdbf::XdbfBlock icon_block = xe::xdbf::get_icon(db); + if (icon_block.buffer != nullptr) { + display_window_->set_icon_from_buffer(icon_block.buffer, + icon_block.size); + } + } + } + } main_thread_ = main_xthread->thread(); WaitUntilExit(); diff --git a/src/xenia/ui/window_win.cc b/src/xenia/ui/window_win.cc index f369cedd4..d3ab0720e 100644 --- a/src/xenia/ui/window_win.cc +++ b/src/xenia/ui/window_win.cc @@ -167,22 +167,23 @@ bool Win32Window::set_title(const std::wstring& title) { return true; } -bool Win32Window::set_icon_from_buffer(void *buffer, size_t size) { +bool Win32Window::set_icon_from_buffer(void* buffer, size_t size) { + if (icon_ != nullptr) { + DestroyIcon(icon_); + } - if (icon_ != nullptr) { - DestroyIcon(icon_); - } - - HICON icon = CreateIconFromResourceEx(reinterpret_cast(buffer), static_cast(size), TRUE, 0x00030000, 0, 0, LR_DEFAULTCOLOR); + HICON icon = CreateIconFromResourceEx(reinterpret_cast(buffer), + static_cast(size), TRUE, + 0x00030000, 0, 0, LR_DEFAULTCOLOR); - if (icon != nullptr) { - icon_ = icon; + if (icon != nullptr) { + icon_ = icon; - SendMessage(hwnd_, WM_SETICON, ICON_BIG, reinterpret_cast(icon)); - SendMessage(hwnd_, WM_SETICON, ICON_SMALL, reinterpret_cast(icon)); - } - - return false; + SendMessage(hwnd_, WM_SETICON, ICON_BIG, reinterpret_cast(icon)); + SendMessage(hwnd_, WM_SETICON, ICON_SMALL, reinterpret_cast(icon)); + } + + return false; } bool Win32Window::is_fullscreen() const { return fullscreen_; } diff --git a/src/xenia/xdbf/xdbf_utils.cc b/src/xenia/xdbf/xdbf_utils.cc index ac08b800a..11f09985d 100644 --- a/src/xenia/xdbf/xdbf_utils.cc +++ b/src/xenia/xdbf/xdbf_utils.cc @@ -12,121 +12,114 @@ namespace xe { namespace xdbf { - XdbfWrapper::XdbfWrapper() = default; +XdbfWrapper::XdbfWrapper() = default; - XBDF_HEADER& XdbfWrapper::get_header() const - { - return *state_.header; - } - - XBDF_ENTRY& XdbfWrapper::get_entry(uint32_t n) const - { - return state_.entries[n]; - } +XBDF_HEADER& XdbfWrapper::get_header() const { return *state_.header; } - XBDF_FILE_LOC& XdbfWrapper::get_file(uint32_t n) const - { - return state_.files[n]; - } +XBDF_ENTRY& XdbfWrapper::get_entry(uint32_t n) const { + return state_.entries[n]; +} - bool XdbfWrapper::initialize(uint8_t* buffer, size_t length) - { - if (length <= sizeof(XBDF_HEADER)) { - return false; - } +XBDF_FILE_LOC& XdbfWrapper::get_file(uint32_t n) const { + return state_.files[n]; +} - XdbfState state; +bool XdbfWrapper::initialize(uint8_t* buffer, size_t length) { + if (length <= sizeof(XBDF_HEADER)) { + return false; + } - state.data = buffer; - state.size = length; + XdbfState state; - uint8_t* ptr = state.data; + state.data = buffer; + state.size = length; - state.header = reinterpret_cast(ptr); - ptr += sizeof(XBDF_HEADER); + uint8_t* ptr = state.data; - state.entries = reinterpret_cast(ptr); - ptr += (sizeof(XBDF_ENTRY) * state.header->entry_max); + state.header = reinterpret_cast(ptr); + ptr += sizeof(XBDF_HEADER); - state.files = reinterpret_cast(ptr); - ptr += (sizeof(XBDF_FILE_LOC) * state.header->free_max); + state.entries = reinterpret_cast(ptr); + ptr += (sizeof(XBDF_ENTRY) * state.header->entry_max); - state.offset = ptr; + state.files = reinterpret_cast(ptr); + ptr += (sizeof(XBDF_FILE_LOC) * state.header->free_max); - if (state.header->magic == 'XDBF') { - state_ = state; - return true; - } + state.offset = ptr; - return false; - } + if (state.header->magic == 'XDBF') { + state_ = state; + return true; + } - XdbfBlock XdbfWrapper::get_entry(XdbfSection section, uint64_t id) const { - - XdbfBlock block = { nullptr,0 }; - uint32_t x = 0; + return false; +} - while( x < get_header().entry_current ) { - auto &entry = get_entry(x); +XdbfBlock XdbfWrapper::get_entry(XdbfSection section, uint64_t id) const { + XdbfBlock block = {nullptr, 0}; + uint32_t x = 0; - if (entry.section == section && entry.id == id) { - block.buffer = state_.offset + entry.offset; - block.size = entry.size; - break; - } + while (x < get_header().entry_current) { + auto& entry = get_entry(x); - ++x; - } + if (entry.section == section && entry.id == id) { + block.buffer = state_.offset + entry.offset; + block.size = entry.size; + break; + } - return block; - } + ++x; + } - XdbfBlock get_icon(XdbfWrapper& ref) - { - return ref.get_entry(kSectionImage, 0x8000); - } + return block; +} - std::string get_title(XdbfWrapper& ref) - { - std::string title_str; +XdbfBlock get_icon(XdbfWrapper& ref) { + return ref.get_entry(kSectionImage, 0x8000); +} - XdbfBlock block = ref.get_entry(kSectionMetadata, 0x58535443); - if (block.buffer != nullptr) { - XDBF_XSTC* xstc = reinterpret_cast(block.buffer); +std::string get_title(XdbfWrapper& ref) { + std::string title_str; - assert_true(xstc->magic == 'XSTC'); - uint32_t def_language = xstc->default_language; + XdbfBlock block = ref.get_entry(kSectionMetadata, 0x58535443); + if (block.buffer != nullptr) { + XDBF_XSTC* xstc = reinterpret_cast(block.buffer); - XdbfBlock lang_block = ref.get_entry(kSectionStringTable, static_cast(def_language)); + assert_true(xstc->magic == 'XSTC'); + uint32_t def_language = xstc->default_language; - if (lang_block.buffer != nullptr) { - XDBF_XSTR_HEADER* xstr_head = reinterpret_cast(lang_block.buffer); + XdbfBlock lang_block = + ref.get_entry(kSectionStringTable, static_cast(def_language)); - assert_true(xstr_head->magic == 'XSTR'); - assert_true(xstr_head->version == 1); + if (lang_block.buffer != nullptr) { + XDBF_XSTR_HEADER* xstr_head = + reinterpret_cast(lang_block.buffer); - uint16_t str_count = xstr_head->string_count; - uint8_t *currentAddress = lang_block.buffer + sizeof(XDBF_XSTR_HEADER); + assert_true(xstr_head->magic == 'XSTR'); + assert_true(xstr_head->version == 1); - uint16_t s = 0; - while( s < str_count && title_str.empty() ) { - XDBF_STRINGTABLE_ENTRY* entry = reinterpret_cast(currentAddress); - currentAddress += sizeof(XDBF_STRINGTABLE_ENTRY); - uint16_t len = entry->string_length; + uint16_t str_count = xstr_head->string_count; + uint8_t* currentAddress = lang_block.buffer + sizeof(XDBF_XSTR_HEADER); - if (entry->id == 0x00008000) { - title_str.resize(static_cast(len)); - std::copy(currentAddress, currentAddress + len, title_str.begin()); - } + uint16_t s = 0; + while (s < str_count && title_str.empty()) { + XDBF_STRINGTABLE_ENTRY* entry = + reinterpret_cast(currentAddress); + currentAddress += sizeof(XDBF_STRINGTABLE_ENTRY); + uint16_t len = entry->string_length; - currentAddress += len; - } - } - } + if (entry->id == 0x00008000) { + title_str.resize(static_cast(len)); + std::copy(currentAddress, currentAddress + len, title_str.begin()); + } - return title_str; - } + currentAddress += len; + } + } + } + return title_str; +} } // namespace xdbf } // namespace xe diff --git a/src/xenia/xdbf/xdbf_utils.h b/src/xenia/xdbf/xdbf_utils.h index 8299c420f..4317fff32 100644 --- a/src/xenia/xdbf/xdbf_utils.h +++ b/src/xenia/xdbf/xdbf_utils.h @@ -17,104 +17,103 @@ namespace xe { namespace xdbf { - - // http://freestyledash.googlecode.com/svn/trunk/Freestyle/Tools/XEX/SPA.h - // http://freestyledash.googlecode.com/svn/trunk/Freestyle/Tools/XEX/SPA.cpp - enum XdbfSection : uint16_t { - kSectionMetadata = 0x0001, - kSectionImage = 0x0002, - kSectionStringTable = 0x0003, - }; +// http://freestyledash.googlecode.com/svn/trunk/Freestyle/Tools/XEX/SPA.h +// http://freestyledash.googlecode.com/svn/trunk/Freestyle/Tools/XEX/SPA.cpp - enum XdbfLocale : uint32_t { - kLocaleDefault = 0, - kLocaleEnglish = 1, - kLocaleJapanese = 2, - }; +enum XdbfSection : uint16_t { + kSectionMetadata = 0x0001, + kSectionImage = 0x0002, + kSectionStringTable = 0x0003, +}; - struct XBDF_HEADER { - xe::be magic; - xe::be version; - xe::be entry_max; - xe::be entry_current; - xe::be free_max; - xe::be free_current; - }; - static_assert_size(XBDF_HEADER, 24); +enum XdbfLocale : uint32_t { + kLocaleDefault = 0, + kLocaleEnglish = 1, + kLocaleJapanese = 2, +}; + +struct XBDF_HEADER { + xe::be magic; + xe::be version; + xe::be entry_max; + xe::be entry_current; + xe::be free_max; + xe::be free_current; +}; +static_assert_size(XBDF_HEADER, 24); #pragma pack(push, 1) - struct XBDF_ENTRY { - xe::be section; - xe::be id; - xe::be offset; - xe::be size; - }; - static_assert_size(XBDF_ENTRY, 18); +struct XBDF_ENTRY { + xe::be section; + xe::be id; + xe::be offset; + xe::be size; +}; +static_assert_size(XBDF_ENTRY, 18); #pragma pack(pop) - struct XBDF_FILE_LOC { - xe::be offset; - xe::be size; - }; - static_assert_size(XBDF_FILE_LOC, 8); +struct XBDF_FILE_LOC { + xe::be offset; + xe::be size; +}; +static_assert_size(XBDF_FILE_LOC, 8); - struct XDBF_XSTC { - xe::be magic; - xe::be version; - xe::be size; - xe::be default_language; - }; - static_assert_size(XDBF_XSTC, 16); +struct XDBF_XSTC { + xe::be magic; + xe::be version; + xe::be size; + xe::be default_language; +}; +static_assert_size(XDBF_XSTC, 16); #pragma pack(push, 1) - struct XDBF_XSTR_HEADER { - xe::be magic; - xe::be version; - xe::be size; - xe::be string_count; - }; - static_assert_size(XDBF_XSTR_HEADER, 14); +struct XDBF_XSTR_HEADER { + xe::be magic; + xe::be version; + xe::be size; + xe::be string_count; +}; +static_assert_size(XDBF_XSTR_HEADER, 14); #pragma pack(pop) - struct XDBF_STRINGTABLE_ENTRY { - xe::be id; - xe::be string_length; - }; - static_assert_size(XDBF_STRINGTABLE_ENTRY, 4); +struct XDBF_STRINGTABLE_ENTRY { + xe::be id; + xe::be string_length; +}; +static_assert_size(XDBF_STRINGTABLE_ENTRY, 4); - struct XdbfState { - XBDF_HEADER* header; - XBDF_ENTRY* entries; - XBDF_FILE_LOC* files; - uint8_t* offset; - uint8_t* data; - size_t size; - }; +struct XdbfState { + XBDF_HEADER* header; + XBDF_ENTRY* entries; + XBDF_FILE_LOC* files; + uint8_t* offset; + uint8_t* data; + size_t size; +}; - struct XdbfBlock { - uint8_t* buffer; - size_t size; - }; +struct XdbfBlock { + uint8_t* buffer; + size_t size; +}; - class XdbfWrapper { - public: - XdbfWrapper(); +class XdbfWrapper { + public: + XdbfWrapper(); - bool initialize(uint8_t* buffer, size_t length); - XdbfBlock get_entry(XdbfSection section, uint64_t id) const; + bool initialize(uint8_t* buffer, size_t length); + XdbfBlock get_entry(XdbfSection section, uint64_t id) const; - private: - XBDF_HEADER& get_header() const; - XBDF_ENTRY& get_entry(uint32_t n) const; - XBDF_FILE_LOC& get_file(uint32_t n) const; + private: + XBDF_HEADER& get_header() const; + XBDF_ENTRY& get_entry(uint32_t n) const; + XBDF_FILE_LOC& get_file(uint32_t n) const; - XdbfState state_; - }; - - XdbfBlock get_icon(XdbfWrapper& ref); - std::string get_title(XdbfWrapper& ref); + XdbfState state_; +}; +XdbfBlock get_icon(XdbfWrapper& ref); +std::string get_title(XdbfWrapper& ref); } // namespace xdbf } // namespace xe