xenia-canary/src/xenia/xenia_main.cc

95 lines
2.8 KiB
C++
Raw Normal View History

/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <gflags/gflags.h>
#include "xenia/base/logging.h"
#include "xenia/base/main.h"
2015-02-01 06:49:47 +00:00
#include "xenia/emulator.h"
#include "xenia/kernel/kernel.h"
2015-05-02 08:25:59 +00:00
#include "xenia/profiling.h"
#include "xenia/ui/file_picker.h"
2015-02-01 06:49:47 +00:00
#include "xenia/ui/main_window.h"
2013-01-13 08:34:08 +00:00
DEFINE_string(target, "", "Specifies the target .xex or .iso to execute.");
2013-01-13 08:34:08 +00:00
2014-12-21 06:17:57 +00:00
namespace xe {
2014-12-20 00:50:27 +00:00
int xenia_main(std::vector<std::wstring>& args) {
2014-05-28 20:59:43 +00:00
Profiler::Initialize();
2014-05-28 05:54:40 +00:00
Profiler::ThreadEnter("main");
// Create the emulator.
2014-08-17 00:58:33 +00:00
auto emulator = std::make_unique<Emulator>(L"");
X_STATUS result = emulator->Setup();
if (XFAILED(result)) {
XELOGE("Failed to setup emulator: %.8X", result);
2014-08-17 00:58:33 +00:00
return 1;
2013-02-01 13:37:42 +00:00
}
2014-12-21 06:17:57 +00:00
// Grab path from the flag or unnamed argument.
std::wstring path;
if (!FLAGS_target.empty() || args.size() >= 2) {
if (!FLAGS_target.empty()) {
2014-12-21 06:17:57 +00:00
// Passed as a named argument.
// TODO(benvanik): find something better than gflags that supports
// unicode.
path = xe::to_wstring(FLAGS_target);
2014-12-21 06:17:57 +00:00
} else {
// Passed as an unnamed argument.
path = args[1];
}
}
// If no path passed, ask the user.
if (path.empty()) {
ui::PlatformFilePicker file_picker;
file_picker.set_mode(ui::FilePicker::Mode::kOpen);
file_picker.set_type(ui::FilePicker::Type::kFile);
file_picker.set_multi_selection(false);
file_picker.set_title(L"Select Content Package");
file_picker.set_extensions({
{L"Supported Files", L"*.iso;*.xex;*.xcp;*.*"},
{L"Disc Image (*.iso)", L"*.iso"},
{L"Xbox Executable (*.xex)", L"*.xex"},
//{ L"Content Package (*.xcp)", L"*.xcp" },
{L"All Files (*.*)", L"*.*"},
});
if (file_picker.Show(emulator->main_window()->hwnd())) {
auto selected_files = file_picker.selected_files();
if (!selected_files.empty()) {
path = selected_files[0];
}
}
}
if (!path.empty()) {
2014-12-21 06:17:57 +00:00
// Normalize the path and make absolute.
std::wstring abs_path = xe::to_absolute_path(path);
2014-12-21 06:17:57 +00:00
result = emulator->main_window()->LaunchPath(abs_path);
if (XFAILED(result)) {
XELOGE("Failed to launch target: %.8X", result);
return 1;
}
2013-01-13 08:34:08 +00:00
// Wait until we are exited.
emulator->main_window()->loop()->AwaitQuit();
}
2014-12-21 06:17:57 +00:00
2014-08-17 00:58:33 +00:00
emulator.reset();
2014-05-28 05:54:40 +00:00
Profiler::Dump();
Profiler::Shutdown();
2014-08-17 00:58:33 +00:00
return 0;
}
2014-12-21 06:17:57 +00:00
} // namespace xe
DEFINE_ENTRY_POINT(L"xenia", L"xenia some.xex", xe::xenia_main);