diff --git a/Core/CmdLine.cpp b/Core/CmdLine.cpp index be0c12bee5..b8ac9fc6b4 100644 --- a/Core/CmdLine.cpp +++ b/Core/CmdLine.cpp @@ -2,57 +2,69 @@ #include "Core/CmdLine.h" #include "Common/StringUtils.h" +#ifdef HAVE_LIBRETRO_VFS + +// Actually, this probably shouldn't be built at all for libretro! But let's add the guard. + +#define PRINT_STDOUT(...) printf(__VA_ARGS__) +#define PRINT_STDERR(...) printf(__VA_ARGS__) + +#else + +#define PRINT_STDOUT(...) printf(__VA_ARGS__) +#define PRINT_STDERR(...) fprintf(stderr, __VA_ARGS__) + +#endif + static int printUsage(int argc, const char *argv[]) { // NOTE: by convention, --help outputs to stdout, // not to stderr, since it is intended output in this // case (usage printed under different circumstances, // say in response to error during parsing commandline, // may go to stderr). - FILE *dst = stdout; - const char *progname = argc > 0 ? argv[0] : "ppsspp"; // NOTE: wording largely taken from // https://www.ppsspp.org/docs/reference/command-line/ - fprintf(dst, "PPSSPP - a PSP emulator (SDL build)\n"); - fprintf(dst, "Usage: %s [options] [FILE]\n\n", progname); - fprintf(dst, "Launches FILE (e.g. ISO image) if present.\n"); - fprintf(dst, "Options (some of these are specific to SDL backend):\n"); - fprintf(dst, " -h, --help show this message and exit\n"); - fprintf(dst, " --version show version information and exit\n"); + PRINT_STDOUT("PPSSPP - a PSP emulator (SDL build)\n"); + PRINT_STDOUT("Usage: %s [options] [FILE]\n\n", progname); + PRINT_STDOUT("Launches FILE (e.g. ISO image) if present.\n"); + PRINT_STDOUT("Options (some of these are specific to SDL backend):\n"); + PRINT_STDOUT(" -h, --help show this message and exit\n"); + PRINT_STDOUT(" --version show version information and exit\n"); - fprintf(dst, " -d set the log level to debug\n"); - fprintf(dst, " -v set the log level to verbose\n"); - fprintf(dst, " --loglevel=INTEGER set the log level to specified value\n"); - fprintf(dst, " --log=FILE output log to FILE\n"); - fprintf(dst, " --state=FILE load state from FILE\n"); + PRINT_STDOUT(" -d set the log level to debug\n"); + PRINT_STDOUT(" -v set the log level to verbose\n"); + PRINT_STDOUT(" --loglevel=INTEGER set the log level to specified value\n"); + PRINT_STDOUT(" --log=FILE output log to FILE\n"); + PRINT_STDOUT(" --state=FILE load state from FILE\n"); - fprintf(dst, " -i use the interpreter\n"); - fprintf(dst, " -r use IR interpreter\n"); - fprintf(dst, " -j use JIT\n"); - fprintf(dst, " -J use IR JIT\n"); + PRINT_STDOUT(" -i use the interpreter\n"); + PRINT_STDOUT(" -r use IR interpreter\n"); + PRINT_STDOUT(" -j use JIT\n"); + PRINT_STDOUT(" -J use IR JIT\n"); - fprintf(dst, " --fullscreen force full screen mode, ignoring saved configuration\n"); - fprintf(dst, " --windowed force windowed mode, ignoring saved configuration\n"); - fprintf(dst, " --xres PIXELS set X resolution\n"); - fprintf(dst, " --yres PIXELS set Y resolution\n"); - fprintf(dst, " --dpi FACTOR set DPI\n"); - fprintf(dst, " --scale FACTOR set scale\n"); - fprintf(dst, " --ipad set resolution to 1024x768\n"); - fprintf(dst, " --portrait portrait mode\n"); - fprintf(dst, " --graphics=BACKEND use a different gpu backend\n"); - fprintf(dst, " options: gles, software, etc. (also opengl3.1, etc.)\n"); + PRINT_STDOUT(" --fullscreen force full screen mode, ignoring saved configuration\n"); + PRINT_STDOUT(" --windowed force windowed mode, ignoring saved configuration\n"); + PRINT_STDOUT(" --xres PIXELS set X resolution\n"); + PRINT_STDOUT(" --yres PIXELS set Y resolution\n"); + PRINT_STDOUT(" --dpi FACTOR set DPI\n"); + PRINT_STDOUT(" --scale FACTOR set scale\n"); + PRINT_STDOUT(" --ipad set resolution to 1024x768\n"); + PRINT_STDOUT(" --portrait portrait mode\n"); + PRINT_STDOUT(" --graphics=BACKEND use a different gpu backend\n"); + PRINT_STDOUT(" options: gles, software, etc. (also opengl3.1, etc.)\n"); - fprintf(dst, " --pause-menu-exit change \"Exit to menu\" in pause menu to \"Exit\"\n"); - fprintf(dst, " --escape-exit escape key exits the application\n"); - fprintf(dst, " --gamesettings go directly to settings\n"); - fprintf(dst, " --touchscreentest go directly to the touchscreentest screen\n"); - fprintf(dst, " --appendconfig=FILE merge config FILE into the current configuration\n"); + PRINT_STDOUT(" --pause-menu-exit change \"Exit to menu\" in pause menu to \"Exit\"\n"); + PRINT_STDOUT(" --escape-exit escape key exits the application\n"); + PRINT_STDOUT(" --gamesettings go directly to settings\n"); + PRINT_STDOUT(" --touchscreentest go directly to the touchscreentest screen\n"); + PRINT_STDOUT(" --appendconfig=FILE merge config FILE into the current configuration\n"); return 0; } // Logging should be done with plain printf here. -// Error reporting is done with fprintf(stderr, ....). +// Error reporting is done with PRINT_STDERR(....). // Actually might want to reconsider given Android... CommandLineParseResult CommandLineOptions::Parse(int argc, const char *argv[]) { constexpr std::string_view gpuBackendStr = "--graphics="; @@ -74,7 +86,7 @@ CommandLineParseResult CommandLineOptions::Parse(int argc, const char *argv[]) { bootFilename = std::string(argv[i]); } else { // Already have a filename. - fprintf(stderr, "Warning: Ignoring extra boot filename '%s'.\n", argv[i]); + PRINT_STDERR("Warning: Ignoring extra boot filename '%s'.\n", argv[i]); } } diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index 9d2bb84e5c..d99d3d345c 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -859,7 +859,7 @@ int main(int argc, char *argv[]) g_logManager.EnableOutput(LogOutput::Stdio); CommandLineOptions cmdLineOptions; - CommandLineParseResult parseResult = cmdLineOptions.Parse(argc, argv); + CommandLineParseResult parseResult = cmdLineOptions.Parse(argc, (const char **)argv); switch (parseResult) { case CommandLineParseResult::Exit: return 0; diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index fa11359f8a..b7585f5095 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -1390,7 +1390,7 @@ int main(int argc, char *argv[]) { TimeInit(); CommandLineOptions cmdLineOptions; - CommandLineParseResult parseResult = cmdLineOptions.Parse(argc, argv); + CommandLineParseResult parseResult = cmdLineOptions.Parse(argc, (const char **)argv); switch (parseResult) { case CommandLineParseResult::Exit: return 0; diff --git a/UWP/App.cpp b/UWP/App.cpp index f48c5d097e..e1862d7380 100644 --- a/UWP/App.cpp +++ b/UWP/App.cpp @@ -15,6 +15,7 @@ #include "Common/System/NativeApp.h" #include "Common/System/System.h" #include "Common/Log/LogManager.h" +#include "Core/CmdLine.h" #include "Core/System.h" #include "Core/Config.h" #include "Core/Core.h" @@ -86,7 +87,8 @@ void App::InitialPPSSPP() { // Since we don't have any async operation in `NativeInit` // it's better to call it here - const char* argv[2] = { "fake", nullptr }; + int argc = 1; + const char* argv[2] = { "ppsspp", nullptr }; std::string cacheFolder = ConvertWStringToUTF8( std::wstring(winrt::Windows::Storage::ApplicationData::Current().TemporaryFolder().Path()) ); @@ -94,7 +96,10 @@ void App::InitialPPSSPP() { // since launch parameters usually handled by `OnActivated` // and `OnActivated` will be invoked later, even after `PPSSPP_UWPMain(..)` // so we are handling launch cases using `LaunchItem` - NativeInit(1, argv, "", "", cacheFolder.c_str()); + + CommandLineOptions cmdLineOptions; + cmdLineOptions.Parse(argc, argv); + NativeInit(1, argv, cmdLineOptions, "", "", cacheFolder.c_str()); // Override backend, `DIRECT3D11` is the only way for UWP apps g_Config.iGPUBackend = (int)GPUBackend::DIRECT3D11; diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 8b684141ef..02d2bdb4ba 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -30,6 +30,7 @@ #include "Core/System.h" #include "Core/Loaders.h" #include "Core/Config.h" +#include "Core/CmdLine.h" #include "Windows/InputDevice.h" #include "Windows/XinputDevice.h" diff --git a/ios/SceneDelegate.mm b/ios/SceneDelegate.mm index 6bf3f62b5a..4226bb01ed 100644 --- a/ios/SceneDelegate.mm +++ b/ios/SceneDelegate.mm @@ -14,6 +14,7 @@ #import "Common/Log.h" #import "IAPManager.h" #include "Core/Util/PathUtil.h" +#include "Core/CmdLine.h" #import #include @@ -150,7 +151,7 @@ static NSString *ExtractGameInfoScheme(NSURL *url) { } CommandLineOptions cmdLineOptions; - CommandLineParseResult parseResult = cmdLineOptions.Parse(argc, argv); + CommandLineParseResult parseResult = cmdLineOptions.Parse(argc, (const char **)argv); switch (parseResult) { case CommandLineParseResult::Exit: INFO_LOG(Log::System, "Command line parse said to exit - mobile, so ignoring."); @@ -165,7 +166,7 @@ static NSString *ExtractGameInfoScheme(NSURL *url) { NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/assets/"]; - NativeInit(argc, (const char**)argv, documentsPath.UTF8String, bundlePath.UTF8String, NULL); + NativeInit(argc, (const char**)argv, cmdLineOptions, documentsPath.UTF8String, bundlePath.UTF8String, NULL); // If we were cold-started by a library export request, serve it now that // the config (and recent games list) has been loaded by NativeInit.