diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_system.cc b/src/xenia/gpu/d3d11/d3d11_graphics_system.cc index 11d113ca4..e6fb9454f 100644 --- a/src/xenia/gpu/d3d11/d3d11_graphics_system.cc +++ b/src/xenia/gpu/d3d11/d3d11_graphics_system.cc @@ -113,7 +113,7 @@ void D3D11GraphicsSystem::Initialize() { // will take place. assert_null(window_); window_ = new D3D11Window(run_loop_, dxgi_factory_, device_); - if (window_->Initialize("Xenia D3D11", 1280, 720)) { + if (window_->Initialize(L"Xenia D3D11", 1280, 720)) { XELOGE("Failed to create D3D11Window"); exit(1); return; diff --git a/src/xenia/gpu/d3d11/d3d11_window.cc b/src/xenia/gpu/d3d11/d3d11_window.cc index da33ab6bb..7b4fa5cbd 100644 --- a/src/xenia/gpu/d3d11/d3d11_window.cc +++ b/src/xenia/gpu/d3d11/d3d11_window.cc @@ -49,7 +49,8 @@ D3D11Window::~D3D11Window() { XESAFERELEASE(dxgi_factory_); } -int D3D11Window::Initialize(const char* title, uint32_t width, uint32_t height) { +int D3D11Window::Initialize(const std::wstring& title, uint32_t width, + uint32_t height) { int result = Win32Window::Initialize(title, width, height); if (result) { return result; diff --git a/src/xenia/gpu/d3d11/d3d11_window.h b/src/xenia/gpu/d3d11/d3d11_window.h index df470df0f..888a797ae 100644 --- a/src/xenia/gpu/d3d11/d3d11_window.h +++ b/src/xenia/gpu/d3d11/d3d11_window.h @@ -27,18 +27,19 @@ public: D3D11Window( xe_run_loop_ref run_loop, IDXGIFactory1* dxgi_factory, ID3D11Device* device); - virtual ~D3D11Window(); + ~D3D11Window() override; ID3D11Device* device() const { return device_; } IDXGISwapChain* swap_chain() const { return swap_chain_; } ID3D11DeviceContext* context() const { return context_; } - virtual int Initialize(const char* title, uint32_t width, uint32_t height); + int Initialize(const std::wstring& title, uint32_t width, + uint32_t height) override; void Swap(); protected: - virtual bool OnResize(uint32_t width, uint32_t height); + bool OnResize(uint32_t width, uint32_t height) override; private: IDXGIFactory1* dxgi_factory_; diff --git a/src/xenia/kernel/fs/devices/host_path_entry.cc b/src/xenia/kernel/fs/devices/host_path_entry.cc index f37f30008..86084a9d1 100644 --- a/src/xenia/kernel/fs/devices/host_path_entry.cc +++ b/src/xenia/kernel/fs/devices/host_path_entry.cc @@ -36,19 +36,16 @@ private: } - HostPathEntry::HostPathEntry(Type type, Device* device, const char* path, - const xechar_t* local_path) : - Entry(type, device, path), - find_file_(INVALID_HANDLE_VALUE) { - local_path_ = xestrdup(local_path); -} + const std::wstring& local_path) + : Entry(type, device, path), + local_path_(local_path), + find_file_(INVALID_HANDLE_VALUE) {} HostPathEntry::~HostPathEntry() { if (find_file_ != INVALID_HANDLE_VALUE) { FindClose(find_file_); } - xe_free(local_path_); } #define COMBINE_TIME(t) (((uint64_t)t.dwHighDateTime << 32) | t.dwLowDateTime) @@ -58,7 +55,7 @@ X_STATUS HostPathEntry::QueryInfo(XFileInfo* out_info) { WIN32_FILE_ATTRIBUTE_DATA data; if (!GetFileAttributesEx( - local_path_, GetFileExInfoStandard, &data)) { + local_path_.c_str(), GetFileExInfoStandard, &data)) { return X_STATUS_ACCESS_DENIED; } @@ -87,16 +84,13 @@ X_STATUS HostPathEntry::QueryDirectory( } if (handle == INVALID_HANDLE_VALUE) { - xechar_t target_path[poly::max_path]; - xestrcpy(target_path, poly::max_path, local_path_); - if (file_name == NULL) { - xestrcat(target_path, poly::max_path, L"*"); + std::wstring target_path = local_path_; + if (!file_name) { + target_path += L"*"; + } else { + target_path += poly::to_wstring(file_name); } - else { - auto target_length = xestrlen(local_path_); - xestrwiden(target_path + target_length, XECOUNT(target_path) - target_length, file_name); - } - handle = find_file_ = FindFirstFile(target_path, &ffd); + handle = find_file_ = FindFirstFile(target_path.c_str(), &ffd); if (handle == INVALID_HANDLE_VALUE) { if (GetLastError() == ERROR_FILE_NOT_FOUND) { return X_STATUS_NO_MORE_FILES; @@ -140,9 +134,11 @@ X_STATUS HostPathEntry::QueryDirectory( return X_STATUS_SUCCESS; } -MemoryMapping* HostPathEntry::CreateMemoryMapping( - xe_file_mode file_mode, const size_t offset, const size_t length) { - xe_mmap_ref mmap = xe_mmap_open(file_mode, local_path_, offset, length); +MemoryMapping* HostPathEntry::CreateMemoryMapping(xe_file_mode file_mode, + const size_t offset, + const size_t length) { + xe_mmap_ref mmap = + xe_mmap_open(file_mode, local_path_.c_str(), offset, length); if (!mmap) { return NULL; } @@ -163,7 +159,7 @@ X_STATUS HostPathEntry::Open( DWORD creation_disposition = OPEN_EXISTING; DWORD flags_and_attributes = async ? FILE_FLAG_OVERLAPPED : 0; HANDLE file = CreateFile( - local_path_, + local_path_.c_str(), desired_access, share_mode, NULL, diff --git a/src/xenia/kernel/fs/devices/host_path_entry.h b/src/xenia/kernel/fs/devices/host_path_entry.h index 3406033b0..c13b7eb34 100644 --- a/src/xenia/kernel/fs/devices/host_path_entry.h +++ b/src/xenia/kernel/fs/devices/host_path_entry.h @@ -15,42 +15,37 @@ #include - namespace xe { namespace kernel { namespace fs { - class HostPathEntry : public Entry { -public: + public: HostPathEntry(Type type, Device* device, const char* path, - const xechar_t* local_path); + const std::wstring& local_path); virtual ~HostPathEntry(); - const xechar_t* local_path() { return local_path_; } + const std::wstring& local_path() { return local_path_; } virtual X_STATUS QueryInfo(XFileInfo* out_info); - virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info, - size_t length, const char* file_name, bool restart); + virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info, size_t length, + const char* file_name, bool restart); virtual bool can_map() { return true; } - virtual MemoryMapping* CreateMemoryMapping( - xe_file_mode file_mode, const size_t offset, const size_t length); + virtual MemoryMapping* CreateMemoryMapping(xe_file_mode file_mode, + const size_t offset, + const size_t length); - virtual X_STATUS Open( - KernelState* kernel_state, - uint32_t desired_access, bool async, - XFile** out_file); + virtual X_STATUS Open(KernelState* kernel_state, uint32_t desired_access, + bool async, XFile** out_file); -private: - xechar_t* local_path_; - HANDLE find_file_; + private: + std::wstring local_path_; + HANDLE find_file_; }; - } // namespace fs } // namespace kernel } // namespace xe - #endif // XENIA_KERNEL_FS_DEVICES_HOST_PATH_ENTRY_H_ diff --git a/src/xenia/kernel/xboxkrnl_io.cc b/src/xenia/kernel/xboxkrnl_io.cc index 6cd9c0fb3..804e3c98d 100644 --- a/src/xenia/kernel/xboxkrnl_io.cc +++ b/src/xenia/kernel/xboxkrnl_io.cc @@ -72,9 +72,8 @@ SHIM_CALL NtCreateFile_shim( assert_true(root_file->type() == XObject::Type::kTypeFile); auto root_path = root_file->absolute_path(); - auto target_path = xestrdupa((std::string(root_path) + std::string(object_name)).c_str()); + auto target_path = root_path + object_name; entry = fs->ResolvePath(target_path); - xe_free(target_path); } else { // Resolve the file using the virtual file system. diff --git a/src/xenia/string.h b/src/xenia/string.h index f2f9b51cc..0f6b9be2c 100644 --- a/src/xenia/string.h +++ b/src/xenia/string.h @@ -21,20 +21,13 @@ int strncpy_s(char* dest, size_t destLength, const char* source, size_t count); #define strcpy_s(dest, destLength, source) !(strcpy(dest, source) == dest + (destLength*0)) #define strcat_s(dest, destLength, source) !(strcat(dest, source) == dest + (destLength*0)) #define _snprintf_s(dest, destLength, x, format, ...) snprintf(dest, destLength, format, ##__VA_ARGS__) -#define xestrdupa strdup -#else -#define xestrdupa _strdup #endif // !WIN32 #define xestrlenw wcslen -#define xestrdupw _wcsdup #define xestrchrw wcschr -#define xestrrchrw wcsrchr #define xestrcpyw(dest, destLength, source) (wcscpy_s(dest, destLength, source) == 0) -#define xestrncpyw(dest, destLength, source, count) (wcsncpy_s(dest, destLength, source, count) == 0) #define xestrcatw(dest, destLength, source) (wcscat_s(dest, destLength, source) == 0) #define xesnprintfw(buffer, bufferCount, format, ...) _snwprintf_s(buffer, bufferCount, (bufferCount) ? (bufferCount - 1) : 0, format, ##__VA_ARGS__) -#define xevsnprintfw(buffer, bufferCount, format, args) _vsnwprintf_s(buffer, bufferCount, (bufferCount) ? (bufferCount - 1) : 0, format, args) #define xestrlena strlen #define xestrchra strchr @@ -50,15 +43,17 @@ int strncpy_s(char* dest, size_t destLength, const char* source, size_t count); typedef wchar_t xechar_t; #define XE_WCHAR 1 -#define xestrlen xestrlenw -#define xestrdup xestrdupw -#define xestrchr xestrchrw -#define xestrrchr xestrrchrw +// xestrchr 2 uses in fs +// xestrrchra xmodule/logging +// xestrcpy fs + module +// xestrncpya one use in xbox.h +// xestrcat 2 uses in platform +// xesnprintf many uses - only remove some? +// xevsnprintf logging, disasm + #define xestrcpy xestrcpyw -#define xestrncpy xestrncpyw #define xestrcat xestrcatw #define xesnprintf xesnprintfw -#define xevsnprintf xevsnprintfw #define xestrnarrow(dest, destLength, source) (wcstombs_s(NULL, dest, destLength, source, _TRUNCATE) == 0) #define xestrwiden(dest, destLength, source) (mbstowcs_s(NULL, dest, destLength, source, _TRUNCATE) == 0) @@ -67,15 +62,9 @@ typedef wchar_t xechar_t; typedef char xechar_t; #define XE_CHAR 1 -#define xestrlen xestrlena -#define xestrdup xestrdupa -#define xestrchr xestrchra -#define xestrrchr xestrrchra #define xestrcpy xestrcpya -#define xestrncpy xestrncpya #define xestrcat xestrcata #define xesnprintf xesnprintfa -#define xevsnprintf xevsnprintfa #define xestrnarrow(dest, destLength, source) xestrcpy(dest, destLength, source) #define xestrwiden(dest, destLength, source) xestrcpy(dest, destLength, source) diff --git a/src/xenia/ui/win32/win32_window.cc b/src/xenia/ui/win32/win32_window.cc index 5e4b12738..78f87bbf4 100644 --- a/src/xenia/ui/win32/win32_window.cc +++ b/src/xenia/ui/win32/win32_window.cc @@ -53,7 +53,8 @@ Win32Window::~Win32Window() { } } -int Win32Window::Initialize(const char* title, uint32_t width, uint32_t height) { +int Win32Window::Initialize(const std::wstring& title, uint32_t width, + uint32_t height) { int result = Window::Initialize(title, width, height); if (result) { return result; @@ -164,11 +165,11 @@ void Win32Window::EnableMMCSS() { FreeLibrary(hLibrary); } -bool Win32Window::set_title(const char* title) { +bool Win32Window::set_title(const std::wstring& title) { if (!Window::set_title(title)) { return false; } - XEIGNORE(SetWindowTextA(handle_, title)); + XEIGNORE(SetWindowText(handle_, title.c_str())); return true; } diff --git a/src/xenia/ui/win32/win32_window.h b/src/xenia/ui/win32/win32_window.h index 20be6dafe..600907574 100644 --- a/src/xenia/ui/win32/win32_window.h +++ b/src/xenia/ui/win32/win32_window.h @@ -10,46 +10,45 @@ #ifndef XENIA_UI_WIN32_WIN32_WINDOW_H_ #define XENIA_UI_WIN32_WIN32_WINDOW_H_ +#include + #include #include - namespace xe { namespace ui { namespace win32 { - class Win32Window : public Window { -public: + public: Win32Window(xe_run_loop_ref run_loop); - virtual ~Win32Window(); + ~Win32Window() override; - virtual int Initialize(const char* title, uint32_t width, uint32_t height); + int Initialize(const std::wstring& title, uint32_t width, + uint32_t height) override; - virtual bool set_title(const char* title); - virtual bool set_cursor_visible(bool value); + bool set_title(const std::wstring& title) override; + bool set_cursor_visible(bool value) override; HWND handle() const { return handle_; } LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); -protected: - virtual bool SetSize(uint32_t width, uint32_t height); - virtual void OnClose(); + protected: + bool SetSize(uint32_t width, uint32_t height) override; + void OnClose() override; -private: + private: void EnableMMCSS(); bool HandleMouse(UINT message, WPARAM wParam, LPARAM lParam); bool HandleKeyboard(UINT message, WPARAM wParam, LPARAM lParam); - HWND handle_; - bool closing_; + HWND handle_; + bool closing_; }; - } // namespace win32 } // namespace ui } // namespace xe - #endif // XENIA_UI_WIN32_WIN32_WINDOW_H_ diff --git a/src/xenia/ui/window.cc b/src/xenia/ui/window.cc index 0a37b1f1c..91a43dde0 100644 --- a/src/xenia/ui/window.cc +++ b/src/xenia/ui/window.cc @@ -9,39 +9,33 @@ #include - using namespace xe; using namespace xe::ui; - -Window::Window(xe_run_loop_ref run_loop) : - title_(0), is_visible_(true), is_cursor_visible_(true), - width_(0), height_(0) { +Window::Window(xe_run_loop_ref run_loop) + : title_(L"Window"), + is_visible_(true), + is_cursor_visible_(true), + width_(0), + height_(0) { run_loop_ = xe_run_loop_retain(run_loop); } -Window::~Window() { - if (title_) { - xe_free(title_); - } - xe_run_loop_release(run_loop_); -} +Window::~Window() { xe_run_loop_release(run_loop_); } -int Window::Initialize(const char* title, uint32_t width, uint32_t height) { - title_ = xestrdupa(title); +int Window::Initialize(const std::wstring& title, uint32_t width, + uint32_t height) { + title_ = title; width_ = width; height_ = height; return 0; } -bool Window::set_title(const char* title) { +bool Window::set_title(const std::wstring& title) { if (title == title_) { return false; } - if (title_) { - xe_free(title_); - } - title_ = xestrdupa(title); + title_ = title; return true; } @@ -74,7 +68,7 @@ void Window::OnHide() { void Window::Resize(uint32_t width, uint32_t height) { BeginResizing(); SetSize(width, height); - OnResize(width, height); // redundant? + OnResize(width, height); // redundant? EndResizing(); } @@ -116,5 +110,4 @@ void Window::Close() { closed(e); } -void Window::OnClose() { -} +void Window::OnClose() {} diff --git a/src/xenia/ui/window.h b/src/xenia/ui/window.h index cdc7b2c39..551458ba1 100644 --- a/src/xenia/ui/window.h +++ b/src/xenia/ui/window.h @@ -10,27 +10,28 @@ #ifndef XENIA_UI_WINDOW_H_ #define XENIA_UI_WINDOW_H_ +#include + #include #include #include - namespace xe { namespace ui { - class Window { -public: + public: Window(xe_run_loop_ref run_loop); virtual ~Window(); - virtual int Initialize(const char* title, uint32_t width, uint32_t height); + virtual int Initialize(const std::wstring& title, uint32_t width, + uint32_t height); xe_run_loop_ref run_loop() const { return run_loop_; } - const char* title() const { return title_; } - virtual bool set_title(const char* title); + const std::wstring& title() const { return title_; } + virtual bool set_title(const std::wstring& title); bool is_visible() const { return is_visible_; } bool is_cursor_visible() const { return is_cursor_visible_; } virtual bool set_cursor_visible(bool value); @@ -40,7 +41,7 @@ public: void Close(); -public: + public: alloy::Delegate shown; alloy::Delegate hidden; alloy::Delegate resizing; @@ -56,7 +57,7 @@ public: alloy::Delegate mouse_up; alloy::Delegate mouse_wheel; -protected: + protected: void OnShow(); void OnHide(); @@ -67,19 +68,17 @@ protected: virtual void OnClose(); -private: + private: xe_run_loop_ref run_loop_; - char* title_; - bool is_visible_; - bool is_cursor_visible_; - bool resizing_; - uint32_t width_; - uint32_t height_; + std::wstring title_; + bool is_visible_; + bool is_cursor_visible_; + bool resizing_; + uint32_t width_; + uint32_t height_; }; - } // namespace ui } // namespace xe - #endif // XENIA_UI_WINDOW_H_