More string conversion.

This commit is contained in:
Ben Vanik 2014-08-16 02:50:08 -07:00
parent a4dfc23abc
commit 66d2336e38
11 changed files with 94 additions and 121 deletions

View File

@ -113,7 +113,7 @@ void D3D11GraphicsSystem::Initialize() {
// will take place. // will take place.
assert_null(window_); assert_null(window_);
window_ = new D3D11Window(run_loop_, dxgi_factory_, device_); 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"); XELOGE("Failed to create D3D11Window");
exit(1); exit(1);
return; return;

View File

@ -49,7 +49,8 @@ D3D11Window::~D3D11Window() {
XESAFERELEASE(dxgi_factory_); 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); int result = Win32Window::Initialize(title, width, height);
if (result) { if (result) {
return result; return result;

View File

@ -27,18 +27,19 @@ public:
D3D11Window( D3D11Window(
xe_run_loop_ref run_loop, xe_run_loop_ref run_loop,
IDXGIFactory1* dxgi_factory, ID3D11Device* device); IDXGIFactory1* dxgi_factory, ID3D11Device* device);
virtual ~D3D11Window(); ~D3D11Window() override;
ID3D11Device* device() const { return device_; } ID3D11Device* device() const { return device_; }
IDXGISwapChain* swap_chain() const { return swap_chain_; } IDXGISwapChain* swap_chain() const { return swap_chain_; }
ID3D11DeviceContext* context() const { return context_; } 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(); void Swap();
protected: protected:
virtual bool OnResize(uint32_t width, uint32_t height); bool OnResize(uint32_t width, uint32_t height) override;
private: private:
IDXGIFactory1* dxgi_factory_; IDXGIFactory1* dxgi_factory_;

View File

@ -36,19 +36,16 @@ private:
} }
HostPathEntry::HostPathEntry(Type type, Device* device, const char* path, HostPathEntry::HostPathEntry(Type type, Device* device, const char* path,
const xechar_t* local_path) : const std::wstring& local_path)
Entry(type, device, path), : Entry(type, device, path),
find_file_(INVALID_HANDLE_VALUE) { local_path_(local_path),
local_path_ = xestrdup(local_path); find_file_(INVALID_HANDLE_VALUE) {}
}
HostPathEntry::~HostPathEntry() { HostPathEntry::~HostPathEntry() {
if (find_file_ != INVALID_HANDLE_VALUE) { if (find_file_ != INVALID_HANDLE_VALUE) {
FindClose(find_file_); FindClose(find_file_);
} }
xe_free(local_path_);
} }
#define COMBINE_TIME(t) (((uint64_t)t.dwHighDateTime << 32) | t.dwLowDateTime) #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; WIN32_FILE_ATTRIBUTE_DATA data;
if (!GetFileAttributesEx( if (!GetFileAttributesEx(
local_path_, GetFileExInfoStandard, &data)) { local_path_.c_str(), GetFileExInfoStandard, &data)) {
return X_STATUS_ACCESS_DENIED; return X_STATUS_ACCESS_DENIED;
} }
@ -87,16 +84,13 @@ X_STATUS HostPathEntry::QueryDirectory(
} }
if (handle == INVALID_HANDLE_VALUE) { if (handle == INVALID_HANDLE_VALUE) {
xechar_t target_path[poly::max_path]; std::wstring target_path = local_path_;
xestrcpy(target_path, poly::max_path, local_path_); if (!file_name) {
if (file_name == NULL) { target_path += L"*";
xestrcat(target_path, poly::max_path, L"*"); } else {
target_path += poly::to_wstring(file_name);
} }
else { handle = find_file_ = FindFirstFile(target_path.c_str(), &ffd);
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);
if (handle == INVALID_HANDLE_VALUE) { if (handle == INVALID_HANDLE_VALUE) {
if (GetLastError() == ERROR_FILE_NOT_FOUND) { if (GetLastError() == ERROR_FILE_NOT_FOUND) {
return X_STATUS_NO_MORE_FILES; return X_STATUS_NO_MORE_FILES;
@ -140,9 +134,11 @@ X_STATUS HostPathEntry::QueryDirectory(
return X_STATUS_SUCCESS; return X_STATUS_SUCCESS;
} }
MemoryMapping* HostPathEntry::CreateMemoryMapping( MemoryMapping* HostPathEntry::CreateMemoryMapping(xe_file_mode file_mode,
xe_file_mode file_mode, const size_t offset, const size_t length) { const size_t offset,
xe_mmap_ref mmap = xe_mmap_open(file_mode, local_path_, offset, length); const size_t length) {
xe_mmap_ref mmap =
xe_mmap_open(file_mode, local_path_.c_str(), offset, length);
if (!mmap) { if (!mmap) {
return NULL; return NULL;
} }
@ -163,7 +159,7 @@ X_STATUS HostPathEntry::Open(
DWORD creation_disposition = OPEN_EXISTING; DWORD creation_disposition = OPEN_EXISTING;
DWORD flags_and_attributes = async ? FILE_FLAG_OVERLAPPED : 0; DWORD flags_and_attributes = async ? FILE_FLAG_OVERLAPPED : 0;
HANDLE file = CreateFile( HANDLE file = CreateFile(
local_path_, local_path_.c_str(),
desired_access, desired_access,
share_mode, share_mode,
NULL, NULL,

View File

@ -15,42 +15,37 @@
#include <xenia/kernel/fs/entry.h> #include <xenia/kernel/fs/entry.h>
namespace xe { namespace xe {
namespace kernel { namespace kernel {
namespace fs { namespace fs {
class HostPathEntry : public Entry { class HostPathEntry : public Entry {
public: public:
HostPathEntry(Type type, Device* device, const char* path, HostPathEntry(Type type, Device* device, const char* path,
const xechar_t* local_path); const std::wstring& local_path);
virtual ~HostPathEntry(); 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 QueryInfo(XFileInfo* out_info);
virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info, virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info, size_t length,
size_t length, const char* file_name, bool restart); const char* file_name, bool restart);
virtual bool can_map() { return true; } virtual bool can_map() { return true; }
virtual MemoryMapping* CreateMemoryMapping( virtual MemoryMapping* CreateMemoryMapping(xe_file_mode file_mode,
xe_file_mode file_mode, const size_t offset, const size_t length); const size_t offset,
const size_t length);
virtual X_STATUS Open( virtual X_STATUS Open(KernelState* kernel_state, uint32_t desired_access,
KernelState* kernel_state, bool async, XFile** out_file);
uint32_t desired_access, bool async,
XFile** out_file);
private: private:
xechar_t* local_path_; std::wstring local_path_;
HANDLE find_file_; HANDLE find_file_;
}; };
} // namespace fs } // namespace fs
} // namespace kernel } // namespace kernel
} // namespace xe } // namespace xe
#endif // XENIA_KERNEL_FS_DEVICES_HOST_PATH_ENTRY_H_ #endif // XENIA_KERNEL_FS_DEVICES_HOST_PATH_ENTRY_H_

View File

@ -72,9 +72,8 @@ SHIM_CALL NtCreateFile_shim(
assert_true(root_file->type() == XObject::Type::kTypeFile); assert_true(root_file->type() == XObject::Type::kTypeFile);
auto root_path = root_file->absolute_path(); 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); entry = fs->ResolvePath(target_path);
xe_free(target_path);
} }
else { else {
// Resolve the file using the virtual file system. // Resolve the file using the virtual file system.

View File

@ -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 strcpy_s(dest, destLength, source) !(strcpy(dest, source) == dest + (destLength*0))
#define strcat_s(dest, destLength, source) !(strcat(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 _snprintf_s(dest, destLength, x, format, ...) snprintf(dest, destLength, format, ##__VA_ARGS__)
#define xestrdupa strdup
#else
#define xestrdupa _strdup
#endif // !WIN32 #endif // !WIN32
#define xestrlenw wcslen #define xestrlenw wcslen
#define xestrdupw _wcsdup
#define xestrchrw wcschr #define xestrchrw wcschr
#define xestrrchrw wcsrchr
#define xestrcpyw(dest, destLength, source) (wcscpy_s(dest, destLength, source) == 0) #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 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 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 xestrlena strlen
#define xestrchra strchr #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; typedef wchar_t xechar_t;
#define XE_WCHAR 1 #define XE_WCHAR 1
#define xestrlen xestrlenw // xestrchr 2 uses in fs
#define xestrdup xestrdupw // xestrrchra xmodule/logging
#define xestrchr xestrchrw // xestrcpy fs + module
#define xestrrchr xestrrchrw // xestrncpya one use in xbox.h
// xestrcat 2 uses in platform
// xesnprintf many uses - only remove some?
// xevsnprintf logging, disasm
#define xestrcpy xestrcpyw #define xestrcpy xestrcpyw
#define xestrncpy xestrncpyw
#define xestrcat xestrcatw #define xestrcat xestrcatw
#define xesnprintf xesnprintfw #define xesnprintf xesnprintfw
#define xevsnprintf xevsnprintfw
#define xestrnarrow(dest, destLength, source) (wcstombs_s(NULL, dest, destLength, source, _TRUNCATE) == 0) #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) #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; typedef char xechar_t;
#define XE_CHAR 1 #define XE_CHAR 1
#define xestrlen xestrlena
#define xestrdup xestrdupa
#define xestrchr xestrchra
#define xestrrchr xestrrchra
#define xestrcpy xestrcpya #define xestrcpy xestrcpya
#define xestrncpy xestrncpya
#define xestrcat xestrcata #define xestrcat xestrcata
#define xesnprintf xesnprintfa #define xesnprintf xesnprintfa
#define xevsnprintf xevsnprintfa
#define xestrnarrow(dest, destLength, source) xestrcpy(dest, destLength, source) #define xestrnarrow(dest, destLength, source) xestrcpy(dest, destLength, source)
#define xestrwiden(dest, destLength, source) xestrcpy(dest, destLength, source) #define xestrwiden(dest, destLength, source) xestrcpy(dest, destLength, source)

View File

@ -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); int result = Window::Initialize(title, width, height);
if (result) { if (result) {
return result; return result;
@ -164,11 +165,11 @@ void Win32Window::EnableMMCSS() {
FreeLibrary(hLibrary); FreeLibrary(hLibrary);
} }
bool Win32Window::set_title(const char* title) { bool Win32Window::set_title(const std::wstring& title) {
if (!Window::set_title(title)) { if (!Window::set_title(title)) {
return false; return false;
} }
XEIGNORE(SetWindowTextA(handle_, title)); XEIGNORE(SetWindowText(handle_, title.c_str()));
return true; return true;
} }

View File

@ -10,32 +10,33 @@
#ifndef XENIA_UI_WIN32_WIN32_WINDOW_H_ #ifndef XENIA_UI_WIN32_WIN32_WINDOW_H_
#define XENIA_UI_WIN32_WIN32_WINDOW_H_ #define XENIA_UI_WIN32_WIN32_WINDOW_H_
#include <string>
#include <xenia/core.h> #include <xenia/core.h>
#include <xenia/ui/window.h> #include <xenia/ui/window.h>
namespace xe { namespace xe {
namespace ui { namespace ui {
namespace win32 { namespace win32 {
class Win32Window : public Window { class Win32Window : public Window {
public: public:
Win32Window(xe_run_loop_ref run_loop); 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); bool set_title(const std::wstring& title) override;
virtual bool set_cursor_visible(bool value); bool set_cursor_visible(bool value) override;
HWND handle() const { return handle_; } HWND handle() const { return handle_; }
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
protected: protected:
virtual bool SetSize(uint32_t width, uint32_t height); bool SetSize(uint32_t width, uint32_t height) override;
virtual void OnClose(); void OnClose() override;
private: private:
void EnableMMCSS(); void EnableMMCSS();
@ -46,10 +47,8 @@ private:
bool closing_; bool closing_;
}; };
} // namespace win32 } // namespace win32
} // namespace ui } // namespace ui
} // namespace xe } // namespace xe
#endif // XENIA_UI_WIN32_WIN32_WINDOW_H_ #endif // XENIA_UI_WIN32_WIN32_WINDOW_H_

View File

@ -9,39 +9,33 @@
#include <xenia/ui/window.h> #include <xenia/ui/window.h>
using namespace xe; using namespace xe;
using namespace xe::ui; using namespace xe::ui;
Window::Window(xe_run_loop_ref run_loop)
Window::Window(xe_run_loop_ref run_loop) : : title_(L"Window"),
title_(0), is_visible_(true), is_cursor_visible_(true), is_visible_(true),
width_(0), height_(0) { is_cursor_visible_(true),
width_(0),
height_(0) {
run_loop_ = xe_run_loop_retain(run_loop); run_loop_ = xe_run_loop_retain(run_loop);
} }
Window::~Window() { Window::~Window() { xe_run_loop_release(run_loop_); }
if (title_) {
xe_free(title_);
}
xe_run_loop_release(run_loop_);
}
int Window::Initialize(const char* title, uint32_t width, uint32_t height) { int Window::Initialize(const std::wstring& title, uint32_t width,
title_ = xestrdupa(title); uint32_t height) {
title_ = title;
width_ = width; width_ = width;
height_ = height; height_ = height;
return 0; return 0;
} }
bool Window::set_title(const char* title) { bool Window::set_title(const std::wstring& title) {
if (title == title_) { if (title == title_) {
return false; return false;
} }
if (title_) { title_ = title;
xe_free(title_);
}
title_ = xestrdupa(title);
return true; return true;
} }
@ -116,5 +110,4 @@ void Window::Close() {
closed(e); closed(e);
} }
void Window::OnClose() { void Window::OnClose() {}
}

View File

@ -10,27 +10,28 @@
#ifndef XENIA_UI_WINDOW_H_ #ifndef XENIA_UI_WINDOW_H_
#define XENIA_UI_WINDOW_H_ #define XENIA_UI_WINDOW_H_
#include <string>
#include <xenia/core.h> #include <xenia/core.h>
#include <alloy/delegate.h> #include <alloy/delegate.h>
#include <xenia/ui/ui_event.h> #include <xenia/ui/ui_event.h>
namespace xe { namespace xe {
namespace ui { namespace ui {
class Window { class Window {
public: public:
Window(xe_run_loop_ref run_loop); Window(xe_run_loop_ref run_loop);
virtual ~Window(); 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_; } xe_run_loop_ref run_loop() const { return run_loop_; }
const char* title() const { return title_; } const std::wstring& title() const { return title_; }
virtual bool set_title(const char* title); virtual bool set_title(const std::wstring& title);
bool is_visible() const { return is_visible_; } bool is_visible() const { return is_visible_; }
bool is_cursor_visible() const { return is_cursor_visible_; } bool is_cursor_visible() const { return is_cursor_visible_; }
virtual bool set_cursor_visible(bool value); virtual bool set_cursor_visible(bool value);
@ -69,7 +70,7 @@ protected:
private: private:
xe_run_loop_ref run_loop_; xe_run_loop_ref run_loop_;
char* title_; std::wstring title_;
bool is_visible_; bool is_visible_;
bool is_cursor_visible_; bool is_cursor_visible_;
bool resizing_; bool resizing_;
@ -77,9 +78,7 @@ private:
uint32_t height_; uint32_t height_;
}; };
} // namespace ui } // namespace ui
} // namespace xe } // namespace xe
#endif // XENIA_UI_WINDOW_H_ #endif // XENIA_UI_WINDOW_H_