From 210199db1ce4760b57e6d7f297a5514042f43617 Mon Sep 17 00:00:00 2001 From: joevt Date: Thu, 2 May 2024 01:06:02 -0700 Subject: [PATCH] main: Add a working directory option. This is an alternative method for specifying the working directory. Normally, the user would change the directory before executing dingusppc to set the working directory. The working directory is the default location for files and sockets used by dingusppc (the bootrom file, symbols file, nvram, pram, serial port sockets, logs, etc.) --- main.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/main.cpp b/main.cpp index c64983c..b1cbe9e 100644 --- a/main.cpp +++ b/main.cpp @@ -39,6 +39,11 @@ along with this program. If not, see . #include #include #include +#ifdef _WIN32 +#include +#else +#include +#endif using namespace std; @@ -64,6 +69,21 @@ static string appDescription = string( "\n" ); +/// Check for an existing directory (returns error message if check fails) +class WorkingDirectoryValidator : public CLI::detail::ExistingDirectoryValidator { + public: + WorkingDirectoryValidator() { + func_ = [](std::string &filename) { + std::string result = CLI::ExistingDirectory.operator()(filename); + if (result.empty()) + _chdir(filename.c_str()); + return result; + }; + } +}; + +const WorkingDirectoryValidator WorkingDirectory; + void run_machine(std::string machine_str, std::string bootrom_path, uint32_t execution_mode, uint32_t profiling_interval_ms); int main(int argc, char** argv) { @@ -77,11 +97,14 @@ int main(int argc, char** argv) { bool realtime_enabled = false; bool debugger_enabled = false; string bootrom_path("bootrom.bin"); + string working_directory_path("."); app.add_flag("-r,--realtime", realtime_enabled, "Run the emulator in real-time"); app.add_flag("-d,--debugger", debugger_enabled, "Enter the built-in debugger"); + app.add_option("-w,--workingdir", working_directory_path, "Specifies working directory") + ->check(WorkingDirectory); app.add_option("-b,--bootrom", bootrom_path, "Specifies BootROM path") ->check(CLI::ExistingFile); app.add_flag("--deterministic", is_deterministic,