C++17ification.

C++17ification!

- Filesystem interaction now uses std::filesystem::path.
- Usage of const char*, std::string have been changed to
  std::string_view where appropriate.
- Usage of printf-style functions changed to use fmt.
This commit is contained in:
gibbed
2020-03-02 09:37:11 -06:00
committed by Rick Gibbed
parent 114cea6fb7
commit 5bf0b34445
220 changed files with 4944 additions and 4294 deletions

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -29,12 +29,13 @@ DECLARE_XAM_EXPORT2(XamIsUIActive, kUI, kImplemented, kHighFrequency);
class MessageBoxDialog : public xe::ui::ImGuiDialog {
public:
MessageBoxDialog(xe::ui::Window* window, std::wstring title,
std::wstring description, std::vector<std::wstring> buttons,
uint32_t default_button, uint32_t* out_chosen_button)
MessageBoxDialog(xe::ui::Window* window, std::u16string title,
std::u16string description,
std::vector<std::u16string> buttons, uint32_t default_button,
uint32_t* out_chosen_button)
: ImGuiDialog(window),
title_(xe::to_string(title)),
description_(xe::to_string(description)),
title_(xe::to_utf8(title)),
description_(xe::to_utf8(description)),
buttons_(std::move(buttons)),
default_button_(default_button),
out_chosen_button_(out_chosen_button) {
@@ -62,7 +63,7 @@ class MessageBoxDialog : public xe::ui::ImGuiDialog {
ImGui::SetKeyboardFocusHere();
}
for (size_t i = 0; i < buttons_.size(); ++i) {
auto button_name = xe::to_string(buttons_[i]);
auto button_name = xe::to_utf8(buttons_[i]);
if (ImGui::Button(button_name.c_str())) {
if (out_chosen_button_) {
*out_chosen_button_ = static_cast<uint32_t>(i);
@@ -84,34 +85,34 @@ class MessageBoxDialog : public xe::ui::ImGuiDialog {
bool has_opened_ = false;
std::string title_;
std::string description_;
std::vector<std::wstring> buttons_;
std::vector<std::u16string> buttons_;
uint32_t default_button_ = 0;
uint32_t* out_chosen_button_ = nullptr;
};
// https://www.se7ensins.com/forums/threads/working-xshowmessageboxui.844116/
dword_result_t XamShowMessageBoxUI(dword_t user_index, lpwstring_t title_ptr,
lpwstring_t text_ptr, dword_t button_count,
dword_result_t XamShowMessageBoxUI(dword_t user_index, lpu16string_t title_ptr,
lpu16string_t text_ptr, dword_t button_count,
lpdword_t button_ptrs, dword_t active_button,
dword_t flags, lpdword_t result_ptr,
pointer_t<XAM_OVERLAPPED> overlapped) {
std::wstring title;
std::u16string title;
if (title_ptr) {
title = title_ptr.value();
} else {
title = L""; // TODO(gibbed): default title based on flags?
title = u""; // TODO(gibbed): default title based on flags?
}
auto text = text_ptr.value();
std::vector<std::wstring> buttons;
std::wstring all_buttons;
std::vector<std::u16string> buttons;
std::u16string all_buttons;
for (uint32_t j = 0; j < button_count; ++j) {
uint32_t button_ptr = button_ptrs[j];
auto button = xe::load_and_swap<std::wstring>(
auto button = xe::load_and_swap<std::u16string>(
kernel_state()->memory()->TranslateVirtual(button_ptr));
all_buttons.append(button);
if (j + 1 < button_count) {
all_buttons.append(L" | ");
all_buttons.append(u" | ");
}
buttons.push_back(button);
}
@@ -166,13 +167,13 @@ DECLARE_XAM_EXPORT1(XamShowMessageBoxUI, kUI, kImplemented);
class KeyboardInputDialog : public xe::ui::ImGuiDialog {
public:
KeyboardInputDialog(xe::ui::Window* window, std::wstring title,
std::wstring description, std::wstring default_text,
std::wstring* out_text, size_t max_length)
KeyboardInputDialog(xe::ui::Window* window, std::u16string title,
std::u16string description, std::u16string default_text,
std::u16string* out_text, size_t max_length)
: ImGuiDialog(window),
title_(xe::to_string(title)),
description_(xe::to_string(description)),
default_text_(xe::to_string(default_text)),
title_(xe::to_utf8(title)),
description_(xe::to_utf8(description)),
default_text_(xe::to_utf8(default_text)),
out_text_(out_text),
max_length_(max_length) {
if (!title_.size()) {
@@ -209,14 +210,16 @@ class KeyboardInputDialog : public xe::ui::ImGuiDialog {
if (ImGui::InputText("##body", text_buffer_.data(), text_buffer_.size(),
ImGuiInputTextFlags_EnterReturnsTrue)) {
if (out_text_) {
*out_text_ = xe::to_wstring(text_buffer_.data());
*out_text_ = xe::to_utf16(
std::string_view(text_buffer_.data(), text_buffer_.size()));
}
ImGui::CloseCurrentPopup();
Close();
}
if (ImGui::Button("OK")) {
if (out_text_) {
*out_text_ = xe::to_wstring(text_buffer_.data());
*out_text_ = xe::to_utf16(
std::string_view(text_buffer_.data(), text_buffer_.size()));
}
ImGui::CloseCurrentPopup();
Close();
@@ -238,16 +241,16 @@ class KeyboardInputDialog : public xe::ui::ImGuiDialog {
std::string title_;
std::string description_;
std::string default_text_;
std::wstring* out_text_ = nullptr;
std::u16string* out_text_ = nullptr;
std::vector<char> text_buffer_;
size_t max_length_ = 0;
};
// https://www.se7ensins.com/forums/threads/release-how-to-use-xshowkeyboardui-release.906568/
dword_result_t XamShowKeyboardUI(dword_t user_index, dword_t flags,
lpwstring_t default_text, lpwstring_t title,
lpwstring_t description, lpwstring_t buffer,
dword_t buffer_length,
lpu16string_t default_text,
lpu16string_t title, lpu16string_t description,
lpu16string_t buffer, dword_t buffer_length,
pointer_t<XAM_OVERLAPPED> overlapped) {
if (!buffer) {
return X_ERROR_INVALID_PARAMETER;
@@ -260,7 +263,7 @@ dword_result_t XamShowKeyboardUI(dword_t user_index, dword_t flags,
// Redirect default_text back into the buffer.
std::memset(buffer, 0, buffer_length * 2);
if (default_text) {
xe::store_and_swap<std::wstring>(buffer, default_text.value());
xe::store_and_swap<std::u16string>(buffer, default_text.value());
}
// Broadcast XN_SYS_UI = false
@@ -274,14 +277,14 @@ dword_result_t XamShowKeyboardUI(dword_t user_index, dword_t flags,
}
}
std::wstring out_text;
std::u16string out_text;
auto display_window = kernel_state()->emulator()->display_window();
xe::threading::Fence fence;
display_window->loop()->PostSynchronous([&]() {
(new KeyboardInputDialog(display_window, title ? title.value() : L"",
description ? description.value() : L"",
default_text ? default_text.value() : L"",
(new KeyboardInputDialog(display_window, title ? title.value() : u"",
description ? description.value() : u"",
default_text ? default_text.value() : u"",
&out_text, buffer_length))
->Then(&fence);
});
@@ -294,7 +297,7 @@ dword_result_t XamShowKeyboardUI(dword_t user_index, dword_t flags,
// Truncate the string.
out_text = out_text.substr(0, buffer_length - 1);
xe::store_and_swap<std::wstring>(buffer, out_text);
xe::store_and_swap<std::u16string>(buffer, out_text);
// Broadcast XN_SYS_UI = false
kernel_state()->BroadcastNotification(0x9, false);