From d5b380170fb52a59a4fa36f4ddb6b5c5e6f5442b Mon Sep 17 00:00:00 2001 From: Dmitry Logashenko Date: Fri, 25 Sep 2020 20:42:48 +0300 Subject: [PATCH] Command line arguments to set paths. --- ugbase/bridge/misc_bridges/util_bridge.cpp | 11 +++- ugbase/ug.cpp | 63 ++++++++++++++++++++++ ugbase/ug.h | 13 +++++ ugbase/ug_shell/ugshell_main.cpp | 20 ++++++- 4 files changed, 104 insertions(+), 3 deletions(-) diff --git a/ugbase/bridge/misc_bridges/util_bridge.cpp b/ugbase/bridge/misc_bridges/util_bridge.cpp index 28d3b2eb9..074f4641f 100644 --- a/ugbase/bridge/misc_bridges/util_bridge.cpp +++ b/ugbase/bridge/misc_bridges/util_bridge.cpp @@ -133,9 +133,18 @@ void RegisterBridge_Util(Registry& reg, string parentGroup) reg.add_function("ug_get_current_path", &GetCurrentPath, grp, "pathName", "", "Returns the current path"); - reg.add_function("ug_set_root_path", &SetRootPath, grp, + reg.add_function("ug_set_root_path", static_cast(&SetRootPath), grp, "", "pathName", "Sets the paths relative to passed root path"); + reg.add_function("ug_set_script_path", static_cast(&SetScriptPath), grp, + "", "pathName", "Sets the script path"); + + reg.add_function("ug_set_apps_path", static_cast(&SetAppsPath), grp, + "", "pathName", "Sets the script path"); + + reg.add_function("ug_set_plugin_path", static_cast(&SetPluginPath), grp, + "", "pathName", "Sets the plugin path"); + reg.add_function("ExecuteSystemCommand", &ExecuteSystemCommand, grp, "success", "command", "Executes a command in the system shell"); diff --git a/ugbase/ug.cpp b/ugbase/ug.cpp index f60f4c88e..25fa3709d 100644 --- a/ugbase/ug.cpp +++ b/ugbase/ug.cpp @@ -152,6 +152,69 @@ void SetRootPath(const std::string& strRoot) PathProvider::set_path(APPS_PATH, strRoot + pathSep + "apps"); } +/** + * init app, script and data paths for a given root path + */ +void SetRootPath(const char* c_strRoot) +{ + std::string strRoot(c_strRoot); + SetRootPath(strRoot); +} + +/** + * init script path + */ +void SetScriptPath(const std::string& strScript) +{ + PROFILE_FUNC(); + PathProvider::set_path(SCRIPT_PATH, strScript); +} + +/** + * init script path + */ +void SetScriptPath(const char* c_strScript) +{ + std::string strScript(c_strScript); + SetScriptPath(strScript); +} + +/** + * init apps path + */ +void SetAppsPath(const std::string& strApps) +{ + PROFILE_FUNC(); + PathProvider::set_path(APPS_PATH, strApps); +} + +/** + * init apps path + */ +void SetAppsPath(const char* c_strApps) +{ + std::string strApps(c_strApps); + SetAppsPath(strApps); +} + +/** + * init plugin path + */ +void SetPluginPath(const std::string& strPlugin) +{ + PROFILE_FUNC(); + PathProvider::set_path(PLUGIN_PATH, strPlugin); +} + +/** + * init plugin path + */ +void SetPluginPath(const char* c_strPlugin) +{ + std::string strPlugin(c_strPlugin); + SetPluginPath(strPlugin); +} + //////////////////////////////////////////////////////////////////////// /// initializes ug /** This method should be called at the beginning of main(...). diff --git a/ugbase/ug.h b/ugbase/ug.h index 62766cb9e..c7262c801 100644 --- a/ugbase/ug.h +++ b/ugbase/ug.h @@ -86,6 +86,19 @@ UG_API bool InitPaths(const char* argv0); * - PLUGIN_PATH */ UG_API void SetRootPath(const std::string& strRoot); +UG_API void SetRootPath(const char* c_strRoot); + +/// Initializes the SCRIPT_PATH of ug::PathProvider. +UG_API void SetScriptPath(const std::string& strScript); +UG_API void SetScriptPath(const char* c_strScript); + +/// Initializes the APPS_PATH of ug::PathProvider. +UG_API void SetAppsPath(const std::string& strApps); +UG_API void SetAppsPath(const char* c_strApps); + +/// Initializes the PLUGIN_PATH of ug::PathProvider. +UG_API void SetPluginPath(const std::string& strPlugin); +UG_API void SetPluginPath(const char* c_strPlugin); /// finalizes ug /** If ug has been compiled for parallel use (UG_PARALLEL is defined) diff --git a/ugbase/ug_shell/ugshell_main.cpp b/ugbase/ug_shell/ugshell_main.cpp index f282fcb2b..e7bc02488 100644 --- a/ugbase/ug_shell/ugshell_main.cpp +++ b/ugbase/ug_shell/ugshell_main.cpp @@ -361,12 +361,28 @@ int ugshell_main(int argc, char* argv[]) if(FindParam("-profile", argc, argv)) UGOutputProfileStatsOnExit(true); - const bool quiet = FindParam("-quiet", argc, argv); + const bool quiet = FindParam("-quiet", argc, argv); - const bool help = FindParam("-help", argc, argv); + const bool help = FindParam("-help", argc, argv); const bool interactiveShellRequested = FindParam("-noquit", argc, argv); bool defaultInteractiveShell = true; // may be changed later + + const char* rootPath = NULL; + if(ParamToString(&rootPath, "-rootpath", argc, argv)) + SetRootPath(rootPath); + + const char* scriptPath = NULL; + if(ParamToString(&scriptPath, "-scriptpath", argc, argv)) + SetScriptPath(scriptPath); + + const char* appsPath = NULL; + if(ParamToString(&appsPath, "-appspath", argc, argv)) + SetAppsPath(appsPath); + + const char* pluginPath = NULL; + if(ParamToString(&pluginPath, "-pluginpath", argc, argv)) + SetPluginPath(pluginPath); #ifdef UG_PARALLEL const bool parallelEnvironment = (pcl::NumProcs() > 1);