summaryrefslogtreecommitdiff
path: root/Runtime/Utilities/Argv.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-14 22:50:43 +0800
committerchai <chaifix@163.com>2019-08-14 22:50:43 +0800
commit15740faf9fe9fe4be08965098bbf2947e096aeeb (patch)
treea730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Utilities/Argv.cpp
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/Utilities/Argv.cpp')
-rw-r--r--Runtime/Utilities/Argv.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/Runtime/Utilities/Argv.cpp b/Runtime/Utilities/Argv.cpp
new file mode 100644
index 0000000..b05da23
--- /dev/null
+++ b/Runtime/Utilities/Argv.cpp
@@ -0,0 +1,129 @@
+#include "UnityPrefix.h"
+#include "Argv.h"
+#if UNITY_WIN
+#include "PlatformDependent/Win/WinUtils.h"
+#endif
+
+using namespace std;
+
+static int argc;
+static const char** argv;
+static vector<string> relaunchArguments;
+
+struct KnownArguments
+{
+ bool isBatchmode;
+ bool isAutomated;
+};
+
+static KnownArguments knownArgs;
+
+void SetupArgv (int a, const char** b)
+{
+ argc = a;
+ argv = b;
+ knownArgs.isBatchmode = HasARGV ("batchmode");
+ knownArgs.isAutomated = HasARGV ("automated");
+}
+
+bool HasARGV (const string& name)
+{
+ for (int i=0;i<argc;i++)
+ {
+ if (StrICmp (argv[i], "-" + name) == 0)
+ return true;
+ }
+ return false;
+}
+
+bool IsBatchmode ()
+{
+ return knownArgs.isBatchmode;
+}
+
+bool IsHumanControllingUs ()
+{
+ return !(knownArgs.isBatchmode || knownArgs.isAutomated);
+}
+
+void SetIsBatchmode (bool value)
+{
+ knownArgs.isBatchmode = true;
+}
+
+void PrintARGV ()
+{
+ for (int i=0;i<argc;i++)
+ {
+ printf_console ("%s\n", argv[i]);
+ }
+}
+
+vector<string> GetValuesForARGV (const string& name)
+{
+ vector<string> values;
+ values.reserve (argc);
+
+ bool found = false;
+ for (int i=0;i<argc;i++)
+ {
+ if (found)
+ {
+ if (argv[i][0] == '-')
+ return values;
+ else
+ values.push_back (argv[i]);
+ }
+ else if (StrICmp (argv[i], "-" + name) == 0)
+ found = true;
+ }
+
+ return values;
+}
+
+string GetFirstValueForARGV (const string& name)
+{
+ vector<string> values = GetValuesForARGV (name);
+ if (values.empty ())
+ return string ();
+ else
+ return values[0];
+}
+
+vector<string> GetAllArguments()
+{
+ vector<string> values;
+ values.reserve (argc);
+ for (int i=1;i<argc;i++)
+ values.push_back (argv[i]);
+ return values;
+}
+
+void SetRelaunchApplicationArguments (const vector<string>& args)
+{
+ relaunchArguments = args;
+}
+
+vector<string> GetRelaunchApplicationArguments ()
+{
+ return relaunchArguments;
+}
+
+void CheckBatchModeErrorString (const string& error)
+{
+ if (error.empty ())
+ return;
+
+ ErrorString(error);
+
+ if (!IsBatchmode())
+ return;
+
+#if UNITY_WIN && UNITY_EDITOR
+ winutils::RedirectStdoutToConsole();
+#elif UNITY_OSX
+ ResetStdout();
+#endif
+ printf_console ("\nAborting batchmode due to failure:\n%s\n\n", error.c_str());
+ exit(1);
+}