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.
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;

View File

@ -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;

View File

@ -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_;

View File

@ -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,

View File

@ -15,42 +15,37 @@
#include <xenia/kernel/fs/entry.h>
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_;
private:
std::wstring local_path_;
HANDLE find_file_;
};
} // namespace fs
} // namespace kernel
} // namespace xe
#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);
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.

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 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)

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);
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;
}

View File

@ -10,34 +10,35 @@
#ifndef XENIA_UI_WIN32_WIN32_WINDOW_H_
#define XENIA_UI_WIN32_WIN32_WINDOW_H_
#include <string>
#include <xenia/core.h>
#include <xenia/ui/window.h>
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);
@ -46,10 +47,8 @@ private:
bool closing_;
};
} // namespace win32
} // namespace ui
} // namespace xe
#endif // XENIA_UI_WIN32_WIN32_WINDOW_H_

View File

@ -9,39 +9,33 @@
#include <xenia/ui/window.h>
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;
}
@ -116,5 +110,4 @@ void Window::Close() {
closed(e);
}
void Window::OnClose() {
}
void Window::OnClose() {}

View File

@ -10,27 +10,28 @@
#ifndef XENIA_UI_WINDOW_H_
#define XENIA_UI_WINDOW_H_
#include <string>
#include <xenia/core.h>
#include <alloy/delegate.h>
#include <xenia/ui/ui_event.h>
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<UIEvent> shown;
alloy::Delegate<UIEvent> hidden;
alloy::Delegate<UIEvent> resizing;
@ -56,7 +57,7 @@ public:
alloy::Delegate<MouseEvent> mouse_up;
alloy::Delegate<MouseEvent> mouse_wheel;
protected:
protected:
void OnShow();
void OnHide();
@ -67,9 +68,9 @@ protected:
virtual void OnClose();
private:
private:
xe_run_loop_ref run_loop_;
char* title_;
std::wstring title_;
bool is_visible_;
bool is_cursor_visible_;
bool resizing_;
@ -77,9 +78,7 @@ private:
uint32_t height_;
};
} // namespace ui
} // namespace xe
#endif // XENIA_UI_WINDOW_H_