Add cmdline support

This commit is contained in:
Nekotekina 2017-10-12 17:58:06 +03:00
parent dbb2251f93
commit 00a0d37455
2 changed files with 34 additions and 7 deletions

View file

@ -528,21 +528,26 @@ void Emulator::Load(bool add_only)
vm::ps3::init(); vm::ps3::init();
if (argv.empty()) if (argv.empty())
{
argv.resize(1);
}
if (argv[0].empty())
{ {
if (m_path.find(hdd0_game) != -1) if (m_path.find(hdd0_game) != -1)
{ {
argv.emplace_back("/dev_hdd0/game/" + m_path.substr(hdd0_game.size())); argv[0] = "/dev_hdd0/game/" + m_path.substr(hdd0_game.size());
} }
else if (!bdvd_dir.empty() && fs::is_dir(bdvd_dir)) else if (!bdvd_dir.empty() && fs::is_dir(bdvd_dir))
{ {
// Disc games are on /dev_bdvd/ // Disc games are on /dev_bdvd/
const std::size_t pos = m_path.rfind("PS3_GAME"); const std::size_t pos = m_path.rfind("PS3_GAME");
argv.emplace_back("/dev_bdvd/" + m_path.substr(pos)); argv[0] = "/dev_bdvd/" + m_path.substr(pos);
} }
else else
{ {
// For homebrew // For homebrew
argv.emplace_back("/host_root/" + m_path); argv[0] = "/host_root/" + m_path;
} }
LOG_NOTICE(LOADER, "Elf path: %s", argv[0]); LOG_NOTICE(LOADER, "Elf path: %s", argv[0]);
@ -581,7 +586,12 @@ void Emulator::Load(bool add_only)
if (argv.empty()) if (argv.empty())
{ {
argv.emplace_back("host_root:" + m_path); argv.resize(1);
}
if (argv[0].empty())
{
argv[0] = "host_root:" + m_path;
LOG_NOTICE(LOADER, "Elf path: %s", argv[0]); LOG_NOTICE(LOADER, "Elf path: %s", argv[0]);
} }

View file

@ -47,16 +47,33 @@ int main(int argc, char** argv)
QCommandLineParser parser; QCommandLineParser parser;
parser.setApplicationDescription("Welcome to RPCS3 command line."); parser.setApplicationDescription("Welcome to RPCS3 command line.");
parser.addPositionalArgument("(S)ELF", "Path for directly executing a (S)ELF"); parser.addPositionalArgument("(S)ELF", "Path for directly executing a (S)ELF");
parser.addPositionalArgument("[Args...]", "Optional args for the executable");
parser.addHelpOption(); parser.addHelpOption();
parser.process(app); parser.process(app);
app.Init(); app.Init();
if (parser.positionalArguments().length() > 0) QStringList args = parser.positionalArguments();
if (args.length() > 0)
{ {
// Ugly workaround // Propagate command line arguments
QTimer::singleShot(2, [path = sstr(QFileInfo(parser.positionalArguments().at(0)).canonicalFilePath())] std::vector<std::string> argv;
if (args.length() > 1)
{ {
argv.emplace_back();
for (std::size_t i = 1; i < args.length(); i++)
{
argv.emplace_back(args[i].toStdString());
}
}
// Ugly workaround
QTimer::singleShot(2, [path = sstr(QFileInfo(args.at(0)).canonicalFilePath()), argv = std::move(argv)]() mutable
{
Emu.argv = std::move(argv);
Emu.BootGame(path, true); Emu.BootGame(path, true);
Emu.Run(); Emu.Run();
}); });