Jelajahi Sumber

Fail gracefully when file pointed by --start path doesn't exist.

Michał W. Urbańczyk 13 tahun lalu
induk
melakukan
79f8e0ea3c
1 mengubah file dengan 13 tambahan dan 3 penghapusan
  1. 13 3
      client/CMT.cpp

+ 13 - 3
client/CMT.cpp

@@ -296,11 +296,21 @@ int main(int argc, char** argv)
 		session["autoSkip"].Bool()  = vm.count("autoSkip");
 		session["oneGoodAI"].Bool() = vm.count("oneGoodAI");
 
+		std::string fileToStartFrom; //none by default
+		if(vm.count("start"))
+			fileToStartFrom = vm["start"].as<std::string>();
 
-		if(!vm.count("start"))
-			GH.curInt = CGPreGame::create(); //will set CGP pointer to itself
+		if(fileToStartFrom.size() && boost::filesystem::exists(fileToStartFrom))
+			startGameFromFile(fileToStartFrom); //ommit pregame and start the game using settings from fiel
 		else
-			startGameFromFile(vm["start"].as<std::string>());
+		{
+			if(fileToStartFrom.size())
+			{
+				tlog3 << "Warning: cannot find given file to start from (" << fileToStartFrom
+					<< "). Falling back to main menu.\n";
+			}
+			GH.curInt = CGPreGame::create(); //will set CGP pointer to itself
+		}
 	}
 	else
 	{