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:
@@ -2,30 +2,31 @@
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "xenia/base/main.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
// Autogenerated by `xb premake`.
|
||||
#include "build/version.h"
|
||||
|
||||
#include "xenia/base/cvar.h"
|
||||
#include "xenia/base/filesystem.h"
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/main.h"
|
||||
#include "xenia/base/platform_win.h"
|
||||
#include "xenia/base/string.h"
|
||||
|
||||
#include "third_party/xbyak/xbyak/xbyak_util.h"
|
||||
// Autogenerated by `xb premake`.
|
||||
#include "build/version.h"
|
||||
|
||||
#include <bcrypt.h>
|
||||
#include "xenia/base/cvar.h"
|
||||
// For RequestHighPerformance.
|
||||
#include <winternl.h>
|
||||
|
||||
// Includes Windows headers, so it goes here.
|
||||
#include "third_party/xbyak/xbyak/xbyak_util.h"
|
||||
|
||||
DEFINE_bool(win32_high_freq, true,
|
||||
"Requests high performance from the NT kernel", "Kernel");
|
||||
@@ -71,9 +72,9 @@ static void RequestHighPerformance() {
|
||||
OUT PULONG CurrentResolution);
|
||||
|
||||
NtQueryTimerResolution = (decltype(NtQueryTimerResolution))GetProcAddress(
|
||||
GetModuleHandle(L"ntdll.dll"), "NtQueryTimerResolution");
|
||||
GetModuleHandleW(L"ntdll.dll"), "NtQueryTimerResolution");
|
||||
NtSetTimerResolution = (decltype(NtSetTimerResolution))GetProcAddress(
|
||||
GetModuleHandle(L"ntdll.dll"), "NtSetTimerResolution");
|
||||
GetModuleHandleW(L"ntdll.dll"), "NtSetTimerResolution");
|
||||
if (!NtQueryTimerResolution || !NtSetTimerResolution) {
|
||||
return;
|
||||
}
|
||||
@@ -85,37 +86,44 @@ static void RequestHighPerformance() {
|
||||
#endif
|
||||
}
|
||||
|
||||
int Main() {
|
||||
auto entry_info = xe::GetEntryInfo();
|
||||
|
||||
// Convert command line to an argv-like format so we can share code/use
|
||||
static bool parse_launch_arguments(const xe::EntryInfo& entry_info,
|
||||
std::vector<std::string>& args) {
|
||||
auto command_line = GetCommandLineW();
|
||||
int argc;
|
||||
wchar_t** argv = CommandLineToArgvW(command_line, &argc);
|
||||
if (!argv) {
|
||||
return 1;
|
||||
|
||||
int wargc;
|
||||
wchar_t** wargv = CommandLineToArgvW(command_line, &wargc);
|
||||
if (!wargv) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert all args to narrow, as cxxopts doesn't support wchar.
|
||||
int argca = argc;
|
||||
char** argva = reinterpret_cast<char**>(alloca(sizeof(char*) * argca));
|
||||
for (int n = 0; n < argca; n++) {
|
||||
size_t len = std::wcstombs(nullptr, argv[n], 0);
|
||||
argva[n] = reinterpret_cast<char*>(alloca(sizeof(char) * (len + 1)));
|
||||
std::wcstombs(argva[n], argv[n], len + 1);
|
||||
int argc = wargc;
|
||||
char** argv = reinterpret_cast<char**>(alloca(sizeof(char*) * argc));
|
||||
for (int n = 0; n < argc; n++) {
|
||||
size_t len = std::wcstombs(nullptr, wargv[n], 0);
|
||||
argv[n] = reinterpret_cast<char*>(alloca(sizeof(char) * (len + 1)));
|
||||
std::wcstombs(argv[n], wargv[n], len + 1);
|
||||
}
|
||||
|
||||
cvar::ParseLaunchArguments(argca, argva, entry_info.positional_usage,
|
||||
LocalFree(wargv);
|
||||
|
||||
cvar::ParseLaunchArguments(argc, argv, entry_info.positional_usage,
|
||||
entry_info.positional_options);
|
||||
|
||||
// Widen all remaining flags and convert to usable strings.
|
||||
std::vector<std::wstring> args;
|
||||
args.clear();
|
||||
for (int n = 0; n < argc; n++) {
|
||||
size_t len = std::mbstowcs(nullptr, argva[n], 0);
|
||||
auto argvw =
|
||||
reinterpret_cast<wchar_t*>(alloca(sizeof(wchar_t) * (len + 1)));
|
||||
std::mbstowcs(argvw, argva[n], len + 1);
|
||||
args.push_back(std::wstring(argvw));
|
||||
args.push_back(std::string(argv[n]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int Main() {
|
||||
auto entry_info = xe::GetEntryInfo();
|
||||
|
||||
std::vector<std::string> args;
|
||||
if (!parse_launch_arguments(entry_info, args)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Setup COM on the main thread.
|
||||
@@ -147,7 +155,6 @@ int Main() {
|
||||
int result = entry_info.entry_point(args);
|
||||
|
||||
xe::ShutdownLogging();
|
||||
LocalFree(argv);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user