Browse Source

If Urho3DPlayer command line is empty, attempt to read Data/CommandLine.txt on all platforms. Closes #615.

Lasse Öörni 11 years ago
parent
commit
6e5d0db379
2 changed files with 14 additions and 11 deletions
  1. 1 1
      Docs/GettingStarted.dox
  2. 13 10
      Source/Tools/Urho3DPlayer/Urho3DPlayer.cpp

+ 1 - 1
Docs/GettingStarted.dox

@@ -252,7 +252,7 @@ The scripting language supported by default is AngelScript (http://www.angelcode
 
 Lua language support can optionally be built in, see \ref Build_Options.
 
-On Android and iOS the command line can not be entered, so it is instead read from the file bin/Data/CommandLine.txt. By default the NinjaSnowWar example will be run.
+If Urho3DPlayer is given no command line arguments at all, it will read the command line from the file bin/Data/CommandLine.txt. This is primarily intended for mobile platforms, where the command line can not be entered. By default the NinjaSnowWar example will be run.
 
 \section Running_Commandline Command line options
 

+ 13 - 10
Source/Tools/Urho3DPlayer/Urho3DPlayer.cpp

@@ -54,16 +54,19 @@ void Urho3DPlayer::Setup()
 {
     FileSystem* filesystem = GetSubsystem<FileSystem>();
 
-    // On Android and iOS, read command line from a file as parameters can not otherwise be easily given
-    #if defined(ANDROID) || defined(IOS)
-    SharedPtr<File> commandFile(new File(context_, filesystem->GetProgramDir() + "Data/CommandLine.txt",
-        FILE_READ));
-    String commandLine = commandFile->ReadLine();
-    commandFile->Close();
-    ParseArguments(commandLine, false);
-    // Reparse engine startup parameters now
-    engineParameters_ = Engine::ParseParameters(GetArguments());
-    #endif
+    // Read command line from a file if no arguments given. This is primarily intended for mobile platforms.
+    // Note that the command file name uses a hardcoded path that does not utilize the resource system
+    // properly (including resource path prefix), as the resource system is not yet initialized at this point
+    const String commandFileName = filesystem->GetProgramDir() + "Data/CommandLine.txt";
+    if (GetArguments().Empty() && filesystem->FileExists(commandFileName))
+    {
+        SharedPtr<File> commandFile(new File(context_, commandFileName));
+        String commandLine = commandFile->ReadLine();
+        commandFile->Close();
+        ParseArguments(commandLine, false);
+        // Reparse engine startup parameters now
+        engineParameters_ = Engine::ParseParameters(GetArguments());
+    }
 
     // Check for script file name
     const Vector<String>& arguments = GetArguments();